OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
getorbnum.c
Go to the documentation of this file.
1 /* -------------------------------------------------------------- */
2 /* getorbnum() - compute seastar orbit number for given time */
3 /* */
4 /* Synopsis: */
5 /* */
6 /* orbnum = getorbnum( time ); */
7 /* */
8 /* INT32 orbnum - orbit number */
9 /* FLOAT64 time - time in seconds since 1/1/70 */
10 /* */
11 /* Description: */
12 /* */
13 /* Given a table of epoch, orbital period, and orbit number, */
14 /* where the epoch is time in seconds at the start of a new */
15 /* orbit number, just divide time since last epoch by orbital */
16 /* period to get orbit number. This function is not intended */
17 /* to be highly accurate as to the exact time of orbit number */
18 /* change, but if the last table entry is within a few months */
19 /* of the input time, and the orbit does not suddenly degrade, */
20 /* the transition time should be accurate to the minute. */
21 /* */
22 /* New table entries should be added every few months. A */
23 /* utility to generate them is called SWorbnum. */
24 /* */
25 /* Modification Hisory: */
26 /* */
27 /* 03 Nov 1997, B. A. Franz, Initial Devalopment */
28 /* */
29 /* -------------------------------------------------------------- */
30 
31 #include "swl0_proto.h"
32 #include <string.h>
33 #include <stdio.h>
34 
35 typedef struct orbtab_struct {
42 } orbtab_str;
43 
45  static int firstCall = 1;
46  static orbtab_str orbtab[MAXORBTAB];
47  static INT32 ntab = 0;
48 
49  FLOAT64 delsec;
50  INT32 orbnum;
51  INT32 itab;
52 
53  if (firstCall) {
54 
55  FILE *fp = NULL;
56  char *tmp_str;
57  char filename[1024] = "";
58  char line[80];
59 
60  INT16 year;
61  INT16 day;
62  FLOAT32 sec;
63  FLOAT64 time;
65 
66  firstCall = 0;
67 
68  if ((tmp_str = getenv("OCDATAROOT")) == NULL) {
69  printf("OCDATAROOT environment variable is not defined.\n");
70  exit(1);
71  }
72  strcpy(filename, tmp_str);
73  strcat(filename, "/seawifs/nav/orbit_table.dat");
74 
75  printf("\nLoading orbit number table from %s\n", filename);
76 
77  if ((fp = fopen(filename, "r")) == NULL) {
78  fprintf(stderr,
79  "-E- %s line %d: unable to open %s for reading\n",
80  __FILE__, __LINE__, filename);
81  exit(1);
82  }
83 
84  itab = 0;
85  while (fgets(line, 80, fp)) {
86  sscanf(line, "%hd %hd %f %lf %f %d",
87  &year, &day, &sec, &time, &period, &orbnum);
88 
89  if (itab > (MAXORBTAB - 1)) {
90  fprintf(stderr,
91  "-E- %s line %d: orbit table exceeded allocation\n",
92  __FILE__, __LINE__);
93  exit(1);
94  }
95 
96  if (year < 1997 || year > 2020)
97  continue;
98 
99  orbtab[itab].year = year;
100  orbtab[itab].day = day;
101  orbtab[itab].sec = sec;
102  orbtab[itab].time = time;
103  orbtab[itab].period = period;
104  orbtab[itab].orbnum = orbnum;
105  itab++;
106  }
107 
108  ntab = itab;
109  fclose(fp);
110 
111  printf("%d orbit records loaded\n", ntab);
112  }
113 
114 
115  for (itab = 1; itab < ntab; itab++) {
116  if (usec < orbtab[itab].time) {
117  itab--;
118  break;
119  }
120  }
121 
122  if (itab == ntab) itab--;
123 
124  printf("Using orbit number extrapolated from %d %d\n\n",
125  orbtab[itab].year, orbtab[itab].day);
126 
127 
128 
129  delsec = usec - orbtab[itab].time;
130  orbnum = orbtab[itab].orbnum + (int32_t) (delsec / orbtab[itab].period);
131 
132  if (delsec < 0.0)
133  orbnum--;
134 
135  if (delsec / 86400. > 180)
136  printf("-W- Orbit table is out of date, closest entry is %lf days old.\n",
137  delsec / 86400.);
138 
139  return (orbnum);
140 }
141 
142 
143 #ifdef GETORBIT
144 
145 void main(int argc, char *argv[]) {
146  INT16 year;
147  INT16 day;
148  FLOAT64 sec;
149  FLOAT64 usec;
150  INT32 orbnum;
151  INT32 orbnum2;
152 
153  year = atoi(argv[1]);
154  day = atoi(argv[2]);
155 
156  orbnum2 = 0;
157 
158  for (sec = 0.0; sec < 86400.0; sec += 0.1) {
159  usec = yds2unix(year, day, sec);
160  orbnum = getorbnum(usec);
161  if (orbnum != orbnum2) {
162  orbnum2 = orbnum;
163  printf("%d %d %lf %d\n", year, day, sec, orbnum);
164  }
165  }
166 
167 }
168 #endif
169 
#define MAXORBTAB
Definition: swl0_parms.h:14
double FLOAT64
Definition: elements.h:8
int32_t day
double yds2unix(int16_t year, int16_t day, double secs)
Definition: yds2unix.c:7
INT32 getorbnum(FLOAT64 usec)
Definition: getorbnum.c:44
FLOAT32 period
Definition: getorbnum.c:40
#define NULL
Definition: decode_rs.h:63
int32_t INT32
Definition: elements.h:6
short int INT16
Definition: elements.h:5
FLOAT32 sec
Definition: getorbnum.c:38
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
float FLOAT32
Definition: elements.h:7
INT32 orbnum
Definition: getorbnum.c:41
FLOAT64 time
Definition: getorbnum.c:39
Definition: common.h:9
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
int main(int argc, char *argv[])
Definition: afrt_nc4.cpp:30
MOD_PR01 Production producing one five minute granule of output data in each run It can be configured to produce as many as three five minute granules per run Each execution with one construction record and one date file for each dataset In normal these are created by which splits them out of the hour datasets For LANCE they are created by which merges all session MODIS L0 datasets overlapping the requested time period
Definition: MOD_PR01_pr.txt:15
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
INT16 year
Definition: getorbnum.c:36