OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l2io_read.c
Go to the documentation of this file.
1 #include <string.h>
2 #include "l1io.h"
3 #include <mfhdf.h>
4 
5 int32 l2io_read(l1info_struct l1info, int irec,
6  float *data, int16 *l2_flags, navblockType *nav)
7 /*******************************************************************
8 
9  l2io_read
10 
11  purpose: read a record of some information from the level 2 dataset
12 
13  Returns type: int32 - return status: 0 is good
14 
15  Parameters: (in calling order)
16  Type Name I/O Description
17  ---- ---- --- -----------
18  struct l1info_struct l1info I information struct
19  about the opened file
20  int irec I line, record # to read
21  float * data O array of data: 1 line
22  with 12 channels, all vals
23  for 1 pixel are together
24  int16 * flags O level 2 flag values
25  struct navblockType * nav O navigation info struct
26 
27  Modification history:
28  Programmer Date Description of change
29  ---------- ---- ---------------------
30  W. Robinson 25-Jan-1995 Original development
31 
32  *******************************************************************/
33  {
34  int i, j, ipix;
35  int32 index, rank, sdid, numbertype, nattrs, data_dims[5];
36  int32 start[5], edge[5];
37  void *ptr; /* generic data pointer */
38  char name[H4_MAX_NC_NAME]; /* MAX_NC_NAME is max # chars for this */
39  /* temporary storage for the unscaled data */
40  int16 *i2temp;
41  uint8 *i1temp;
42  /* the bias and slope are stored here */
43  static float l2_bias[12] ={0., 0., 0., 0., 0., 0., 0., 32., 32., 0., 0., 0.};
44  static float l2_slope[12] ={.001, .001, .001, .001, .001, .002,
45  .001, .001, .001, .0002, .01, .005};
46 
47  /* This is the list of names of the data elements we will be getting */
48  static char *namelist[20] ={"nLw_412", "nLw_443", "nLw_490", "nLw_510",
49  "nLw_555", "La_670", "La_865", "CZCS_pigment",
50  "chlor_a", "K_490", "eps_78", "tau_865",
51  "l2_flags", "orb_vec", "l_vert", "sun_ref",
52  "att_ang", "sen_mat", "scan_ell", "nflag"};
53 
54  /*
55  * before the festivities start, allocate space for the temp storage
56  */
57  i2temp = malloc(248 * 2);
58  i1temp = malloc(248);
59 
60  /*
61  * now, SDnametoindex is used to zero in on the data we want,
62  * ie. get the index of the data
63  */
64 
65  for (i = 0; i < 20; i++) {
66  if ((index = SDnametoindex(l1info.sdfid, namelist[i])) < 0) {
67  printf("l1io_read: couldn't find %s in the qc dataset\n",
68  namelist[i]);
69  return -1;
70  }
71 
72  /*
73  * next, get the SD ID for the data
74  */
75  if ((sdid = SDselect(l1info.sdfid, index)) < 0) {
76  printf("l1io_read: Failed in SDselect for item %s\n",
77  namelist[i]);
78  return -1;
79  }
80 
81  /*
82  * now, get the size information of the data item
83  */
84  if (SDgetinfo(sdid, name, &rank, data_dims, &numbertype,
85  &nattrs) < 0) {
86  printf("l1io_read: Failed in SDgetinfo for item %s\n",
87  namelist[i]);
88  return -1;
89  }
90 
91  /*
92  * compute the read controls
93  */
94  for (j = 0; j < rank; j++) {
95  start[j] = 0;
96  edge[j] = 1; /* test WDR */
97  edge[j] = data_dims[j];
98  }
99  start[0] = irec; /* the first dim is the row dim so set for the rec */
100  edge[0] = 1;
101 
102  /*
103  * set the pointer to read into for the 8 sds arrays being read
104  */
105 
106  switch (i) {
107  case 0: /* This is the 10 channels of 2-byte values */
108  case 1:
109  case 2:
110  case 3:
111  case 4:
112  case 5:
113  case 6:
114  case 7:
115  case 8:
116  case 9:
117  {
118  ptr = (void *) i2temp;
119  break;
120  }
121  case 10: /* This is the 2 channels of byte data */
122  case 11:
123  {
124  ptr = (void *) i1temp;
125  break;
126  }
127  case 12:
128  {
129  ptr = (void *) l2_flags;
130  break;
131  }
132  case 13: /* "orb_vec" */
133  {
134  ptr = (void *) (nav->orb_vec);
135  break;
136  }
137  case 14: /* "l_vert" */
138  {
139  ptr = (void *) (nav->l_vert);
140  break;
141  }
142  case 15: /* "sun_ref" */
143  {
144  ptr = (void *) (nav->sun_ref);
145  break;
146  }
147  case 16: /* "att_ang" */
148  {
149  ptr = (void *) (nav->att_ang);
150  break;
151  }
152  case 17: /* "sen_mat" */
153  {
154  ptr = (void *) (nav->sen_mat);
155  break;
156  }
157  case 18: /* "scan_ell" */
158  {
159  ptr = (void *) (nav->scan_ell);
160  break;
161  }
162  case 19: /* "nflag" */
163  {
164  ptr = (void *) (nav->nflag);
165  break;
166  }
167  }
168  /*
169  * read the data
170  */
171  if (SDreaddata(sdid, start, NULL, edge, ptr) < 0)
172  /* if( SDreaddata( sdid, start, stride, edge, ptr ) < 0 ) */ {
173  printf("l2io_read: failure to read data for item %s\n", namelist[i]);
174  return -1;
175  }
176  /*
177  * for the data that needs to be scaled to floats, do the work here
178  */
179  if (i < 12) {
180  if (i < 10) /* do the 2 byte values here */ {
181  for (ipix = 0; ipix < 248; ipix++) {
182  *(data + i + 12 * ipix) =
183  l2_bias[i] + l2_slope[i] * i2temp[ipix];
184  }
185  } else /* do the 1 byte values here */ {
186  for (ipix = 0; ipix < 248; ipix++) {
187  *(data + i + 12 * ipix) =
188  l2_bias[i] + l2_slope[i] * i1temp[ipix];
189  }
190  }
191  }
192  }
193  /*
194  * free that temp space
195  */
196  free(i2temp);
197  free(i1temp);
198  return 0;
199 }
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
integer, parameter int16
Definition: cubeio.f90:3
int j
Definition: decode_rs.h:73
#define NULL
Definition: decode_rs.h:63
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
int32 l2io_read(l1info_struct l1info, int irec, float *data, int16 *l2_flags, navblockType *nav)
Definition: l2io_read.c:5
Extra metadata that will be written to the HDF4 file l2prod rank
int i
Definition: decode_rs.h:71