OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
time-utils.c
Go to the documentation of this file.
1 /*
2  *----------------------------------------------------------------------
3  * @(#) time-utils.c 1.0 05 Jun 98 <shc>
4  * Copyright (c) 1993, CSIRO Division of Oceanography.
5  * Copyright (c) 1998, Datron Transco Inc.
6  *----------------------------------------------------------------------
7  *
8  * time-utils --
9  *
10  * A collection of routines for converting between normal time/date
11  * formats and Julian dates.
12  *
13  * History:
14  * 05 Jun 98 <shc>
15  * Split out from old julian.c
16  *
17  *----------------------------------------------------------------------
18  */
19 
20 #include <math.h>
21 #include <time.h>
22 
23 #include "orbit.h" /* Prototype checking */
24 
25 /*
26  * This function converts the date and time in a tm struct to the
27  * modified Julian day format used internally in all the astronomical
28  * and orbit prediction code.
29  */
30 
31 double
33 struct tm *time;
34 {
35  int year, month, day;
36  int32_t hour, minute, second;
37  int32_t mjd;
38  double fday;
39  double result;
40 
41  day = time->tm_mday;
42  month = time->tm_mon + 1; /* tm_mon is in range 0-11 */
43  year = 1900 + time->tm_year; /* tm_year is years since 1900 */
44 
45  second = time->tm_sec;
46  minute = time->tm_min;
47  hour = time->tm_hour;
48 
49  mjd = julday(year, month, day) - 2400000;
50 
51  fday = ((hour * 60 + minute)*60 + second) / 86400.0;
52 
53  result = mjd + fday - 0.5;
54  return (result);
55 }
56 
57 /*
58  * This function does the inverse of TOJUL.
59  */
60 
61 void
63 double tjd;
64 struct tm *time;
65 {
66  int32_t mjd;
67  double secs;
68  int year, month, day;
69  int hour, minute, second;
70 
71  mjd = (int32_t) (tjd + 0.5);
72  secs = (tjd + 0.5 - mjd) * 86400.0 + 0.0005;
73  mjd += 2400000;
74 
75  caldat(mjd, &year, &month, &day);
76 
77  hour = (int) (secs / 3600.0);
78  minute = (int) (secs / 60.0) % 60;
79  second = (int) (secs) % 60;
80 
81  time->tm_sec = second;
82  time->tm_min = minute;
83  time->tm_hour = hour;
84  time->tm_mday = day;
85  time->tm_mon = month;
86  time->tm_year = year;
87  time->tm_isdst = 0;
88 
89  return;
90 }
91 
92 /*
93  * This function converts a date and time in compact integer form to the
94  * modified Julian day format used internally in all the orbit prediction
95  * code. Note that a year number of less than 50 is interpreted as being
96  * in the range 2000 - 2049.
97  */
98 
99 double
100 itojul(date, time)
101 int32_t date; /* yymmdd */
102 int32_t time; /* hhmmssfff */
103 {
104  int year, month, day, hour, minute, second, millisec;
105  int32_t mjd;
106  double fday, result;
107 
108  day = date % 100L;
109  month = date / 100L % 100L;
110  year = date / 10000L % 100L;
111  millisec = time % 1000L;
112  second = time / 1000L % 100L;
113  minute = time / 100000L % 100L;
114  hour = time / 10000000L % 100L;
115 
116  if (year >= 50)
117  year = year + 1900;
118  else
119  year = year + 2000;
120 
121  mjd = julday(year, month, day) - 2400000L;
122 
123  fday = (((hour * 60.0 + minute)*60.0 + second) + millisec / 1000.0) / 86400.0;
124 
125  result = mjd + fday - 0.5;
126  return (result);
127 }
128 
129 /*
130  * This function does the inverse of ITOJUL.
131  */
132 
133 void
134 jultoi(tjd, date, time)
135 double tjd;
136 int32_t *date, *time;
137 {
138  int year, month, day;
139  int32_t mjd, hour, minute, second, millisec;
140  double secs;
141 
142  mjd = (int32_t) (tjd + 0.5);
143  secs = (tjd + 0.5 - mjd) * 86400.0 + 0.0005;
144  caldat(mjd + 2400000L, &year, &month, &day);
145 
146  hour = (int32_t) (secs / 3600.0);
147  minute = (int32_t) (secs / 60.0) % 60L;
148  second = (int32_t) (secs) % 60L;
149  millisec = (int32_t) (secs * 1000.0) % 1000L;
150 
151  *date = ((int32_t) year % 100L)*10000L + (int32_t) month * 100L + (int32_t) day;
152  *time = hour * 10000000L + minute * 100000L + second * 1000L + millisec;
153 
154  return;
155 }
void jultoi(double tjd, int32_t *date, int32_t *time)
Definition: time-utils.c:134
int32_t day
#define L(lambda, T)
Definition: PreprocessP.h:185
float tm[MODELMAX]
subroutine julday(YYMMDD, JDAY)
Definition: julday.f:2
double tmtojul(struct tm *time)
Definition: time-utils.c:32
void jultotm(double tjd, struct tm *time)
Definition: time-utils.c:62
double itojul(int32_t date, int32_t time)
Definition: time-utils.c:100
void caldat(long julian, int *mm, int *id, int *iyyy)
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that and then aggregated up to Resolved feature request Bug by adding three new int8 SDSs for each high resolution offsets between the high resolution geolocation and a bi linear interpolation extrapolation of the positions This can be used to reconstruct the high resolution geolocation Resolved Bug by delaying cumulation of gflags until after validation of derived products Resolved Bug by setting Latitude and Longitude to the correct fill resolving to support Near Real Time because they may be unnecessary if use of entrained ephemeris and attitude data is turned resolving bug report Corrected to filter out Aqua attitude records with missing status helping resolve bug MOD_PR03 will still correctly write scan and pixel data that does not depend upon the start time
Definition: HISTORY.txt:248