OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
tconv.c
Go to the documentation of this file.
1 /*
2  *----------------------------------------------------------------------
3  * @(#) tconv.c 1.0 20 Oct 93 <shc>
4  * Copyright (c) 1993, CSIRO Division of Oceanography
5  *----------------------------------------------------------------------
6  *
7  * tconv --
8  *
9  * Time conversions between UT, UT1 and TDT, which is required for
10  * calculation of solar/lunar positions and precession/nutation
11  * conversions. Rigorously, Barycentric Dynamical Time (TDB) should be
12  * used, but it differs from TDT by at most 2msec.
13  *
14  * The difference between UTC and TDT can be specified accurately using
15  * the initialisation routine TCSET. If no difference is specified, a
16  * polynomial approximation is used, but any resulting errors in
17  * miscalculation of solar/lunar/precession/nutation effects are
18  * probably in the noise. The approximation is derived from a cubic fit
19  * to the UT/TDT difference from 1950 to 1992 plus some speculative
20  * points for 1993, 2000 and 2010. A cubic, rather than a higher order
21  * polynomial, is used so the divergence isn't too wild past 2010.
22  *
23  * Results:
24  * Given a time in modified Julian days and a conversion code string
25  * of the form "<in_type>:<out_type>", return the appropriate time.
26  * On error, ERRSTR is set to point to an error message and FP_ERRVAL
27  * is returned.
28  *
29  * Side effects:
30  * None.
31  *
32  * References:
33  * "Astronomical Algorithms", Jean Meeus, Willmann-Bell Inc, 1991.
34  *
35  * History:
36  * 1.0 20 Oct 93 <shc>
37  * Converted from FORTRAN to C.
38  *
39  * 1.0 12 Dec 94 <shc>
40  * Added errmsg stuff for integration with Python
41  *
42  *----------------------------------------------------------------------
43  */
44 
45 #include <stdio.h>
46 #include <string.h>
47 #include "orbit.h"
48 
49 
50 /* User specified corrections (if any) */
51 static double dtmutc = 0, /* TDT-UTC */
52  ut1mtc = 0; /* UT1-UTC */
53 
54 double
55 tconv(tjd, conv, errmsg)
56 double tjd;
57 char *conv;
58 char **errmsg;
59 {
60  double c, u, tdt;
61 
62  if (strlen(conv) != 7 || conv[3] != ':') {
63  if (errmsg)
64  *errmsg = "conversion spec should be <inp_type>:<out_type>";
65  return FP_ERRVAL;
66  }
67 
68  /* Get or calculate a rough value for TDT-UTC in days */
69  if (dtmutc != 0)
70  u = dtmutc;
71  else {
72  c = (tjd - J2000) / 36525.0;
73  u = ((-44.177 * c + 26.763) * c + 104.011) * c + 68.215;
74  u /= 86400.0;
75  }
76 
77  /* Convert input time to TDT */
78  if (conv[0] == 'u' && conv[1] == 't' && conv[2] == 'c')
79  tdt = tjd + u;
80  else if (conv[0] == 'u' && conv[1] == 't' && conv[2] == '1')
81  tdt = tjd - ut1mtc + u;
82  else if (conv[0] == 't' && conv[1] == 'd' && conv[2] == 't')
83  tdt = tjd;
84  else {
85  if (errmsg)
86  *errmsg = "input type should be utc | ut1 | tdt";
87  return FP_ERRVAL;
88  }
89 
90 
91  /* Convert TDT to output time */
92  if (conv[4] == 'u' && conv[5] == 't' && conv[6] == 'c')
93  return tdt - u;
94  else if (conv[4] == 'u' && conv[5] == 't' && conv[6] == '1')
95  return tdt - u + ut1mtc;
96  else if (conv[4] == 't' && conv[5] == 'd' && conv[6] == 't')
97  return tdt;
98  else {
99  if (errmsg)
100  *errmsg = "output type should be utc | ut1 | tdt";
101  return FP_ERRVAL;
102  }
103 }
104 
105 /*
106  * This routine allows specification of the value of TDT-UT in seconds.
107  */
108 int
109 tcset(x, what, errmsg)
110 double x;
111 char *what;
112 char **errmsg;
113 {
114  if (strcmp(what, "tdt-utc") == 0)
115  dtmutc = x / 86400.0;
116  if (strcmp(what, "ut1-utc") == 0)
117  ut1mtc = x / 86400.0;
118  else {
119  if (errmsg)
120  *errmsg = "identifier should be tdt-utc | ut1-utc";
121  return -1;
122  }
123 
124  return 0;
125 }
#define FP_ERRVAL
Definition: orbit.h:48
int tcset(double x, char *what, char **errmsg)
Definition: tconv.c:109
double tconv(double tjd, char *conv, char **errmsg)
Definition: tconv.c:55
data_t u
Definition: decode_rs.h:74
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed as required for compatibility with version of the SDP toolkit Corrected test output file names to end in per delivery and then split off a new MYD_PR03 pcf file for Aqua Added AssociatedPlatformInstrumentSensor to the inventory metadata in MOD01 mcf and MOD03 mcf Created new versions named MYD01 mcf and MYD03 where AssociatedPlatformShortName is rather than Terra The program itself has been changed to read the Satellite Instrument validate it against the input L1A and LUT and to use it determine the correct files to retrieve the ephemeris and attitude data from Changed to produce a LocalGranuleID starting with MYD03 if run on Aqua data Added the Scan Type file attribute to the Geolocation copied from the L1A and attitude_angels to radians rather than degrees The accumulation of Cumulated gflags was moved from GEO_validate_earth_location c to GEO_locate_one_scan c
Definition: HISTORY.txt:464
#define J2000
Definition: orbit.h:72