OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1_hdf_generic_write.c
Go to the documentation of this file.
1 /* =========================================================== */
2 /* Module l1_hdf_generic_write.c */
3 /* */
4 /* Functions to open and write a multi-sensor (generic) l1 */
5 /* file in HDF format. */
6 /* */
7 /* Written By: */
8 /* B. A. Franz, SAIC GSC, SIMBIOS Project, January 1999. */
9 /* */
10 /* Modified By: */
11 /* J. G. Gales, Futuretech, SIMBIOS Project, Sept. 1999. */
12 /* Generate standard L1B product */
13 /* Gene Eplee, SAIC GSC, SeaWiFS Project, December 2000. */
14 /* Update time correction and mirror side */
15 /* factors. */
16 /* Gene Eplee, SAIC, SeaWiFS Project, March 2004. */
17 /* Convert time correction and mirror side */
18 /* factors to simultaneous exponentials. */
19 /* =========================================================== */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <libgen.h>
24 #include <string.h>
25 #include <time.h>
26 #include <math.h>
27 
28 #include "l12_proto.h"
29 
30 #include "hdf_utils.h"
31 #include <timeutils.h>
32 #include "mfhdf.h"
33 
34 /* Global variables to facilitate communication
35 between some of the functions defined in this file */
36 static int32 sd_id;
37 static int32 numScans;
38 static int32 numPixels;
39 static int32 numBands;
40 static int32 spix;
41 static int32 cpix;
42 static int32 epix;
43 static int32 dpix;
44 static int32 cscan;
45 static int32 nctl;
46 static int32 *ictl;
47 static int32 *jctl;
48 static int32 sensorID;
49 static int32_t evalmask;
50 int32 *wavelength;
51 char rad_name[8];
52 
53 int32 get_ctl_pts(int32 npix, int32 nscans, int32 ictl[], int32 jctl[]) {
54  int32_t i;
55 
56  for (i = 0; i < nscans; i++)
57  jctl[i] = i + 1;
58 
59  for (i = 0; i < npix; i++)
60  ictl[i] = i + 1;
61 
62  return (npix);
63 }
64 
65 /* -------------------------------------------------------- */
66 /* Assign SDSes to Vgroups */
67 
68 /* -------------------------------------------------------- */
69 int MakeVgroupsL1(filehandle *file) {
70 
71  int32 i;
72  int32 h_id;
73  int32 v_id;
74  int32 sd_id = file->sd_id;
75 
76  /* Do we have the extra meta-data for SeaWiFS */
77  int seawifs_meta = 0;
78  if (sensorID == SEAWIFS) {
79  int32 sds_id;
80  if (sd_select(sd_id, "scan_ell", &sds_id) == 0)
81  seawifs_meta = 1;
82  }
83 
84  h_id = Hopen(file->name, DFACC_RDWR, 0);
85  if (h_id == FAIL) {
86  fprintf(stderr, "-E- %s line %d: Hopen() failed for file, %s.\n",
87  __FILE__, __LINE__, file->name);
88  return (HDF_FUNCTION_ERROR);
89  }
90  Vstart(h_id);
91 
92  if (seawifs_meta) {
93 
94  /* Sensor Tilt */
95  DPTB(v_attach(h_id, &v_id));
96  Vsetclass(v_id, "Per File Data");
97  Vsetname(v_id, "Sensor Tilt");
98  DPTB(AddSdsToVgroup(sd_id, v_id, "ntilts"));
99  DPTB(AddSdsToVgroup(sd_id, v_id, "tilt_flags"));
100  DPTB(AddSdsToVgroup(sd_id, v_id, "tilt_ranges"));
101  Vdetach(v_id);
102 
103  }
104 
105  /* Scan-Line Attributes */
106  PTB(v_attach(h_id, &v_id));
107  Vsetclass(v_id, "Per Scan Data");
108  Vsetname(v_id, "Scan-Line Attributes");
109  PTB(AddSdsToVgroup(sd_id, v_id, "year"));
110  PTB(AddSdsToVgroup(sd_id, v_id, "day"));
111  PTB(AddSdsToVgroup(sd_id, v_id, "msec"));
112  DPTB(AddSdsToVgroup(sd_id, v_id, "slon"));
113  DPTB(AddSdsToVgroup(sd_id, v_id, "clon"));
114  DPTB(AddSdsToVgroup(sd_id, v_id, "elon"));
115  DPTB(AddSdsToVgroup(sd_id, v_id, "slat"));
116  DPTB(AddSdsToVgroup(sd_id, v_id, "clat"));
117  DPTB(AddSdsToVgroup(sd_id, v_id, "elat"));
118  DPTB(AddSdsToVgroup(sd_id, v_id, "csol_z"));
119  Vdetach(v_id);
120 
121  /* Image Data */
122  PTB(v_attach(h_id, &v_id));
123  Vsetclass(v_id, "Per Scan Data");
124  Vsetname(v_id, "Geophysical Data");
125  for (i = 0; i < numBands; i++) {
126  sprintf(rad_name, "L_%3d", wavelength[i]);
127  PTB(AddSdsToVgroup(sd_id, v_id, rad_name));
128  }
129  Vdetach(v_id);
130 
131  /* Navigation */
132  PTB(v_attach(h_id, &v_id));
133  Vsetclass(v_id, "Per Scan Data");
134  Vsetname(v_id, "Navigation Data");
135  PTB(AddSdsToVgroup(sd_id, v_id, "longitude"));
136  PTB(AddSdsToVgroup(sd_id, v_id, "latitude"));
137  PTB(AddSdsToVgroup(sd_id, v_id, "solz"));
138  PTB(AddSdsToVgroup(sd_id, v_id, "sola"));
139  PTB(AddSdsToVgroup(sd_id, v_id, "senz"));
140  PTB(AddSdsToVgroup(sd_id, v_id, "sena"));
141  PTB(AddSdsToVgroup(sd_id, v_id, "tilt"));
142 
143  if (seawifs_meta) {
144  DPTB(AddSdsToVgroup(sd_id, v_id, "orb_vec"));
145  DPTB(AddSdsToVgroup(sd_id, v_id, "sun_ref"));
146  DPTB(AddSdsToVgroup(sd_id, v_id, "att_ang"));
147  DPTB(AddSdsToVgroup(sd_id, v_id, "sen_mat"));
148  DPTB(AddSdsToVgroup(sd_id, v_id, "scan_ell"));
149  DPTB(AddSdsToVgroup(sd_id, v_id, "nflag"));
150  }
151  Vdetach(v_id);
152 
153  Vend(h_id);
154 
155  if (Hclose(h_id) != SUCCEED) {
156  fprintf(stderr, "-E- %s line %d: Hclose(%d) failed for file, %s .\n",
157  __FILE__, __LINE__, h_id, file->name);
158  return (HDF_FUNCTION_ERROR);
159  }
160  return (LIFE_IS_GOOD);
161 }
162 
163 
164 /* -------------------------------------------------------- */
165 /* Create the level 2 SDSes for the scan-line data */
166 
167 /* -------------------------------------------------------- */
168 int32 CreateScanData(int32 np, int32 nb, int32 nscan,
169  int32 sensorID, int32 bindx[]) {
170  int32 i;
171  int32 status;
172  char longname[64];
173  int32 *wavelen;
174 
175  /* Get sensor wavelengths */
176  if (rdsensorinfo(sensorID, evalmask, "Lambda", (void **) &wavelen) != nb) {
177  printf("-E- %s: Unable to determine sensor wavelengths\n", __FILE__);
178  exit(FATAL_ERROR);
179  }
180 
181  if ((wavelength = (int32 *) calloc(nb, sizeof (int32))) == NULL) {
182  printf("-E- %s line %d : error allocating memory for l2_generic:openl2.\n",
183  __FILE__, __LINE__);
184  exit(1);
185  }
186 
187  for (i = 0; i < nb; i++)
188  wavelength[i] = wavelen[bindx[i]];
189 
190  PTB(CreateSDS(
191  sd_id, /* file id */
192  "year", /* short name */
193  "Scan year", /* long name */
194  NULL, /* standard name */
195  "years", /* units */
196  0, 0, /* valid range */
197  0, 0, /* slope */
198  DFNT_INT32, /* HDF number type */
199  1, /* rank */
200  nscan, 1, 1, /* dimension sizes */
201  "Number of Scan Lines", NULL, NULL /* dimension names */
202  ));
203 
204  PTB(CreateSDS(
205  sd_id, /* file id */
206  "day", /* short name */
207  "Scan day of year", /* long name */
208  NULL, /* standard name */
209  "days", /* units */
210  0, 0, /* valid range */
211  0, 0, /* slope */
212  DFNT_INT32, /* HDF number type */
213  1, /* rank */
214  nscan, 1, 1, /* dimension sizes */
215  "Number of Scan Lines", NULL, NULL /* dimension names */
216  ));
217 
218  PTB(CreateSDS(
219  sd_id, /* file id */
220  "msec", /* short name */
221  "Scan-line time, milliseconds of day", /* long name */
222  NULL, /* standard name */
223  "milliseconds", /* units */
224  0, 0, /* valid range */
225  0, 0, /* slope */
226  DFNT_INT32, /* HDF number type */
227  1, /* rank */
228  nscan, 1, 1, /* dimension sizes */
229  "Number of Scan Lines", NULL, NULL /* dimension names */
230  ));
231 
232  PTB(CreateSDS(
233  sd_id, /* file id */
234  "detnum", /* short name */
235  "Detector Number", /* long name */
236  NULL, /* standard name */
237  "", /* units */
238  0, 0, /* valid range */
239  0, 0, /* slope */
240  DFNT_INT8, /* HDF number type */
241  1, /* rank */
242  nscan, 1, 1, /* dimension sizes */
243  "Number of Scan Lines", NULL, NULL /* dimension names */
244  ));
245 
246  PTB(CreateSDS(
247  sd_id, /* file id */
248  "mside", /* short name */
249  "Mirror Side", /* long name */
250  NULL, /* standard name */
251  "", /* units */
252  0, 0, /* valid range */
253  0, 0, /* slope */
254  DFNT_INT8, /* HDF number type */
255  1, /* rank */
256  nscan, 1, 1, /* dimension sizes */
257  "Number of Scan Lines", NULL, NULL /* dimension names */
258  ));
259 
260  PTB(CreateSDS(
261  sd_id, /* file id */
262  "longitude", /* short name */
263  "Longitude", /* long name */
264  NULL, /* standard name */
265  "degree", /* units */
266  -180.0, 180.0, /* valid range */
267  0, 0, /* slope */
268  DFNT_FLOAT32, /* HDF number type */
269  2, /* rank */
270  nscan, np, 1, /* dimension sizes */
271  "Number of Scan Lines", "Pixels per Scan Line", NULL /* dimension names */
272  ));
273 
274  PTB(CreateSDS(
275  sd_id, /* file id */
276  "latitude", /* short name */
277  "Latitude", /* long name */
278  NULL, /* standard name */
279  "degree", /* units */
280  -90.0, 90.0, /* valid range */
281  0, 0, /* slope */
282  DFNT_FLOAT32, /* HDF number type */
283  2, /* rank */
284  nscan, np, 1, /* dimension sizes */
285  "Number of Scan Lines", "Pixels per Scan Line", NULL /* dimension names */
286  ));
287 
288  PTB(CreateSDS(
289  sd_id, /* file id */
290  "solz", /* short name */
291  "Solar zenith angle", /* long name */
292  NULL, /* standard name */
293  "degree", /* units */
294  -90.0, 90.0, /* valid range */
295  0, 0, /* slope */
296  DFNT_FLOAT32, /* HDF number type */
297  2, /* rank */
298  nscan, np, 1, /* dimension sizes */
299  "Number of Scan Lines", "Pixels per Scan Line", NULL /* dimension names */
300  ));
301 
302  PTB(CreateSDS(
303  sd_id, /* file id */
304  "sola", /* short name */
305  "Solar azimuth angle", /* long name */
306  NULL, /* standard name */
307  "degree", /* units */
308  -180.0, 180.0, /* valid range */
309  0, 0, /* slope */
310  DFNT_FLOAT32, /* HDF number type */
311  2, /* rank */
312  nscan, np, 1, /* dimension sizes */
313  "Number of Scan Lines", "Pixels per Scan Line", NULL /* dimension names */
314  ));
315 
316  PTB(CreateSDS(
317  sd_id, /* file id */
318  "senz", /* short name */
319  "Sensor zenith angle", /* long name */
320  NULL, /* standard name */
321  "degree", /* units */
322  -90.0, 90.0, /* valid range */
323  0, 0, /* slope */
324  DFNT_FLOAT32, /* HDF number type */
325  2, /* rank */
326  nscan, np, 1, /* dimension sizes */
327  "Number of Scan Lines", "Pixels per Scan Line", NULL /* dimension names */
328  ));
329 
330  PTB(CreateSDS(
331  sd_id, /* file id */
332  "sena", /* short name */
333  "Sensor azimuth angle", /* long name */
334  NULL, /* standard name */
335  "degree", /* units */
336  -180.0, 180.0, /* valid range */
337  0, 0, /* slope */
338  DFNT_FLOAT32, /* HDF number type */
339  2, /* rank */
340  nscan, np, 1, /* dimension sizes */
341  "Number of Scan Lines", "Pixels per Scan Line", NULL /* dimension names */
342  ));
343 
344  PTB(CreateSDS(
345  sd_id, /* file id */
346  "tilt", /* short name */
347  "Sensor tilt angle", /* long name */
348  NULL, /* standard name */
349  "degree", /* units */
350  -20.1, 20.1, /* valid range */
351  0, 0, /* slope */
352  DFNT_FLOAT32, /* HDF number type */
353  1, /* rank */
354  nscan, 1, 1, /* dimension sizes */
355  "Number of Scan Lines", NULL, NULL /* dimension names */
356  ));
357 
358 
359  for (i = 0; i < nb; i++) {
360 
361  sprintf(rad_name, "L_%3d", wavelength[i]);
362  sprintf(longname, "Top of atmosphere %3d nm radiance", wavelength[i]);
363 
364  PTB(CreateSDS(
365  sd_id,
366  rad_name, /* short name */
367  longname, /* long name */
368  NULL, /* standard name */
369  "mW cm^-2 um^-1 sr^-1", /* units */
370  0, 0, /* valid range */
371  0, 0, /* slope */
372  DFNT_FLOAT32, /* HDF number type */
373  2, /* rank */
374  nscan, np, 1, /* dimension sizes */
375  "Number of Scan Lines", "Pixels per Scan Line", NULL
376  /* dimension names */
377  ));
378  }
379 
380  PTB(CreateSDS(
381  sd_id, /* file id */
382  "l2_flags", /* short name */
383  "Bit masks and flags", /* long name */
384  NULL, /* standard name */
385  "", /* units */
386  0, 0, /* valid range */
387  0, 0, /* slope */
388  DFNT_INT32, /* HDF number type */
389  2, /* rank */
390  nscan, np, 1, /* dimension sizes */
391  "Number of Scan Lines", "Pixels per Scan Line", NULL
392  /* dimension names */
393  ));
394 
395  PTB(CreateSDS(
396  sd_id, /* file id */
397  "slon", /* short name */
398  "Starting Longitude", /* long name */
399  NULL, /* standard name */
400  "degree", /* units */
401  -180.0, 180.0, /* valid range */
402  0, 0, /* slope */
403  DFNT_FLOAT32, /* HDF number type */
404  1, /* rank */
405  nscan, 1, 1, /* dimension sizes */
406  "Number of Scan Lines", NULL, NULL /* dimension names */
407  ));
408 
409  PTB(CreateSDS(
410  sd_id, /* file id */
411  "clon", /* short name */
412  "Center Longitude", /* long name */
413  NULL, /* standard name */
414  "degree", /* units */
415  -180.0, 180.0, /* valid range */
416  0, 0, /* slope */
417  DFNT_FLOAT32, /* HDF number type */
418  1, /* rank */
419  nscan, 1, 1, /* dimension sizes */
420  "Number of Scan Lines", NULL, NULL /* dimension names */
421  ));
422 
423  PTB(CreateSDS(
424  sd_id, /* file id */
425  "elon", /* short name */
426  "Ending Longitude", /* long name */
427  NULL, /* standard name */
428  "degree", /* units */
429  -180.0, 180.0, /* valid range */
430  0, 0, /* slope */
431  DFNT_FLOAT32, /* HDF number type */
432  1, /* rank */
433  nscan, 1, 1, /* dimension sizes */
434  "Number of Scan Lines", NULL, NULL /* dimension names */
435  ));
436 
437  PTB(CreateSDS(
438  sd_id, /* file id */
439  "slat", /* short name */
440  "Starting Latitude", /* long name */
441  NULL, /* standard name */
442  "degree", /* units */
443  -90.0, 90.0, /* valid range */
444  0, 0, /* slope */
445  DFNT_FLOAT32, /* HDF number type */
446  1, /* rank */
447  nscan, 1, 1, /* dimension sizes */
448  "Number of Scan Lines", NULL, NULL /* dimension names */
449  ));
450 
451  PTB(CreateSDS(
452  sd_id, /* file id */
453  "clat", /* short name */
454  "Center Latitude", /* long name */
455  NULL, /* standard name */
456  "degree", /* units */
457  -90.0, 90.0, /* valid range */
458  0, 0, /* slope */
459  DFNT_FLOAT32, /* HDF number type */
460  1, /* rank */
461  nscan, 1, 1, /* dimension sizes */
462  "Number of Scan Lines", NULL, NULL /* dimension names */
463  ));
464 
465  PTB(CreateSDS(
466  sd_id, /* file id */
467  "elat", /* short name */
468  "Ending Latitude", /* long name */
469  NULL, /* standard name */
470  "degree", /* units */
471  -90.0, 90.0, /* valid range */
472  0, 0, /* slope */
473  DFNT_FLOAT32, /* HDF number type */
474  1, /* rank */
475  nscan, 1, 1, /* dimension sizes */
476  "Number of Scan Lines", NULL, NULL /* dimension names */
477  ));
478 
479  PTB(CreateSDS(
480  sd_id, /* file id */
481  "csol_z", /* short name */
482  "Center Solar Zenith Angle", /* long name */
483  NULL, /* standard name */
484  "degree", /* units */
485  -90.0, 90.0, /* valid range */
486  0, 0, /* slope */
487  DFNT_FLOAT32, /* HDF number type */
488  1, /* rank */
489  nscan, 1, 1, /* dimension sizes */
490  "Number of Scan Lines", NULL, NULL /* dimension names */
491  ));
492 
493  free(wavelength);
494  return (LIFE_IS_GOOD);
495 }
496 
497 
498 /* -------------------------------------------------------- */
499 /* Open an HDF file and store global attributes in it. */
500 
501 /* -------------------------------------------------------- */
502 int openl1_write_hdf(filehandle *l1file) {
503  char *name = l1file->name;
504  int32 nbands = (int32) l1file->nbands;
505  int32 npix = (int32) l1file->npix;
506  int32 nscans = (int32) l1file->nscan;
507  int32 sensorID = (int32) l1file->sensorID;
508  int32 format = (int32) l1file->format;
509  int32 *bindx = (int32 *) l1file->bindx;
510  char *pro_control = l1file->pro_control;
511 
512  char title [255];
513  char soft_id[200]; /* software version info */
514 
515  /* set globals */
516  numScans = nscans;
517  numPixels = npix;
518  numBands = nbands;
519  spix = l1file->spix + 1;
520  cpix = numPixels / 2;
521  epix = l1file->epix + 1;
522  dpix = l1file->dpix;
523  cscan = numScans / 2;
524  evalmask = l1file->input->evalmask;
525 
526  /* Get control-point array */
527  if ((ictl = calloc(numPixels, sizeof (int32))) == NULL) {
528  fprintf(stderr,
529  "-E- %s line %d: Unable to allocate control-point array.\n",
530  __FILE__, __LINE__);
531  return (MEMORY_ALLOCATION_ERROR);
532  }
533  if ((jctl = calloc(numScans, sizeof (int32))) == NULL) {
534  fprintf(stderr,
535  "-E- %s line %d: Unable to allocate control-point array.\n",
536  __FILE__, __LINE__);
537  return (MEMORY_ALLOCATION_ERROR);
538  }
539  nctl = get_ctl_pts(numPixels, numScans, ictl, jctl);
540 
541  /* Create the HDF file */
542  sd_id = SDstart(name, DFACC_CREATE);
543  l1file->sd_id = sd_id;
544  if (sd_id == FAIL) {
545  fprintf(stderr,
546  "-E- %s line %d: Could not create HDF file, %s .\n",
547  __FILE__, __LINE__, name);
548  return (HDF_FUNCTION_ERROR);
549  }
550 
551 
552  /* Write out some global attributes */
553  strcpy(title, sensorName[sensorID]);
554  strcat(title, " Level-1B");
555  strcpy(soft_id, VERSION);
556 
557  idDS ds_id;
558  ds_id.deflate = 0;
559  ds_id.fid = sd_id;
560  ds_id.fftype = DS_HDF;
561 
562  PTB(SetChrGA(ds_id, "product_name", basename(name)));
563  PTB(SetChrGA(ds_id, "title", title));
564  PTB(SetChrGA(ds_id, "software_name", "MSl1bgen"));
565  PTB(SetChrGA(ds_id, "software_version", soft_id));
566  PTB(SetChrGA(ds_id, "date_created", ydhmsf(now(), 'G')));
567  PTB(SetChrGA(ds_id, "history", pro_control));
568  //PTB( SetI32GA (ds_id, "Number of Bands", numBands) );
569  //PTB( SetI32GA (ds_id, "Pixels per Scan Line", numPixels) );
570  //PTB( SetI32GA (ds_id, "Number of Scan Lines",numScans));
571  //PTB( SetI32GA (ds_id, "Start Pixel",spix) );
572  //PTB( SetI32GA (ds_id, "Pixel Subsampling Interval",dpix) );
573  // PTB( SetI32GA (ds_id, "Scene Center Scan Line", cscan) );
574  //PTB( SetI32GA (ds_id, "Number of Scan Control Points",numScans) );
575  //PTB( SetI32GA (ds_id, "Number of Pixel Control Points",nctl) );
576 
577  /* Write control-point arrays */
578  PTB(CreateSDS(
579  sd_id, /* file id */
580  "cntl_pt_cols", /* short name */
581  "Pixel control points", /* long name */
582  NULL, /* standard name */
583  NULL, /* units */
584  0, 0, /* range */
585  0, 0, /* slope */
586  DFNT_INT32, /* HDF number type */
587  1, /* rank */
588  nctl, 1, 1, /* dimension sizes */
589  "Number of Pixel Control Points", NULL, NULL /* dimension names */
590  ));
591 
592  PTB(CreateSDS(
593  sd_id, /* file id */
594  "cntl_pt_rows", /* short name */
595  "Scan control points", /* long name */
596  NULL, /* standard name */
597  NULL, /* units */
598  0, 0, /* range */
599  0, 0, /* slope */
600  DFNT_INT32, /* HDF number type */
601  1, /* rank */
602  numScans, 1, 1, /* dimension sizes */
603  "Number of Scan Control Points", NULL, NULL /* dimension names */
604  ));
605  PTB(sd_writedata(sd_id, "cntl_pt_cols", ictl, 0, 0, 0, nctl, 0, 0));
606  PTB(sd_writedata(sd_id, "cntl_pt_rows", jctl, 0, 0, 0, numScans, 0, 0));
607 
608  /* Create the scan-line SDSes */
609  PTB(CreateScanData(numPixels, numBands, nscans, sensorID, bindx));
610 
611  return (LIFE_IS_GOOD);
612 }
613 
614 /* -------------------------------------------------------- */
615 /* Create the SDSes for the scan-line data */
616 
617 /* -------------------------------------------------------- */
618 int writel1_hdf(filehandle *l1file, int32_t recnum, l1str *l1rec) {
619  int32 *year = (int32 *) l1rec->year;
620  int32 *day = (int32 *) l1rec->day;
621  int32 *msec = (int32 *) l1rec->msec;
622  float32 *lon = (float32 *) l1rec->lon;
623  float32 *lat = (float32 *) l1rec->lat;
624  float32 *solz = (float32 *) l1rec->solz;
625  float32 *sola = (float32 *) l1rec->sola;
626  float32 *senz = (float32 *) l1rec->senz;
627  float32 *sena = (float32 *) l1rec->sena;
628  float32 *tilt = (float32 *)&(l1rec->tilt);
629  int32 *l2_flags = (int32 *) l1rec->flags;
630  int32 *bindx = (int32 *) l1file->bindx;
631 
632  static float32 *data = NULL;
633  int32 i, j;
634 
635  idDS ds_id;
636  ds_id.deflate = 0;
637  ds_id.fid = sd_id;
638  ds_id.fftype = DS_HDF;
639 
640  /* Write the scan-line data */
641  PTB(sd_writedata(sd_id, "year", year, recnum, 0, 0, 1, 1, 1));
642  PTB(sd_writedata(sd_id, "day", day, recnum, 0, 0, 1, 1, 1));
643  PTB(sd_writedata(sd_id, "msec", msec, recnum, 0, 0, 1, 1, 1));
644  PTB(sd_writedata(sd_id, "longitude", lon, recnum, 0, 0, 1, numPixels, 1));
645  PTB(sd_writedata(sd_id, "latitude", lat, recnum, 0, 0, 1, numPixels, 1));
646 
647  PTB(sd_writedata(sd_id, "detnum", &l1rec->detnum, recnum, 0, 0, 1, 1, 1));
648  PTB(sd_writedata(sd_id, "mside", &l1rec->mside, recnum, 0, 0, 1, 1, 1));
649 
650  PTB(sd_writedata(sd_id, "slon", &lon[0], recnum, 0, 0, 1, 1, 1));
651  PTB(sd_writedata(sd_id, "clon", &lon[cpix], recnum, 0, 0, 1, 1, 1));
652  PTB(sd_writedata(sd_id, "elon", &lon[numPixels - 1], recnum, 0, 0, 1, 1, 1));
653  PTB(sd_writedata(sd_id, "slat", &lat[0], recnum, 0, 0, 1, 1, 1));
654  PTB(sd_writedata(sd_id, "clat", &lat[cpix], recnum, 0, 0, 1, 1, 1));
655  PTB(sd_writedata(sd_id, "elat", &lat[numPixels - 1], recnum, 0, 0, 1, 1, 1));
656  PTB(sd_writedata(sd_id, "csol_z", &solz[cpix], recnum, 0, 0, 1, 1, 1));
657 
658  PTB(sd_writedata(sd_id, "solz", solz, recnum, 0, 0, 1, numPixels, 1));
659  PTB(sd_writedata(sd_id, "sola", sola, recnum, 0, 0, 1, numPixels, 1));
660  PTB(sd_writedata(sd_id, "senz", senz, recnum, 0, 0, 1, numPixels, 1));
661  PTB(sd_writedata(sd_id, "sena", sena, recnum, 0, 0, 1, numPixels, 1));
662  PTB(sd_writedata(sd_id, "tilt", tilt, recnum, 0, 0, 1, 1, 1));
663 
664  /* Write the radiance data */
665  if (data == NULL) {
666  if ((data = (float32 *) malloc(numPixels * sizeof (float32))) == NULL) {
667  fprintf(stderr,
668  "-E- %s line %d: Memory allocation failure.\n",
669  __FILE__, __LINE__);
670  exit(FATAL_ERROR);
671  }
672  }
673 
674  for (i = 0; i < numBands; i++) {
675  sprintf(rad_name, "L_%3d", wavelength[i]);
676  for (j = 0; j < numPixels; j++) {
677  data[j] = (float32) l1rec->Lt[j * numBands + bindx[i]];
678  }
679  PTB(sd_writedata(sd_id, rad_name, data,
680  recnum, 0, 0, 1, numPixels, 0));
681  }
682 
683  /* Write the l2_flag data */
684  PTB(sd_writedata(sd_id, "l2_flags", l2_flags,
685  recnum, 0, 0, 1, numPixels, 0));
686 
687  /* Write global attributes */
688  if (recnum == (numScans - 1)) {
689  scene_meta_write(ds_id);
690  }
691 
692  return (LIFE_IS_GOOD);
693 }
694 
695 
696 
697 /* -------------------------------------------------------- */
698 /* Finish access for the current file. */
699 
700 /* -------------------------------------------------------- */
701 void closel1_hdf(filehandle *l1file) {
702  /* Define Vgroups */
704 
705  if (SDend(l1file->sd_id)) {
706  fprintf(stderr, "-E- %s line %d: SDend(%d) failed.\n",
707  __FILE__, __LINE__, sd_id);
708  }
709 }
710 
711 
char * ydhmsf(double dtime, char zone)
Definition: ydhmsf.c:12
int v_attach(int32_t h_id, int32_t *v_id)
Definition: hdf_utils.c:404
int32 l1file(int32 sdfid, int32 *nsamp, int32 *nscans, int16 *dtynum)
Definition: l1stat_chk.c:586
int CreateSDS(int32_t sd_id, const char *sname, const char *lname, const char *standard_name, const char *units, double low, double high, float slope, float offset, int32_t nt, int32_t rank, int32_t d0, int32_t d1, int32_t d2, const char *dn0, const char *dn1, const char *dn2)
Definition: hdf_utils.c:77
const int bindx[3]
Definition: DbLutNetcdf.cpp:28
int j
Definition: decode_rs.h:73
int32_t day
int status
Definition: l1_czcs_hdf.c:32
int sd_select(int32_t sd_id, const char *name, int32_t *sds_id)
Definition: hdf_utils.c:355
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
int32 CreateScanData(int32 np, int32 nb, int32 nscan, int32 sensorID, int32 bindx[])
read l1rec
int MakeVgroupsL1(filehandle *file)
int32_t deflate
Definition: dfutils.h:32
float * lat
int32 * msec
Definition: l1_czcs_hdf.c:31
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
int32 get_ctl_pts(int32 npix, int32 nscans, int32 ictl[], int32 jctl[])
int32 nscan
Definition: l1_czcs_hdf.c:19
ds_format_t fftype
Definition: dfutils.h:31
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 VERSION
#define LIFE_IS_GOOD
Definition: passthebuck.h:4
#define DPTB(function)
Definition: passthebuck.h:24
void scene_meta_write(idDS ds_id)
Definition: scene_meta.c:241
read recnum
#define FATAL_ERROR
Definition: swl0_parms.h:5
int openl1_write_hdf(filehandle *l1file)
#define PTB(function)
Definition: passthebuck.h:16
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
int32 * wavelength
#define basename(s)
Definition: l0chunk_modis.c:29
int32 dpix
Definition: l1_czcs_hdf.c:22
int32_t nbands
int SetChrGA(idDS ds_id, const char *name, const char *value)
Definition: wrapper.c:236
int32 spix
Definition: l1_czcs_hdf.c:21
int32_t fid
Definition: dfutils.h:29
u5 which has been done in the LOCALGRANULEID metadata should have an extension NRT It is requested to identify the NRT production Changes from v6 which may affect scientific the sector rotation may actually occur during one of the scans earlier than the one where it is first reported As a the b1 values are about the LOCALGRANULEID metadata should have an extension NRT It is requested to identify the NRT to fill pixels affected by dead subframes with a special value Output the metadata of noisy and dead subframe Dead Subframe EV and Detector Quality Flag2 Removed the function call of Fill_Dead_Detector_SI to stop interpolating SI values for dead but also for all downstream products for science test only Changes from v5 which will affect scientific to conform to MODIS requirements Removed the Mixed option from the ScanType in the code because the L1A Scan Type is never Mixed Changed for ANSI C compliance and comments to better document the fact that when the HDF_EOS metadata is stricly the and products are off by and in the track respectively Corrected some misspelling of RCS swir_oob_sending_detector to the Reflective LUTs to enable the SWIR OOB correction detector so that if any of the sending detectors becomes noisy or non near by good detectors from the same sending band can be specified as the substitute in the new look up table Code change for adding an additional dimension of mirror side to the Band_21_b1 LUT to separate the coefficient of the two mirror sides for just like other thermal emissive so that the L1B code can calibrate Band scan to scan with mirror side dependency which leads better calibration result Changes which do not affect scientific when the EV data are not provided in this Crosstalk Correction will not be performed to the Band calibration data Changes which do not affect scientific and BB_500m in L1A Logic was added to turn off the or to spatial aggregation processes and the EV_250m_Aggr1km_RefSB and EV_500m_Aggr1km_RefSB fields were set to fill values when SDSs EV_250m and EV_500m are absent in L1A file Logic was added to skip the processing and turn off the output of the L1B QKM and HKM EV data when EV_250m and EV_500m are absent from L1A In this the new process avoids accessing and reading the and L1A EV skips and writing to the L1B and EV omits reading and subsampling SDSs from geolocation file and writing them to the L1B and omits writing metadata to L1B and EV and skips closing the L1A and L1B EV and SDSs Logic was added to turn off the L1B OBC output when the high resolution OBC SDSs are absent from L1A This is accomplished by skipping the openning the writing of metadata and the closing of the L1B OBC hdf which is Bit in the scan by scan bit QA has been changed Until now
Definition: HISTORY.txt:361
void closel1_hdf(filehandle *l1file)
#define MEMORY_ALLOCATION_ERROR
Definition: passthebuck.h:6
@ DS_HDF
Definition: dfutils.h:19
Definition: dfutils.h:28
int AddSdsToVgroup(int32_t sd_id, int32_t v_id, const char *name)
Definition: hdf_utils.c:383
float * lon
int sd_writedata(int32_t sd_id, const char *name, const void *data, int32_t s0, int32_t s1, int32_t s2, int32_t e0, int32_t e1, int32_t e2)
Definition: hdf_utils.c:293
int32 epix
Definition: l1_czcs_hdf.c:23
int32_t rdsensorinfo(int32_t, int32_t, const char *, void **)
Definition: rdsensorinfo.c:69
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
#define SEAWIFS
Definition: sensorDefs.h:12
int16_t * tilt
Definition: l2bin.cpp:86
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int32_t sensorID[MAXNFILES]
Definition: l2bin.cpp:97
int writel1_hdf(filehandle *l1file, int32_t recnum, l1str *l1rec)
int npix
Definition: get_cmp.c:27
char rad_name[8]
#define HDF_FUNCTION_ERROR
Definition: passthebuck.h:7
int32_t nb
Definition: atrem_corl1.h:132