OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1_xcal_hdf.c
Go to the documentation of this file.
1 /* ============================================================================ */
2 /* module l1_xcal_hdf.c - functions to read the XCAL cross-calibration file */
3 /* from MCcalmerge for processing through MSL12 */
4 /* */
5 /* Written By: B. Franz, NASA/SIMBIOS, December 2003. */
6 /* */
7 /* ============================================================================ */
8 
9 #include "l1_xcal_hdf.h"
10 
11 #include <hdf4utils.h>
12 #include "l1.h"
13 #include <genutils.h>
14 
15 #include <hdf.h>
16 #include <mfhdf.h>
17 
18 #define OBSERVED 1
19 #define VICARIOUS 2
20 #define NPIX 1
21 #define SBUF 5000
22 
23 static int32_t sd_id;
24 
25 /* ----------------------------------------------------------------------------------- */
26 /* openl1_xcal_hdf() - opens an XCAL file for reading. */
27 /* */
28 /* B. Franz, SAIC, February 2003. */
29 
30 /* ----------------------------------------------------------------------------------- */
31 int openl1_xcal_hdf(filehandle *file) {
32  int32_t nscan;
33  int32_t dims[3];
34 
35  /* Open the HDF input file */
36  sd_id = SDstart(file->name, DFACC_RDONLY);
37  if (sd_id == FAIL) {
38  fprintf(stderr, "-E- %s line %d: SDstart(%s, %d) failed.\n",
39  __FILE__, __LINE__, file->name, DFACC_RDONLY);
40  return (HDF_FUNCTION_ERROR);
41  }
42 
43  /* Get pixel and scan dimensions */
44  if (getDims(sd_id, "fileID", dims) != 0) {
45  printf("-E- %s line %d: Could not read HDF file dimensions, %s .\n",
46  __FILE__, __LINE__, file->name);
47  SDend(sd_id);
48  return (FATAL_ERROR);
49  }
50  if (dims[0] < 0) {
51  printf("-E- %s line %d: Invalid dimension information for %s.\n",
52  __FILE__, __LINE__, file->name);
53  SDend(sd_id);
54  return (FATAL_ERROR);
55  }
56  nscan = dims[0];
57 
58  file->npix = 1;
59  file->nscan = nscan;
60  file->sd_id = sd_id;
61 
62  return (LIFE_IS_GOOD);
63 }
64 
65 
66 /* ----------------------------------------------------------------------------------- */
67 /* readl1_xcal_hdf() - reads 1 line (1 pixel) from a cross-calibration (XCAL) file. */
68 /* */
69 /* B. Franz, SAIC, February 2003. */
70 
71 /* ----------------------------------------------------------------------------------- */
72 int readl1_xcal_hdf(filehandle *file, int32_t scan, l1str *l1rec) {
73  static int16_t *year;
74  static int16_t *day;
75  static int32_t *msec;
76  static int16_t *pixnum;
77  static int8_t *detnum;
78  static int8_t *mside;
79  static float *lon;
80  static float *lat;
81  static float *solz;
82  static float *sola;
83  static float *senz;
84  static float *sena;
85  static float *alpha;
86  static float *Lt;
87 
88  static int32_t lastscan = -SBUF, firstCall = 1;
89 
90  int32_t nbands = (int32_t) file->nbands;
91  int32_t nscan = (int32_t) file->nscan;
92  int32_t indx = scan % SBUF;
93 
94  int32_t nread;
95 
96  if (firstCall == 1) {
97  year = (int16_t*) allocateMemory(SBUF * sizeof (int16_t), "readl1_xcal_hdf - year");
98  day = (int16_t*) allocateMemory(SBUF * sizeof (int16_t), "readl1_xcal_hdf - day");
99  msec = (int32_t*) allocateMemory(SBUF * sizeof (int32_t), "readl1_xcal_hdf - msec");
100  pixnum = (int16_t*) allocateMemory(SBUF * sizeof (int16_t), "readl1_xcal_hdf - pixnum");
101  detnum = (int8_t*) allocateMemory(SBUF * sizeof (int8_t), "readl1_xcal_hdf - detnum");
102  mside = (int8_t*) allocateMemory(SBUF * sizeof (int8_t), "readl1_xcal_hdf - mside");
103  lon = (float*) allocateMemory(SBUF * sizeof (float), "readl1_xcal_hdf - lon");
104  lat = (float*) allocateMemory(SBUF * sizeof (float), "readl1_xcal_hdf - lat");
105  solz = (float*) allocateMemory(SBUF * sizeof (float), "readl1_xcal_hdf - solz");
106  sola = (float*) allocateMemory(SBUF * sizeof (float), "readl1_xcal_hdf - sola");
107  senz = (float*) allocateMemory(SBUF * sizeof (float), "readl1_xcal_hdf - senz");
108  sena = (float*) allocateMemory(SBUF * sizeof (float), "readl1_xcal_hdf - sena");
109  alpha = (float*) allocateMemory(SBUF * sizeof (float), "readl1_xcal_hdf - alpha");
110  Lt = (float*) allocateMemory(file->nbands * SBUF * sizeof (float32), "readl1_xcal_hdf - Lt");
111  firstCall = 0;
112  }
113  /* Do we need to read the next buffered block? */
114  if (scan / SBUF != lastscan / SBUF) {
115 
116  if (scan + SBUF < nscan)
117  nread = SBUF;
118  else
119  nread = nscan - scan + 1;
120 
121  printf("%d %d %d\n", scan, nread, nscan);
122 
123  /* Read scan time */
124  READ_SDS_ID(sd_id, "year", year, scan, 0, 0, 0, nread, 1, 1, 1);
125  READ_SDS_ID(sd_id, "day", day, scan, 0, 0, 0, nread, 1, 1, 1);
126  READ_SDS_ID(sd_id, "msec", msec, scan, 0, 0, 0, nread, 1, 1, 1);
127 
128  /* Get location within instrument */
129  READ_SDS_ID(sd_id, "ipix", pixnum, scan, 0, 0, 0, nread, 1, 1, 1);
130  READ_SDS_ID(sd_id, "idet", detnum, scan, 0, 0, 0, nread, 1, 1, 1);
131  READ_SDS_ID(sd_id, "mside", mside, scan, 0, 0, 0, nread, 1, 1, 1);
132 
133  /* Get position and path geometry */
134  READ_SDS_ID(sd_id, "lon", lon, scan, 0, 0, 0, nread, 1, 1, 1);
135  READ_SDS_ID(sd_id, "lat", lat, scan, 0, 0, 0, nread, 1, 1, 1);
136  READ_SDS_ID(sd_id, "solz", solz, scan, 0, 0, 0, nread, 1, 1, 1);
137  READ_SDS_ID(sd_id, "sola", sola, scan, 0, 0, 0, nread, 1, 1, 1);
138  READ_SDS_ID(sd_id, "senz", senz, scan, 0, 0, 0, nread, 1, 1, 1);
139  READ_SDS_ID(sd_id, "sena", sena, scan, 0, 0, 0, nread, 1, 1, 1);
140  READ_SDS_ID(sd_id, "alpha", alpha, scan, 0, 0, 0, nread, 1, 1, 1);
141 
142  /* Read radiances */
143  READ_SDS_ID(sd_id, "Lt", Lt, scan, 0, 0, 0, nread, nbands, 1, 1);
144  }
145 
146  l1rec->scantime = yds2unix(year[indx], day[indx], (double) (msec[indx] / 1.e3));
147 
148  l1rec->pixnum[0] = (int32_t) pixnum [indx];
149  l1rec->detnum = (int32_t) detnum [indx];
150  l1rec->mside = (int32_t) mside [indx];
151 
152  l1rec->lon [0] = lon [indx];
153  l1rec->lat [0] = lat [indx];
154  l1rec->solz [0] = solz [indx];
155  l1rec->sola [0] = sola [indx];
156  l1rec->senz [0] = senz [indx];
157  l1rec->sena [0] = sena [indx];
158  l1rec->alpha[0] = alpha [indx];
159 
160  memcpy(l1rec->Lt, &Lt[indx * nbands], nbands);
161 
162  l1rec->npix = 1;
163  l1rec->iscan = scan;
164 
165  lastscan = scan;
166 
167  return (LIFE_IS_GOOD);
168 }
169 
170 int closel1_xcal_hdf(filehandle *file) {
171  if (SDend(sd_id)) {
172  fprintf(stderr, "-E- %s line %d: SDend(%d) failed for file, %s.\n",
173  __FILE__, __LINE__, sd_id, file->name);
174  return (HDF_FUNCTION_ERROR);
175  }
176 
177  return (LIFE_IS_GOOD);
178 }
179 
180 
181 
182 
183 
int closel1_xcal_hdf(filehandle *file)
Definition: l1_xcal_hdf.c:170
int32_t day
double yds2unix(int16_t year, int16_t day, double secs)
Definition: yds2unix.c:7
#define FAIL
Definition: ObpgReadGrid.h:18
void * allocateMemory(size_t numBytes, const char *name)
Definition: allocateMemory.c:7
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 and extracts from the merged data those packets which fall within that time period Each scan of data is stored in the L1A granule that covers the start time of that scan
Definition: MOD_PR01_pr.txt:19
read l1rec
float * lat
int32 * msec
Definition: l1_czcs_hdf.c:31
int32 nscan
Definition: l1_czcs_hdf.c:19
#define READ_SDS_ID(sd_id, nam, ptr, s0, s1, s2, s3, e0, e1, e2, e3)
Definition: hdf4utils.h:109
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 file
Definition: HISTORY.txt:413
#define LIFE_IS_GOOD
Definition: passthebuck.h:4
int getDims(int32_t fileID, const char sdsname[], int32_t dims[])
int32_t mside
#define FATAL_ERROR
Definition: swl0_parms.h:5
int openl1_xcal_hdf(filehandle *file)
Definition: l1_xcal_hdf.c:31
int32_t nbands
int readl1_xcal_hdf(filehandle *file, int32_t scan, l1str *l1rec)
Definition: l1_xcal_hdf.c:72
float * lon
#define SBUF
Definition: l1_xcal_hdf.c:21
#define HDF_FUNCTION_ERROR
Definition: passthebuck.h:7