OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1_hdf_generic_read.c
Go to the documentation of this file.
1 #include "l1_hdf_generic_read.h"
2 #include "l1.h"
3 #include <hdf4utils.h>
4 
5 
6 #define BANDED 2
7 #define INTERLACED 3
8 
9 static int32_t format = 0;
10 static int32_t dformat = INTERLACED;
11 static char **dname;
12 //static char dname[NBANDS][32];
13 static float *data = NULL;
14 
15 #include <hdf.h>
16 #include <mfhdf.h>
17 
18 
19 void get_l1data(int32_t sd_id,
20  int32_t scan,
21  int32_t npix,
22  int32_t nbands,
23  int32_t bindx[],
24  int32_t format,
25  l1str *l1rec) {
26  // int16 angles[NBANDS];
27  int32_t i, j;
28  static int firstCall = 1;
29  int32_t year, day, msec;
30 
31  READ_SDS("year", &year, scan, 0, 0, 1, 1, 1);
32  READ_SDS("day", &day, scan, 0, 0, 1, 1, 1);
33  READ_SDS("msec", &msec, scan, 0, 0, 1, 1, 1);
34  l1rec->scantime = yds2unix((int16) year, (int16) day, (double) (msec / 1.e3));
35  READ_SDS("mside", &(l1rec->mside), scan, 0, 0, 1, 1, 1);
36  READ_SDS("detnum", &(l1rec->detnum), scan, 0, 0, 1, 1, 1);
37  READ_SDS("tilt", &(l1rec->tilt), scan, 0, 0, 1, 1, 1);
38  READ_SDS("longitude", l1rec->lon, scan, 0, 0, 1, npix, 1);
39  READ_SDS("latitude", l1rec->lat, scan, 0, 0, 1, npix, 1);
40  READ_SDS("solz", l1rec->solz, scan, 0, 0, 1, npix, 1);
41  READ_SDS("sola", l1rec->sola, scan, 0, 0, 1, npix, 1);
42  READ_SDS("senz", l1rec->senz, scan, 0, 0, 1, npix, 1);
43  READ_SDS("sena", l1rec->sena, scan, 0, 0, 1, npix, 1);
44 
45  if (firstCall == 1) {
46  if ((dname = (char **) malloc(l1rec->l1file->nbands * sizeof (char *))) == NULL) {
47  printf("-E- %s line %d: Error allocating data space.\n",
48  __FILE__, __LINE__);
49  exit(EXIT_FAILURE);
50  }
51 
52  for (i = 0; i < l1rec->l1file->nbands; i++)
53  if ((dname[i] = (char *) malloc(32 * sizeof (char))) == NULL) {
54  printf("-E- %s line %d: Error allocating data space.\n",
55  __FILE__, __LINE__);
56  exit(EXIT_FAILURE);
57  }
58  firstCall = 0;
59  }
60 
61  if (dformat == INTERLACED) {
62  READ_SDS("l1b_data", l1rec->Lt, scan, 0, 0, 1, npix, nbands);
63  } else {
64  for (i = 0; i < nbands; i++) {
65  READ_SDS(dname[i], data, scan, 0, 0, 1, npix, 1);
66  for (j = 0; j < npix; j++)
67  l1rec->Lt[j * nbands + bindx[i]] = data[j];
68  }
69  }
70 
71  /* Read L2 flags */
72  READ_SDS("l2_flags", l1rec->flags, scan, 0, 0, 1, npix, 1);
73  for (j = 0; j < npix; j++) {
74  l1rec->stlight[j] = ((l1rec->flags[j] & STRAYLIGHT) > 0);
75  l1rec->hilt [j] = ((l1rec->flags[j] & HILT) > 0);
76  l1rec->navwarn[j] = ((l1rec->flags[j] & NAVWARN) > 0);
77  l1rec->navfail[j] = ((l1rec->flags[j] & ATMFAIL) > 0);
78  }
79 
80 }
81 
82 int openl1_read_hdf_g(filehandle *file) {
83  int32_t npix;
84  int32_t nscan;
85  int32_t nbands;
86  char sensor[20];
87  int32_t sd_id;
88  int32_t sds_id;
89 
90  /* Open the HDF input file */
91  sd_id = SDstart(file->name, DFACC_RDONLY);
92  if (sd_id == FAIL) {
93  fprintf(stderr, "-E- %s line %d: SDstart(%s, %d) failed.\n",
94  __FILE__, __LINE__, file->name, DFACC_RDONLY);
95  return (HDF_FUNCTION_ERROR);
96  }
97 
98  /* Read some of the level-1A global attributes. */
99  READ_GLBL_ATTR("Pixels per Scan Line", &npix);
100  READ_GLBL_ATTR("Number of Scan Lines", &nscan);
101  READ_GLBL_ATTR("Number of Bands", &nbands);
102  READ_GLBL_ATTR("Sensor Name", sensor);
103 
104  /* Determine which kind of radiance format we have */
105  if (sd_select(sd_id, "l1b_data", &sds_id) == 0)
106  dformat = INTERLACED;
107  else
108  dformat = BANDED;
109 
110 
111  file->npix = npix;
112  file->nscan = nscan;
113  file->nbands = nbands;
114  file->sd_id = sd_id;
115 
116  return (LIFE_IS_GOOD);
117 }
118 
119 int readl1_hdf_g(filehandle *file, int32_t recnum, l1str *l1rec) {
120  static int firstCall = 1;
121  int32_t sd_id = file->sd_id;
122 
123  if (firstCall) {
124 
125  firstCall = 0;
126 
127  if (dformat == BANDED) {
128 
129  int32_t i;
130  int32_t *wavelen;
131 
132  if (rdsensorinfo(file->sensorID, l1_input->evalmask, "Lambda", (void **) &wavelen) != file->nbands) {
133  printf("-E- %s line %d: Error reading sensor table file\n",
134  __FILE__, __LINE__);
135  return (1);
136  }
137 
138  for (i = 0; i < file->nbands; i++)
139  sprintf(dname[i], "Lt_%3d", wavelen[file->bindx[i]]);
140 
141  if ((data = (float *) calloc(file->npix, sizeof (float))) == NULL) {
142  printf("-E- %s line %d: Error allocating data space.\n",
143  __FILE__, __LINE__);
144  return (1);
145  }
146  }
147 
148  }
149 
150  get_l1data(sd_id, recnum, file->npix, file->nbands, (int32_t *) file->bindx, format, l1rec);
151 
152  l1rec->npix = file->npix;
153 
154  return (LIFE_IS_GOOD);
155 }
156 
157 int closel1_hdf_g(filehandle *file) {
158  if (SDend(file->sd_id)) {
159  fprintf(stderr, "-E- %s line %d: SDend(%d) failed for file, %s.\n",
160  __FILE__, __LINE__, file->sd_id, file->name);
161  return (HDF_FUNCTION_ERROR);
162  }
163 
164  return (LIFE_IS_GOOD);
165 }
166 
167 
168 
169 
170 
#define INTERLACED
integer, parameter int16
Definition: cubeio.f90:3
const int bindx[3]
Definition: DbLutNetcdf.cpp:28
int readl1_hdf_g(filehandle *file, int32_t recnum, l1str *l1rec)
int j
Definition: decode_rs.h:73
int32_t day
double yds2unix(int16_t year, int16_t day, double secs)
Definition: yds2unix.c:7
int sd_select(int32_t sd_id, const char *name, int32_t *sds_id)
Definition: hdf_utils.c:355
int closel1_hdf_g(filehandle *file)
#define BANDED
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
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
#define STRAYLIGHT
Definition: l2_flags.h:19
int32 * msec
Definition: l1_czcs_hdf.c:31
int32 nscan
Definition: l1_czcs_hdf.c:19
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
read recnum
l1_input_t * l1_input
Definition: l1_options.c:9
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
#define HILT
Definition: l2_flags.h:15
#define ATMFAIL
Definition: l2_flags.h:11
int32_t nbands
int openl1_read_hdf_g(filehandle *file)
#define READ_SDS(nam, ptr, s0, s1, s2, e0, e1, e2)
Definition: bindepths.c:54
int32_t rdsensorinfo(int32_t, int32_t, const char *, void **)
Definition: rdsensorinfo.c:69
#define NAVWARN
Definition: l2_flags.h:27
int i
Definition: decode_rs.h:71
int npix
Definition: get_cmp.c:27
#define HDF_FUNCTION_ERROR
Definition: passthebuck.h:7
#define READ_GLBL_ATTR(nam, ptr)
Definition: bindepths.c:36
void get_l1data(int32_t sd_id, int32_t scan, int32_t npix, int32_t nbands, int32_t bindx[], int32_t format, l1str *l1rec)