OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_l3m.c
Go to the documentation of this file.
1 #include "map.h"
2 #include "mapproto.h"
3 #include "mapattr.h"
4 #include <hdf.h>
5 #include <mfhdf.h>
6 #include "hdf5.h"
7 
8 uint8_t isHDF5;
9 
10 /*-----------------------------------------------------------------------------
11 
12  Function: get_l3m
13 
14  Returns: intn (status)
15  The return code is FAIL (-1) if an error occurs, SUCCEED (0)
16  otherwise.
17 
18  Description:
19  The function get_l3m.c reads a level 3 Standard Map Image (SMI)
20  file with the file name given by l3m_path. Level 3 SMI file meta
21  data, palette, data and calibration information will be retrieved.
22  See "INTERFACE SPECIFICATIONS FOR SeaWiFS OPERATIONAL PRODUCT INPUT
23  AND OUTPUT SOFTWARE" (By Fred Patt, Jim Firestone, and Mike Darzi)
24  and "SeaWiFS Level 3 Standard Map CDL" (By Fred Patt) for details.
25 
26  Arguments: (in calling order)
27  Type Name I/O Description
28  ---- ---- --- -----------
29  char * l3m_path I directory path & file name for SMI product
30  int16 syear O data start time year (from l3 bin product)
31  int16 sday O data start time day-of-year
32  int32 smsec O data start time milliseconds-of-day
33  int16 eyear O data end time year; read from l3 bin product
34  int16 eday O data end day-of-year
35  int16 emsec O data end time milliseconds-of-day
36  char * prod_type O binning period description(scene, day.....)
37  char * l3m_name O name of the geophysical parameter to which
38  l3m_data corresponds
39  uint8 * l3m_data O image data for parameter l3m_name
40  uint8 * palette O RGB wts for each of 256 gray-levels of the
41  l3m_data byte values
42  struct * meta_l3m O structure containing station info, product
43  name, input files, ptime, proc_con, proc_log,
44  parameter info.
45 
46  Notes:
47 
48  Modification history:
49  Programmer Organization Date Description of change
50  -------------- ------------ -------- ---------------------
51  Lakshmi Kumar Hughes STX 12/16/93 Original development
52  Lakshmi Kumar Hughes STX 08/30/94 Revised version
53  Lakshmi Kumar Hughes STX 05/18/95 Modified code for access
54  ing flag_use as string
55  Lakshmi Kumar Hughes STX 09/28/95 Added orbit as output arg
56  (see V4.4 I/O Specs.)
57  Lakshmi Kumar Hughes STX 10/27/95 Read "Start Orbit" &
58  "End Orbit" global attrs.
59  Lakshmi Kumar Hughes STX 06/18/96 Changed defn. of MAX to
60  MAXVAL inorder to remove
61  compile time warning
62  Lakshmi Kumar Hughes STX 12/11/96 Removed orbit from inter
63  face. It is stored in
64  meta_l3m structure
65  Also removed non-ANSI
66  declarations
67  Joel Gales Futuretech 09/27/13 Removed netcdf code
68  HDF5 calls can be used
69  for NETCDF4 files
70  -----------------------------------------------------------------------------*/
71 
72 int32_t get_l3m(char *l3m_path, int16_t *syear, int16_t *sday, int32_t *smsec,
73  int16_t *eyear, int16_t *eday, int32_t *emsec, char *prod_type,
74  char *l3m_name, uint8_t *l3m_data, unsigned char *palette,
75  meta_struct *meta_l3m) {
76 
77  int i;
78  int32 fid, sdfid, sdsid, dimsizes[2], start[2];
79  int32 rank = 2, nattrs, numbertype, index = 0;
80  char name[MAXVAL];
81  size_t buf_size = 255;
82  hid_t h5fid, dataset, datatype, filespace, grp0, attr, atype, atype_mem;
83  hsize_t dims[2];
84  hsize_t num_obj;
85  H5O_info_t infobuf;
86 
87  start[0] = start[1] = 0;
88 
89  if (H5Fis_hdf5(l3m_path)) {
90  isHDF5 = 1;
91  h5fid = H5Fopen(l3m_path, H5F_ACC_RDONLY, H5P_DEFAULT);
92  sdfid = h5fid;
93  } else {
94  isHDF5 = 0;
95  sdfid = SDstart(l3m_path, DFACC_RDONLY);
96  fid = Hopen(l3m_path, DFACC_RDONLY, 0);
97  }
98 
99  /* read global attributes */
100  if (meta_l3m != NULL) {
101 
102  if (isHDF5 == 1) {
103  H5E_auto_t old_func;
104  void *old_client_data;
105  H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
106  H5Eset_auto(H5E_DEFAULT, NULL, NULL); // Turn off error handling
107  H5Gget_num_objs(h5fid, &num_obj);
108  index = -1;
109  for (i = 0; i < num_obj; i++) {
110  H5Gget_objname_by_idx(h5fid, i, name, 80);
111  H5Oget_info_by_name(h5fid, name, &infobuf, H5O_INFO_BASIC, H5P_DEFAULT);
112  if (infobuf.type == H5O_TYPE_DATASET) {
113 
114  if ((strcmp("lon", name) != 0) && (strcmp("lat", name) != 0)
115  && (strcmp("eightbitcolor", name) != 0)
116  && (strcmp("palette", name) != 0)
117  && (strcmp("rgb", name) != 0)
118  && (strstr(name, "qual") == NULL)
119  ) {
120  index = i;
121  break;
122  }
123  }
124  }
125  // Restore previous error handler
126  H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
127  dataset = H5Dopen1(h5fid, name);
128 
129  datatype = H5Dget_type(dataset);
130  filespace = H5Dget_space(dataset);
131  H5Sget_simple_extent_dims(filespace, dims, NULL);
132  meta_l3m->nrows = dims[0];
133  meta_l3m->ncols = dims[1];
134  numbertype = datatype;
135  H5Sclose(filespace);
136  H5Dclose(dataset);
137 
138  grp0 = H5Gopen1(h5fid, "/");
139  H5Oget_info(grp0, &infobuf, H5O_INFO_NUM_ATTRS);
140  char string_out[80];
141  H5T_class_t type_class;
142  for (i = 0; i < infobuf.num_attrs; i++) {
143  attr = H5Aopen_by_idx(grp0, "/", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t) i, H5P_DEFAULT, H5P_DEFAULT);
144  H5Aget_name(attr, buf_size, name);
145  atype = H5Aget_type(attr);
146  type_class = H5Tget_class(atype);
147  if (type_class == H5T_FLOAT) {
148  atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND);
149  if ((strcmp("suggested_image_scaling_minimum", name) == 0)
150  || (strcmp("Suggested Image Scaling Minimum", name) == 0)) {
151  H5Aread(attr, atype_mem, &meta_l3m->scaled_data_min);
152  }
153  if ((strcmp("suggested_image_scaling_maximum", name) == 0)
154  || (strcmp("Suggested Image Scaling Maximum", name) == 0)) {
155  H5Aread(attr, atype_mem, &meta_l3m->scaled_data_max);
156  }
157  H5Aread(attr, atype_mem, string_out);
158  } else if (type_class == H5T_STRING) {
159  atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND);
160  if ((strcmp("suggested_image_scaling_type", name) == 0) ||
161  (strcmp("Suggested Image Scaling Type", name) == 0)) {
162  if ((meta_l3m->scaled_data_type = (char *) malloc(
163  sizeof (char) * 7 + 1)) == NULL)
164  return FAIL;
165  H5Aread(attr, atype, meta_l3m->scaled_data_type);
166  }
167  }
168  }
169 
170  H5Aclose(attr);
171  H5Gclose(grp0);
172  } else {
173  // HDF4
174  if ((read_meta(sdfid, meta_l3m)) < 0)
175  return FAIL;
176 
177  *syear = meta_l3m->syear;
178  *sday = meta_l3m->sday;
179  *smsec = meta_l3m->smsec;
180  *eyear = meta_l3m->eyear;
181  *eday = meta_l3m->eday;
182  *emsec = meta_l3m->emsec;
183 
184  if (prod_type != NULL)
185  strcpy(prod_type, meta_l3m->prodtype);
186 
187  if (l3m_name != NULL)
188  strcpy(l3m_name, meta_l3m->parameter);
189 
190  if ((sdsid = SDselect(sdfid, 0)) < 0)
191  return FAIL;
192  if ((SDgetinfo(sdsid, name, &rank, dimsizes, &numbertype, &nattrs))
193  < 0)
194  return FAIL;
195  SDendaccess(sdsid);
196  }
197 
198  meta_l3m->bintype = numbertype;
199  }
200 
201  /* read SDS */
202  if (l3m_data != NULL) {
203 
204  if (strcmp(l3m_name, "l3m_qual") == 0)
205  index = 1;
206 
207  if (isHDF5 == 1) {
208  H5E_auto_t old_func;
209  void *old_client_data;
210  H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
211  H5Eset_auto(H5E_DEFAULT, NULL, NULL); // Turn off error handling
212  H5Gget_num_objs(h5fid, &num_obj);
213  index = -1;
214 
215  if (strcmp(l3m_name, "l3m_qual") != 0) {
216  for (i = 0; i < num_obj; i++) {
217  H5Gget_objname_by_idx(h5fid, i, name, 80);
218  H5Oget_info_by_name(h5fid, name, &infobuf, H5O_INFO_BASIC, H5P_DEFAULT);
219  if (infobuf.type == H5O_TYPE_DATASET) {
220 
221  if ((strcmp("lon", name) != 0) && (strcmp("lat", name) != 0)
222  && (strcmp("eightbitcolor", name) != 0)
223  && (strcmp("palette", name) != 0)
224  && (strcmp("rgb", name) != 0)
225  && (strstr(name, "qual") == NULL)) {
226  index = i;
227  break;
228  }
229  }
230  }
231  } else {
232  for (i = 0; i < num_obj; i++) {
233  H5Gget_objname_by_idx(h5fid, i, name, 80);
234  H5Oget_info_by_name(h5fid, name, &infobuf, H5O_INFO_BASIC, H5P_DEFAULT);
235  if (infobuf.type == H5O_TYPE_DATASET) {
236  if ((strstr(name, "qual")) != NULL) {
237  index = i;
238  break;
239  }
240  }
241  }
242  }
243  // Restore previous error handler
244  H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
245 
246  if (index >= 0) {
247  dataset = H5Dopen1(h5fid, name);
248  } else {
249  H5Fclose(h5fid);
250  return 0;
251  }
252 
253  datatype = H5Dget_type(dataset);
254  sdsid = dataset;
255  if ((H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
256  l3m_data)) < 0)
257  return FAIL;
258 
259  H5Dclose(dataset);
260  } else {
261  if ((sdsid = SDselect(sdfid, index)) < 0)
262  return FAIL;
263 
264  if ((SDgetinfo(sdsid, name, &rank, dimsizes, &numbertype, &nattrs))
265  < 0)
266  return FAIL;
267 
268  if ((SDreaddata(sdsid, start, NULL, dimsizes, (VOIDP) l3m_data))
269  < 0)
270  return FAIL;
271 
272  SDendaccess(sdsid);
273  }
274  }
275 
276  /* read palette */
277  if (isHDF5 && palette != NULL) {
278  dataset = H5Dopen1(h5fid, "palette");
279  datatype = H5Dget_type(dataset);
280  sdsid = dataset;
281  if ((H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, palette))
282  < 0)
283  return FAIL;
284  H5Dclose(dataset);
285  } else {
286  if (palette != NULL) {
287  if ((DFPgetpal(l3m_path, (VOIDP) palette)) < 0)
288  return FAIL;
289  }
290  }
291 
292  /* close down interfaces and close file */
293  if (isHDF5 == 1) {
294  H5Fclose(h5fid);
295  } else {
296  SDend(sdfid);
297  Hclose(fid);
298  }
299 
300  return SUCCEED;
301 }
302 
303 /*-----------------------------------------------------------------------------
304  Function: read_meta
305 
306  Returns: int32 (status)
307  The return code is a negative value if any error occurs, otherwise,
308  returns 0.
309 
310  Description:
311  The function read_meta reads all the global attributes from the given
312  map file
313 
314  Parameters: (in calling order)
315  Type Name I/O Description
316  ---- ---- --- -----------
317  int32 sdfid I ID req to access HDF SDS interface
318  meta_struct *meta_l3m O Product meta data passed to the calling
319  function
320  Modification history:
321  Programmer Organization Date Description of change
322  -------------- ------------ -------- ---------------------
323  Lakshmi Kumar Hughes STX 11/23/94 Original development
324  Lakshmi Kumar Hughes STX 02/27/94 Added code to read the new global
325  attrs measure, flags, max & min
326  (I/O specs V4.2 & product specs 2.6)
327  ----------------------------------------------------------------------------*/
328 int32_t read_meta(int32_t sdfid, meta_struct *meta_l3m) {
329  int32_t nt, count;
330 
331  /**** read global attribute "product_name" */
332  if ((getattrsz(sdfid, L3M_PNAME, &nt, &count)) < 0)
333  return FAIL;
334  if ((meta_l3m->pname = (char *) malloc(sizeof (char) * count + 1)) == NULL)
335  return FAIL;
336  if ((rdattr(sdfid, L3M_PNAME, (VOIDP *) meta_l3m->pname)) < 0)
337  return FAIL;
338  meta_l3m->pname[count] = 0;
339 
340  /**** read global attribute "title" */
341  if ((getattrsz(sdfid, L3M_TITLE, &nt, &count)) < 0)
342  return FAIL;
343  if ((meta_l3m->title = (char *) malloc(sizeof (char) * count + 1)) == NULL)
344  return FAIL;
345  if ((rdattr(sdfid, L3M_TITLE, (VOIDP *) meta_l3m->title)) < 0)
346  return FAIL;
347  meta_l3m->title[count] = 0;
348 
349  /**** read global attribute "project" */
350  if ((getattrsz(sdfid, L3M_DCENTER, &nt, &count)) >= 0) {
351  if ((meta_l3m->dcenter = (char *) malloc(sizeof (char) * count + 1))
352  == NULL)
353  return FAIL;
354  if ((rdattr(sdfid, L3M_DCENTER, (VOIDP *) meta_l3m->dcenter)) < 0)
355  return FAIL;
356  meta_l3m->dcenter[count] = 0;
357  } else
358  meta_l3m->dcenter = 0;
359 
360  /**** read global attribute "mission" */
361  if ((getattrsz(sdfid, L3M_MISSION, &nt, &count)) >= 0) {
362  if ((meta_l3m->mission = (char *) malloc(sizeof (char) * count + 1))
363  == NULL)
364  return FAIL;
365  if ((rdattr(sdfid, L3M_MISSION, (VOIDP *) meta_l3m->mission)) < 0)
366  return FAIL;
367  meta_l3m->mission[count] = 0;
368  } else
369  meta_l3m->mission = 0;
370 
371  /**** read global attribute "sensor" */
372  if ((getattrsz(sdfid, L3M_SENSOR_NAME, &nt, &count)) >= 0) {
373  if ((meta_l3m->sensor_name = (char *) malloc(sizeof (char) * count + 1))
374  == NULL)
375  return FAIL;
376  if ((rdattr(sdfid, L3M_SENSOR_NAME, (VOIDP *) meta_l3m->sensor_name))
377  < 0)
378  return FAIL;
379  meta_l3m->sensor_name[count] = 0;
380  } else
381  meta_l3m->sensor_name = 0;
382 
383  /**** read global attribute "Data Type" */
384  if ((getattrsz(sdfid, L3M_PRODTYPE, &nt, &count)) >= 0) {
385  if ((meta_l3m->prodtype = (char *) malloc(sizeof (char) * count + 1))
386  == NULL)
387  return FAIL;
388  if ((rdattr(sdfid, L3M_PRODTYPE, (VOIDP *) meta_l3m->prodtype)) < 0)
389  return FAIL;
390  meta_l3m->prodtype[count] = 0;
391  } else
392  meta_l3m->prodtype = 0;
393 
394  /**** read global attribute "Replacement Flag" */
395  if ((getattrsz(sdfid, L3M_REPLACE, &nt, &count)) >= 0) {
396  if ((meta_l3m->replace = (char *) malloc(sizeof (char) * count + 1))
397  == NULL)
398  return FAIL;
399  if ((rdattr(sdfid, L3M_REPLACE, (VOIDP *) meta_l3m->replace)) < 0)
400  return FAIL;
401  meta_l3m->replace[count] = 0;
402  } else
403  meta_l3m->replace = 0;
404 
405  /**** read global attribute "Software ID" */
406  if ((getattrsz(sdfid, L3M_SOFTID, &nt, &count)) >= 0) {
407  if ((meta_l3m->softid = (char *) malloc(sizeof (char) * count + 1))
408  == NULL)
409  return FAIL;
410  if ((rdattr(sdfid, L3M_SOFTID, (VOIDP *) meta_l3m->softid)) < 0)
411  return FAIL;
412  meta_l3m->softid[count] = 0;
413  } else
414  meta_l3m->softid = 0;
415 
416  /**** read global attribute "Software Name" */
417  if ((getattrsz(sdfid, L3M_SOFTNM, &nt, &count)) >= 0) {
418  if ((meta_l3m->softnm = (char *) malloc(sizeof (char) * count + 1))
419  == NULL)
420  return FAIL;
421  if ((rdattr(sdfid, L3M_SOFTNM, (VOIDP *) meta_l3m->softnm)) < 0)
422  return FAIL;
423  meta_l3m->softnm[count] = 0;
424  } else
425  meta_l3m->softnm = 0;
426 
427  /**** read global attribute "Software Version" */
428  if ((getattrsz(sdfid, L3M_SOFTVER, &nt, &count)) >= 0) {
429  if ((meta_l3m->softver = (char *) malloc(sizeof (char) * count + 1))
430  == NULL)
431  return FAIL;
432  if ((rdattr(sdfid, L3M_SOFTVER, (VOIDP *) meta_l3m->softver)) < 0)
433  return FAIL;
434  meta_l3m->softver[count] = 0;
435  } else
436  meta_l3m->softver = 0;
437 
438  /**** read global attribute "Processing Time" */
439  if ((getattrsz(sdfid, L3M_PTIME, &nt, &count)) < 0)
440  return FAIL;
441  if ((meta_l3m->ptime = (char *) malloc(sizeof (char) * count + 1)) == NULL)
442  return FAIL;
443  if ((rdattr(sdfid, L3M_PTIME, (VOIDP *) meta_l3m->ptime)) < 0)
444  return FAIL;
445  meta_l3m->ptime[count] = 0;
446 
447  /**** read global attribute "Input Files" */
448  if ((getattrsz(sdfid, L3M_INFILES, &nt, &count)) < 0)
449  return FAIL;
450  if ((meta_l3m->infiles = (char *) malloc(sizeof (char) * count + 1)) == NULL)
451  return FAIL;
452  if ((rdattr(sdfid, L3M_INFILES, (VOIDP *) meta_l3m->infiles)) < 0)
453  return FAIL;
454  meta_l3m->infiles[count] = 0;
455 
456  /**** read global attribute "Processing Control" */
457  if ((getattrsz(sdfid, L3M_PROCCON, &nt, &count)) < 0)
458  return FAIL;
459  if ((meta_l3m->proccon = (char *) malloc(sizeof (char) * count + 1)) == NULL)
460  return FAIL;
461  if ((rdattr(sdfid, L3M_PROCCON, (VOIDP *) meta_l3m->proccon)) < 0)
462  return FAIL;
463  meta_l3m->proccon[count] = 0;
464 
465  /**** read global attribute "Processing Log" */
466  /*
467  if ((getattrsz(sdfid, L3M_PROCLOG, &nt, &count)) < 0) return FAIL;
468  if ((meta_l3m->proclog = (char *) malloc (sizeof(char) * count + 1)) == NULL)
469  return FAIL;
470  if ((rdattr(sdfid, L3M_PROCLOG, (VOIDP *)meta_l3m->proclog))<0) return FAIL;
471  meta_l3m->proclog[count] = 0;
472  */
473 
474  /**** read global attribute "L2 Flag Usage" */
475  /*
476  if ((getattrsz(sdfid, L3M_FLAG_USE, &nt, &count)) < 0) return FAIL;
477  if ((meta_l3m->flag_use =(char *)malloc(sizeof(char) * count + 1)) == NULL)
478  return FAIL;
479  if ((rdattr(sdfid, L3M_FLAG_USE, (VOIDP *)meta_l3m->flag_use))<0)
480  return FAIL;
481  */
482 
483  /**** read global attribute "L2 Engineering Quality Usage" */
484  /*
485  if ((rdattr(sdfid, L3M_ENG_Q_USE, (VOIDP *)&meta_l3m->eng_q_use)) < 0)
486  return FAIL;
487  */
488 
489  /**** read global attribute "time_coverage_start" */
490  if ((getattrsz(sdfid, L3M_STIME, &nt, &count)) < 0)
491  return FAIL;
492  if ((meta_l3m->stime = (char *) malloc(sizeof (char) * count + 1)) == NULL)
493  return FAIL;
494  if ((rdattr(sdfid, L3M_STIME, (VOIDP *) meta_l3m->stime)) < 0)
495  return FAIL;
496  meta_l3m->stime[count] = 0;
497 
498  /**** read global attribute "time_coverage_end" */
499  if ((getattrsz(sdfid, L3M_ETIME, &nt, &count)) < 0)
500  return FAIL;
501  if ((meta_l3m->etime = (char *) malloc(sizeof (char) * count + 1)) == NULL)
502  return FAIL;
503  if ((rdattr(sdfid, L3M_ETIME, (VOIDP *) meta_l3m->etime)) < 0)
504  return FAIL;
505  meta_l3m->etime[count] = 0;
506 
507  /**** read global attribute "Orbit" */
508  // if ((rdattr(sdfid, L3M_ORBIT, (VOIDP *) &meta_l3m->orbit)) < 0)
509  // return FAIL;
510 
511  /**** read global attribute "Start Orbit" */
512  if ((rdattr(sdfid, L3M_SORBIT, (VOIDP *) & meta_l3m->start_orb)) < 0)
513  return FAIL;
514 
515  /**** read global attribute "End Orbit" */
516  if ((rdattr(sdfid, L3M_EORBIT, (VOIDP *) & meta_l3m->end_orb)) < 0)
517  return FAIL;
518 
519  /**** read global attribute "Map Projection" */
520  if ((getattrsz(sdfid, L3M_MAPPROJ, &nt, &count)) < 0)
521  return FAIL;
522  if ((meta_l3m->mapproj = (char *) malloc(sizeof (char) * count + 1)) == NULL)
523  return FAIL;
524  if ((rdattr(sdfid, L3M_MAPPROJ, (VOIDP *) meta_l3m->mapproj)) < 0)
525  return FAIL;
526  meta_l3m->mapproj[count] = 0;
527 
528  /**** read global attribute "geospatial_lat_units" */
529  if ((getattrsz(sdfid, L3M_LATUNITS, &nt, &count)) < 0)
530  return FAIL;
531  if ((meta_l3m->lat_units = (char *) malloc(sizeof (char) * count + 1))
532  == NULL)
533  return FAIL;
534  if ((rdattr(sdfid, L3M_LATUNITS, (VOIDP *) meta_l3m->lat_units)) < 0)
535  return FAIL;
536  meta_l3m->lat_units[count] = 0;
537 
538  /**** read global attribute "geospatial_lon_units" */
539  if ((getattrsz(sdfid, L3M_LONUNITS, &nt, &count)) < 0)
540  return FAIL;
541  if ((meta_l3m->lon_units = (char *) malloc(sizeof (char) * count + 1))
542  == NULL)
543  return FAIL;
544  if ((rdattr(sdfid, L3M_LONUNITS, (VOIDP *) meta_l3m->lon_units)) < 0)
545  return FAIL;
546  meta_l3m->lon_units[count] = 0;
547 
548  /**** read global attribute "Nrothernmost Latitude" */
549  if ((rdattr(sdfid, L3M_NLAT, (VOIDP *) & meta_l3m->nlat)) < 0)
550  return FAIL;
551 
552  /**** read global attribute "Southernmost Latitude" */
553  if ((rdattr(sdfid, L3M_SLAT, (VOIDP *) & meta_l3m->slat)) < 0)
554  return FAIL;
555 
556  /**** read global attribute "Westernmost Longitude" */
557  if ((rdattr(sdfid, L3M_WLON, (VOIDP *) & meta_l3m->wlon)) < 0)
558  return FAIL;
559 
560  /**** read global attribute "Easternmost Latitude" */
561  if ((rdattr(sdfid, L3M_ELON, (VOIDP *) & meta_l3m->elon)) < 0)
562  return FAIL;
563 
564  /**** read global attribute "Latitude Step" */
565  if ((rdattr(sdfid, L3M_LAT_STEP, (VOIDP *) & meta_l3m->lat_step)) < 0)
566  return FAIL;
567 
568  /**** read global attribute "Longitude Step" */
569  if ((rdattr(sdfid, L3M_LON_STEP, (VOIDP *) & meta_l3m->lon_step)) < 0)
570  return FAIL;
571 
572  /**** read global attribute "Data Bins" */
573  if ((rdattr(sdfid, L3M_DATABINS, (VOIDP *) & meta_l3m->nbins)) < 0)
574  return FAIL;
575 
576  /**** read global attribute "Number of Lines" */
577  if ((rdattr(sdfid, L3M_NROWS, (VOIDP *) & meta_l3m->nrows)) < 0)
578  return FAIL;
579 
580  /**** read global attribute "Number of Columns" */
581  if ((rdattr(sdfid, L3M_NCOLS, (VOIDP *) & meta_l3m->ncols)) < 0)
582  return FAIL;
583 
584  /**** read global attribute "Parameter" */
585  if ((getattrsz(sdfid, L3M_PARAMETER, &nt, &count)) < 0)
586  return FAIL;
587  if ((meta_l3m->parameter = (char *) malloc(sizeof (char) * count + 1))
588  == NULL)
589  return FAIL;
590  if ((rdattr(sdfid, L3M_PARAMETER, (VOIDP *) meta_l3m->parameter)) < 0)
591  return FAIL;
592  meta_l3m->parameter[count] = 0;
593 
594  /**** read global attribute "Measure" */
595  if ((getattrsz(sdfid, L3M_MEASURE, &nt, &count)) < 0)
596  return FAIL;
597  if ((meta_l3m->measure = (char *) malloc(sizeof (char) * count + 1)) == NULL)
598  return FAIL;
599  if ((rdattr(sdfid, L3M_MEASURE, (VOIDP *) meta_l3m->measure)) < 0)
600  return FAIL;
601  meta_l3m->measure[count] = 0;
602 
603  /**** read global attribute "Units" */
604  if ((getattrsz(sdfid, L3M_UNITS, &nt, &count)) < 0)
605  return FAIL;
606  if ((meta_l3m->units = (char *) malloc(sizeof (char) * count + 1)) == NULL)
607  return FAIL;
608  if ((rdattr(sdfid, L3M_UNITS, (VOIDP *) meta_l3m->units)) < 0)
609  return FAIL;
610  meta_l3m->units[count] = 0;
611 
612  /**** read global attribute "Scaling" */
613  if ((getattrsz(sdfid, L3M_SCALING, &nt, &count)) < 0)
614  return FAIL;
615  if ((meta_l3m->scaling_type = (char *) malloc(sizeof (char) * count + 1))
616  == NULL)
617  return FAIL;
618  if ((rdattr(sdfid, L3M_SCALING, (VOIDP *) meta_l3m->scaling_type)) < 0)
619  return FAIL;
620  meta_l3m->scaling_type[count] = 0;
621 
622  /**** read global attribute "Scaling Equation" */
623  if ((getattrsz(sdfid, L3M_SC_EQN, &nt, &count)) < 0)
624  return FAIL;
625  if ((meta_l3m->scaling_eqn = (char *) malloc(sizeof (char) * count + 1))
626  == NULL)
627  return FAIL;
628  if ((rdattr(sdfid, L3M_SC_EQN, (VOIDP *) meta_l3m->scaling_eqn)) < 0)
629  return FAIL;
630  meta_l3m->scaling_eqn[count] = 0;
631 
632 #if 0
633  /**** read global attribute "Slope" */
634  if ((rdattr(sdfid, L3M_SLOPE, (VOIDP *) & meta_l3m->slope)) < 0) return FAIL;
635 
636  /**** read global attribute "Intercept" */
637  if ((rdattr(sdfid, L3M_INTERCEPT, (VOIDP *) & meta_l3m->intercept)) < 0)
638  return FAIL;
639 #endif
640 
641  /**** read global attribute "Data Minimum" */
642  if ((rdattr(sdfid, L3M_MIN, (VOIDP *) & meta_l3m->data_min)) < 0)
643  return FAIL;
644 
645  /**** read global attribute "Data Maximum" */
646  if ((rdattr(sdfid, L3M_MAX, (VOIDP *) & meta_l3m->data_max)) < 0)
647  return FAIL;
648 
649  /**** read global attribute "Scaled Data Minimum" */
650  if ((rdattr(sdfid, "Suggested Image Scaling Minimum",
651  (VOIDP *) & meta_l3m->scaled_data_min)) < 0)
652  return FAIL;
653 
654  /**** read global attribute "Scaled Data Maximum" */
655  if ((rdattr(sdfid, "Suggested Image Scaling Maximum",
656  (VOIDP *) & meta_l3m->scaled_data_max)) < 0)
657  return FAIL;
658 
659  /**** read global attribute "Scaled Data Type" */
660  if ((getattrsz(sdfid, "Suggested Image Scaling Type", &nt, &count)) < 0)
661  return FAIL;
662  if ((meta_l3m->scaled_data_type = (char *) malloc(sizeof (char) * count + 1))
663  == NULL)
664  return FAIL;
665  if ((rdattr(sdfid, "Suggested Image Scaling Type",
666  (VOIDP *) meta_l3m->scaled_data_type)) < 0)
667  return FAIL;
668  meta_l3m->scaled_data_type[count] = 0;
669 
670 #if 0
671  /**** read global attribute "Slope (8 bit)" */
672  meta_l3m->slope_8bit = 0.0;
673  rdattr(sdfid, "B2F_slope", (VOIDP *) & meta_l3m->slope_8bit);
674 
675  /**** read global attribute "Intercept (8 bit)" */
676  meta_l3m->intercept_8bit = 0.0;
677  rdattr(sdfid, "B2F_intercept", (VOIDP *) & meta_l3m->intercept_8bit);
678 #endif
679 
680  return 0;
681 }
682 
683 /*-----------------------------------------------------------------------------
684  Function: getattrsz
685 
686  Returns: int32 (status)
687  The return code is a negative value if any error occurs, otherwise,
688  returns 0.
689 
690  Description:
691  The function getattrsz passes the requested global attribute's
692  number type (data type) and the number of values
693 
694  Parameters: (in calling order)
695  Type Name I/O Description
696  ---- ---- --- -----------
697  int32 sdfid I ID req to access HDF SDS interface
698  char * attr_name I attribute name
699  int32 * nt O HDF data type
700  int32 * count O number of values in the specified attribute
701 
702  Modification history:
703  Programmer Organization Date Description of change
704  -------------- ------------ -------- ---------------------
705  Lakshmi Kumar Hughes STX 11/07/94 Original development
706 
707  ----------------------------------------------------------------------------*/
708 
709 int32 getattrsz(int32 id, char *attr_name, int32 *nt, int32 *count) {
710  int32 attrnum;
711  char name[MAXVAL];
712 
713  attrnum = SDfindattr(id, attr_name);
714  if ((SDattrinfo(id, attrnum, name, nt, count)) < 0) {
715  /*
716  printf("\ngetattrsz: Error reading attribute size of - %s\n", attr_name);
717  */
718  return FAIL;
719  }
720  return SUCCEED;
721 }
722 
723 /*-----------------------------------------------------------------------------
724  Function: rdattr
725 
726  Returns: int32 (status)
727  The return code is a negative value if any error occurs, otherwise,
728  returns 0.
729 
730  Description:
731  The function rdattr reads the requested global attribute
732 
733  Parameters: (in calling order)
734  Type Name I/O Description
735  ---- ---- --- -----------
736  int32 sdfid I ID req to access HDF SDS interface
737  char * attr_name I attribute name
738  void * buf I/O pointer to data buffer
739 
740  Modification history:
741  Programmer Organization Date Description of change
742  -------------- ------------ -------- ---------------------
743  Lakshmi Kumar Hughes STX 11/07/94 Original development
744 
745  ----------------------------------------------------------------------------*/
746 
747 int32 rdattr(int32 sdfid, char *attr_name, void *buf) {
748  int32 attrnum;
749 
750  attrnum = SDfindattr(sdfid, attr_name);
751  if ((SDreadattr(sdfid, attrnum, buf)) < 0) {
752  /*
753  printf("\nrdattr: Error reading attribute - %s\n", attr_name);
754  */
755  return FAIL;
756  }
757  return SUCCEED;
758 }
#define L3M_LATUNITS
Definition: mapattr.h:67
int32_t bintype
Definition: map.h:79
#define L3M_TITLE
Definition: mapattr.h:9
int32_t end_orb
Definition: map.h:53
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
char * proccon
Definition: map.h:35
#define L3M_SOFTVER
Definition: mapattr.h:35
float slat
Definition: map.h:58
char * softid
Definition: map.h:30
int16 eday
Definition: l1_czcs_hdf.c:17
uint8_t isHDF5
Definition: get_l3m.c:8
#define L3M_NLAT
Definition: mapattr.h:71
#define L3M_WLON
Definition: mapattr.h:75
char * scaling_eqn
Definition: map.h:70
char * scaled_data_type
Definition: map.h:76
#define L3M_NCOLS
Definition: mapattr.h:92
float intercept
Definition: map.h:73
#define L3M_INFILES
Definition: mapattr.h:37
float wlon
Definition: map.h:60
float lon_step
Definition: map.h:62
char * softnm
Definition: map.h:31
#define L3M_SC_EQN
Definition: mapattr.h:99
char * replace
Definition: map.h:29
#define FAIL
Definition: ObpgReadGrid.h:18
#define MAXVAL
Definition: l3stat.h:13
#define NULL
Definition: decode_rs.h:63
int16_t syear
Definition: map.h:45
char * units
Definition: map.h:68
#define L3M_MAX
Definition: mapattr.h:106
#define L3M_LAT_STEP
Definition: mapattr.h:79
char * etime
Definition: map.h:44
#define L3M_SORBIT
Definition: mapattr.h:60
#define L3M_MISSION
Definition: mapattr.h:19
#define L3M_LON_STEP
Definition: mapattr.h:80
#define L3M_SCALING
Definition: mapattr.h:96
int32_t nrows
Definition: map.h:64
#define L3M_LONUNITS
Definition: mapattr.h:69
char * pname
Definition: map.h:17
char * lat_units
Definition: map.h:55
int32_t smsec
Definition: map.h:47
char * prodtype
Definition: map.h:28
int16 eyear
Definition: l1_czcs_hdf.c:17
#define L3M_DCENTER
Definition: mapattr.h:11
int syear
Definition: l1_czcs_hdf.c:15
char * dcenter
Definition: map.h:19
char * mapproj
Definition: map.h:54
#define L3M_MEASURE
Definition: mapattr.h:93
int32 smsec
Definition: l1_czcs_hdf.c:16
#define L3M_REPLACE
Definition: mapattr.h:32
#define L3M_PNAME
Definition: mapattr.h:8
int32_t emsec
Definition: map.h:50
char * parameter
Definition: map.h:66
int sday
Definition: l1_czcs_hdf.c:15
#define L3M_MIN
Definition: mapattr.h:105
float scaled_data_max
Definition: map.h:75
int32_t ncols
Definition: map.h:65
char * measure
Definition: map.h:67
int16_t eyear
Definition: map.h:48
float lat_step
Definition: map.h:61
float elon
Definition: map.h:59
#define L3M_DATABINS
Definition: mapattr.h:90
int32 getattrsz(int32 id, char *attr_name, int32 *nt, int32 *count)
Definition: get_l3m.c:709
#define L3M_NROWS
Definition: mapattr.h:91
int32_t read_meta(int32_t sdfid, meta_struct *meta_l3m)
Definition: get_l3m.c:328
char * softver
Definition: map.h:32
char * title
Definition: map.h:18
#define L3M_PROCCON
Definition: mapattr.h:38
#define L3M_SOFTNM
Definition: mapattr.h:34
float slope
Definition: map.h:72
char * ptime
Definition: map.h:33
but the philosophy of the MODIS L1 routines is that the output granule must be if it contains even a single packet of useable data Some of the spacecraft ancillary data in L0 datasets is available only on a cycle that repeates every seconds MOD_PR01 therefore looks backwards up to for such packets If the seconds preceeding the start of an MOD_PR01 run are covered by a different L0 dataset
Definition: MOD_PR01_pr.txt:33
int32_t get_l3m(char *l3m_path, int16_t *syear, int16_t *sday, int32_t *smsec, int16_t *eyear, int16_t *eday, int32_t *emsec, char *prod_type, char *l3m_name, uint8_t *l3m_data, unsigned char *palette, meta_struct *meta_l3m)
Definition: get_l3m.c:72
int16_t eday
Definition: map.h:49
int32 rdattr(int32 sdfid, char *attr_name, void *buf)
Definition: get_l3m.c:747
float data_max
Definition: map.h:78
int32_t nbins
Definition: map.h:63
float data_min
Definition: map.h:77
int32 emsec
Definition: l1_czcs_hdf.c:18
#define L3M_STIME
Definition: mapattr.h:51
char * sensor_name
Definition: map.h:26
#define L3M_ETIME
Definition: mapattr.h:52
#define L3M_SLOPE
Definition: mapattr.h:103
#define L3M_UNITS
Definition: mapattr.h:95
char * mission
Definition: map.h:23
char * infiles
Definition: map.h:34
Extra metadata that will be written to the HDF4 file l2prod rank
#define L3M_PARAMETER
Definition: mapattr.h:94
char * scaling_type
Definition: map.h:69
float scaled_data_min
Definition: map.h:74
#define L3M_MAPPROJ
Definition: mapattr.h:65
#define L3M_ELON
Definition: mapattr.h:77
#define L3M_EORBIT
Definition: mapattr.h:61
int i
Definition: decode_rs.h:71
#define L3M_SOFTID
Definition: mapattr.h:33
int16_t sday
Definition: map.h:46
float nlat
Definition: map.h:57
#define L3M_INTERCEPT
Definition: mapattr.h:104
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
char * lon_units
Definition: map.h:56
char * stime
Definition: map.h:43
#define L3M_SLAT
Definition: mapattr.h:73
int32_t start_orb
Definition: map.h:52
#define L3M_PRODTYPE
Definition: mapattr.h:30
#define L3M_SENSOR_NAME
Definition: mapattr.h:24
int count
Definition: decode_rs.h:79
#define L3M_PTIME
Definition: mapattr.h:36