OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
atteph_info_modis.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <PGS_EPH.h>
6 #include <stddef.h> /* for `size_t' */
7 #include <timeutils.h>
8 
9 /* prototype for function used to swap byte order */
10 extern int byteswap(char *, int);
11 
12 #define RTRN_ERROR 255
13 #define RTRN_SUCCEED 0
14 
15 int getEphemHeaders(char *ephfile) {
16  FILE *ephemFilePtr;
17  PGSt_ephemHeader header;
18  char *ptr, *ptr1, *ptr2, *ptr3, *ptr4;
19  int ll, ll1, n, m, q;
20  int16_t year, month, day, hour, minute, second;
21  double secs;
22  double secTAI93 = 725846400.;
23 
24  static char buf[255];
25  static char shortname[8];
26  size_t len = 8;
27 
28  strcpy(buf, ephfile);
29  strncpy(shortname, buf, len);
30  fprintf(stdout, "shortname=%s\n", shortname);
31  fprintf(stdout, "localgranuleid=%s\n", buf);
32 
33  if ((ephemFilePtr = fopen(buf, "r")) == NULL) {
34  fprintf(stderr, "Error opening Ephemeris file\n");
35  return RTRN_ERROR;
36  } else {
37  fread(&header, sizeof (PGSt_ephemHeader), 1, ephemFilePtr);
38  fclose(ephemFilePtr);
39  }
40 
41  ptr = (char *) (&header.startTime);
42  ll = sizeof (PGSt_double);
43  byteswap(ptr, ll);
44 
45  ptr1 = (char *) (&header.endTime);
46  ll1 = sizeof (PGSt_double);
47  byteswap(ptr1, ll1);
48 
49  ptr2 = (char *) (&header.interval);
50  for (n = 0; n < 6; n++, ptr2 += 4) byteswap(ptr2, 4);
51 
52  ptr3 = (char *) (&header.keplerElements);
53  for (m = 0; m < 7; m++, ptr3 += 8) byteswap(ptr3, 8);
54 
55  ptr4 = (char *) (&header.qaParameters);
56  for (q = 0; q < 20; q++, ptr4 += 4) byteswap(ptr4, 4);
57 
58  unix2ymds(secTAI93 + header.startTime, &year, &month, &day, &secs);
59 
60  fprintf(stdout, "rangebeginningdate=%4d-%02d-%02d\n", year, month, day);
61 
62  hour = (int) (24. * (secs / 86400.));
63  minute = (int) ((secs - 3600. * (double) hour) / 60.);
64  second = (int) ((secs - 3600. * (double) hour - (double) minute * 60.));
65  double fsec = 1000000. * (secs - 3600. * (double) hour - (double) minute * 60. -
66  (double) second);
67 
68  fprintf(stdout, "rangebeginningtime=%02d:%02d:%02d.%d\n", hour, minute, second, (int) fsec);
69 
70  unix2ymds(secTAI93 + header.endTime, &year, &month, &day, &secs);
71 
72  fprintf(stdout, "rangeendingdate=%4d-%02d-%02d\n", year, month, day);
73 
74  hour = (int) (24. * (secs / 86400.));
75  minute = (int) ((secs - 3600. * (double) hour) / 60.);
76  second = (int) ((secs - 3600. * (double) hour - (double) minute * 60.));
77  fsec = 1000000. * (secs - 3600. * (double) hour - (double) minute * 60. -
78  (double) second);
79 
80  fprintf(stdout, "rangeendingtime=%02d:%02d:%02d.%d\n", hour, minute, second, (int) fsec);
81  fprintf(stdout, "percentMissingData=%lf\n", header.qaStatistics[1]);
82 
83  return RTRN_SUCCEED;
84 }
85 
86 int getAttHeaders(char *attfile) {
87  FILE *attitFilePtr;
88  PGSt_attitHeader header;
89  char *ptr, *ptr1, *ptr2;
90  int ll, ll1, n;
91  static char buf[255];
92  int16_t year, month, day, hour, minute, second;
93  double secs;
94  double secTAI93 = 725846400.;
95  static char shortname[8];
96  size_t len = 8;
97 
98  strcpy(buf, attfile);
99  strncpy(shortname, buf, len);
100  fprintf(stdout, "shortname=%s\n", shortname);
101  fprintf(stdout, "localgranuleid=%s\n", buf);
102 
103  if ((attitFilePtr = fopen(buf, "r")) == NULL) {
104  fprintf(stderr, "Error opening Attitude file\n");
105  return RTRN_ERROR;
106  } else {
107  fread(&header, sizeof (PGSt_attitHeader), 1, attitFilePtr);
108  fclose(attitFilePtr);
109  }
110  ptr = (char *) (&header.startTime);
111  ll = sizeof (PGSt_double);
112  byteswap(ptr, ll);
113 
114  ptr1 = (char *) (&header.endTime);
115  ll1 = sizeof (PGSt_double);
116  byteswap(ptr1, ll1);
117 
118  ptr2 = (char *) (&header.interval);
119  for (n = 0; n < 26; n++, ptr2 += 4) byteswap(ptr2, 4);
120 
121  unix2ymds(secTAI93 + header.startTime, &year, &month, &day, &secs);
122 
123  fprintf(stdout, "rangebeginningdate=%4d-%02d-%02d\n", year, month, day);
124 
125  hour = (int) (24. * (secs / 86400.));
126  minute = (int) ((secs - 3600. * (double) hour) / 60.);
127  second = (int) ((secs - 3600. * (double) hour - (double) minute * 60.));
128  double fsec = 1000000. * (secs - 3600. * (double) hour - (double) minute * 60. -
129  (double) second);
130 
131  fprintf(stdout, "rangebeginningtime=%02d:%02d:%02d.%d\n", hour, minute, second, (int) fsec);
132 
133  unix2ymds(secTAI93 + header.endTime, &year, &month, &day, &secs);
134 
135  fprintf(stdout, "rangeendingdate=%4d-%02d-%02d\n", year, month, day);
136 
137  hour = (int) (24. * (secs / 86400.));
138  minute = (int) ((secs - 3600. * (double) hour) / 60.);
139  second = (int) ((secs - 3600. * (double) hour - (double) minute * 60.));
140  fsec = 1000000. * (secs - 3600. * (double) hour - (double) minute * 60. -
141  (double) second);
142 
143  fprintf(stdout, "rangeendingtime=%02d:%02d:%02d.%d\n", hour, minute, second, (int) fsec);
144  fprintf(stdout, "percentMissingData=%lf\n", header.qaStatistics[1]);
145 
146  return RTRN_SUCCEED;
147 }
148 
149 int main(int argc, char *argv[]) {
150  char *attephfile;
151  int rtrn;
152 
153 
154  if (2 == argc) {
155  attephfile = argv[1];
156 
157  if (strstr(attephfile, "ATT")) {
158  rtrn = getAttHeaders(attephfile);
159  } else {
160  rtrn = getEphemHeaders(attephfile);
161  }
162  } else {
163  printf("Usage: %s atteph-file\n", argv[0]);
164  rtrn = RTRN_ERROR;
165  }
166 
167  return rtrn;
168 }
data_t q
Definition: decode_rs.h:74
int32_t day
int byteswap(char *, int)
#define NULL
Definition: decode_rs.h:63
int getEphemHeaders(char *ephfile)
int main(int argc, char *argv[])
void unix2ymds(double usec, int16_t *year, int16_t *mon, int16_t *day, double *secs)
Definition: unix2ymds.c:8
#define RTRN_ERROR
#define RTRN_SUCCEED
integer, parameter double
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second and prod_ix set to PARAM_TYPE_INT name_prefix is compared with the beginning of the product name If name_suffix is not empty the it must match the end of the product name The characters right after the prefix are read as an integer and prod_ix is set to that number strncpy(l2prod->name_prefix, "myprod", UNITLEN)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int getAttHeaders(char *attfile)