OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
init_sdr.c
Go to the documentation of this file.
1 #include "viirs_sim_sdr.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <libgen.h>
6 #include <time.h>
7 /* this is used mainly in setting up the grougs in the output SDRs */
8 char *core_g_nm[] = {"VIIRS-MOD-GEO-TC", "VIIRS-M1-SDR",
9  "VIIRS-M2-SDR", "VIIRS-M3-SDR", "VIIRS-M4-SDR", "VIIRS-M5-SDR",
10  "VIIRS-M6-SDR", "VIIRS-M7-SDR", "VIIRS-M8-SDR", "VIIRS-M9-SDR",
11  "VIIRS-M10-SDR", "VIIRS-M11-SDR", "VIIRS-M12-SDR", "VIIRS-M13-SDR",
12  "VIIRS-M14-SDR", "VIIRS-M15-SDR", "VIIRS-M16-SDR"};
13 
14 int init_sdr(ctl_struc *ctl, sdr_info_struc *sdr_info, in_rec_struc *in_rec,
15  out_rec_struc *out_rec)
16 /*-----------------------------------------------------------------------------
17  Program: init_sdr.c
18 
19  Description: create the geolocation and band files with everything but
20  data lines
21 
22  Arguments:
23  Type Name I/O Description
24  ---- ---- --- -----------
25  ctl_struc * ctl I input controls
26  sdr_info_struc * sdr_info I general SDR information
27  in_rec_struc * in_rec I/O controls for input record reading
28  out_rec_struc * out_rec I/O controls for output file writing
29 
30  Modification history:
31 
32  W. Robinson, SAIC 15 Oct 2008 Original development
33 
34 ----------------------------------------------------------------------------*/ {
35  h5io_str dat1_g_id, dat2_g_id;
36  char out_file[500], grp_nam[50], *sdr_base;
37  int isdr;
38  char lcl_out_bnd_typ[] = {0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0};
39  char lcl_meas_typ[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1};
40  /*
41  * set the radiance storage and type flag
42  */
43  for (isdr = 0; isdr < MAX_BND; isdr++) {
44  out_rec->out_bnd_typ[isdr] = lcl_out_bnd_typ[isdr];
45  out_rec->meas_typ[isdr] = lcl_meas_typ[isdr];
46  }
47  /*
48  * initialize the lat, lon limit values
49  */
50  in_rec->ll_lims[0] = 99.;
51  in_rec->ll_lims[1] = -99.;
52  in_rec->ll_lims[2] = 200.;
53  in_rec->ll_lims[3] = -200.;
54  in_rec->ll_lims[4] = 200.;
55  in_rec->ll_lims[5] = -200.;
56  /*
57  * based on the controls and the input scan format, set controls for
58  * output scan format information
59  * base state is to leave as-is (out_scn_fmt = 2)
60  */
61  out_rec->nbnd = in_rec->nbnd;
62  out_rec->npix = in_rec->npix;
63  out_rec->nlin = in_rec->nlin;
64  out_rec->nscan = in_rec->nscan;
65  out_rec->scn_fmt = in_rec->scn_fmt;
66  out_rec->margin[0] = in_rec->margin[0];
67  out_rec->margin[1] = in_rec->margin[1];
68  out_rec->ndet_scan = in_rec->ndet_scan;
69 
70  if (ctl->out_scn_fmt == 0) /* make aggregated */ {
71  out_rec->scn_fmt = 0;
72  out_rec->npix = 3200;
73  out_rec->nlin = in_rec->nscan * NDET;
74  out_rec->margin[0] = 0;
75  out_rec->margin[1] = 0;
76  out_rec->ndet_scan = NDET;
77  } else if (ctl->out_scn_fmt == 1) /* make unaggregated with no margin */ {
78  out_rec->margin[0] = 0;
79  out_rec->margin[1] = 0;
80  out_rec->ndet_scan = NDET;
81  out_rec->nlin = in_rec->nscan * NDET;
82 
83  if (in_rec->scn_fmt == 0) {
84  printf(
85  "%s, %d: Warning - requested output format (%d) of unaggregated\n",
86  __FILE__, __LINE__, in_rec->scn_fmt);
87  printf(" will default to input scan format of aggregated\n");
88  out_rec->npix = 3200;
89  out_rec->scn_fmt = 0;
90  } else {
91  out_rec->npix = 6304;
92  out_rec->scn_fmt = 1;
93  }
94  }
95  /*
96  * go through the SDR files and initialize each one
97  */
98  for (isdr = 0; isdr < in_rec->nbnd + 1; isdr++) {
99  /*
100  * divide the work among creating the major parts of the file
101  * first, open output file and set up the top attributes
102  */
103  if (gen_sdr_fname(isdr, ctl->out_loc, sdr_info, ctl->fname_opt,
104  out_file) != 0) {
105  printf("%s, %d: Unable to generate output file for sdr index %d\n\n",
106  __FILE__, __LINE__, isdr);
107  return 1;
108  }
109  sdr_base = basename(out_file);
110  strcpy(sdr_info->sdr_files[isdr], sdr_base);
111  if (h5io_openw(out_file, ctl->sdr_overwrite,
112  &(out_rec->sdr_fid[isdr])) != 0) {
113  printf("%s, %d: Unable to open output geo file: \n%s\n\n",
114  __FILE__, __LINE__, out_file);
115  return 1;
116  }
117  if (init_sdr_top(isdr, sdr_info, out_rec) != 0) return 1;
118  /*
119  * and then make the data group and write the data
120  */
121  if (h5io_mk_grp(&(out_rec->sdr_fid[isdr]), "All_Data",
122  &(out_rec->sdr_dat_gid[0][isdr])) != 0) {
123  printf("%s, %d - could not create data group: All_Data\n",
124  __FILE__, __LINE__);
125  return 1;
126  }
127  sprintf(grp_nam, "%s_All", core_g_nm[isdr]);
128  if (h5io_mk_grp(&(out_rec->sdr_dat_gid[0][isdr]), grp_nam,
129  &(out_rec->sdr_dat_gid[1][isdr])) != 0) {
130  printf("%s, %d - could not create data group: %s\n",
131  __FILE__, __LINE__, grp_nam);
132  return 1;
133  }
134  if (isdr == 0) {
135  if (init_geo_data(sdr_info, in_rec, out_rec) != 0) return 1;
136  } else {
137  /*
138  * allocate the dn storage here (depends on ctl) but do rest in
139  * call to init_bnd_data
140  */
141  if (ctl->count_cal_opt != 0) {
142  if ((in_rec->dn[ isdr - 1 ] = (float *)
143  malloc(in_rec->ndet_scan * in_rec->npix * sizeof (float)))
144  == NULL) {
145  printf("%s, %d: Error, allocation of dn storage failed\n",
146  __FILE__, __LINE__);
147  return 1;
148  }
149  }
150  if ((in_rec->gain_bit[ isdr - 1 ] = (unsigned char *)
151  calloc(in_rec->ndet_scan * in_rec->npix, sizeof (unsigned char)))
152  == NULL) {
153  printf(
154  "%s, %d: Error, allocation of count gain bit storage failed\n",
155  __FILE__, __LINE__);
156  return 1;
157  }
158  if ((in_rec->dn_sat[ isdr - 1 ] = (char *)
159  calloc(in_rec->ndet_scan * in_rec->npix, sizeof (char)))
160  == NULL) {
161  printf(
162  "%s, %d: Error, allocation of dn saturation storage failed\n",
163  __FILE__, __LINE__);
164  return 1;
165  }
166  if (init_bnd_data(isdr - 1, sdr_info, in_rec, out_rec) != 0) return 1;
167  }
168  /*
169  * make the other group pair for data products and fill
170  */
171  if (h5io_mk_grp(&(out_rec->sdr_fid[isdr]),
172  "Data_Products", &dat1_g_id) != 0) {
173  printf("%s, %d - could not create data group: Data_Products\n",
174  __FILE__, __LINE__);
175  return 1;
176  }
177  if (h5io_mk_grp(&dat1_g_id, core_g_nm[isdr], &dat2_g_id) != 0) {
178  printf("%s, %d - could not create data group: %s\n",
179  __FILE__, __LINE__, core_g_nm[isdr]);
180  return 1;
181  }
182  /*
183  * set up attributes in the group, the aggregate and granule datasets
184  * and their attributes
185  */
186  if (init_sdr_dpattr(isdr, &dat2_g_id, sdr_info) != 0) return 1;
187  if (init_sdr_agg(isdr, &dat2_g_id, sdr_info) != 0) return 1;
188  if (init_sdr_gran(isdr, &dat2_g_id, sdr_info, out_rec) != 0) return 1;
189  /*
190  * and finish up, closing the group ids
191  */
192  if (h5io_close(&dat2_g_id) != 0) {
193  printf("%s, %d - could not close dat2_g_id\n", __FILE__, __LINE__);
194  return 1;
195  }
196  if (h5io_close(&dat1_g_id) != 0) {
197  printf("%s, %d - could not close dat1_g_id\n", __FILE__, __LINE__);
198  return 1;
199  }
200  }
201  /*
202  * we still need to place the data lines
203  */
204  return 0;
205 }
206 
207 int init_sdr_top(int isdr, sdr_info_struc *sdr_info, out_rec_struc *out_rec)
208 /*-----------------------------------------------------------------------------
209  Routine: init_sdr_top
210 
211  Description: make the top-level attributes for the geolocation or
212  band SDR file
213 
214  Arguments:
215  Type Name I/O Description
216  ---- ---- --- -----------
217  int isdr I SDR file to work on: 0 geo, > 0 band isdr
218  sdr_info_struc * sdr_info I general SDR information
219  out_rec_struc * out_rec I output dataset information
220 
221  Modification history:
222 
223  W. Robinson, SAIC 15 Oct 2008 Original development
224  W. Robinson, SAIC 18 Mar 2010 place non-standard attributes here for the
225  non-aggregated file types
226 
227 ----------------------------------------------------------------------------*/ {
228  int i, n_attr = 13, dims_1_1[] = {1, 1}, len_geo;
229  int dims_1[] = {1}, dims_2[] = {2};
230  char geo_name[150], *bloc = ".";
231  int16_t lcl_scn_fmt, lcl_margin[2], lcl_ndet_scan;
232  int32_t lcl_npix, lcl_nlin;
233 
234  gen_sdr_fname(0, bloc, sdr_info, 0, geo_name);
235  len_geo = strlen(geo_name);
236 
237  h5attr_struc attrs[] = {
238  { 1, 1, "Distributor", H5T_NATIVE_CHAR, 4, 2, dims_1_1,
239  (void *) (sdr_info->origin)},
240  { 1, 1, "Instrument_Short_Name", H5T_NATIVE_CHAR, 6, 2, dims_1_1,
241  (void *) "VIIRS"},
242  { 1, 1, "Mission_Name", H5T_NATIVE_CHAR, 4, 2, dims_1_1,
243  (void *) "NPP"},
244  { 1, 1, "N_Dataset_Source", H5T_NATIVE_CHAR, 5, 2, dims_1_1,
245  (void *) "OBPG"},
246  { 1, 1, "N_GEO_Ref", H5T_NATIVE_CHAR, len_geo, 2, dims_1_1,
247  (void *) geo_name},
248  { 1, 1, "N_HDF_Creation_Date", H5T_NATIVE_CHAR, 9, 2, dims_1_1,
249  (void *) sdr_info->cre_date},
250  { 1, 1, "N_HDF_Creation_Time", H5T_NATIVE_CHAR, 14, 2, dims_1_1,
251  (void *) sdr_info->cre_time},
252  { 1, 1, "Platform_Short_Name", H5T_NATIVE_CHAR, 4, 2, dims_1_1,
253  (void *) "NPP"},
254  { 0, 0, "Data Scan Format", H5T_STD_I16BE, 0, 1, dims_1,
255  (void *) &lcl_scn_fmt},
256  { 0, 0, "Scan Margin (track, scan)", H5T_STD_I16BE, 0, 1, dims_2,
257  (void *) lcl_margin},
258  { 0, 0, "Pixels per Scan Line", H5T_STD_I32BE, 0, 1, dims_1,
259  (void *) &lcl_npix},
260  { 0, 0, "Number of Scan Lines", H5T_STD_I32BE, 0, 1, dims_1,
261  (void *) &lcl_nlin},
262  { 0, 0, "Number of Detectors per Scan", H5T_STD_I16BE, 0, 1, dims_1,
263  (void *) &lcl_ndet_scan}
264  };
265  /*
266  * for the geo file, don't output the N_GEO_Ref attrib
267  */
268  if (isdr == 0) attrs[4].express = 0;
269  /*
270  * for non-aggregated file formats, add the descriptors
271  */
272  if (out_rec->scn_fmt != 0) {
273  for (i = 0; i < 5; i++)
274  attrs[ i + 8 ].express = 1;
275  lcl_scn_fmt = (int16_t) out_rec->scn_fmt;
276  lcl_margin[0] = (int16_t) out_rec->margin[0];
277  lcl_margin[1] = (int16_t) out_rec->margin[1];
278  lcl_npix = (int32_t) out_rec->npix;
279  lcl_nlin = (int32_t) out_rec->nlin;
280  lcl_ndet_scan = (int16_t) out_rec->ndet_scan;
281  }
282  /*
283  * output the attributes to the location
284  */
285  if (wr_attr_seq(&(out_rec->sdr_fid[isdr]), n_attr, attrs) != 0) {
286  printf("%s, %d: Could not write top attributes\n", __FILE__, __LINE__);
287  return 1;
288  }
289  return 0;
290 }
291 
292 int init_geo_data(sdr_info_struc *sdr_info, in_rec_struc *in_rec,
293  out_rec_struc *out_rec)
294 /*-----------------------------------------------------------------------------
295  Routine: init_geo_data
296 
297  Description: make the data arrays for the geo file and fill some
298  Also, get some data start, end times
299 
300  Arguments:
301  Type Name I/O Description
302  ---- ---- --- -----------
303  sdr_info_struc * sdr_info I/O general SDR information
304  in_rec_struc * in_rec I/O input file information
305  out_rec_struc * out_rec I/O output file information
306 
307  Modification history:
308 
309  W. Robinson, SAIC 21 Oct 2008 Original development
310  W. Robinson, SAIC 02 Oct 2009 use geoloc file attitude, position,
311  velocity in the SDR
312 
313 ----------------------------------------------------------------------------*/ {
314  h5io_str ds_id, in_ds_id, *gid;
315  int dim_siz[2], dim_siz2[2], *arr_int, i;
316  float *flt_data;
317  double *dbl_data;
318  int64 *llon_data;
319  unsigned char *uchar_data;
320  /*
321  * define gid for convenience
322  */
323  gid = &(out_rec->sdr_dat_gid[1][0]);
324  /*
325  * datasets are:
326  * Height -- may be derivable but not necessary
327  */
328  dim_siz[0] = out_rec->nlin;
329  dim_siz[1] = out_rec->npix;
330 
331  if ((flt_data = (float *) malloc(out_rec->npix * out_rec->nlin *
332  sizeof (float))) == NULL) {
333  printf("%s, %d: Could not allocate local float buffer\n",
334  __FILE__, __LINE__);
335  return 1;
336  }
337 
338  for (i = 0; i < out_rec->nlin * out_rec->npix; i++)
339  *(flt_data + i) = 0;
340  if (h5io_mk_ds(gid, "Height", H5T_IEEE_F32BE, 2, dim_siz,
341  &ds_id) != 0) {
342  printf("%s, %d: Could not do h5io_mk_ds for Height\n",
343  __FILE__, __LINE__);
344  return 1;
345  }
346  if (h5io_wr_ds(&ds_id, (void *) flt_data) != 0) {
347  printf("%s, %d: Could not write to Height\n", __FILE__, __LINE__);
348  return 1;
349  }
350  if (h5io_close(&ds_id) != 0) {
351  printf("%s, %d: Could not close Height\n", __FILE__, __LINE__);
352  return 1;
353  }
354  /*
355  * Latitude
356  * The lat, lon, senz, sena, solz, sola arrays will be filled scae-by-scan
357  * later. just create these datasets here (others will be filled here)
358  */
359  if (h5io_set_ds(&(in_rec->geo_fid), "latitude",
360  &(in_rec->geo_dat_id[0])) != 0) {
361  printf("%s, %d: Could not do h5io_set_ds for latitude\n",
362  __FILE__, __LINE__);
363  return 1;
364  }
365 
366  dim_siz[0] = out_rec->nlin;
367  dim_siz[1] = out_rec->npix;
368  if (h5io_mk_ds(gid, "Latitude", H5T_IEEE_F32BE, 2, dim_siz,
369  &(out_rec->geo_dat_id[0])) != 0) {
370  printf("%s, %d: Could not do h5io_mk_ds for Latitude\n",
371  __FILE__, __LINE__);
372  return 1;
373  }
374  /*
375  * allocate the data transfer buffer and make it the same for output
376  **** good for now as long as out size = in size but will need change
377  if scn_fnt is changed
378  */
379  if ((in_rec->lat = (float *) malloc(in_rec->npix * in_rec->ndet_scan *
380  sizeof (float))) == NULL) {
381  printf("%s, %d: Could not allocate space for lat data transfer buffer\n",
382  __FILE__, __LINE__);
383  return 1;
384  }
385  out_rec->lat = in_rec->lat;
386  /*
387  * Longitude
388  */
389  if (h5io_set_ds(&(in_rec->geo_fid), "longitude",
390  &(in_rec->geo_dat_id[1])) != 0) {
391  printf("%s, %d: Could not do h5io_set_ds for longitude\n",
392  __FILE__, __LINE__);
393  return 1;
394  }
395 
396  if (h5io_mk_ds(gid, "Longitude", H5T_IEEE_F32BE, 2, dim_siz,
397  &(out_rec->geo_dat_id[1])) != 0) {
398  printf("%s, %d: Could not do h5io_mk_ds for Longitude\n",
399  __FILE__, __LINE__);
400  return 1;
401  }
402 
403  if ((in_rec->lon = (float *) malloc(in_rec->npix * in_rec->ndet_scan *
404  sizeof (float))) == NULL) {
405  printf("%s, %d: Could not allocate space for lon data transfer buffer\n",
406  __FILE__, __LINE__);
407  return 1;
408  }
409  out_rec->lon = in_rec->lon;
410  /*
411  * MidTime - an 8 byte int of microsecs past 1/1958 -- for now,
412  * fill the ScanStartTime but leave this 0
413  */
414  llon_data = (int64 *) calloc(out_rec->nscan, sizeof (int64));
415  dim_siz2[0] = out_rec->nscan;
416  if (h5io_mk_ds(gid, "MidTime", H5T_STD_I64BE, 1, dim_siz2, &ds_id)
417  != 0) {
418  printf("%s, %d: Could not do h5io_mk_ds for MidTime\n",
419  __FILE__, __LINE__);
420  return 1;
421  }
422  if (h5io_wr_ds(&ds_id, (void *) llon_data) != 0) {
423  printf("%s, %d: Could not write to MidTime\n", __FILE__, __LINE__);
424  return 1;
425  }
426  if (h5io_close(&ds_id) != 0) {
427  printf("%s, %d: Could not close MidTime\n", __FILE__, __LINE__);
428  return 1;
429  }
430  free(llon_data);
431  /*
432  * ModeGran 1 value, 1 is day, so fill with 1
433  */
434  uchar_data = (unsigned char *) malloc(out_rec->nscan *
435  sizeof ( unsigned char));
436  *uchar_data = 1;
437  dim_siz2[0] = 1;
438  if (h5io_mk_ds(gid, "ModeGran", H5T_STD_U8BE, 1, dim_siz2, &ds_id)
439  != 0) {
440  printf("%s, %d: Could not do h5io_mk_ds for ModeGran\n",
441  __FILE__, __LINE__);
442  return 1;
443  }
444  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
445  printf("%s, %d: Could not write to ModeGran\n", __FILE__, __LINE__);
446  return 1;
447  }
448  if (h5io_close(&ds_id) != 0) {
449  printf("%s, %d: Could not close ModeGran\n", __FILE__, __LINE__);
450  return 1;
451  }
452  free(uchar_data);
453  /*
454  * ModeScan 48 bytes, 1 is day, so fill with 1
455  */
456  uchar_data = (unsigned char *) malloc(out_rec->nscan *
457  sizeof ( unsigned char));
458  for (i = 0; i < out_rec->nscan; i++)
459  *(uchar_data + i) = 1;
460  dim_siz2[0] = out_rec->nscan;
461  if (h5io_mk_ds(gid, "ModeScan", H5T_STD_U8BE, 1, dim_siz2, &ds_id)
462  != 0) {
463  printf("%s, %d: Could not do h5io_mk_ds for ModeScan\n",
464  __FILE__, __LINE__);
465  return 1;
466  }
467  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
468  printf("%s, %d: Could not write to ModeScan\n", __FILE__, __LINE__);
469  return 1;
470  }
471  if (h5io_close(&ds_id) != 0) {
472  printf("%s, %d: Could not close ModeScan\n", __FILE__, __LINE__);
473  return 1;
474  }
475  free(uchar_data);
476  /*
477  * NumberOfScans
478  */
479  arr_int = (int *) malloc(sizeof ( int));
480  *arr_int = out_rec->nscan;
481  dim_siz2[0] = 1;
482  if (h5io_mk_ds(gid, "NumberOfScans", H5T_STD_I32BE, 1, dim_siz2, &ds_id)
483  != 0) {
484  printf("%s, %d: Could not do h5io_mk_ds for NumberOfScans\n",
485  __FILE__, __LINE__);
486  return 1;
487  }
488  if (h5io_wr_ds(&ds_id, (void *) arr_int) != 0) {
489  printf("%s, %d: Could not write to NumberOfScans\n", __FILE__, __LINE__);
490  return 1;
491  }
492  if (h5io_close(&ds_id) != 0) {
493  printf("%s, %d: Could not close NumberOfScans\n", __FILE__, __LINE__);
494  return 1;
495  }
496  free(arr_int);
497  /*
498  * PadByte1 ( 3 values of 0) -- just fill with 0 for the 3 values
499  */
500  uchar_data = (unsigned char *) malloc(3 * sizeof ( unsigned char));
501  for (i = 0; i < 3; i++)
502  *(uchar_data + i) = 0;
503  dim_siz2[0] = 3;
504  if (h5io_mk_ds(gid, "PadByte1", H5T_STD_U8BE, 1, dim_siz2, &ds_id)
505  != 0) {
506  printf("%s, %d: Could not do h5io_mk_ds for PadByte\n",
507  __FILE__, __LINE__);
508  return 1;
509  }
510  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
511  printf("%s, %d: Could not write to PadByte\n", __FILE__, __LINE__);
512  return 1;
513  }
514  if (h5io_close(&ds_id) != 0) {
515  printf("%s, %d: Could not close PadByte\n", __FILE__, __LINE__);
516  return 1;
517  }
518  free(uchar_data);
519  /*
520  * QF1_SCAN_VIIRSSDRGEO - contains info on HAM encoder qual and attitude,
521  * ephem availability good is 48 * 0
522  */
523  uchar_data = (unsigned char *) malloc(out_rec->nscan *
524  sizeof ( unsigned char));
525  for (i = 0; i < out_rec->nscan; i++)
526  *(uchar_data + i) = 0;
527  dim_siz2[0] = out_rec->nscan;
528  if (h5io_mk_ds(gid, "QF1_SCAN_VIIRSSDRGEO", H5T_STD_U8BE, 1,
529  dim_siz2, &ds_id) != 0) {
530  printf("%s, %d: Could not do h5io_mk_ds for QF1_SCAN_VIIRSSDRGEO\n",
531  __FILE__, __LINE__);
532  return 1;
533  }
534  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
535  printf("%s, %d: Could not write to QF1_SCAN_VIIRSSDRGEO\n",
536  __FILE__, __LINE__);
537  return 1;
538  }
539  if (h5io_close(&ds_id) != 0) {
540  printf("%s, %d: Could not close QF1_SCAN_VIIRSSDRGEO\n",
541  __FILE__, __LINE__);
542  return 1;
543  }
544  free(uchar_data);
545  /*
546  * QF2_VIIRSSDRGEO - valid / invalid state for 4 items: input data,
547  * pointing, terrain and solar angles - all 0 for all pixels is all good
548  */
549  uchar_data = (unsigned char *) calloc(out_rec->npix * out_rec->nlin,
550  sizeof ( unsigned char));
551  if (h5io_mk_ds(gid, "QF2_VIIRSSDRGEO", H5T_STD_U8BE, 2, dim_siz, &ds_id)
552  != 0) {
553  printf("%s, %d: Could not do h5io_mk_ds for QF2_VIIRSSDRGEO\n",
554  __FILE__, __LINE__);
555  return 1;
556  }
557  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
558  printf("%s, %d: Could not write to QF2_VIIRSSDRGEO\n",
559  __FILE__, __LINE__);
560  return 1;
561  }
562  if (h5io_close(&ds_id) != 0) {
563  printf("%s, %d: Could not close QF2_VIIRSSDRGEO\n", __FILE__, __LINE__);
564  return 1;
565  }
566  free(uchar_data);
567  /*
568  * SCAttitude attitude information 48 X 3 from geoloc dataset
569  * convert from deg to arcsec
570  */
571  for (i = 0; i < out_rec->nscan * 3; i++)
572  *(flt_data + i) = *(sdr_info->geo_att + i) * 3600.;
573  /* free the space as it is no longer in use */
574  free(sdr_info->geo_att);
575  dim_siz2[0] = out_rec->nscan;
576  dim_siz2[1] = 3;
577  if (h5io_mk_ds(gid, "SCAttitude", H5T_IEEE_F32BE, 2, dim_siz2,
578  &ds_id) != 0) {
579  printf("%s, %d: Could not do h5io_mk_ds for SCAttitude\n",
580  __FILE__, __LINE__);
581  return 1;
582  }
583  if (h5io_wr_ds(&ds_id, (void *) flt_data) != 0) {
584  printf("%s, %d: Could not write to SCAttitude\n", __FILE__, __LINE__);
585  return 1;
586  }
587  if (h5io_close(&ds_id) != 0) {
588  printf("%s, %d: Could not close SCAttitude\n", __FILE__, __LINE__);
589  return 1;
590  }
591  /*
592  * SCPosition SC position, ECR coords., from geoloc dataset
593  */
594  for (i = 0; i < out_rec->nscan * 3; i++)
595  *(flt_data + i) = *(sdr_info->geo_pos + i) * 1000.;
596  /* free the space as it is no longer in use */
597  free(sdr_info->geo_pos);
598  dim_siz2[0] = out_rec->nscan;
599  dim_siz2[1] = 3;
600  if (h5io_mk_ds(gid, "SCPosition", H5T_IEEE_F32BE, 2, dim_siz2,
601  &ds_id) != 0) {
602  printf("%s, %d: Could not do h5io_mk_ds for SCPosition\n",
603  __FILE__, __LINE__);
604  return 1;
605  }
606  if (h5io_wr_ds(&ds_id, (void *) flt_data) != 0) {
607  printf("%s, %d: Could not write to SCPosition\n", __FILE__, __LINE__);
608  return 1;
609  }
610  if (h5io_close(&ds_id) != 0) {
611  printf("%s, %d: Could not close SCPosition\n", __FILE__, __LINE__);
612  return 1;
613  }
614  /*
615  * SCSolarAzimuthAngle - 48 array of az angle on solar diffuser
616  */
617  for (i = 0; i < out_rec->nscan; i++)
618  *(flt_data + i) = 0.;
619  dim_siz2[0] = out_rec->nscan;
620  if (h5io_mk_ds(gid, "SCSolarAzimuthAngle", H5T_IEEE_F32BE, 1, dim_siz2,
621  &ds_id) != 0) {
622  printf("%s, %d: Could not do h5io_mk_ds for SCSolarAzimuthAngle\n",
623  __FILE__, __LINE__);
624  return 1;
625  }
626  if (h5io_wr_ds(&ds_id, (void *) flt_data) != 0) {
627  printf("%s, %d: Could not write to SCSolarAzimuthAngle\n",
628  __FILE__, __LINE__);
629  return 1;
630  }
631  if (h5io_close(&ds_id) != 0) {
632  printf("%s, %d: Could not close SCSolarAzimuthAngle\n",
633  __FILE__, __LINE__);
634  return 1;
635  }
636  /*
637  * SCSolarZenithAngle - a 48 array of zen angle on solar diffuser
638  */
639  for (i = 0; i < out_rec->nscan; i++)
640  *(flt_data + i) = 0.;
641  dim_siz2[0] = out_rec->nscan;
642  if (h5io_mk_ds(gid, "SCSolarZenithAngle", H5T_IEEE_F32BE, 1, dim_siz2,
643  &ds_id) != 0) {
644  printf("%s, %d: Could not do h5io_mk_ds for SCSolarZenithAngle\n",
645  __FILE__, __LINE__);
646  return 1;
647  }
648  if (h5io_wr_ds(&ds_id, (void *) flt_data) != 0) {
649  printf("%s, %d: Could not write to SCSolarZenithAngle\n",
650  __FILE__, __LINE__);
651  return 1;
652  }
653  if (h5io_close(&ds_id) != 0) {
654  printf("%s, %d: Could not close SCSolarZenithAngle\n",
655  __FILE__, __LINE__);
656  return 1;
657  }
658  /*
659  * SCVelocity -- get from geoloc dataset
660  */
661  dim_siz2[0] = out_rec->nscan;
662  dim_siz2[1] = 3;
663  for (i = 0; i < out_rec->nscan * 3; i++)
664  *(flt_data + i) = *(sdr_info->geo_vel + i) * 1000.;
665  /* free the space as it is no longer in use */
666  free(sdr_info->geo_vel);
667  if (h5io_mk_ds(gid, "SCVelocity", H5T_IEEE_F32BE, 2, dim_siz2,
668  &ds_id) != 0) {
669  printf("%s, %d: Could not do h5io_mk_ds for SCVelocity\n",
670  __FILE__, __LINE__);
671  return 1;
672  }
673  if (h5io_wr_ds(&ds_id, (void *) flt_data) != 0) {
674  printf("%s, %d: Could not write to SCVelocity\n", __FILE__, __LINE__);
675  return 1;
676  }
677  if (h5io_close(&ds_id) != 0) {
678  printf("%s, %d: Could not close SCVelocity\n", __FILE__, __LINE__);
679  return 1;
680  }
681  /*
682  * SatelliteAzimuthAngle
683  */
684  if (h5io_set_ds(&(in_rec->geo_fid), "sena",
685  &(in_rec->geo_dat_id[2])) != 0) {
686  printf("%s, %d: Could not do h5io_set_ds for sena\n", __FILE__, __LINE__);
687  return 1;
688  }
689 
690  if (h5io_mk_ds(gid, "SatelliteAzimuthAngle", H5T_IEEE_F32BE, 2,
691  dim_siz, &(out_rec->geo_dat_id[2])) != 0) {
692  printf("%s, %d: Could not do h5io_mk_ds for SatelliteAzimuthAngle\n",
693  __FILE__, __LINE__);
694  return 1;
695  }
696 
697  if ((in_rec->sena = (float *) malloc(in_rec->npix * in_rec->ndet_scan *
698  sizeof (float))) == NULL) {
699  printf(
700  "%s, %d: Could not allocate transfer buffer for SatelliteAzimuthAngle\n",
701  __FILE__, __LINE__);
702  return 1;
703  }
704  out_rec->sena = in_rec->sena;
705  /*
706  * SatelliteRange -- We may be able to get, but not necessary now
707  * Just zero out
708  */
709  for (i = 0; i < out_rec->npix * out_rec->nlin; i++)
710  *(flt_data + i) = 0.;
711  if (h5io_mk_ds(gid, "SatelliteRange", H5T_IEEE_F32BE, 2, dim_siz, &ds_id)
712  != 0) {
713  printf("%s, %d: Could not do h5io_mk_ds for SatelliteRange\n",
714  __FILE__, __LINE__);
715  return 1;
716  }
717  if (h5io_wr_ds(&ds_id, (void *) flt_data) != 0) {
718  printf("%s, %d: Could not write to SatelliteRange\n", __FILE__, __LINE__);
719  return 1;
720  }
721  if (h5io_close(&ds_id) != 0) {
722  printf("%s, %d: Could not close SatelliteRange\n", __FILE__, __LINE__);
723  return 1;
724  }
725  /*
726  * SatelliteZenithAngle
727  */
728  if (h5io_set_ds(&(in_rec->geo_fid), "senz",
729  &(in_rec->geo_dat_id[3])) != 0) {
730  printf("%s, %d: Could not do h5io_set_ds for senz\n", __FILE__, __LINE__);
731  return 1;
732  }
733 
734  if (h5io_mk_ds(gid, "SatelliteZenithAngle", H5T_IEEE_F32BE, 2,
735  dim_siz, &(out_rec->geo_dat_id[3])) != 0) {
736  printf("%s, %d: Could not do h5io_mk_ds for SatelliteZenithAngle\n",
737  __FILE__, __LINE__);
738  return 1;
739  }
740 
741  if ((in_rec->senz = (float *) malloc(in_rec->npix * in_rec->ndet_scan *
742  sizeof (float))) == NULL) {
743  printf(
744  "%s, %d: Could not allocate transfer buffer for SatelliteZenithAngle\n",
745  __FILE__, __LINE__);
746  return 1;
747  }
748  out_rec->senz = in_rec->senz;
749  /*
750  * SolarAzimuthAngle
751  */
752  if (h5io_set_ds(&(in_rec->geo_fid), "sola",
753  &(in_rec->geo_dat_id[4])) != 0) {
754  printf("%s, %d: Could not do h5io_set_ds on sola\n", __FILE__, __LINE__);
755  return 1;
756  }
757 
758  if (h5io_mk_ds(gid, "SolarAzimuthAngle", H5T_IEEE_F32BE, 2, dim_siz,
759  &(out_rec->geo_dat_id[4])) != 0) {
760  printf("%s, %d: Could not do h5io_mk_ds for SolarAzimuthAngle\n",
761  __FILE__, __LINE__);
762  return 1;
763  }
764 
765  if ((in_rec->solz = (float *) malloc(in_rec->npix * in_rec->ndet_scan *
766  sizeof (float))) == NULL) {
767  printf(
768  "%s, %d: Could not allocate transfer buffer for SolarAzimuthAngle\n",
769  __FILE__, __LINE__);
770  return 1;
771  }
772  out_rec->solz = in_rec->solz;
773  /*
774  * SolarZenithAngle
775  */
776  if (h5io_set_ds(&(in_rec->geo_fid), "solz",
777  &(in_rec->geo_dat_id[5])) != 0) {
778  printf("%s, %d: Could not do h5io_set_ds on solz\n", __FILE__, __LINE__);
779  return 1;
780  }
781 
782  if (h5io_mk_ds(gid, "SolarZenithAngle", H5T_IEEE_F32BE, 2, dim_siz,
783  &(out_rec->geo_dat_id[5])) != 0) {
784  printf("%s, %d: Could not do h5io_mk_ds for SolarZenithAngle\n",
785  __FILE__, __LINE__);
786  return 1;
787  }
788 
789  if ((in_rec->sola = (float *) malloc(in_rec->npix * in_rec->ndet_scan *
790  sizeof (float))) == NULL) {
791  printf("%s, %d: Could not allocate transfer buffer for SolarZenithAngle\n",
792  __FILE__, __LINE__);
793  return 1;
794  }
795  out_rec->sola = in_rec->sola;
796  /*
797  * StartTime, again the microsecs
798  */
799  dbl_data = (double *) malloc(out_rec->nscan * sizeof (double));
800  if (h5io_set_ds(&(in_rec->geo_fid), "time", &in_ds_id) != 0) {
801  printf("%s, %d: Could not do h5io_set_ds for time\n", __FILE__, __LINE__);
802  return 1;
803  }
804  if (h5io_rd_ds(&in_ds_id, (void *) dbl_data) != 0) {
805  printf("%s, %d: Could not read time\n", __FILE__, __LINE__);
806  return 1;
807  }
808  if (h5io_close(&in_ds_id) != 0) {
809  printf("%s, %d: Could not close time\n", __FILE__, __LINE__);
810  return 1;
811  }
812 
813  llon_data = (int64 *) malloc(out_rec->nscan * sizeof (int64));
814  for (i = 0; i < out_rec->nscan; i++)
815  *(llon_data + i) = sdr_info->t58_day +
816  (int64) (*(dbl_data + i) * 1e6);
817  dim_siz2[0] = out_rec->nscan;
818  if (h5io_mk_ds(gid, "StartTime", H5T_STD_I64BE, 1, dim_siz2, &ds_id)
819  != 0) {
820  printf("%s, %d: Could not do h5io_mk_ds for StartTime\n",
821  __FILE__, __LINE__);
822  return 1;
823  }
824  if (h5io_wr_ds(&ds_id, (void *) llon_data) != 0) {
825  printf("%s, %d: Could not write StartTime\n", __FILE__, __LINE__);
826  return 1;
827  }
828  if (h5io_close(&ds_id) != 0) {
829  printf("%s, %d: Could not close StartTime\n", __FILE__, __LINE__);
830  return 1;
831  }
832 
833  free(flt_data);
834  return 0;
835 }
836 
837 int init_bnd_data(int ibnd, sdr_info_struc *sdr_info, in_rec_struc *in_rec,
838  out_rec_struc *out_rec)
839 /*-----------------------------------------------------------------------------
840  Routine: init_bnd_data
841 
842  Description: make the data arrays for the band files and fill some
843 
844  Arguments:
845  Type Name I/O Description
846  ---- ---- --- -----------
847  int ibnd I band index 0 is band M1...
848  sdr_info_struc * sdr_info I/O general SDR information
849  in_rec_struc * in_rec I/O input file information
850  out_rec_struc * out_rec I/O output file information
851 
852  Modification history:
853 
854  W. Robinson, SAIC 9 Dec 2008 Original development
855  W. Robinson, SAIC 7 Jul 2010 add ability to make all 16 M bands
856  W. Robinson, SAIC 24 Feb 2011 switch scale, offset values to those used
857  by IDPS (keep old method commented just in case)
858 
859 ----------------------------------------------------------------------------*/ {
860  h5io_str ds_id, *gid;
861  int dim_siz[2], dim_siz2[2], *arr_int, i, isdr, iret;
862  static unsigned char m_side = 0;
863  unsigned char *uchar_data;
864  unsigned int *uint32_data;
865  float rad_fac[2], refl_fac[2]; /* versions of scale, offset for sdr
866  scaled values */
867  /* float lam_um; --- not used currently, but may come back */
868  /* these values are scale, offset used/found in IDPS SDR files. Some
869  match my F0 assumptions well, but just use IDPS to avoid confusion
870  Used for RadianceFactors, ReflectanceFactors and
871  BrightnessTemperatureFactors */
872  static float lcl_scale[] = {0.0112657, 0.0125841, 1., 1., 1., 0.000752209,
873  1., 0.00302196, 0.00141331, 0.00130450, 0.000582661, 5.17344e-05,
874  1., 0.000321547, 0.000313153, 0.000265539};
875  static float lcl_offset[] = {-0.21, -0.2, 0., 0., 0., -0.09, 0., -0.14,
876  -0.09, -0.04, -0.02, 0., 0., -0.03, -0.02, -0.02};
877  static float lcl_scale_ref[] = {2.28913e-05, 2.28913e-05, 2.28913e-05,
878  2.28913e-05, 2.28913e-05, 2.28913e-05, 2.28913e-05, 2.28913e-05,
879  2.28913e-05, 2.28913e-05, 2.28913e-05, 0.00251805, 1., 0.00373892,
880  0.00412044, 0.00425779};
881  static float lcl_offset_ref[] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
882  0., 203., 0., 120., 111., 103.};
883  /*
884  * define gid for convenience
885  */
886  m_side = 0;
887  isdr = ibnd + 1; /* isdr is also the commonly known band # M1, ... */
888  gid = &(out_rec->sdr_dat_gid[1][isdr]);
889  /*
890  * datasets are:
891  * ModeGran 1 value, 1 is day, so fill with 1
892  */
893  uchar_data = (unsigned char *) malloc(out_rec->nscan *
894  sizeof ( unsigned char));
895  *uchar_data = 1;
896  dim_siz2[0] = 1;
897  if (h5io_mk_ds(gid, "ModeGran", H5T_STD_U8BE, 1, dim_siz2, &ds_id)
898  != 0) {
899  printf("%s, %d: Could not do h5io_mk_ds for ModeGran\n",
900  __FILE__, __LINE__);
901  return 1;
902  }
903  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
904  printf("%s, %d: Could not write to ModeGran\n", __FILE__, __LINE__);
905  return 1;
906  }
907  if (h5io_close(&ds_id) != 0) {
908  printf("%s, %d: Could not close ModeGran\n", __FILE__, __LINE__);
909  return 1;
910  }
911  free(uchar_data);
912  /*
913  * ModeScan 48 bytes, 1 is day, so fill with 1
914  */
915  uchar_data = (unsigned char *) malloc(out_rec->nscan *
916  sizeof ( unsigned char));
917  for (i = 0; i < out_rec->nscan; i++)
918  *(uchar_data + i) = 1;
919  dim_siz2[0] = out_rec->nscan;
920  if (h5io_mk_ds(gid, "ModeScan", H5T_STD_U8BE, 1, dim_siz2, &ds_id)
921  != 0) {
922  printf("%s, %d: Could not do h5io_mk_ds for ModeScan\n",
923  __FILE__, __LINE__);
924  return 1;
925  }
926  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
927  printf("%s, %d: Could not write to ModeScan\n", __FILE__, __LINE__);
928  return 1;
929  }
930  if (h5io_close(&ds_id) != 0) {
931  printf("%s, %d: Could not close ModeScan\n", __FILE__, __LINE__);
932  return 1;
933  }
934  free(uchar_data);
935  /*
936  * NumberOfBadChecksums
937  */
938  arr_int = (int *) malloc(out_rec->nscan * sizeof ( int));
939  for (i = 0; i < out_rec->nscan; i++)
940  *(arr_int + i) = 1;
941  dim_siz2[0] = out_rec->nscan;
942  if (h5io_mk_ds(gid, "NumberOfBadChecksums", H5T_STD_I32BE, 1,
943  dim_siz2, &ds_id) != 0) {
944  printf("%s, %d: Could not do h5io_mk_ds for NumberOfBadChecksums\n",
945  __FILE__, __LINE__);
946  return 1;
947  }
948  if (h5io_wr_ds(&ds_id, (void *) arr_int) != 0) {
949  printf("%s, %d: Could not write to NumberOfBadChecksums\n",
950  __FILE__, __LINE__);
951  return 1;
952  }
953  if (h5io_close(&ds_id) != 0) {
954  printf("%s, %d: Could not close NumberOfBadChecksums\n",
955  __FILE__, __LINE__);
956  return 1;
957  }
958  free(arr_int);
959  /*
960  * NumberOfDiscardedPackets
961  */
962  arr_int = (int *) malloc(out_rec->nscan * sizeof ( int));
963  for (i = 0; i < out_rec->nscan; i++)
964  *(arr_int + i) = 1;
965  dim_siz2[0] = out_rec->nscan;
966  if (h5io_mk_ds(gid, "NumberOfDiscardedPackets", H5T_STD_I32BE, 1,
967  dim_siz2, &ds_id) != 0) {
968  printf("%s, %d: Could not do h5io_mk_ds for NumberOfDiscardedPackets\n",
969  __FILE__, __LINE__);
970  return 1;
971  }
972  if (h5io_wr_ds(&ds_id, (void *) arr_int) != 0) {
973  printf("%s, %d: Could not write to NumberOfDiscardedPackets\n",
974  __FILE__, __LINE__);
975  return 1;
976  }
977  if (h5io_close(&ds_id) != 0) {
978  printf("%s, %d: Could not close NumberOfDiscardedPackets\n",
979  __FILE__, __LINE__);
980  return 1;
981  }
982  free(arr_int);
983  /*
984  * NumberOfMissingPkts
985  */
986  arr_int = (int *) malloc(out_rec->nscan * sizeof ( int));
987  for (i = 0; i < out_rec->nscan; i++)
988  *(arr_int + i) = 1;
989  dim_siz2[0] = out_rec->nscan;
990  if (h5io_mk_ds(gid, "NumberOfMissingPkts", H5T_STD_I32BE, 1,
991  dim_siz2, &ds_id) != 0) {
992  printf("%s, %d: Could not do h5io_mk_ds for NumberOfMissingPkts\n",
993  __FILE__, __LINE__);
994  return 1;
995  }
996  if (h5io_wr_ds(&ds_id, (void *) arr_int) != 0) {
997  printf("%s, %d: Could not write to NumberOfMissingPkts\n",
998  __FILE__, __LINE__);
999  return 1;
1000  }
1001  if (h5io_close(&ds_id) != 0) {
1002  printf("%s, %d: Could not close NumberOfMissingPkts\n",
1003  __FILE__, __LINE__);
1004  return 1;
1005  }
1006  free(arr_int);
1007  /*
1008  * NumberOfScans
1009  */
1010  arr_int = (int *) malloc(sizeof ( int));
1011  *arr_int = out_rec->nscan;
1012  dim_siz[0] = 1;
1013  if (h5io_mk_ds(gid, "NumberOfScans", H5T_STD_I32BE, 1, dim_siz, &ds_id)
1014  != 0) {
1015  printf("%s, %d: Could not do h5io_mk_ds for NumberOfScans\n",
1016  __FILE__, __LINE__);
1017  return 1;
1018  }
1019  if (h5io_wr_ds(&ds_id, (void *) arr_int) != 0) {
1020  printf("%s, %d: Could not write to NumberOfScans\n", __FILE__, __LINE__);
1021  return 1;
1022  }
1023  if (h5io_close(&ds_id) != 0) {
1024  printf("%s, %d: Could not close NumberOfScans\n", __FILE__, __LINE__);
1025  return 1;
1026  }
1027  free(arr_int);
1028  /*
1029  * PadByte1 ( 3 values of 0) -- just fill with 0 for the 3 values
1030  */
1031  uchar_data = (unsigned char *) malloc(3 * sizeof ( unsigned char));
1032  for (i = 0; i < 3; i++)
1033  *(uchar_data + i) = 0;
1034  dim_siz[0] = 3;
1035  if (h5io_mk_ds(gid, "PadByte1", H5T_STD_U8BE, 1, dim_siz, &ds_id)
1036  != 0) {
1037  printf("%s, %d: Could not do h5io_mk_ds for PadByte1\n",
1038  __FILE__, __LINE__);
1039  return 1;
1040  }
1041  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
1042  printf("%s, %d: Could not write to PadByte1\n", __FILE__, __LINE__);
1043  return 1;
1044  }
1045  if (h5io_close(&ds_id) != 0) {
1046  printf("%s, %d: Could not close PadByte1\n", __FILE__, __LINE__);
1047  return 1;
1048  }
1049  free(uchar_data);
1050  /*
1051  * QF1_VIIRSMBANDSDR Qual flag for all pixels
1052  * set up dataset ids for each band
1053  */
1054  dim_siz[0] = out_rec->nlin;
1055  dim_siz[1] = out_rec->npix;
1056  if (h5io_mk_ds(gid, "QF1_VIIRSMBANDSDR", H5T_STD_U8BE, 2, dim_siz,
1057  &(out_rec->qual1_m_id[ibnd])) != 0) {
1058  printf("%s, %d: Could not do h5io_mk_ds for QF1_VIIRSMBANDSDR\n",
1059  __FILE__, __LINE__);
1060  return 1;
1061  }
1062  /*
1063  * and set a 0 filled default array
1064  */
1065  if ((out_rec->qual1_m[ibnd] = (unsigned char *)
1066  calloc(out_rec->npix * out_rec->ndet_scan, sizeof ( unsigned char)))
1067  == NULL) {
1068  printf("%s, %d: Could not allocate space for qual1_m output for band %d\n",
1069  __FILE__, __LINE__, ibnd);
1070  return 1;
1071  }
1072  /*
1073  * QF2_SCAN_SDR has more qual plus HAM mirror side in low bit
1074  * also set it in the sdr_info ham_side array
1075  */
1076  uchar_data = (unsigned char *) calloc(out_rec->nscan,
1077  sizeof ( unsigned char));
1078  for (i = 0; i < out_rec->nscan; i++) {
1079  *(uchar_data + i) = m_side;
1080  m_side = 1 - m_side;
1081  *(sdr_info->ham_side + i) = m_side;
1082  }
1083  dim_siz[0] = out_rec->nscan;
1084  if (h5io_mk_ds(gid, "QF2_SCAN_SDR", H5T_STD_U8BE, 1, dim_siz, &ds_id)
1085  != 0) {
1086  printf("%s, %d: Could not do h5io_mk_ds for QF2_SCAN_SDR\n",
1087  __FILE__, __LINE__);
1088  return 1;
1089  }
1090  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
1091  printf("%s, %d: Could not write to QF2_SCAN_SDR\n", __FILE__, __LINE__);
1092  return 1;
1093  }
1094  if (h5io_close(&ds_id) != 0) {
1095  printf("%s, %d: Could not close QF2_SCAN_SDR\n", __FILE__, __LINE__);
1096  return 1;
1097  }
1098  free(uchar_data);
1099  /*
1100  * QF3_SCAN_RDR a nscan x 4 value array
1101  */
1102  dim_siz[0] = out_rec->nscan;
1103  dim_siz[1] = 4;
1104  uint32_data = (unsigned int *)
1105  calloc(dim_siz[0] * dim_siz[1], sizeof ( unsigned int));
1106  if (h5io_mk_ds(gid, "QF3_SCAN_RDR", H5T_STD_U32BE, 2, dim_siz, &ds_id)
1107  != 0) {
1108  printf("%s, %d: Could not do h5io_mk_ds for QF3_SCAN_RDR\n",
1109  __FILE__, __LINE__);
1110  return 1;
1111  }
1112  if (h5io_wr_ds(&ds_id, (void *) uint32_data) != 0) {
1113  printf("%s, %d: Could not write to QF3_SCAN_RDR\n", __FILE__, __LINE__);
1114  return 1;
1115  }
1116  if (h5io_close(&ds_id) != 0) {
1117  printf("%s, %d: Could not close QF3_SCAN_RDR\n", __FILE__, __LINE__);
1118  return 1;
1119  }
1120  free(uint32_data);
1121  /*
1122  * QF4_SCAN_SDR 768 values reduced line quality # lines in size
1123  */
1124  uchar_data = (unsigned char *) calloc(out_rec->nlin,
1125  sizeof ( unsigned char));
1126  dim_siz2[0] = out_rec->nlin;
1127  if (h5io_mk_ds(gid, "QF4_SCAN_SDR", H5T_STD_U8BE, 1, dim_siz2, &ds_id)
1128  != 0) {
1129  printf("%s, %d: Could not do h5io_mk_ds for QF4_SCAN_SDR\n",
1130  __FILE__, __LINE__);
1131  return 1;
1132  }
1133  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
1134  printf("%s, %d: Could not write to QF4_SCAN_SDR\n", __FILE__, __LINE__);
1135  return 1;
1136  }
1137  if (h5io_close(&ds_id) != 0) {
1138  printf("%s, %d: Could not close QF4_SCAN_SDR\n", __FILE__, __LINE__);
1139  return 1;
1140  }
1141  free(uchar_data);
1142  /*
1143  * QF5_GRAN_BADDETECTOR 16 values 0 if not any bad detectors
1144  */
1145  uchar_data = (unsigned char *) calloc(out_rec->ndet_scan,
1146  sizeof ( unsigned char));
1147  dim_siz2[0] = out_rec->ndet_scan;
1148  if (h5io_mk_ds(gid, "QF5_GRAN_BADDETECTOR", H5T_STD_U8BE, 1, dim_siz2,
1149  &ds_id) != 0) {
1150  printf("%s, %d: Could not do h5io_mk_ds for QF5_GRAN_BADDETECTOR\n",
1151  __FILE__, __LINE__);
1152  return 1;
1153  }
1154  if (h5io_wr_ds(&ds_id, (void *) uchar_data) != 0) {
1155  printf("%s, %d: Could not write to QF5_GRAN_BADDETECTOR\n",
1156  __FILE__, __LINE__);
1157  return 1;
1158  }
1159  if (h5io_close(&ds_id) != 0) {
1160  printf("%s, %d: Could not close QF5_GRAN_BADDETECTOR\n",
1161  __FILE__, __LINE__);
1162  return 1;
1163  }
1164  free(uchar_data);
1165  /*
1166  * Radiance This is a scan-by-scan output item
1167  */
1168  dim_siz[0] = out_rec->nlin;
1169  dim_siz[1] = out_rec->npix;
1170  /*
1171  * There will have to be an initialization for the input radiance
1172  * dataset dependent on if we do a dummy or take from a L2. If we
1173  * follow the model for init_geo_data, it is put here. However, input
1174  * data for the TOA radiances either are dummy values or come from
1175  * the L2 made by running l2gen in reverse. So, the initialization of
1176  * input rads is best done in rd_l2_init under rd_sim_init.
1177  */
1178  /*
1179  * The radiance dataset is either unsigned short or float depending on
1180  * the band number (argh), so set up accordingly
1181  */
1182  if (out_rec->out_bnd_typ[ibnd] == 0)
1183  iret = h5io_mk_ds(gid, "Radiance", H5T_STD_U16BE, 2, dim_siz,
1184  &(out_rec->bnd_dat_id[0][ibnd]));
1185  else
1186  iret = h5io_mk_ds(gid, "Radiance", H5T_IEEE_F32BE, 2, dim_siz,
1187  &(out_rec->bnd_dat_id[0][ibnd]));
1188  if (iret != 0) {
1189  printf("%s, %d: Could not do h5io_mk_ds for Radiance\n",
1190  __FILE__, __LINE__);
1191  return 1;
1192  }
1193  /*
1194  * allocate the data transfer buffer and make it the same for output
1195  * Note that dn storage allocation (if needed) is done above in init_sdr
1196  */
1197  if ((in_rec->bnd_lt[ibnd] = (float *)
1198  malloc(in_rec->npix * in_rec->ndet_scan * sizeof (float)))
1199  == NULL) {
1200  printf(
1201  "%s, %d: Could not allocate space for radiance data transfer buffer\n",
1202  __FILE__, __LINE__);
1203  return 1;
1204  }
1205 
1206  out_rec->bnd_lt[ibnd] = in_rec->bnd_lt[ibnd];
1207  /*
1208  * set up the flags for the radiances - for missing or bad value output
1209  */
1210  if ((in_rec->bnd_q[ibnd] = (unsigned char *)
1211  malloc(in_rec->npix * in_rec->ndet_scan * sizeof (unsigned char)))
1212  == NULL) {
1213  printf(
1214  "%s, %d: Could not allocate space for output radiance flag buffer\n",
1215  __FILE__, __LINE__);
1216  return 1;
1217  }
1218  out_rec->bnd_q[ibnd] = in_rec->bnd_q[ibnd];
1219  /*
1220  * RadianceFactors - 2 floats of scale and offset:
1221  * only needed for scaled bands
1222  * Lt = <scale> * count + <offset>
1223  * short of finding min, max in granule, could do
1224  * <offset> = 0, <scale> = 1.3 * f0(lambda) / ( PI * ( max_short - 10 ) )
1225  * the f0 is in MKS already and the 1.3 is to allow some room
1226  *
1227  * 24 Feb 2011 WDR This and reflectance set-up does suprisingly well at
1228  * matching the IDPS scale... except for offset and in bands that saturate
1229  * KEEP the old methods for setup and add the aray list set
1230  */
1231  dim_siz[0] = 2;
1232  /*
1233  * The scaling is only set different from [1., 0.] for the scaled radiances
1234  */
1235  if (out_rec->out_bnd_typ[ibnd] == 0) {
1236  /* KEEP, initial way of computing using F0 or top BBT of 500K
1237  *** ALSO note that if this is used again, the scale, offset needs to
1238  be for radiance all the way through, not changing to BBT for M12 - 16
1239  if( out_rec->meas_typ[ibnd] == 0 )
1240  {
1241  out_rec->scale[ibnd] = ( 1.3 * out_rec->f0[ibnd] ) /
1242  ( M_PI * ( float ) ( SOUB_UINT16_FILL - 1 ) );
1243  out_rec->offset[ibnd] = 0.;
1244  }
1245  else
1246  {
1247  lam_um = (float) out_rec->lam_band[ibnd] /1000.;
1248  out_rec->scale[ibnd] = bbt_2_rad( 500., lam_um ) /
1249  (float) ( SOUB_UINT16_FILL - 1 );
1250  out_rec->offset[ibnd] = 0.;
1251  }
1252  */
1253  /* Use IDPS scale offset for radiance scaling */
1254  out_rec->scale[ibnd] = lcl_scale[ibnd];
1255  out_rec->offset[ibnd] = lcl_offset[ibnd];
1256  } else {
1257  out_rec->scale[ibnd] = 1.;
1258  out_rec->offset[ibnd] = 0.;
1259  }
1260  rad_fac[0] = out_rec->scale[ibnd];
1261  rad_fac[1] = out_rec->offset[ibnd];
1262  if (h5io_mk_ds(gid, "RadianceFactors", H5T_IEEE_F32BE, 1, dim_siz, &ds_id)
1263  != 0) {
1264  printf("%s, %d: Could not do h5io_mk_ds for RadianceFactors\n",
1265  __FILE__, __LINE__);
1266  return 1;
1267  }
1268  if (h5io_wr_ds(&ds_id, (void *) rad_fac) != 0) {
1269  printf("%s, %d: Could not write to RadianceFactors\n",
1270  __FILE__, __LINE__);
1271  return 1;
1272  }
1273  if (h5io_close(&ds_id) != 0) {
1274  printf("%s, %d: Could not close RadianceFactors\n", __FILE__, __LINE__);
1275  return 1;
1276  }
1277  if (out_rec->meas_typ[ibnd] == 0) {
1278  /*
1279  * Reflectance - just set up the dataset for output
1280  */
1281  dim_siz[0] = out_rec->nlin;
1282  dim_siz[1] = out_rec->npix;
1283  if (h5io_mk_ds(gid, "Reflectance", H5T_STD_U16BE, 2, dim_siz,
1284  &(out_rec->bnd_dat_id[1][ibnd])) != 0) {
1285  printf("%s, %d: Could not do h5io_mk_ds for Latitude\n",
1286  __FILE__, __LINE__);
1287  return 1;
1288  }
1289  /*
1290  * ReflectanceFactors - 2 floats of scale and offset for all bands
1291  * ref = <scale> * count + <offset>
1292  * short of finding min, max in granule, could do
1293  * <offset> = 0, <scale> = 1.5 / ( max_short - 10 )
1294  */
1295  dim_siz[0] = 2;
1296  /* AGAIN as in RadianceFactors above, KEEP this, same caveats
1297  out_rec->refl_scale[ibnd] = 1.5 / ( float) ( SOUB_UINT16_FILL - 1 );
1298  out_rec->refl_offset[ibnd] = 0.;
1299  */
1300  out_rec->refl_scale[ibnd] = lcl_scale_ref[ibnd];
1301  out_rec->refl_offset[ibnd] = lcl_offset_ref[ibnd];
1302  refl_fac[0] = out_rec->refl_scale[ibnd];
1303  refl_fac[1] = out_rec->refl_offset[ibnd];
1304  if (h5io_mk_ds(gid, "ReflectanceFactors", H5T_IEEE_F32BE, 1,
1305  dim_siz, &ds_id) != 0) {
1306  printf("%s, %d: Could not do h5io_mk_ds for ReflectanceFactors\n",
1307  __FILE__, __LINE__);
1308  return 1;
1309  }
1310  if (h5io_wr_ds(&ds_id, (void *) refl_fac) != 0) {
1311  printf("%s, %d: Could not write to ReflectanceFactors\n",
1312  __FILE__, __LINE__);
1313  return 1;
1314  }
1315  if (h5io_close(&ds_id) != 0) {
1316  printf("%s, %d: Could not close ReflectanceFactors\n",
1317  __FILE__, __LINE__);
1318  return 1;
1319  }
1320  } else {
1321  /*
1322  * BBT, This is a scan-by-scan output item
1323  */
1324  dim_siz[0] = out_rec->nlin;
1325  dim_siz[1] = out_rec->npix;
1326  /*
1327  * The BBT dataset is either unsigned short or float depending on
1328  * the band number, so set up accordingly
1329  */
1330  if (out_rec->out_bnd_typ[ibnd] == 0)
1331  iret = h5io_mk_ds(gid, "BrightnessTemperature", H5T_STD_U16BE, 2,
1332  dim_siz, &(out_rec->bnd_dat_id[1][ibnd]));
1333  else
1334  iret = h5io_mk_ds(gid, "BrightnessTemperature", H5T_IEEE_F32BE, 2,
1335  dim_siz, &(out_rec->bnd_dat_id[1][ibnd]));
1336  if (iret != 0) {
1337  printf("%s, %d: Could not do h5io_mk_ds for BrightnessTemperature\n",
1338  __FILE__, __LINE__);
1339  return 1;
1340  }
1341  /*
1342  * BrightnessTemperatureFactors - 2 floats of scale and offset:
1343  * only needed for scaled bands
1344  * BBT = <scale> * count + <offset>
1345  * short of finding min, max in granule, could do
1346  * <offset> = 0, <scale> = 500. / ( max_short - 10 )
1347  *
1348  * use the refl factor storage for the BBT scaling
1349  */
1350  dim_siz[0] = 2;
1351  /*
1352  * The scaling is only set different from [1., 0.] for the scaled radiances
1353  */
1354  if (out_rec->out_bnd_typ[ibnd] == 0) {
1355  /* AGAIN as in RadianceFactors above, KEEP this, same caveats
1356  out_rec->refl_scale[ibnd] = 500. / ( ( float ) ( SOUB_UINT16_FILL - 1 ) );
1357  out_rec->refl_offset[ibnd] = 0.;
1358  */
1359  out_rec->refl_scale[ibnd] = lcl_scale_ref[ibnd];
1360  out_rec->refl_offset[ibnd] = lcl_offset_ref[ibnd];
1361  } else {
1362  out_rec->refl_scale[ibnd] = 1.;
1363  out_rec->refl_offset[ibnd] = 0.;
1364  }
1365  rad_fac[0] = out_rec->refl_scale[ibnd];
1366  rad_fac[1] = out_rec->refl_offset[ibnd];
1367  if (h5io_mk_ds(gid, "BrightnessTemperatureFactors", H5T_IEEE_F32BE,
1368  1, dim_siz, &ds_id) != 0) {
1369  printf(
1370  "%s, %d: Could not do h5io_mk_ds for BrightnessTemperatureFactors\n",
1371  __FILE__, __LINE__);
1372  return 1;
1373  }
1374  if (h5io_wr_ds(&ds_id, (void *) rad_fac) != 0) {
1375  printf("%s, %d: Could not write to BrightnessTemperatureFactors\n",
1376  __FILE__, __LINE__);
1377  return 1;
1378  }
1379  if (h5io_close(&ds_id) != 0) {
1380  printf("%s, %d: Could not close BrightnessTemperatureFactors\n",
1381  __FILE__, __LINE__);
1382  return 1;
1383  }
1384  }
1385  return 0;
1386 }
1387 
1388 int init_sdr_dpattr(int isdr, h5io_str *dat2_g_id, sdr_info_struc *sdr_info)
1389 /*-----------------------------------------------------------------------------
1390  Routine: init_sdr_dpattr
1391 
1392  Description: make the data product attributes for the sdr files
1393 
1394  Arguments:
1395  Type Name I/O Description
1396  ---- ---- --- -----------
1397  int isdr I SDR file #
1398  h5io_str * dat2_g_id I id for group to place attributes in
1399  sdr_info_struc* sdr_info I structure to hold geolocation
1400  information
1401 
1402  Modification history:
1403 
1404  W. Robinson, SAIC 21 Oct 2008 Original development
1405 
1406 ----------------------------------------------------------------------------*/ {
1407  int n_attr = 7, dims_1_1[] = {1, 1};
1408  int fsw_v = 0;
1409  char op_mode[] = "NPP Normal Operations, VIIRS Operational";
1410  int len_op_mode, len_domain;
1411 
1412  len_op_mode = strlen(op_mode);
1413  len_domain = strlen(sdr_info->domain);
1414  /* note that the attribute info is set up for the geo file and changes
1415  are made for any band differences */
1416  h5attr_struc attrs[] = {
1417  { 1, 1, "Instrument_Short_name", H5T_NATIVE_CHAR, 6, 2, dims_1_1,
1418  (void *) "VIIRS"},
1419  { 1, 1, "N_Anc_Type_Tasked", H5T_NATIVE_CHAR, 9, 2, dims_1_1,
1420  (void *) "Official"},
1421  { 1, 1, "N_Collection_Short_Name", H5T_NATIVE_CHAR, 17, 2, dims_1_1,
1422  (void *) core_g_nm[isdr]},
1423  { 1, 1, "N_Dataset_Type_Tag", H5T_NATIVE_CHAR, 4, 2, dims_1_1,
1424  (void *) "GEO"},
1425  { 0, 0, "N_Instrument_Flight_SW_Version", H5T_STD_I32BE, 0, 2, dims_1_1,
1426  (void *) &fsw_v},
1427  { 1, 1, "N_Processing_Domain", H5T_NATIVE_CHAR, len_domain, 2, dims_1_1,
1428  (void *) sdr_info->domain},
1429  { 1, 1, "Operation_Mode", H5T_NATIVE_CHAR, len_op_mode, 2, dims_1_1,
1430  (void *) op_mode}
1431  };
1432  /*
1433  * ATTRIB NOTES - hard coded except for domain and band specific for
1434  * N_Collection_Short_Name. Some geo / band specific attrs
1435  */
1436  if (isdr > 0) {
1437  /* the N_Anc_Type_Tasked needs to be repressed in the SDR */
1438  attrs[1].express = 0;
1439  /* the N_Dataset_Type_Tag is SDR for the band files */
1440  attrs[3].data = (void *) "SDR";
1441  /* the N_Instrument_Flight_SW_Version needs to be expressed in the SDR */
1442  attrs[4].express = 1;
1443  }
1444  /*
1445  * output the attributes to the location
1446  */
1447  if (wr_attr_seq(dat2_g_id, n_attr, attrs) != 0) {
1448  printf("%s, %d: Could not write data prod attributes\n",
1449  __FILE__, __LINE__);
1450  return 1;
1451  }
1452  return 0;
1453 }
1454 
1455 int init_sdr_agg(int isdr, h5io_str *gid, sdr_info_struc *sdr_info)
1456 /*-----------------------------------------------------------------------------
1457  Routine: init_sdr_agg
1458 
1459  Description: create the aggregation dataset and attributes
1460  in the data products group for a SDR file
1461 
1462  Arguments:
1463  Type Name I/O Description
1464  ---- ---- --- -----------
1465  int isdr I SDR file number
1466  h5io_str * gid I id for group to place dataset and
1467  attributes
1468  sdr_info_struc * sdr_info I structure to hold geolocation
1469  information
1470 
1471  Modification history:
1472 
1473  W. Robinson, SAIC 21 Oct 2008 Original development
1474 
1475 ----------------------------------------------------------------------------*/ {
1476  int n_attr = 9, dims_1_1[] = {1, 1};
1477  char grp_name[100];
1478  uint64 abon = 14;
1479  int ang = 1;
1480  h5attr_struc attrs[] = {
1481  { 1, 1, "AggregateBeginningDate", H5T_NATIVE_CHAR, 9, 2, dims_1_1,
1482  (void *) sdr_info->st_date},
1483  { 1, 1, "AggregateBeginningGranuleID", H5T_NATIVE_CHAR, 16, 2, dims_1_1,
1484  (void *) "NPP001212012151"},
1485  { 1, 0, "AggregateBeginningOrbitNumber", H5T_STD_U64BE, 0, 2, dims_1_1,
1486  (void *) &abon},
1487  { 1, 1, "AggregateBeginningTime", H5T_NATIVE_CHAR, 15, 2, dims_1_1,
1488  (void *) sdr_info->st_time},
1489  { 1, 1, "AggregateEndingDate", H5T_NATIVE_CHAR, 9, 2, dims_1_1,
1490  (void *) sdr_info->en_date},
1491  { 1, 1, "AggregateEndingGranuleID", H5T_NATIVE_CHAR, 16, 2, dims_1_1,
1492  (void *) "NPP001212012151"},
1493  { 1, 0, "AggregateEndingOrbitNumber", H5T_STD_U64BE, 0, 2, dims_1_1,
1494  (void *) &abon},
1495  { 1, 1, "AggregateEndingTime", H5T_NATIVE_CHAR, 15, 2, dims_1_1,
1496  (void *) sdr_info->en_time},
1497  { 1, 0, "AggregateNumberGranules", H5T_STD_I32BE, 0, 2, dims_1_1,
1498  (void *) &ang}
1499  };
1500  /*
1501  * ATTRIB NOTES - some values are hard-coded now
1502  */
1503  h5io_str ds_id;
1504  int dim_siz[2], *arr_int;
1505  /*
1506  * the dataset is a reference dataset, so we'll forgo and just place an int
1507  */
1508  arr_int = (int *) malloc(sizeof ( int));
1509  *arr_int = 666;
1510  dim_siz[0] = 1;
1511  sprintf(grp_name, "%s_Aggr", core_g_nm[isdr]);
1512  if (h5io_mk_ds(gid, grp_name, H5T_NATIVE_INT, 1,
1513  dim_siz, &ds_id) != 0) {
1514  printf("%s, %d: Could not do h5io_mk_ds for grp VIIRS-MOD-GEO-TC_Aggr\n",
1515  __FILE__, __LINE__);
1516  return 1;
1517  }
1518  if (h5io_wr_ds(&ds_id, (void *) arr_int) != 0) {
1519  printf("%s, %d: Could not write to VIIRS-MOD-GEO-TC_Aggr\n",
1520  __FILE__, __LINE__);
1521  return 1;
1522  }
1523  free(arr_int);
1524  /*
1525  * output the attributes to the location
1526  */
1527  if (wr_attr_seq(&ds_id, n_attr, attrs) != 0) {
1528  printf(
1529  "%s, %d: Could not write top attributes for VIIRS-MOD-GEO-TC_Aggr\n",
1530  __FILE__, __LINE__);
1531  return 1;
1532  }
1533  if (h5io_close(&ds_id) != 0) {
1534  printf("%s, %d: Could not close VIIRS-MOD-GEO-TC_Aggr\n",
1535  __FILE__, __LINE__);
1536  return 1;
1537  }
1538  return 0;
1539 }
1540 
1541 int init_sdr_gran(int isdr, h5io_str *gid, sdr_info_struc *sdr_info, out_rec_struc *out_rec)
1542 /*-----------------------------------------------------------------------------
1543  Routine: init_geo_gran
1544 
1545  Description: make the granule dataset and attributes under the data
1546  products groups
1547 
1548  Arguments:
1549  Type Name I/O Description
1550  ---- ---- --- -----------
1551  int isdr I SDR file number
1552  h5io_str * dat2_g_id I id for group to place attributes in
1553  sdr_info_struc * sdr_info I structure to hold geolocation
1554  information
1555  out_rec_struc * out_rec I output record information
1556 
1557  Modification history:
1558 
1559  W. Robinson, SAIC 21 Oct 2008 Original development
1560  W. Robinson, SAIC 13 Oct 2011 change N_Granule_ID to be VYYYYMMDDHHMMSS
1561 
1562 ----------------------------------------------------------------------------*/ {
1563  int n_attr = 49, dims_1_1[] = {1, 1}, len_str, i;
1564  int dims_8_1[] = {8, 1}, dims_9_1[] = {9, 1};
1565  int dims_2_1[] = {2, 1}, dims_anc[] = {19, 1}, dims_aux[] = {5, 1};
1566  int qual_sum_val[2];
1567  float g_ring_lat[8], g_ring_lon[8], gran_bdy[4], nadir_bdy[4];
1568  float fill = 0.;
1569  uint64 beg_orb = 14;
1570  char char33_9[33 * 9], band_id[4], char_100_49[100 * 49 ], grp_nam[100];
1571  char gran_vers[10] = "A1M", doc_ref[10] = "N/A";
1572  char *sw_vers = "viirs_sim_sdr_v0.0", gran_id[16];
1573  char qual_sum_name[ 26 * 2 ], char_anc[ 19 * 106 ], char_aux[ 5 * 106];
1574  unsigned char asc_dec = 0;
1575 
1576  len_str = strlen(sw_vers);
1577  sprintf(gran_id, "V%8.8s%6.6s", sdr_info->st_date, sdr_info->st_time);
1578  h5attr_struc attrs[] = {
1579  { 1, 0, "Ascending/Descending_Indicator", H5T_NATIVE_UCHAR, 0, 2, dims_1_1,
1580  (void *) &asc_dec},
1581  { 0, 1, "Band_ID", H5T_NATIVE_CHAR, 2, 2, dims_1_1,
1582  (void *) band_id},
1583  { 1, 1, "Beginning_Date", H5T_NATIVE_CHAR, 9, 2, dims_1_1,
1584  (void *) sdr_info->st_date},
1585  { 1, 1, "Beginning_Time", H5T_NATIVE_CHAR, 15, 2, dims_1_1,
1586  (void *) sdr_info->st_time},
1587  { 0, 0, "East_Bounding_Coordinate", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1588  (void *) gran_bdy},
1589  { 1, 1, "Ending_Date", H5T_NATIVE_CHAR, 9, 2, dims_1_1,
1590  (void *) sdr_info->en_date},
1591  { 1, 1, "Ending_Time", H5T_NATIVE_CHAR, 15, 2, dims_1_1,
1592  (void *) sdr_info->en_time},
1593  { 1, 0, "G-Ring-Latitude", H5T_IEEE_F32BE, 0, 2, dims_8_1,
1594  (void *) g_ring_lat},
1595  { 1, 0, "G-Ring-Longitude", H5T_IEEE_F32BE, 0, 2, dims_8_1,
1596  (void *) g_ring_lon},
1597  { 1, 1, "N_Algorithm_Version", H5T_NATIVE_CHAR, 8, 2, dims_1_1,
1598  (void *) "Fill"},
1599  { 1, 1, "N_Anc_Filename", H5T_NATIVE_CHAR, 106, 2, dims_anc,
1600  (void *) char_anc},
1601  { 1, 1, "N_Aux_Filename", H5T_NATIVE_CHAR, 106, 2, dims_aux,
1602  (void *) char_aux},
1603  { 1, 0, "N_Beginning_Orbit_Number", H5T_STD_U64BE, 0, 2, dims_1_1,
1604  (void *) &beg_orb},
1605  { 1, 0, "N_Beginning_Time_IET", H5T_STD_U64BE, 0, 1, dims_1_1,
1606  (void *) &(sdr_info->st_58_t)},
1607  { 1, 1, "N_Creation_Date", H5T_NATIVE_CHAR, 9, 2, dims_1_1,
1608  (void *) sdr_info->cre_date},
1609  { 1, 1, "N_Creation_Time", H5T_NATIVE_CHAR, 15, 2, dims_1_1,
1610  (void *) sdr_info->cre_time},
1611  { 1, 0, "N_Ending_Time_IET", H5T_STD_U64BE, 0, 1, dims_1_1,
1612  (void *) &(sdr_info->en_58_t)},
1613  { 0, 1, "N_Graceful_Degradation", H5T_NATIVE_CHAR, 3, 2, dims_1_1,
1614  (void *) "No"},
1615  { 1, 1, "N_Granule_ID", H5T_NATIVE_CHAR, 15, 2, dims_1_1,
1616  (void *) gran_id},
1617  /* old val inserted: (void *)"NPP001212012151" }, */
1618  { 1, 1, "N_Granule_Status", H5T_NATIVE_CHAR, 5, 2, dims_1_1,
1619  (void *) "Fill"},
1620  { 1, 1, "N_Granule_Version", H5T_NATIVE_CHAR, 4, 2, dims_1_1,
1621  (void *) gran_vers},
1622  { 1, 1, "N_Input_Prod", H5T_NATIVE_CHAR, 33, 2, dims_9_1,
1623  (void *) char33_9},
1624  { 1, 1, "N_LEOA_Flag", H5T_NATIVE_CHAR, 4, 2, dims_1_1,
1625  (void *) "Off"},
1626  { 1, 0, "N_Nadir_Latitude_Max", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1627  (void *) (nadir_bdy + 2)},
1628  { 1, 0, "N_Nadir_Latitude_Min", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1629  (void *) (nadir_bdy + 3)},
1630  { 1, 0, "N_Nadir_Longitude_Max", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1631  (void *) nadir_bdy},
1632  { 1, 0, "N_Nadir_Longitude_Min", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1633  (void *) (nadir_bdy + 1)},
1634  { 1, 1, "N_NPOES_Document_Ref", H5T_NATIVE_CHAR, 4, 2, dims_1_1,
1635  (void *) doc_ref},
1636  { 1, 0, "N_Number_Of_Scans", H5T_STD_I32BE, 0, 2, dims_1_1,
1637  (void *) &(out_rec->nscan)},
1638  { 0, 0, "N_Percent_Erroneous_Data", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1639  (void *) &fill},
1640  { 0, 0, "N_Percent_Missing_Data", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1641  (void *) &fill},
1642  { 0, 0, "N_Percent_Not_Applicable_Data", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1643  (void *) &fill},
1644  { 1, 1, "N_Quality_Summary_Names", H5T_NATIVE_CHAR, 26, 2, dims_2_1,
1645  (void *) qual_sum_name},
1646  { 1, 0, "N_Quality_Summary_Values", H5T_STD_I32BE, 0, 2, dims_2_1,
1647  (void *) qual_sum_val},
1648  { 1, 1, "N_Reference_ID", H5T_NATIVE_CHAR, 10, 2, dims_1_1,
1649  (void *) "Who_Cares"},
1650  { 0, 0, "N_Satellite/Local_Azimuth_Angle_Max", H5T_IEEE_F32BE, 0, 2,
1651  dims_1_1, (void *) &fill},
1652  { 0, 0, "N_Satellite/Local_Azimuth_Angle_Min", H5T_IEEE_F32BE, 0, 2,
1653  dims_1_1, (void *) &fill},
1654  { 0, 0, "N_Satellite/Local_Zenith_Angle_Max", H5T_IEEE_F32BE, 0, 2,
1655  dims_1_1, (void *) &fill},
1656  { 0, 0, "N_Satellite/Local_Zenith_Angle_Min", H5T_IEEE_F32BE, 0, 2,
1657  dims_1_1, (void *) &fill},
1658  { 1, 1, "N_Software_Version", H5T_NATIVE_CHAR, len_str, 2, dims_1_1,
1659  (void *) sw_vers},
1660  { 0, 0, "N_Solar_Azimuth_Angle_Max", H5T_IEEE_F32BE, 0, 2,
1661  dims_1_1, (void *) &fill},
1662  { 0, 0, "N_Solar_Azimuth_Angle_Min", H5T_IEEE_F32BE, 0, 2,
1663  dims_1_1, (void *) &fill},
1664  { 0, 0, "N_Solar_Zenith_Angle_Max", H5T_IEEE_F32BE, 0, 2,
1665  dims_1_1, (void *) &fill},
1666  { 0, 0, "N_Solar_Zenith_Angle_Min", H5T_IEEE_F32BE, 0, 2,
1667  dims_1_1, (void *) &fill},
1668  { 1, 1, "N_Spacecraft_Maneuver", H5T_NATIVE_CHAR, 18, 2, dims_1_1,
1669  (void *) "Normal Operations"},
1670  { 0, 0, "North_Bounding_Coordinate", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1671  (void *) (gran_bdy + 2)},
1672  { 0, 0, "South_Bounding_Coordinate", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1673  (void *) (gran_bdy + 3)},
1674  { 0, 0, "West_Bounding_Coordinate", H5T_IEEE_F32BE, 0, 2, dims_1_1,
1675  (void *) (gran_bdy + 1)},
1676  { 1, 1, "N_Day_Night_Flag", H5T_NATIVE_CHAR, 4, 2, dims_1_1,
1677  (void *) "Day"}
1678  };
1679  /*
1680  * ATTRIB NOTES - many attrs are hard-coded now
1681  */
1682  h5io_str ds_id;
1683  int dim_siz[2], *arr_int;
1684  /*
1685  * set the g_ring values here - coordinates of granule perimeter)
1686  */
1687  for (i = 0; i < 8; i++) {
1688  *(g_ring_lat + i) = (float) i * 2.5;
1689  *(g_ring_lon + i) = (float) i * 25;
1690  }
1691  /*
1692  * set something in the input prod strings demo
1693  */
1694  for (i = 0; i < 9; i++)
1695  sprintf((char33_9 + (i * 33)), "Input_prod_#_%d", i);
1696  /*
1697  * Modifications for the band files
1698  */
1699  if (isdr > 0) {
1700  for (i = 0; i < n_attr; i++)
1701  attrs[i].express = 1;
1702  sprintf(band_id, "M%d", isdr);
1703  }
1704  for (i = 0; i < 49; i++)
1705  sprintf((char_100_49 + (i * 100)), "Aux file #%d", i);
1706  for (i = 0; i < 4; i++) {
1707  *(gran_bdy + i) = 0.;
1708  *(nadir_bdy + i) = 0.;
1709  }
1710  strcpy(gran_vers, "A1");
1711  strcpy(doc_ref, "TBD");
1712  /*
1713  * quality summary names fill
1714  */
1715  for (i = 0; i < 2; i++) {
1716  sprintf((qual_sum_name + (i * 26)), "qual sum name %d", i);
1717  *(qual_sum_val + i) = i;
1718  }
1719  /*
1720  * anc and aux fill
1721  */
1722  for (i = 0; i < 19; i++)
1723  sprintf((char_anc + (i * 106)), "Anc file # %d", i);
1724  for (i = 0; i < 5; i++)
1725  sprintf((char_aux + (i * 106)), "Aux file # %d", i);
1726  /*
1727  * the dataset is a reference dataset, so we'll forgo and just place an int
1728  */
1729  arr_int = (int *) malloc(sizeof ( int));
1730  *arr_int = 666;
1731  dim_siz[0] = 1;
1732  sprintf(grp_nam, "%s_Gran_0", core_g_nm[isdr]);
1733  if (h5io_mk_ds(gid, grp_nam, H5T_NATIVE_INT, 1,
1734  dim_siz, &ds_id) != 0) {
1735  printf("%s, %d: Could not do h5io_mk_ds for VIIRS-MOD-GEO-TC_Gran_0\n",
1736  __FILE__, __LINE__);
1737  return 1;
1738  }
1739  if (h5io_wr_ds(&ds_id, (void *) arr_int) != 0) {
1740  printf("%s, %d: Could not write to VIIRS-MOD-GEO-TC_Gran_0\n",
1741  __FILE__, __LINE__);
1742  return 1;
1743  }
1744  free(arr_int);
1745  /*
1746  * output the attributes to the location
1747  */
1748  if (wr_attr_seq(&ds_id, n_attr, attrs) != 0) {
1749  printf(
1750  "%s %d: Could not write top attributes for VIIRS-MOD-GEO-TC_Gran_0\n",
1751  __FILE__, __LINE__);
1752  return 1;
1753  }
1754  if (h5io_close(&ds_id) != 0) {
1755  printf("%s %d: Could not close VIIRS-MOD-GEO-TC_Gran_0\n",
1756  __FILE__, __LINE__);
1757  return 1;
1758  }
1759  return 0;
1760 }
int gen_sdr_fname(int isdr, char *path, sdr_info_struc *sdr_info, int fname_opt, char *fname)
Definition: gen_sdr_fname.c:3
int h5io_mk_grp(h5io_str *id, char *grp_nam, h5io_str *grp_id)
Definition: h5io.c:778
int h5io_wr_ds(h5io_str *ds_id, void *data)
Definition: h5io.c:1094
char * core_g_nm[]
Definition: init_sdr.c:8
#define NULL
Definition: decode_rs.h:63
int init_sdr_agg(int isdr, h5io_str *gid, sdr_info_struc *sdr_info)
Definition: init_sdr.c:1455
#define MAX_BND
Definition: viirs_sim_sdr.h:34
int h5io_close(h5io_str *id)
Definition: h5io.c:115
int wr_attr_seq(h5io_str *, int, h5attr_struc *)
Definition: wr_attr_seq.c:5
int init_sdr(ctl_struc *ctl, sdr_info_struc *sdr_info, in_rec_struc *in_rec, out_rec_struc *out_rec)
Definition: init_sdr.c:14
unsigned long long uint64
int h5io_set_ds(h5io_str *id, char *path_name, h5io_str *ds_id)
Definition: h5io.c:324
long long int64
int init_sdr_gran(int isdr, h5io_str *gid, sdr_info_struc *sdr_info, out_rec_struc *out_rec)
Definition: init_sdr.c:1541
#define basename(s)
Definition: l0chunk_modis.c:29
int init_geo_data(sdr_info_struc *sdr_info, in_rec_struc *in_rec, out_rec_struc *out_rec)
Definition: init_sdr.c:292
int init_bnd_data(int ibnd, sdr_info_struc *sdr_info, in_rec_struc *in_rec, out_rec_struc *out_rec)
Definition: init_sdr.c:837
int h5io_openw(char *file, int opt, h5io_str *id)
Definition: h5io.c:68
int init_sdr_dpattr(int isdr, h5io_str *dat2_g_id, sdr_info_struc *sdr_info)
Definition: init_sdr.c:1388
int h5io_mk_ds(h5io_str *id, char *ds_name, hid_t type, int ndim, int *dim_siz, h5io_str *ds_id)
Definition: h5io.c:821
#define NDET
Definition: polcor.c:13
int h5io_rd_ds(h5io_str *ds_id, void *data)
Definition: h5io.c:505
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")
int init_sdr_top(int isdr, sdr_info_struc *sdr_info, out_rec_struc *out_rec)
Definition: init_sdr.c:207