OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
smigen.cpp
Go to the documentation of this file.
1 // This program reads a l3_bin land product in a sinusoidal projection and
2 // writes either a SMI file in either sinusoidal or platte carre projection or
3 // a true color pgm file.
4 
5 #include <stdio.h>
6 #include <math.h>
7 #include <time.h>
8 #include <libgen.h>
9 #include <stdlib.h>
10 #include <stdint.h>
11 #include <sys/types.h>
12 #include <sys/utsname.h>
13 
14 #include "netcdf.h" // Needs to be first to define netcdf stuff JMG
15 #include "smiinc.h"
16 #include "smigen_input.h"
17 #include "palette.h"
18 #include "hdf.h"
19 #include "hdf5.h"
20 //#include "netcdf.h"
21 #include "hdf_bin.h"
22 
23 #include "smi_maplists.h"
24 
25 #include "genutils.h"
26 #include <timeutils.h>
27 
28 #define PI2 1.570796326794897
29 #define PI 3.141592653589793
30 
31 #define CMD_ARGS "p:r:w:g:" /* Valid commandline options */
32 #define BYTE unsigned char
33 
34 #define MAX_NUM_INPUTROW 1000
35 
36 #define VERSION L3M_SOFTVER_VAL
37 
38 using namespace std;
39 
40 int32 nrows;
41 
42 int32 L3M_PARAMS = 0;
45 char **unit_list;
46 char **scaling_list;
47 float32 *maximum_list;
48 float32 *minimum_list;
49 char **palette_list;
51 
52 extern "C" int32 read_attrs(int32, meta_l3bType *);
53 
54 extern "C" int getlut_file(char * lut_file, short *rlut, short *glut, short *blut);
55 
56 //extern "C" int32_t put_smi(char *l3m_path,
57 int32_t put_smi(char *l3m_path,
58  char *l3m_name,
59  uint8 *l3m_data,
60  int32 *dim_sizes,
61  float32 *lat_range,
62  float32 *lon_range,
63  char *measure,
64  char *scale_type,
65  float32 *si_used,
66  float32 *aminmax,
67  char *atype,
68  char *aopt,
69  char *infiles,
70  float32 *l3m_dminmax,
71  meta_l3bType *meta_l3b,
72  unsigned char *map_palette,
73  char *softid,
74  char *proc_con,
75  instr input,
76  char *precision,
77  /* float32 *si8_used,*/
78  uint8 *qual_byt,
79  uint8 isHDF5,
80  VOIDP fill);
81 
82 extern "C" int smigen_input(int argc, char **argv, instr *input);
83 extern "C" void set_param_string(instr *input_str);
84 
85 /*
86  Revision 5.20 10/31/16
87  Add support for CF compliant metadata
88  J. Gales
89 
90  Revision 5.10 08/03/15
91  Add support for L2C SMAP binfile input
92  J. Gales
93 
94  Revision 5.04 06/06/15
95  Fill "Product Type" attribute for Aquarius
96  J. Gales
97 
98  Revision 5.03 08/08/14
99  Check whether output product exists in input binfile
100  If not then exit with error
101  J. Gales
102 
103  Revision 5.02 03/05/14
104  Add support for additional CF metadata
105  Modify isHDF5/isCDF4 code to handle new netcdf4 library
106  Check for Aquarius mission attribute if possible
107  J. Gales
108 
109  Revision 5.01 02/28/14
110  Add support for l3m data compression
111  J. Gales
112 
113  Revision 5.00 02/14/14
114  Add support for NETCDF4 output
115  J. Gales
116 
117  Revision 4.44 10/04/13
118  Revert default stype to 0
119  Force stype to be specified for non-default products
120  J. Gales
121 
122  Revision 4.43 09/27/13
123  Default stype to 1
124  Add user-defined resolutions: ukm, udeg
125  J. Gales
126 
127  Revision 4.42 06/27/13
128  Check whether specified product exists in NETCDF4 file
129  Call read_attrs()
130  J. Gales
131 
132  Revision 4.41 06/24/13
133  Fix NETCDF4 metadata bug
134  Call read_attrs()
135  J. Gales
136 
137  Revision 4.40 06/14/13
138  Add support for NETCDF4 i/o
139  Add support for HEALPIX
140  J. Gales
141 
142  Revision 4.30 01/30/13
143  Add CF-compliant metadata (HDF5)
144  J. Gales
145 
146  Revision 4.29 09/21/12
147  Test for HDF5 with error handling off
148  J. Gales
149 
150  Revision 4.28 08/08/12
151  Delare "k" variable as int64_t to handle 1km resolution.
152  J. Gales
153 
154  Revision 4.27 02/12/12
155  Print bad resolution in "Improper resolution type" statement.
156  J. Gales
157 
158  Revision 4.26 09/21/11
159  Add support for arctangent scaling (SSS)
160  J. Gales
161 
162  Revision 4.25 07/28/11
163  Incorporate quality fix for gap-fill from Susan Walsh (Miami)
164  J. Gales
165 
166  Revision 4.20 07/18/11
167  Use hdf_bin.h rather than hdf5_bin.h
168  J. Gales
169 
170  Revision 4.18 09/03/10
171  Exit if bad vdata reads
172  J. Gales
173 
174  Revision 4.17 06/21/10
175  Reduce scl_fac for F precision to 100000 to mininize chance of integer
176  overflow for large values.
177  J. Gales
178 
179  Revision 4.16 06/05/10
180  Fix metadata for HDF5 files
181  J. Gales
182 
183  Revision 4.14 12/17/09
184  Trap NaN in sum_buf[k*2]
185  J. Gales
186 
187  Revision 4.13 10/02/09
188  Use endianess() rather than u_name.sysname to check for endian
189  J. Gales
190 
191  Revision 4.12 09/01/09
192  Include the scaling attributes for float
193  Change resolution default to 9km (not SMI)
194  Add fill_value global attribute
195  B. Franz
196 
197  Revision 4.11 08/28/09
198  Fix bad ifile behavior
199  J. Gales
200 
201  Revision 4.10 08/11/09
202  Add processing version
203  Remover rflag
204  J. Gales
205 
206  Revision 4.00 03/12/09
207  Add support for HDF5 input/output
208  J. Gales
209 
210  Revision 3.60 07/16/07
211  Fix 16-bit output for land products
212  Skip "white" coastline for 16-bit land products
213  J. Gales
214 
215  Revision 3.40 04/12/07
216  LONWEST/LONEAST not allowed with SEAMLON
217  Handle cases where min_out_col > max_out_col (regions split by dateline)
218  J. Gales
219 
220  Revision 3.38 04/11/07
221  Fix free() bug for seam_lon != -180
222  J. Gales
223 
224  Revision 3.37 02/07/07
225  Set default value of precision parameter to "B"
226  J. Gales
227 
228  Revision 3.36 11/07/06
229  Set palette to default if not specified for non-prodtable product
230  Set proddesc to "Not Specified" if not specified for non-prodtable product
231  Set precison to "B" if not specified for non-prodtable product
232  J. Gales
233 
234  Revision 3.35 11/07/06
235  Write quality vdata if FLOAT precision
236  J. Gales
237 
238  Revision 3.33 03/28/06
239  Check whether input_row > MAX_NUM_INPUTROW
240  J. Gales
241 
242  Revision 3.32 03/23/06
243  Fix unsigned int print bug for total # of grid points
244  J. Gales
245 
246  Revision 3.31 03/17/06
247  Request palette name if product not found in product list
248  J. Gales
249 
250  */
251 
252 void usage(const char *progname) {
253  printf("%s %s (%s %s)\n",
254  progname, VERSION, __DATE__, __TIME__);
255 
256  printf("\nUsage: %s ifile ofile prod-name\n", progname);
257  printf(" par = parameter filename\n");
258  printf(" ifile = input bin filename\n");
259  printf(" ofile = output map filename\n");
260  printf(" oformat = output format: 1 (HDF4 [default]), 2 (netCDF4), 3 (HDF5)\n");
261  printf(" deflate = apply internal compression for netCDF output\n");
262  printf(" prod = product name\n");
263  printf(" precision = output map precision: 'B' (default), 'I', 'F'\n");
264  printf(" palfile = palette filename\n");
265  printf(" pversion = processing version (default is Unspecified)\n");
266  printf(" datamin = minumum value for data scaling (default is prod-specific)\n");
267  printf(" datamax = maximum value for data scaling (default is prod-specific)\n");
268  printf(" stype = scaling type,1=LINEAR,2=LOG (default is prod-specific)\n");
269  printf(" meas = measurement to map, 1=mean, 2=var, 3=stdev, 4=pixels, 5=scenes (default=1)\n");
270  printf(" loneast = Easternmost longitude (default=+180)\n");
271  printf(" lonwest = Westernmost longitude (default=-180)\n");
272  printf(" latnorth = Northernmost latitude (default=+90)\n");
273  printf(" latsouth = Southernmost latitude (default=-90)\n");
274  printf(" projection = SIN | RECT (default=RECT)\n");
275  printf(" resolution = 36km | 18km | 9km | 4km | 2km | 1km | hkm | qkm\n");
276  printf(" 1deg (one deg) | hdeg (0.5 deg) | qdeg (0.25 deg)\n");
277  printf(" 10deg (0.1 deg) |udeg-#.# (#.# deg)| ukm-#.# (#.# km) (default=9km)\n");
278  printf(" seam_lon = Longitude of Left Edge of Map (default=-180)\n");
279  printf(" proddesc = Product Description\n");
280  printf(" units = Product Units\n");
281  exit(0);
282 }
283 
284 int main(int argc, char **argv) {
285  int32 i, j, l, jm1, tk;
286  int64_t k;
287  int32 out_row;
288  int32 prev_input_row;
289  int32 input_row;
290  int32 input_row_array[MAX_NUM_INPUTROW];
291  int32 *in2out;
292 
293  int32 fid;
294  int32 sdfid;
295  int32 sds_id;
296  int32 vgid;
297  int32 vdata_id[4];
298  int32 status;
299  int32 dims_in[8];
300  int32 rank;
301  int32 nattrs;
302  int32 dims_out[2];
303  int32 dims_out_sub[2];
304  int32 type;
305  int32 max_rowbuf;
306  int32 start[2], edges[2];
307  int32 *out_sum;
308  int32 *out_num;
309  int32 *out_sum_rot;
310  int32 *out_num_rot;
311  int32 input_col;
312  int32 pixmin;
313  int32 pixmax;
314  int32 binindex_buf[4];
315  int32 nread;
316  int32 offset;
317  int32 bin_num;
318  int32 min_out_col, max_out_col;
319  int32 min_out_row, max_out_row;
320  int32 sub_scan[2] = {0, 0};
321  int32 sub_pixl[2];
322  int32 prod_num = -1;
323  int32 filled_data_bins = 0;
324  int32 rotate;
325 
326  uint32 tgp;
327 
328  float32 ratio;
329  float32 cos_theta_output;
330  float32 cos_theta_input;
331  float32 cos_fac;
332  float32 flt_val;
333  float32 wgt;
334  float32 *sum_buf = NULL;
335  float32 scl_fac;
336  float32 latf, lonf;
337 
338  float32 slope, intercept;
339 
340  float64 pix_sz=0;
341 
342  int32 *input_databuf;
343  int32 input_value;
344  int16 nobs;
345  int16 nscenes;
346  int16 *input_databuf_16;
347  int16 cur_ptr;
348  int16 last_ptr;
349  int16 lon, lat;
350  uint16 *ptr_arr;
351  uint16 maxval;
352  uint8 *input_qualbuf;
353  uint8 *qual_buf = NULL;
354  uint8 input_qual;
355  uint8 *best_qual;
356  uint8 *best_qual_rot;
357 
358  uint8 *par_byt;
359  uint8 *qual_byt = NULL;
360  uint16 scale_val_16b;
361  char buf[128];
362  char prodtablename[128];
363  uint8 *binlist_buf = NULL;
364  uint8 fill_val = 255;
365  uint16 fill_val_int16 = 65535;
366  float32 fill_val_float = -32767.0;
367  uint8 i8;
368  uint8 *ptr_i8;
369  VOIDP fill=nullptr;
370 
371  uint8 land_input = 0;
372  uint8 hdf4_input = 0;
373  uint8 hdf5_input = 0;
374  uint8 ncdf4_input = 0;
375  uint8 healpix_input = 0;
376  uint8 default_palfile = 0;
377  meta_l3bType meta_l3b;
378  meta_l3bType *ptr_meta_l3b;
379  instr input;
380 
381  float32 si_used[2], aminmax[2], dminmax[2] = {+1e10, -1e10}, f32;
382 
383  char atype[SMI_MAX_STR_SHORT];
384  char aopt[SMI_MAX_STR_SHORT];
385  char scale_type[SMI_MAX_STR_SHORT];
386  char ptime[SMI_MAX_STR_SHORT];
387 
388  char proc_con[SMI_MAX_STR];
389  char softid[SMI_MAX_STR];
390 
391  char *tmp_str;
392  char *cptr;
393 
394  int16 * mixed_buf[360 * 180];
395  int16 mixed[128][8];
396 
397  short *r, *g, *b;
398 
399  static unsigned int pow2[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256,
400  512, 1024, 2048, 4096, 8192, 16384, 32768};
401  time_t tnow;
402  struct tm *tmnow;
403 
404  struct utsname u_name;
405 
406  FILE *fp;
407  FILE *mask_fp;
408 
409  hid_t binlist_tid;
410  hid_t binindex_tid;
411  hid_t bindata_tid;
412  hid_t bin_dataset_idx;
413  hsize_t one = 1;
414 
415  int get_minmax_rowcol(float32 [], float32 [], char *, int32,
416  int32 *, int32 *, int32 *, int32 *);
417 
418  int32 open_input_hdf(char *, char *, int32 *, int32 *,
419  int32 *, int32 [], meta_l3bType *);
420 
421  int32 open_input_hdf5(char *hdf5_file, char *pname,
422  Hdf::hdf5_bin *input_binfile,
423  hid_t * bin_dataset_idx);
424 
425  int32 open_input_ncdf4(int ncid, const char *pname,
426  size_t *nrows, int *grpid,
427  int *binindex_id, int *binlist_id,
428  int *bindata_id, int *binqual_id,
429  meta_l3bType * meta_l3b);
430 
431  /*
432  row_inp = Nrow_inp * (0.5 - (theta/180))
433  row_out = Nrow_out * (0.5 - (theta/180))
434 
435  Solving for theta/180 we get:
436 
437  row_out = (Nrow_out/Nrow_inp) * row_inp
438 
439 
440  col_inp = Npix_inp * (0.5 + (phi/360) * cos(theta_inp)) "SIN"
441 
442  col_out = Npix_out * (0.5 + (phi/360) * cos(theta_out)) "SIN"
443  col_out = Npix_out * (0.5 + (phi/360)) "RECT"
444 
445  Solving for phi/360 we get:
446 
447  col_out = Npix_out * (0.5 * (1 - fac) + (col_inp/Npix_inp) * fac)
448 
449  where fac = cos(theta_out) / cos(theta_inp) "SIN"
450  where fac = 1 / cos(theta_inp) "RECT"
451 
452  */
453 
455 
456  get_time(ptime);
457 
458  if (smigen_input(argc, argv, &input) != 0) {
459  usage(argv[0]);
460  exit(1);
461  }
462 
463  printf("%s %s (%s %s)\n", argv[0], VERSION, __DATE__, __TIME__);
464 
465  strcpy(proc_con, argv[0]);
466  for (i = 1; i < argc; i++) {
467  strcat(proc_con, " ");
468  strcat(proc_con, argv[i]);
469  }
470 
471  if (input.loneast < -180 || input.loneast > +180) {
472  printf("LONEAST must be between -180 and +180.\n");
473  exit(1);
474  }
475 
476  if (input.lonwest < -180 || input.lonwest > +180) {
477  printf("LONWEST must be between -180 and +180.\n");
478  exit(1);
479  }
480 
481 
482  if ((tmp_str = getenv("OCDATAROOT")) == NULL) {
483  printf("OCDATAROOT environment variable is not defined.\n");
484  return (1);
485  }
486  strcpy(buf, tmp_str);
487  strcat(buf, "/common/smigen_defaults.par");
488  fp = fopen(buf, "r");
489 
490  if (fp == 0x0) {
491  printf("SMIGEN defaults file: %s not found.\n", buf);
492  printf("Using defaults for product table and palette directory.\n");
493 
494  if (strcmp(input.palfile, "DEFAULT") == 0) {
495  strcpy(input.palfile, tmp_str);
496  strcat(input.palfile, "/common/palette");
497  default_palfile = 1;
498  }
499 
500  strcpy(prodtablename, tmp_str);
501  strcat(prodtablename, "/common/smigen_product_table.dat");
502 
503  } else {
504  fgets(buf, 128, fp);
505  if (strcmp(input.palfile, "DEFAULT") == 0) {
506  buf[strlen(buf) - 1] = 0;
507  cptr = strchr(buf, '=') + 1;
508  strcpy(input.palfile, tmp_str);
509  strcat(input.palfile, "/");
510  strcat(input.palfile, cptr);
511  default_palfile = 1;
512  }
513  fgets(buf, 128, fp);
514  buf[strlen(buf) - 1] = 0;
515  cptr = strchr(buf, '=') + 1;
516  strcpy(prodtablename, tmp_str);
517  strcat(prodtablename, "/");
518  strcat(prodtablename, cptr);
519 
520  // kludge for adding deflate to the smigen_defaults.par file
521  // since this code doesn't use clo...
522  fgets(buf, 128, fp);
523  buf[strlen(buf) - 1] = 0;
524  cptr = strchr(buf, '=') + 1;
525  input.deflate = atoi(cptr);
526  fclose(fp);
527  }
528 
529 
530  /* Read product table */
531  fp = fopen(prodtablename, "r");
532  if (fp == 0x0) {
533  printf("SMIGEN product table \"%s\" not found.\n", buf);
534  exit(1);
535  }
536  while (fgets(buf, 128, fp) != NULL) {
537  if ((buf[0] >= 0x41) && (buf[0] <= 0x5a)) L3M_PARAMS++;
538  }
539  fseek(fp, 0, SEEK_SET);
540 
541  parmname_list = (char**) calloc(L3M_PARAMS, sizeof (char *));
542  parmname_short = (char**) calloc(L3M_PARAMS, sizeof (char *));
543  unit_list = (char**) calloc(L3M_PARAMS, sizeof (char *));
544  scaling_list = (char**) calloc(L3M_PARAMS, sizeof (char *));
545  palette_list = (char**) calloc(L3M_PARAMS, sizeof (char *));
546  maximum_list = (float32 *) calloc(L3M_PARAMS, sizeof (float32));
547  minimum_list = (float32 *) calloc(L3M_PARAMS, sizeof (float32));
548  precision_list = (char **) calloc(L3M_PARAMS, sizeof (char *));
549 
550  i = 0;
551  while (fgets(buf, 128, fp) != NULL) {
552  if ((buf[0] >= 0x41) && (buf[0] <= 0x5a)) {
553 
554  cptr = strtok(buf, ":");
555  parmname_list[i] = (char*) malloc(strlen(cptr) + 1);
556  strcpy(parmname_list[i], cptr);
557 
558  cptr = strtok(NULL, ":");
559  parmname_short[i] = (char*) malloc(strlen(cptr) + 1);
560  strcpy(parmname_short[i], cptr);
561 
562  cptr = strtok(NULL, ":");
563  unit_list[i] = (char*) malloc(strlen(cptr) + 1);
564  strcpy(unit_list[i], cptr);
565 
566  cptr = strtok(NULL, ":");
567  scaling_list[i] = (char*) malloc(strlen(cptr) + 1);
568  strcpy(scaling_list[i], cptr);
569 
570  cptr = strtok(NULL, ":");
571  minimum_list[i] = (float32) atof(cptr);
572 
573  cptr = strtok(NULL, ":");
574  maximum_list[i] = (float32) atof(cptr);
575 
576  cptr = strtok(NULL, ":");
577  precision_list[i] = (char*) malloc(strlen(cptr) + 1);
578  strcpy(precision_list[i], cptr);
579 
580  cptr = strtok(NULL, "\n");
581  palette_list[i] = (char*) malloc(strlen(cptr) + 1);
582  strcpy(palette_list[i], cptr);
583 
584  i++;
585  }
586  }
587  fclose(fp);
588 
589 
590  if (strncmp(input.prod, "refl", 4) == 0) {
591 
592  prod_num = -2;
593  input.datamin = 0.0;
594  if (input.datamax == 0.0) input.datamax = 0.394863;
595 
596  intercept = 0.0;
597  slope = 0.0;
598 
599  } else if (strncmp(input.prod, "rhos", 4) == 0) {
600 
601  prod_num = -3;
602  input.datamin = 0.0;
603  if (input.datamax == 0.0) input.datamax = 0.394863;
604 
605  intercept = 0.0;
606  slope = 0.0;
607 
608  } else {
609 
610  for (i = 0; i < L3M_PARAMS; i++) {
611  if (strcmp(parmname_short[i], input.prod) == 0) {
612  cout << i << " " << parmname_short[i] << endl;
613  prod_num = i;
614 
615  strcpy(scale_type, scaling_list[i]);
616  if (input.stype == 1) strcpy(scale_type, "linear");
617  if (input.stype == 2) strcpy(scale_type, "logarithmic");
618  if (input.stype == 3) strcpy(scale_type, "arctan");
619  if (input.stype == 0) {
620  if (strcmp("linear", scale_type) == 0) {
621  input.stype = 1;
622  } else if (strcmp("logarithmic", scale_type) == 0) {
623  input.stype = 2;
624  } else if (strcmp("arctan", scale_type) == 0) {
625  input.stype = 3;
626  }
627  }
628 
629  if (input.datamin == 0.0) input.datamin = minimum_list[i];
630  if (input.datamax == 0.0) input.datamax = maximum_list[i];
631 
632  if (input.precision[0] == 0)
633  strcpy(input.precision, precision_list[i]);
634 
635  /* Set Maximum value */
636  /* ----------------- */
637  if (strcmp(input.precision, "I") == 0) {
638  maxval = 65534;
639  } else {
640  maxval = 250;
641  }
642 
643  if (strcmp(scale_type, "linear") == 0) {
644 
645  strcpy(scale_type, "LINEAR");
646 
647  intercept = input.datamin;
648  slope = (input.datamax - intercept) / maxval;
649  }
650 
651  if (strcmp(scale_type, "logarithmic") == 0) {
652 
653  strcpy(scale_type, "LOG");
654 
655  intercept = log10(input.datamin);
656  slope = (log10(input.datamax) - intercept) / maxval;
657  }
658 
659  if (strcmp(scale_type, "arctan") == 0) {
660  strcpy(scale_type, "ATAN");
661  }
662 
663  if (input.proddesc[0] == 0)
664  strcpy(input.proddesc, parmname_list[i]);
665 
666  if (input.units[0] == 0)
667  strcpy(input.units, unit_list[i]);
668 
669  /* Read palette file */
670  if (default_palfile) {
671  strcat(input.palfile, "/");
672  strcat(input.palfile, palette_list[i]);
673  strcat(input.palfile, ".pal");
674  }
675 
676  if (!(r = (short *) calloc(256, sizeof (short)))) {
677  fprintf(stderr, "smigen: Error allocating space for red.\n");
678  return -1;
679  };
680  if (!(g = (short *) calloc(256, sizeof (short)))) {
681  fprintf(stderr, "smigen: Error allocating space for green.\n");
682  return -1;
683  };
684  if (!(b = (short *) calloc(256, sizeof (short)))) {
685  fprintf(stderr, "smigen: Error allocating space for blue.\n");
686  return -1;
687  };
688 
689  if (getlut_file(input.palfile, r, g, b)) {
690  fprintf(stderr, "Error reading palette file %s\n", input.palfile);
691  free(r);
692  free(g);
693  free(b);
694  return -1;
695  }
696  for (i = 0; i < 256; i++) {
697  input.palette[i * 3] = r[i];
698  input.palette[i * 3 + 1] = g[i];
699  input.palette[i * 3 + 2] = b[i];
700  }
701  free(r);
702  free(g);
703  free(b);
704 
705  break;
706  }
707  }
708  }
709 
710 
711 
712  /* Non-Product Table product */
713  /* ------------------------- */
714  if (prod_num == -1) {
715  printf("Product: \"%s\" not found in default product list.\n\n", input.prod);
716 
717  if (input.datamin == 0 && input.datamax == 0 && input.stype == 0) {
718  printf("Make sure \"datamin\", \"datamax\" and \"stype\"\n");
719  printf("are specified on the command line.\n");
720  exit(1);
721  }
722  if (input.proddesc[0] == 0) strcpy(input.proddesc, "Not Specified");
723  if (input.precision[0] == 0) strcpy(input.precision, "B");
724 
725  if (input.stype == 1) strcpy(scale_type, "linear");
726  if (input.stype == 2) strcpy(scale_type, "logarithmic");
727  if (input.stype == 3) strcpy(scale_type, "arctan");
728 
729  /* Set Maximum value */
730  /* ----------------- */
731  if (strcmp(input.precision, "I") == 0) {
732  maxval = 65534;
733  } else {
734  maxval = 250;
735  }
736 
737  if (strcmp(scale_type, "linear") == 0) {
738 
739  strcpy(scale_type, "LINEAR");
740 
741  intercept = input.datamin;
742  slope = (input.datamax - intercept) / maxval;
743  }
744 
745  if (strcmp(scale_type, "logarithmic") == 0) {
746 
747  strcpy(scale_type, "LOG");
748 
749  intercept = log10(input.datamin);
750  slope = (log10(input.datamax) - intercept) / maxval;
751  }
752 
753  if (strcmp(scale_type, "arctan") == 0) {
754  strcpy(scale_type, "ATAN");
755  }
756 
757  /* Read palette file */
758 
759  if (!(r = (short *) calloc(256, sizeof (short)))) {
760  fprintf(stderr, "smigen: Error allocating space for red.\n");
761  return -1;
762  };
763  if (!(g = (short *) calloc(256, sizeof (short)))) {
764  fprintf(stderr, "smigen: Error allocating space for green.\n");
765  return -1;
766  };
767  if (!(b = (short *) calloc(256, sizeof (short)))) {
768  fprintf(stderr, "smigen: Error allocating space for blue.\n");
769  return -1;
770  };
771 
772  if (strstr(input.palfile, ".pal") == NULL) {
773  strcat(input.palfile, "/default.pal");
774  }
775 
776  if (getlut_file(input.palfile, r, g, b)) {
777  fprintf(stderr, "Error reading palette file %s\n", input.palfile);
778  free(r);
779  free(g);
780  free(b);
781  return -1;
782  }
783  for (i = 0; i < 256; i++) {
784  input.palette[i * 3] = r[i];
785  input.palette[i * 3 + 1] = g[i];
786  input.palette[i * 3 + 2] = b[i];
787  }
788  free(r);
789  free(g);
790  free(b);
791  }
792 
793  aminmax[0] = input.datamin;
794  aminmax[1] = input.datamax;
795  strcpy(atype, scale_type);
796 
797  si_used[0] = slope;
798  si_used[1] = intercept;
799 
800 
801  /* Set slope to 1 and intercept to 0 if float output */
802  /* ------------------------------------------------- */
803  if (strcmp(input.precision, "F") == 0) {
804  strcpy(aopt, "No");
805  si_used[0] = 1;
806  si_used[1] = 0;
807  strcpy(scale_type, "LINEAR");
808  } else {
809  strcpy(aopt, "Yes");
810  }
811 
812  if (strcmp(input.resolution, "SMI") == 0) {
813  dims_out[0] = 2048;
814  dims_out[1] = 4096;
815  } else if (strcmp(input.resolution, "SMI4") == 0) {
816  dims_out[0] = 4096;
817  dims_out[1] = 8192;
818  } else if (strcmp(input.resolution, "LAND") == 0) {
819  dims_out[0] = 4320;
820  dims_out[1] = 8640;
821  } else if (strcmp(input.resolution, "9km") == 0) {
822  dims_out[0] = 2160;
823  dims_out[1] = 4320;
824  } else if (strcmp(input.resolution, "4km") == 0) {
825  dims_out[0] = 4320;
826  dims_out[1] = 8640;
827  } else if (strcmp(input.resolution, "2km") == 0) {
828  dims_out[0] = 4320 * 2;
829  dims_out[1] = 8640 * 2;
830  } else if (strcmp(input.resolution, "1km") == 0) {
831  dims_out[0] = 4320 * 4;
832  dims_out[1] = 8640 * 4;
833  } else if (strcmp(input.resolution, "hkm") == 0) {
834  dims_out[0] = 4320 * 8;
835  dims_out[1] = 8640 * 8;
836  } else if (strcmp(input.resolution, "qkm") == 0) {
837  dims_out[0] = 4320 * 16;
838  dims_out[1] = 8640 * 16;
839  } else if (strcmp(input.resolution, "18km") == 0) {
840  dims_out[0] = 1080;
841  dims_out[1] = 2160;
842  } else if (strcmp(input.resolution, "36km") == 0) {
843  dims_out[0] = 540;
844  dims_out[1] = 1080;
845  } else if (strcmp(input.resolution, "90km") == 0) {
846  dims_out[0] = 216;
847  dims_out[1] = 432;
848  } else if (strcmp(input.resolution, "thirddeg") == 0) {
849  dims_out[0] = 180 * 3;
850  dims_out[1] = 360 * 3;
851  } else if (strcmp(input.resolution, "1deg") == 0) {
852  dims_out[0] = 180;
853  dims_out[1] = 360;
854  } else if (strcmp(input.resolution, "hdeg") == 0) {
855  dims_out[0] = 360;
856  dims_out[1] = 720;
857  } else if (strcmp(input.resolution, "qdeg") == 0) {
858  dims_out[0] = 720;
859  dims_out[1] = 1440;
860  } else if (strcmp(input.resolution, "10deg") == 0) {
861  dims_out[0] = 1800;
862  dims_out[1] = 3600;
863  } else if (strncmp(input.resolution, "udeg-", 5) == 0) {
864  dims_out[0] = (int32) (180 / atof(&input.resolution[5]));
865  dims_out[1] = 2 * dims_out[0];
866  } else if (strncmp(input.resolution, "ukm-", 4) == 0) {
867  dims_out[0] = (int32) (4320 * 4 / atof(&input.resolution[4]) + 0.5);
868  dims_out[1] = 2 * dims_out[0];
869  } else {
870  printf("Improper resolution type: %s\n", input.resolution);
871  exit(1);
872  }
873  printf("dims_out: %d x %d\n", dims_out[0], dims_out[1]);
874  static Hdf::hdf5_bin input_binfile;
875 
876  // Check if HDF5 input file
877  H5E_auto_t old_func;
878  void *old_client_data;
879  H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
880  H5Eset_auto(H5E_DEFAULT, NULL, NULL); // Turn off error handling
881  htri_t ishdf5 = H5Fis_hdf5(input.ifile);
882  // Restore previous error handler
883  H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
884 
885  int ncid, grpid, binindex_id, binlist_id, bindata_id, binqual_id;
886  int nside;
887 
888  if (ishdf5 > 0) {
889  status = nc_open(input.ifile, 0, &ncid);
890  if (status != NC_NOERR) {
891  status = open_input_hdf5(input.ifile, input.prod, &input_binfile,
892  &bin_dataset_idx);
893  if (status == FAIL) exit(1);
894  hdf5_input = 1;
895  } else {
896  char nam_buf[256];
897  nam_buf[0] = 0;
898  status = nc_get_att(ncid, NC_GLOBAL, "Mission", nam_buf);
899  if (status != NC_NOERR)
900  status = nc_get_att(ncid, NC_GLOBAL, "mission", nam_buf);
901  if ((strcmp(nam_buf, "SAC-D Aquarius") == 0) ||
902  (strcmp(nam_buf, "SMAP") == 0)) {
903  nc_close(ncid);
904  status = open_input_hdf5(input.ifile, input.prod, &input_binfile,
905  &bin_dataset_idx);
906  if (status == FAIL) exit(1);
907  hdf5_input = 1;
908  } else {
909  status = open_input_ncdf4(ncid, input.prod, (size_t *) & nrows,
910  &grpid, &binindex_id, &binlist_id,
911  &bindata_id, &binqual_id, &meta_l3b);
912  ncdf4_input = 1;
913  if ((nrows % 2) == 1) {
914  healpix_input = 1;
915  printf("HEALPIX input\n");
916  nside = (nrows + 1) / 4;
917  } else {
918  healpix_input = 0;
919  }
920  }
921  }
922  } else {
923  status = open_input_hdf(input.ifile, input.prod, &fid, &sdfid,
924  &vgid, vdata_id, &meta_l3b);
925 
926  if (status == FAIL) exit(1);
927 
928  sds_id = SDselect(sdfid, SDnametoindex(sdfid, input.prod));
929  if (sds_id != -1) land_input = 1;
930  else hdf4_input = 1;
931 
932  if (hdf4_input == 1 &&
933  (strcmp(input.prod, "pixels") != 0) &&
934  (strcmp(input.prod, "scenes") != 0)) {
935  if (VSfind(fid, input.prod) == 0) {
936  printf("Product \"%s\" not found.\n", input.prod);
937  exit(-1);
938  }
939  }
940  }
941 
942  printf("Input file : %s\n", input.ifile);
943  printf("Projection : %s\n", input.projection);
944  printf("Resolution : %s\n", input.resolution);
945  printf("Gap Fill : %d\n", input.gap_fill);
946  if (input.minobs != 0) printf("Min Obs : %d\n", input.minobs);
947  if (prod_num >= 0) printf("Parameter : %s\n", parmname_list[prod_num]);
948  if (prod_num == -2) printf("Parameter : %s\n", input.prod);
949  if (prod_num == -3) printf("Parameter : %s\n", input.prod);
950  printf("Measure : %s\n", measure_list[input.meas - 1]);
951  printf("Scale Type : %s\n", scale_type);
952  printf("Data Min (abs) : %8.4f\n", input.datamin);
953  printf("Data Max (abs) : %8.4f\n", input.datamax);
954  printf("Precision : %s\n", input.precision);
955  printf("Scale Slope : %8.4f\n", si_used[0]);
956  printf("Scale Intercept : %8.4f\n", si_used[1]);
957  printf("Palette File : %s\n", input.palfile);
958  printf("Eastmost Long. : %8.3f\n", input.loneast);
959  printf("Westmost Long. : %8.3f\n", input.lonwest);
960  printf("Northmost Lat. : %8.3f\n", input.latnorth);
961  printf("Southmost Lat. : %8.3f\n", input.latsouth);
962  printf("Seam Longitude : %8.3f\n\n", input.seam_lon);
963 
964 
965  /* LAND INPUT */
966  /* ========== */
967  if (land_input) {
968 
969  /* SDS input */
970  /* --------- */
971  status = SDgetinfo(sds_id, buf, &rank, dims_in, &type, &nattrs);
972 
973  i = SDfindattr(sdfid, "Pixel size (meters)");
974  if (i != -1) SDreadattr(sdfid, i, (VOIDP) & pix_sz);
975  /* printf("pixsz: %d %f\n", i,pix_sz);*/
976 
977  /* 6371007.181 Earth Radius (m) */
978  dims_in[0] =
979  (int32) ((180 * 6371007.181) / (57.29577951308232087684 * pix_sz) + 0.5);
980  dims_in[1] = 2 * dims_in[0];
981  /*printf("input dimensions (full map): %d %d\n", dims_in[0], dims_in[1]);*/
982 
983  sub_scan[0] = 0;
984  sub_pixl[0] = 0;
985  sub_scan[1] = dims_in[0] - 1;
986  sub_pixl[1] = dims_in[1] - 1;
987  i = SDfindattr(sdfid, "Subset Scan Range");
988  if (i != -1) SDreadattr(sdfid, i, (VOIDP) sub_scan);
989  i = SDfindattr(sdfid, "Subset Pixel Range");
990  if (i != -1) SDreadattr(sdfid, i, (VOIDP) sub_pixl);
991  /* printf("sub_scan (r/c): %d %d sub_pixl (r/c): %d %d\n",
992  sub_scan[0], sub_scan[1], sub_pixl[0], sub_pixl[1]);*/
993 
994  } else if (hdf4_input == 1) {
995 
996  /* BIN INPUT */
997  /* ========= */
998 
999  /* Vdata (bin file) input */
1000  /* ---------------------- */
1001  dims_in[0] = nrows;
1002  dims_in[1] = 2 * nrows;
1003  printf("input dimensions (full map): %d %d\n", dims_in[0], dims_in[1]);
1004 
1005  binlist_buf = (uint8 *) calloc(dims_in[1], 12);
1006  sum_buf = (float32 *) calloc(dims_in[1], 2 * sizeof (float32));
1007  qual_buf = (uint8 *) calloc(dims_in[1], sizeof (uint8));
1008 
1009  strcpy(buf, input.prod);
1010  strcat(buf, "_sum,");
1011  strcat(buf, input.prod);
1012  strcat(buf, "_sum_sq");
1013  status = VSsetfields(vdata_id[0], "bin_num,nobs,nscenes,weights");
1014  status = VSsetfields(vdata_id[1], "start_num,begin,extent,max");
1015  status = VSsetfields(vdata_id[2], buf);
1016  if (vdata_id[3] != -1)
1017  status = VSsetfields(vdata_id[3], "qual_l3");
1018  } else if (hdf5_input == 1) {
1019  // HDF5 BinList
1020  nrows = input_binfile.nrows;
1021  dims_in[0] = nrows;
1022  dims_in[1] = 2 * nrows;
1023  printf("input dimensions (full map): %d %d\n", dims_in[0], dims_in[1]);
1024 
1025  binlist_buf = (uint8 *) calloc(dims_in[1], 12);
1026  sum_buf = (float32 *) calloc(dims_in[1], 2 * sizeof (float32));
1027 
1028  binlist_tid = H5Tcreate(H5T_COMPOUND, 12);
1029  H5Tinsert(binlist_tid, "bin_num", 0, H5T_STD_U32LE);
1030  H5Tinsert(binlist_tid, "nobs", 4, H5T_NATIVE_USHORT);
1031  H5Tinsert(binlist_tid, "nscenes", 6, H5T_NATIVE_USHORT);
1032  H5Tinsert(binlist_tid, "weights", 8, H5T_NATIVE_FLOAT);
1033 
1034  // HDF5 Binindex
1035  binindex_tid = H5Tcreate(H5T_COMPOUND, 16);
1036  H5Tinsert(binindex_tid, "start_num", 0, H5T_STD_I32LE);
1037  H5Tinsert(binindex_tid, "begin", 4, H5T_STD_I32LE);
1038  H5Tinsert(binindex_tid, "extent", 8, H5T_STD_I32LE);
1039  H5Tinsert(binindex_tid, "max", 12, H5T_STD_I32LE);
1040 
1041  // HDF5 BinProduct
1042  bindata_tid = H5Tcreate(H5T_COMPOUND, 2 * sizeof (H5T_NATIVE_FLOAT));
1043 
1044  strcpy(buf, input.prod);
1045  strcat(buf, "_sum");
1046  H5Tinsert(bindata_tid, buf, 0, H5T_NATIVE_FLOAT);
1047 
1048  strcat(buf, "_sq");
1049  H5Tinsert(bindata_tid, buf, sizeof (H5T_NATIVE_FLOAT), H5T_NATIVE_FLOAT);
1050 
1051  vdata_id[3] = -1;
1052  } else {
1053  // NETCDF4
1054  dims_in[0] = nrows;
1055  dims_in[1] = 2 * nrows;
1056 
1057  binlist_buf = (uint8 *) calloc(dims_in[1], 16);
1058  sum_buf = (float32 *) calloc(dims_in[1], 2 * sizeof (float32));
1059 
1060  vdata_id[3] = -1;
1061  if (binqual_id != -1) {
1062  qual_buf = (uint8 *) calloc(dims_in[1], sizeof (uint8));
1063  vdata_id[3] = 0;
1064  }
1065  }
1066 
1067  int binlist_sz;
1068  if (ncdf4_input)
1069  binlist_sz = 16;
1070  else
1071  binlist_sz = 12;
1072 
1073  /* Adjust for geo-subset with bin file input */
1074  /* ----------------------------------------- */
1075  if (hdf4_input || hdf5_input) {
1076  f32 = input.latnorth;
1077  input.latnorth = -input.latsouth;
1078  input.latsouth = -f32;
1079  }
1080 
1081  get_minmax_rowcol(&input.latnorth, &input.lonwest, input.projection,
1082  dims_out[0],
1083  &min_out_row, &max_out_row, &min_out_col, &max_out_col);
1084 
1085  printf("min/max out row/col: %d %d %d %d\n",
1086  min_out_row, max_out_row, min_out_col, max_out_col);
1087 
1088  /*
1089  if ((max_out_row - min_out_row) <= 0 || (max_out_col - min_out_col) <= 0) {
1090  printf("Improper boundary limits: East: %f West: %f North: %f South: %f\n",
1091  input.loneast, input.lonwest, -input.latsouth, -input.latnorth);
1092  exit(1);
1093  }
1094  */
1095 
1096 
1097  if (hdf4_input || hdf5_input) {
1098  f32 = input.latnorth;
1099  input.latnorth = -input.latsouth;
1100  input.latsouth = -f32;
1101  }
1102 
1103  if (land_input && max_out_col < min_out_col) {
1104  printf("max_out_col must be greater than min_out_col for land input.\n");
1105  exit(1);
1106  }
1107 
1108  dims_out_sub[0] = max_out_row - min_out_row + 1;
1109  if (max_out_col > min_out_col) {
1110  dims_out_sub[1] = max_out_col - min_out_col + 1;
1111  } else {
1112  dims_out_sub[1] = dims_out[1] - (min_out_col - max_out_col + 1);
1113  }
1114 
1115  if (strcmp(input.precision, "F") == 0)
1116  par_byt = (uint8 *) calloc(dims_out_sub[0] * dims_out_sub[1],
1117  4 * sizeof (uint8));
1118  else if (strcmp(input.precision, "I") == 0)
1119  par_byt = (uint8 *) calloc(dims_out_sub[0] * dims_out_sub[1],
1120  2 * sizeof (uint8));
1121  else
1122  par_byt = (uint8 *) calloc(dims_out_sub[0] * dims_out_sub[1],
1123  sizeof (uint8));
1124 
1125  if (vdata_id[3] != -1) {
1126  qual_byt = (uint8 *) calloc(dims_out_sub[0] * dims_out_sub[1],
1127  sizeof (uint8));
1128  memset(qual_byt, 255, dims_out_sub[0] * dims_out_sub[1]);
1129  }
1130 
1131 
1132  /* Setup Arrays */
1133  /* ------------ */
1134  out_sum = (int32 *) calloc(dims_out[1], sizeof (int32));
1135  out_num = (int32 *) calloc(dims_out[1], sizeof (int32));
1136  best_qual = (uint8 *) calloc(dims_out[1], sizeof (uint8));
1137 
1138  if (input.seam_lon != -180) {
1139  out_sum_rot = (int32 *) calloc(dims_out[1], sizeof (int32));
1140  out_num_rot = (int32 *) calloc(dims_out[1], sizeof (int32));
1141  best_qual_rot = (uint8 *) calloc(dims_out[1], sizeof (uint8));
1142  }
1143 
1144  ratio = (float32) dims_out[0] / dims_in[0];
1145  max_rowbuf = (int32) (1 / ratio + 1);
1146  if (healpix_input) max_rowbuf *= 2;
1147 
1148  /* input_databuf (sinusoidal rojection) */
1149  input_databuf = (int32 *) calloc(max_rowbuf * dims_in[1], sizeof (int32));
1150  input_databuf_16 = (int16 *) calloc(max_rowbuf * dims_in[1], sizeof (int16));
1151  input_qualbuf = (uint8 *) calloc(max_rowbuf * dims_in[1], sizeof (uint8));
1152 
1153  in2out = (int32 *) calloc(dims_in[0], sizeof (int32));
1154  for (i = 0; i < dims_in[0]; i++) in2out[i] = (int32) ((i + 0.5) * ratio);
1155 
1156  start[1] = 0;
1157  edges[1] = sub_pixl[1] - sub_pixl[0] + 1;
1158 
1159  prev_input_row = 0;
1160  input_row = 0;
1161  int32_t nbinsread = 0;
1162 
1163  if (land_input) scl_fac = 10000;
1164  if (hdf4_input || hdf5_input || ncdf4_input) scl_fac = 1000000;
1165  if (strcmp(input.precision, "F") == 0 && hdf4_input) scl_fac = 100000;
1166  if (strcmp(input.precision, "F") == 0 && hdf5_input) scl_fac = 100000;
1167 
1168  /* For each scan ... (Main Loop) (NORTH to SOUTH) */
1169  /* ---------------------------------------------- */
1170  for (out_row = 0; out_row < dims_out[0]; out_row++) {
1171 
1172  if ((out_row % 500) == 0) {
1173  time(&tnow);
1174  tmnow = localtime(&tnow);
1175  printf("out_row:%6d %s", out_row, asctime(tmnow));
1176  }
1177 
1178  if (healpix_input) {
1179  float cs = cos((out_row + 1)*(180.0 / dims_out[0])*(PI / 180));
1180  if (cs > (2. / 3))
1181  input_row = nside * sqrt(3 * (1 - cs));
1182  else if (cs >= -(2. / 3))
1183  input_row = nside * (2 - 1.5 * cs);
1184  else
1185  input_row = nside * (4 - sqrt(3 * (1 + cs)));
1186  for (i = prev_input_row; i < input_row; i++)
1187  input_row_array[i - prev_input_row] = i;
1188  } else {
1189  i = 0;
1190  while (in2out[input_row] == out_row) {
1191  input_row_array[i++] = input_row;
1192  input_row++;
1193  if (i == MAX_NUM_INPUTROW) {
1194  printf("i > MAX_NUM_INPUTROW\n");
1195  exit(-1);
1196  }
1197  }
1198  }
1199 
1200  start[0] = prev_input_row - sub_scan[0];
1201  edges[0] = input_row - prev_input_row;
1202  /* printf("prev: %d sub_scan: %d\n", prev_input_row, sub_scan[0]);*/
1203 
1204  /* Fill Input Data Buffer */
1205  /* ---------------------- */
1206  if (land_input) {
1207 
1208  /* (Land) Map File Input */
1209  /* --------------------- */
1210  if (start[0] >= 0 && start[0] <= sub_scan[1] - sub_scan[0]) {
1211  status = SDreaddata(sds_id, start, NULL, edges,
1212  (VOIDP) & input_databuf_16[sub_pixl[0]]);
1213 
1214  for (i = 0; i < edges[0] * edges[1]; i++)
1215  input_databuf[sub_pixl[0] + i] = input_databuf_16[sub_pixl[0] + i];
1216  }
1217  } else {
1218 
1219  /* Bin File Input */
1220  /* -------------- */
1221 
1222  /* vdata 0: BinList (bin_num, nobs, nscenes, weights)
1223  vdata 1: BinIndex (start_num, begin, extent, max)
1224  vdata 2: Data (sum, sum_sq)
1225 
1226  where start_num is the starting bin # for each row (1-based)
1227  begin is the starting bin # where data actually exist
1228  (0 if row empty)
1229  extent is the number of bins in row for which data exists
1230  max is the total number of bins in row
1231 
1232  */
1233 
1234  /* Initialize input_databuf */
1235  /* ------------------------ */
1236  for (i = 0; i < max_rowbuf * dims_in[1]; i++) input_databuf[i] = -32767;
1237 
1238  /* For each line in databuf ... */
1239  /* ---------------------------- */
1240  for (i = 0; i < edges[0]; i++) {
1241 
1242  /* Get bin row info */
1243  /* ---------------- */
1244  if (hdf4_input) {
1245  VSseek(vdata_id[1], start[0] + i);
1246  nread = VSread(vdata_id[1], (uint8 *) binindex_buf,
1247  1, FULL_INTERLACE);
1248 
1249  if (nread == -1) {
1250  printf("Problem with binindex read: %d\n", out_row);
1251  exit(1);
1252  }
1253  } else if (hdf5_input) {
1254  // HDF5 input
1255  hid_t dataset = input_binfile.get_index_table();
1256  hid_t filespace = H5Dget_space(dataset);
1257  hsize_t strt = start[0] + i;
1258  status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, &strt, NULL,
1259  &one, NULL);
1260  hid_t dataspace = H5Screate_simple(1, &one, NULL);
1261  status = H5Dread(dataset, binindex_tid, dataspace,
1262  filespace, H5P_DEFAULT, binindex_buf);
1263 
1264  H5Sclose(dataspace);
1265  H5Sclose(filespace);
1266  } else {
1267  size_t indexp = start[0] + i;
1268  status = nc_get_var1(grpid, binindex_id, &indexp, binindex_buf);
1269  }
1270 
1271  /* If row has data ... */
1272  /* ------------------- */
1273  if (binindex_buf[1] != 0) {
1274 
1275  /* error check */
1276  if (binindex_buf[2] > dims_in[1]) {
1277  printf("Bin Index (%d) greater than column dimension (%d) for out row: %d\n",
1278  binindex_buf[2], dims_in[1], out_row);
1279  printf("%d %d\n", out_row, start[0] + i);
1280  exit(1);
1281  }
1282 
1283  /* Get bin #, # of scenes and weights for each filled bin in row */
1284  /* ------------------------------------------------------------- */
1285  if (hdf4_input) {
1286  nread = VSread(vdata_id[0], binlist_buf, binindex_buf[2],
1287  FULL_INTERLACE);
1288  if (nread == -1) {
1289  printf("Problem with binlist read: %d\n", out_row);
1290  exit(1);
1291  }
1292 
1293  /* Get data values (sum, sum_sq) for each filled bin in row */
1294  /* -------------------------------------------------------- */
1295  if (strcmp(input.prod, "pixels") != 0 &&
1296  strcmp(input.prod, "scenes") != 0) {
1297  nread = VSread(vdata_id[2], (uint8 *) sum_buf, binindex_buf[2],
1298  FULL_INTERLACE);
1299 
1300  if (nread == -1) {
1301  printf("Problem with sum/sum_sqr read: %d\n", out_row);
1302  exit(1);
1303  }
1304 
1305  if (vdata_id[3] != -1) {
1306  nread = VSread(vdata_id[3], (uint8 *) qual_buf,
1307  binindex_buf[2], FULL_INTERLACE);
1308 
1309  if (nread == -1) {
1310  printf("Problem with qual_l3 read: %d\n", out_row);
1311  exit(1);
1312  }
1313  }
1314  }
1315  } else if (hdf5_input) {
1316  // HDF5 input
1317 
1318  hsize_t strt = nbinsread;
1319  hsize_t count = binindex_buf[2];
1320 
1321  // Get bin #, # of scenes and weights for each filled bin in row
1322  hid_t dataset = input_binfile.get_list_table();
1323  hid_t filespace = H5Dget_space(dataset);
1324 
1325  status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, &strt,
1326  NULL, &count, NULL);
1327  hid_t dataspace = H5Screate_simple(1, &count, NULL);
1328  status = H5Dread(dataset, binlist_tid, dataspace,
1329  filespace, H5P_DEFAULT, binlist_buf);
1330 
1331  H5Sclose(dataspace);
1332  H5Sclose(filespace);
1333 
1334  // Get data values (sum, sum_sq) for each filled bin in row
1335  if (strcmp(input.prod, "pixels") != 0 &&
1336  strcmp(input.prod, "scenes") != 0) {
1337 
1338  hid_t dataset = input_binfile.get_data_table(bin_dataset_idx);
1339 
1340  hid_t filespace = H5Dget_space(dataset);
1341 
1342  status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, &strt,
1343  NULL, &count, NULL);
1344  hid_t dataspace = H5Screate_simple(1, &count, NULL);
1345  status = H5Dread(dataset, bindata_tid, dataspace,
1346  filespace, H5P_DEFAULT, sum_buf);
1347 
1348  H5Sclose(dataspace);
1349  H5Sclose(filespace);
1350  }
1351 
1352  nbinsread += binindex_buf[2];
1353  } else {
1354  // CDF4 input
1355  size_t strt = nbinsread;
1356  size_t count = binindex_buf[2];
1357 
1358  status = nc_get_vara(grpid, binlist_id, &strt, &count,
1359  binlist_buf);
1360 
1361  if (binqual_id != -1) {
1362  status = nc_get_vara(grpid, binqual_id, &strt, &count,
1363  qual_buf);
1364  }
1365 
1366  if (strcmp(input.prod, "pixels") != 0 &&
1367  strcmp(input.prod, "scenes") != 0) {
1368  status = nc_get_vara(grpid, bindata_id, &strt, &count, sum_buf);
1369  }
1370 
1371  nbinsread += binindex_buf[2];
1372  }
1373 
1374  float heal2sin;
1375  if (healpix_input) {
1376  cos_theta_input =
1377  cos((((input_row_array[i] + 0.5) / dims_in[0]) - 0.5) * PI);
1378  heal2sin = (dims_in[1] * cos_theta_input) / binindex_buf[3];
1379  } else {
1380  offset = (dims_in[1] - binindex_buf[3]) / 2;
1381  }
1382 
1383 
1384  /* Populate input databuf with bin data */
1385  /* ------------------------------------ */
1386  for (k = 0; k < binindex_buf[2]; k++) {
1387  memcpy(&bin_num, &binlist_buf[k * binlist_sz], 4);
1388  memcpy(&nobs, &binlist_buf[k * binlist_sz + 4], 2);
1389  memcpy(&nscenes, &binlist_buf[k * binlist_sz + 6], 2);
1390  memcpy(&wgt, &binlist_buf[k * binlist_sz + 8], 4);
1391 
1392  // Skip if nan
1393  if (input.meas == 1 || input.meas == 2) {
1394  if (isnan(sum_buf[k * 2])) {
1395  continue;
1396  }
1397  }
1398 
1399  /* Check if less than minobs */
1400  if (input.minobs != 0)
1401  if ((uint32_t) nobs < input.minobs) continue;
1402 
1403  if (healpix_input) {
1404  int32_t rot_bin_num = ((bin_num - binindex_buf[0]) +
1405  binindex_buf[3] / 2) % binindex_buf[3];
1406  // j = i*dims_in[1] + (bin_num - binindex_buf[0]) * heal2sin
1407  //+ (dims_in[1] - binindex_buf[3]*heal2sin) / 2;
1408 
1409  j = i * dims_in[1] + rot_bin_num * heal2sin
1410  + (dims_in[1] - binindex_buf[3] * heal2sin) / 2;
1411 
1412  } else {
1413  j = i * dims_in[1] + (bin_num - binindex_buf[0]) + offset;
1414  }
1415  // printf("%d %d %f\n", out_row, j, (bin_num - binindex_buf[0]) * heal2sin);
1416  if (j >= (max_rowbuf * dims_in[1])) {
1417  printf("Databuf element (%d) greater than buffer size (%d) for out_row: %d\n",
1418  j, max_rowbuf * dims_in[1], out_row);
1419  printf("i: %d k: %d bin_num: %d offset: %d\n",
1420  i, (int) k, bin_num, offset);
1421  printf("binindex_buf[0]: %d binindex_buf[1]: %d\n",
1422  binindex_buf[0], binindex_buf[1]);
1423  printf("binindex_buf[2]: %d binindex_buf[3]: %d\n",
1424  binindex_buf[2], binindex_buf[3]);
1425  exit(1);
1426  }
1427 
1428  if (j < 0) {
1429  printf("Databuf element (%d) is negative for out_row: %d\n",
1430  j, out_row);
1431  printf("i: %d k: %d bin_num: %d offset: %d bin_row: %d\n",
1432  i, (int) k, bin_num, offset, start[0] + i);
1433  printf("bin start number for row: %d data starting bin #: %d\n",
1434  binindex_buf[0], binindex_buf[1]);
1435  printf("# of bins in row with data: %d # of bins in row: %d\n",
1436  binindex_buf[2], binindex_buf[3]);
1437  exit(1);
1438  }
1439 
1440  if (vdata_id[3] != -1) input_qualbuf[j] = qual_buf[k];
1441 
1442  if (input.meas == 1) {
1443 
1444  flt_val = sum_buf[k * 2] / wgt;
1445  input_databuf[j] = (int32) (scl_fac * flt_val + 0.5);
1446 
1447  } else if ((input.meas == 2 || input.meas == 3) &&
1448  (wgt * wgt > nscenes)) {
1449 
1450  flt_val = sum_buf[k * 2] / wgt;
1451  flt_val = (sum_buf[k * 2 + 1] / wgt) - (flt_val * flt_val);
1452 
1453  flt_val = flt_val * wgt * wgt / (wgt * wgt - nscenes);
1454 
1455  if (input.meas == 3) flt_val = sqrt(flt_val);
1456 
1457  input_databuf[j] = (int32) (scl_fac * flt_val + 0.5);
1458 
1459  } else if (input.meas == 4) {
1460 
1461  input_databuf[j] = (int32) ((1.0 * nobs) / nscenes + 0.5);
1462 
1463  } else if (input.meas == 5) {
1464 
1465  input_databuf[j] = (int32) (nscenes);
1466  }
1467 
1468  } /* for (k=0; */
1469 
1470 
1471 
1472  /* Shift bin rows with odd number of pixels by "half" pixel */
1473  /* -------------------------------------------------------- */
1474  if (binindex_buf[3] % 2 == 1 &&
1475  input.meas <= 3 &&
1476  getenv("SMIGENNOHALF") == NULL) {
1477 
1478  /* SMIGENNOHALF only set for debugging */
1479 
1480  for (k = dims_in[1] - offset - 2; k >= offset; k--) {
1481 
1482  j = i * dims_in[1] + k;
1483  if (k == offset) jm1 = j + binindex_buf[3] - 1;
1484  else jm1 = j - 1;
1485 
1486  if (input_databuf[jm1] != -32767) {
1487  if (input_databuf[j] != -32767) {
1488  /*
1489  input_databuf[j] += input_databuf[jm1];
1490  input_databuf[j] /= 2;
1491  */
1492  }
1493  }
1494 
1495  } /* k loop */
1496 
1497  /* Last pixel equal to first */
1498  input_databuf[(i + 1) * dims_in[1] - offset - 1] = input_databuf[j];
1499 
1500  } /* if (binindex_buf[3] ... */
1501 
1502  /* Fill in gaps in input buffer */
1503  /* ---------------------------- */
1504  /* 1 pixel gaps */
1505  if (input.gap_fill >= 1 && input.meas <= 3) {
1506  for (k = 1; k < max_rowbuf * dims_in[1] - 1; k++) {
1507  if (input_databuf[k - 1] != -32767 &&
1508  input_databuf[k] == -32767 &&
1509  input_databuf[k + 1] != -32767) {
1510  if ((vdata_id[3] != -1)) {
1511  if (input_qualbuf[k - 1] == input_qualbuf[k + 1]) {
1512  /* same quality, avg data and copy qual to filled pixel */
1513  input_databuf[k] = (int32)
1514  (0.5 * (input_databuf[k - 1] + input_databuf[k + 1]) + 0.5);
1515  input_qualbuf[k] = input_qualbuf[k - 1];
1516  } else {
1517  /* use whichever value has the better (lower) quality */
1518  tk = (input_databuf[k - 1] < input_databuf[k + 1]) ? k - 1 : k + 1;
1519  input_qualbuf[k] = input_qualbuf[tk];
1520  input_databuf[k] = input_databuf[tk];
1521  }
1522  } else {
1523  input_databuf[k] = (int32)
1524  (0.5 * (input_databuf[k - 1] + input_databuf[k + 1]) + 0.5);
1525  }
1526  }
1527  }
1528  }
1529 
1530  /* 2 pixel gaps */
1531  if (input.gap_fill >= 2 && input.meas <= 3) {
1532  for (k = 1; k < max_rowbuf * dims_in[1] - 2; k++) {
1533  if (input_databuf[k - 1] != -32767 &&
1534  input_databuf[k] == -32767 &&
1535  input_databuf[k + 1] == -32767 &&
1536  input_databuf[k + 2] != -32767) {
1537  if ((vdata_id[3] != -1)) {
1538  if (input_qualbuf[k - 1] == input_qualbuf[k + 2]) {
1539  /* same quality, average data and copy quality to filled pixel */
1540  input_databuf[k] = (int32)
1541  ((input_databuf[k + 2] + 2 * input_databuf[k - 1]) / 3 + 0.5);
1542  input_databuf[k + 1] = (int32)
1543  ((2 * input_databuf[k + 2] + input_databuf[k - 1]) / 3 + 0.5);
1544  input_qualbuf[k] = input_qualbuf[k - 1];
1545  input_qualbuf[k + 1] = input_qualbuf[k - 1];
1546  } else {
1547  /* use whichever value has the better (lower) quality */
1548  tk = (input_databuf[k - 1] < input_databuf[k + 2]) ? k - 1 : k + 2;
1549  input_qualbuf[k] = input_qualbuf[tk];
1550  input_databuf[k] = input_databuf[tk];
1551  input_qualbuf[k + 1] = input_qualbuf[tk];
1552  input_databuf[k + 1] = input_databuf[tk];
1553  }
1554  } else {
1555  input_databuf[k] = (int32)
1556  ((input_databuf[k + 2] + 2 * input_databuf[k - 1]) / 3 + 0.5);
1557  input_databuf[k + 1] = (int32)
1558  ((2 * input_databuf[k + 2] + input_databuf[k - 1]) / 3 + 0.5);
1559  }
1560  }
1561  }
1562  }
1563 
1564  } /* if binindex_buf ... */
1565  } /* for (i=0; */
1566 
1567  } /* if (land_input) */
1568 
1569  prev_input_row = input_row;
1570 
1571  if (out_row < min_out_row) continue;
1572  if (out_row > max_out_row) break;
1573 
1574  for (i = 0; i < dims_out[1]; i++) out_sum[i] = -32767;
1575  for (i = 0; i < dims_out[1]; i++) out_num[i] = 0;
1576  for (i = 0; i < dims_out[1]; i++) best_qual[i] = 255;
1577 
1578  cos_theta_output = cos((((out_row + 0.5) / dims_out[0]) - 0.5) * PI);
1579 
1580  /* Loop over rows contributing to output row */
1581  /* ----------------------------------------- */
1582  for (j = 0; j < edges[0]; j++) {
1583 
1584  cos_theta_input =
1585  cos((((input_row_array[j] + 0.5) / dims_in[0]) - 0.5) * PI);
1586 
1587  if (strcmp(input.projection, "SIN") == 0) {
1588  cos_fac = cos_theta_output / cos_theta_input;
1589  pixmin = (int32) (0.5 * dims_out[1] * (1 - cos_theta_output));
1590  pixmax = (int32) (0.5 * dims_out[1] * (1 + cos_theta_output));
1591  }
1592 
1593  if (strcmp(input.projection, "RECT") == 0) {
1594  cos_fac = 1 / cos_theta_input;
1595  pixmin = 0;
1596  pixmax = dims_out[1];
1597  }
1598 
1599  if (pixmin < 0) pixmin = 0;
1600  if (pixmax > dims_out[1]) pixmax = dims_out[1];
1601 
1602  /* For each output pixel accumulate from input pixels */
1603  /* -------------------------------------------------- */
1604  for (i = pixmin; i < pixmax; i++) {
1605 
1606  input_col =
1607  (int32) ((((float32) (i + 0.5) / dims_out[1]) -
1608  0.5 * (1 - cos_fac)) * (dims_in[1] / cos_fac));
1609 
1610  input_value = input_databuf[j * dims_in[1] + input_col];
1611 
1612  if (input_value != -32767) {
1613  // printf("%d %d %d %d\n", out_row, j, i, input_col);
1614  if ((vdata_id[3] != -1)) {
1615  input_qual = input_qualbuf[j * dims_in[1] + input_col];
1616  if (input_qual < best_qual[i]) {
1617  out_num[i] = 0;
1618  out_sum[i] = -32767;
1619  best_qual[i] = input_qual;
1620  } else if (input_qual > best_qual[i]) continue;
1621  }
1622 
1623  out_num[i]++;
1624 
1625  if (out_sum[i] != -32767)
1626  out_sum[i] += input_value;
1627  else
1628  out_sum[i] = input_value;
1629  } /* if ... */
1630  } /* i loop */
1631  } /* j loop */
1632 
1633 
1634  /* Rotate if SEAM_LON != -180 */
1635  /* -------------------------- */
1636  if (input.seam_lon != -180 && land_input == 0) {
1637  rotate = (int32) ((input.seam_lon + 180) * (pixmax - pixmin) / 360 + 0.5);
1638 
1639  for (i = pixmin; i < pixmax; i++) {
1640  out_sum_rot[i] = out_sum[(i + rotate) % (pixmax - pixmin)];
1641  out_num_rot[i] = out_num[(i + rotate) % (pixmax - pixmin)];
1642  best_qual_rot[i] = best_qual[(i + rotate) % (pixmax - pixmin)];
1643  }
1644 
1645  for (i = pixmin; i < pixmax; i++) {
1646  out_sum[i] = out_sum_rot[i];
1647  out_num[i] = out_num_rot[i];
1648  best_qual[i] = best_qual_rot[i];
1649  }
1650  }
1651 
1652 
1653  /* Initialize output byte arrays with fill values */
1654  /* --------------------------------------------- */
1655  if (strncmp(input.prod, "refl", 4) == 0 ||
1656  strncmp(input.prod, "rhos", 4) == 0) {
1657  fill_val = 0;
1658  } else {
1659  fill_val = 255;
1660  }
1661 
1662  for (i = 0; i < dims_out[1]; i++) {
1663 
1664  if (max_out_col > min_out_col) {
1665  if (i < min_out_col || i > max_out_col) continue;
1666  } else {
1667  if (i < min_out_col && i > max_out_col) continue;
1668  }
1669 
1670  if (max_out_col > min_out_col) {
1671  if (land_input || healpix_input)
1672  k = (out_row - min_out_row) * dims_out_sub[1] + (i - min_out_col);
1673  else
1674  k = (max_out_row - out_row) * dims_out_sub[1] + (i - min_out_col);
1675  } else {
1676  if (land_input || healpix_input)
1677  k = (out_row - min_out_row) * dims_out_sub[1] +
1678  (i - min_out_col) * (i >= min_out_col) +
1679  (dims_out[1] - min_out_col + i - 1) * (i < max_out_col);
1680  else
1681  k = (max_out_row - out_row) * dims_out_sub[1] +
1682  (i - min_out_col) * (i >= min_out_col) +
1683  (dims_out[1] - min_out_col + i - 1) * (i < max_out_col);
1684  }
1685 
1686  if (k < 0 || k >= (dims_out_sub[0] * dims_out_sub[1])) {
1687  printf("k: %d i: %d\n", (int) k, i);
1688  exit(1);
1689  }
1690 
1691  if (strcmp(input.precision, "F") == 0) {
1692  memcpy(&par_byt[4 * k], &fill_val_float, 4);
1693  } else if (strcmp(input.precision, "I") == 0) {
1694  memcpy(&par_byt[2 * k], &fill_val, 1);
1695  memcpy(&par_byt[2 * k + 1], &fill_val, 1);
1696  } else if (strcmp(input.precision, "B") == 0) {
1697  par_byt[k] = fill_val;
1698  }
1699  }
1700 
1701  /* Scale each output pixel */
1702  /* ----------------------- */
1703  for (i = 0; i < dims_out[1]; i++) {
1704 
1705  if (max_out_col > min_out_col) {
1706  if (i < min_out_col || i > max_out_col) continue;
1707  } else {
1708  if (i < min_out_col && i > max_out_col) continue;
1709  }
1710 
1711  if (max_out_col > min_out_col) {
1712  if (land_input || healpix_input)
1713  k = (out_row - min_out_row) * dims_out_sub[1] + (i - min_out_col);
1714  else
1715  k = (max_out_row - out_row) * dims_out_sub[1] + (i - min_out_col);
1716  } else {
1717  if (land_input || healpix_input)
1718  k = (out_row - min_out_row) * dims_out_sub[1] +
1719  (i - min_out_col) * (i >= min_out_col) +
1720  (dims_out[1] - min_out_col + i - 1) * (i < max_out_col);
1721  else
1722  k = (max_out_row - out_row) * dims_out_sub[1] +
1723  (i - min_out_col) * (i >= min_out_col) +
1724  (dims_out[1] - min_out_col + i - 1) * (i < max_out_col);
1725  }
1726 
1727  if (out_sum[i] != -32767) {
1728 
1729  filled_data_bins++;
1730 
1731  flt_val = (out_sum[i] / out_num[i]) / scl_fac;
1732 
1733  if (strcmp(input.precision, "F") == 0) {
1734  if (flt_val < dminmax[0]) dminmax[0] = flt_val;
1735  if (flt_val > dminmax[1]) dminmax[1] = flt_val;
1736  memcpy(&par_byt[4 * k], &flt_val, 4);
1737  if (vdata_id[3] != -1) qual_byt[k] = best_qual[i];
1738  continue;
1739  }
1740 
1741  if (flt_val < dminmax[0]) dminmax[0] = flt_val;
1742  if (flt_val > dminmax[1]) dminmax[1] = flt_val;
1743 
1744  if (flt_val < input.datamin) flt_val = input.datamin;
1745  if (flt_val > input.datamax) flt_val = input.datamax;
1746 
1747  if (prod_num == -2) {
1748 
1749  if (out_sum[i] > 0.0) {
1750  flt_val = 396.3 * log10(8.546 * flt_val + 1);
1751  }
1752 
1753  } else if (prod_num == -3) {
1754 
1755  if (flt_val > 0.01)
1756  flt_val = rint((log10(flt_val) + 2.0) / (2.0 / 255));
1757  else
1758  flt_val = 0;
1759 
1760  if (flt_val < 0) flt_val = 0;
1761  if (flt_val > 255) flt_val = 255;
1762 
1763  /*
1764  if (out_sum[i] > 0.0) {
1765  flt_val = 400.0*log10(50.0*flt_val+1);
1766  */
1767 
1768  } else if (strcmp(scale_type, "LINEAR") == 0) {
1769  flt_val = (flt_val - intercept) / slope;
1770  } else if (strcmp(scale_type, "LOG") == 0) {
1771  flt_val = (log10(flt_val) - intercept) / slope;
1772  }
1773 
1774  if (strcmp(input.precision, "I") == 0) {
1775  if (strcmp(input.prod, "pixels") == 0 ||
1776  strcmp(input.prod, "scenes") == 0) {
1777  scale_val_16b = (uint16) out_sum[i];
1778  if (scale_val_16b < dminmax[0]) dminmax[0] = scale_val_16b;
1779  if (scale_val_16b > dminmax[1]) dminmax[1] = scale_val_16b;
1780  } else {
1781  scale_val_16b = (uint16) (flt_val + 0.5);
1782  }
1783  memcpy(&par_byt[2 * k], &scale_val_16b, 2);
1784  } else {
1785  par_byt[k] = (uint8) (flt_val + 0.5);
1786  }
1787 
1788  /* Fill quality output buf */
1789  /* ----------------------- */
1790  if (vdata_id[3] != -1) qual_byt[k] = best_qual[i];
1791 
1792  }
1793  } /* i loop */
1794 
1795  } /* out_row loop */
1796 
1797  if (land_input) SDendaccess(sds_id);
1798 
1799 
1800  /* LAND MASK */
1801  /* --------- */
1802  if (land_input && strcmp(input.projection, "RECT") == 0) {
1803 
1804  tmp_str = getenv("OCDATAROOT");
1805  if (tmp_str == 0x0) {
1806  printf("Environment variable OCDATAROOT not defined.\n");
1807  exit(1);
1808  }
1809  strcpy(buf, tmp_str);
1810  strcat(buf, "/common/landmask.dat");
1811 
1812  printf("Opening: %s for masking\n", buf);
1813  mask_fp = fopen(buf, "rb");
1814 
1815  if (mask_fp == 0x0) {
1816  printf("Land mask file: %s not found.\n", buf);
1817  exit(1);
1818  }
1819 
1820  ptr_arr = (uint16 *) calloc(1024 * 64, sizeof (uint16));
1821  for (i = 0; i < 8 * 128; i++) mixed_buf[i] = NULL;
1822 
1823  fseek(mask_fp, 1024 * 2, SEEK_SET);
1824  fread(ptr_arr, 2, 1024 * 64, mask_fp);
1825 
1826  uname(&u_name);
1827  // if (strcmp(u_name.sysname, "Linux") == 0) {
1828  if (endianess() == 1) {
1829  ptr_i8 = (uint8 *) ptr_arr;
1830  for (i = 0; i < 1024 * 64; i++) {
1831  memcpy(&i8, ptr_i8, 1);
1832  memcpy(ptr_i8, ptr_i8 + 1, 1);
1833  memcpy(ptr_i8 + 1, &i8, 1);
1834  ptr_i8 += 2;
1835  }
1836  }
1837 
1838  /* (NORTH to SOUTH) */
1839  /* ---------------- */
1840  for (out_row = 0; out_row < dims_out[0]; out_row++) {
1841 
1842  if ((out_row % 500) == 0) {
1843  time(&tnow);
1844  tmnow = localtime(&tnow);
1845  /* printf("out_row:%6d %s", out_row, asctime(tmnow));*/
1846  }
1847 
1848  if (out_row < min_out_row) continue;
1849  if (out_row > max_out_row) break;
1850 
1851  if (strcmp(input.projection, "RECT") == 0) {
1852  pixmin = 0;
1853  pixmax = dims_out[1];
1854  }
1855 
1856  if (pixmin < 0) pixmin = 0;
1857  if (pixmax > dims_out[1]) pixmax = dims_out[1];
1858 
1859  lat = 180 - (int32) (((out_row + 0.5) / dims_out[0]) * 180) - 1;
1860  latf = lat - (180 - (((out_row + 0.5) / dims_out[0]) * 180) - 1);
1861 
1862  /* For each output pixel accumulate from input pixels */
1863  /* -------------------------------------------------- */
1864  for (i = pixmin; i < pixmax; i++) {
1865 
1866  if (max_out_col > min_out_col) {
1867  if (i < min_out_col || i > max_out_col) continue;
1868  } else {
1869  if (i < min_out_col && i > max_out_col) continue;
1870  }
1871 
1872  lon = (int32) (((i + 0.5) / dims_out[1]) * 360);
1873  lonf = (((i + 0.5) / dims_out[1]) * 360) - lon;
1874 
1875  cur_ptr = ptr_arr[360 * lat + lon];
1876 
1877  if (cur_ptr == 0) {
1878  last_ptr = 0;
1879 
1880  if (max_out_col > min_out_col) {
1881  k = (out_row - min_out_row) * dims_out_sub[1] + (i - min_out_col);
1882  } else {
1883  k = (out_row - min_out_row) * dims_out_sub[1] +
1884  (i - min_out_col) * (i >= min_out_col) +
1885  (dims_out[1] - min_out_col + i - 1) * (i < max_out_col);
1886  }
1887 
1888  if (strcmp(input.precision, "F") == 0) {
1889  memcpy(&par_byt[4 * k], &fill_val_float, 4);
1890  } else if (strcmp(input.precision, "I") == 0) {
1891  memcpy(&par_byt[2 * k], &fill_val, 1);
1892  memcpy(&par_byt[2 * k + 1], &fill_val, 1);
1893  } else if (strcmp(input.precision, "B") == 0) {
1894  par_byt[k] = fill_val;
1895  }
1896  continue;
1897  }
1898 
1899  if (cur_ptr == 1) {
1900  last_ptr = 1;
1901  continue;
1902  }
1903 
1904  if (cur_ptr > 65 && cur_ptr != last_ptr) {
1905  last_ptr = cur_ptr;
1906  if (mixed_buf[cur_ptr - 66] == NULL) {
1907 
1908  fseek(mask_fp, cur_ptr * 1024 * 2, SEEK_SET);
1909  fread(&mixed[0], 2, 1024, mask_fp);
1910 
1911  // if (strcmp(u_name.sysname, "Linux") == 0) {
1912  if (endianess() == 1) {
1913  ptr_i8 = (uint8 *) & mixed[0];
1914  for (k = 0; k < 1024; k++) {
1915  memcpy(&i8, ptr_i8, 1);
1916  memcpy(ptr_i8, ptr_i8 + 1, 1);
1917  memcpy(ptr_i8 + 1, &i8, 1);
1918  ptr_i8 += 2;
1919  }
1920  }
1921 
1922  mixed_buf[cur_ptr - 66] = (int16 *) calloc(8 * 128, 2);
1923  memcpy(mixed_buf[cur_ptr - 66], &mixed[0], 8 * 128 * 2);
1924 
1925  } else {
1926  memcpy(&mixed[0], mixed_buf[cur_ptr - 66], 8 * 128 * 2);
1927  }
1928  }
1929 
1930  j = (int32) (128 * (1 - latf));
1931  l = (int32) (128 * lonf);
1932  if ((mixed[j][l / 16] & pow2[15 - (l % 16)]) == 0) {
1933 
1934  if (max_out_col > min_out_col) {
1935  k = (out_row - min_out_row) * dims_out_sub[1] + (i - min_out_col);
1936  } else {
1937  k = (out_row - min_out_row) * dims_out_sub[1] +
1938  (i - min_out_col) * (i >= min_out_col) +
1939  (dims_out[1] - min_out_col + i - 1) * (i < max_out_col);
1940  }
1941 
1942  if (strcmp(input.precision, "F") == 0) {
1943  memcpy(&par_byt[4 * k], &fill_val_float, 4);
1944  } else if (strcmp(input.precision, "I") == 0) {
1945  memcpy(&par_byt[2 * k], &fill_val, 1);
1946  memcpy(&par_byt[2 * k + 1], &fill_val, 1);
1947  } else if (strcmp(input.precision, "B") == 0) {
1948  par_byt[k] = fill_val;
1949  }
1950  }
1951 
1952  } /* pixel loop */
1953 
1954  /* Remove "white" coastline pixels */
1955  /* ------------------------------- */
1956  if (strcmp(input.precision, "B") == 0) {
1957 
1958  for (i = pixmin; i < pixmax; i++) {
1959  if (max_out_col > min_out_col) {
1960  if (i < min_out_col || i > max_out_col) continue;
1961  } else {
1962  if (i < min_out_col && i > max_out_col) continue;
1963  }
1964 
1965  if (max_out_col > min_out_col) {
1966  k = (out_row - min_out_row) * dims_out_sub[1] + (i - min_out_col);
1967  } else {
1968  k = (out_row - min_out_row) * dims_out_sub[1] +
1969  (i - min_out_col) * (i >= min_out_col) +
1970  (dims_out[1] - min_out_col + i - 1) * (i < max_out_col);
1971  }
1972 
1973 
1974  /* Left Edge */
1975  /* --------- */
1976  if (i >= min_out_col + 2 && par_byt[k] == 0 && par_byt[k - 1] == 255) {
1977  for (j = k + 1; j < dims_out[1]; j++) {
1978  if (par_byt[j] != 0) {
1979  i8 = par_byt[j];
1980  break;
1981  }
1982  }
1983 
1984  for (l = j - 1; l >= k; l--) {
1985  par_byt[l] = i8;
1986  }
1987  } /* left edge */
1988 
1989  /* Right Edge */
1990  /* ---------- */
1991  if (i <= max_out_col - 2 && par_byt[k] == 0 && par_byt[k + 1] == 255) {
1992  for (j = k - 1; j >= 0; j--) {
1993  if (par_byt[j] != 0) {
1994  i8 = par_byt[j];
1995  break;
1996  }
1997  }
1998 
1999  for (l = j + 1; l <= k; l++) {
2000  par_byt[l] = i8;
2001  }
2002  } /* right edge */
2003 
2004  } /* pixel loop (coastline) */
2005  } /* remove white coastline */
2006 
2007  } /* out_row loop */
2008 
2009  free(ptr_arr);
2010  for (i = 0; i < 360 * 180; i++) {
2011  if (mixed_buf[i] != NULL) free(mixed_buf[i]);
2012  }
2013  fclose(mask_fp);
2014 
2015  } /* End LANDMASK section */
2016 
2017 
2018  printf("\n");
2019  printf("Actual Data Min : %8.4f\n", dminmax[0]);
2020  printf("Actual Data Max : %8.4f\n", dminmax[1]);
2021 
2022  if (strcmp(input.precision, "F") == 0) {
2023  printf("\nData is output in float format (unscaled)\n");
2024  } else {
2025  printf("Scaled Data Min : %8.4f\n", aminmax[0]);
2026  printf("Scaled Data Max : %8.4f\n\n", aminmax[1]);
2027  }
2028 
2029  if (hdf4_input)
2030  printf("\nNumber of input bins : %ld\n", (long)meta_l3b.data_bins);
2031 
2032  printf("Number of filled grid points : %d\n", filled_data_bins);
2033 
2034  tgp = dims_out[0] * dims_out[1];
2035  printf("Total number of grid points : %u\n", tgp);
2036 
2037  printf("Percentage of filled grid points: %8.4f%%\n",
2038  (100 * (float32) filled_data_bins) / tgp);
2039  printf("Output File : %s\n", input.ofile);
2040 
2041 
2042 
2043  /* Write byte data to file */
2044  /* ----------------------- */
2045  if (strncmp(input.prod, "refl", 4) == 0 ||
2046  strncmp(input.prod, "rhos", 4) == 0) {
2047  fp = fopen(input.ofile, "wb");
2048  fprintf(fp, "%s\n", "P5");
2049  fprintf(fp, "%d\n", dims_out_sub[1]);
2050  fprintf(fp, "%d\n", dims_out_sub[0]);
2051  fprintf(fp, "%d\n", 255);
2052  fwrite(&par_byt[0], 1, dims_out_sub[0] * dims_out_sub[1], fp);
2053  fclose(fp);
2054  } else {
2055 
2056  if (strcmp(input.precision, "I") == 0) {
2057  for (i = 0; i < L3M_PARAMS; i++) {
2058  if (strcmp(parmname_short[i], input.prod) == 0) {
2059 
2060  prod_num = i;
2061  /*
2062  si8_used[0] = maximum_list[i];
2063  si8_used[1] = minimum_list[i];
2064  */
2065  break;
2066  }
2067  }
2068  }
2069 
2070  uint8 isHDF5 = 0;
2071  if (getFileFormatName(input.oformat) == NULL) {
2072  if (hdf4_input) strcpy(input.oformat, "HDF4");
2073  if (hdf5_input) strcpy(input.oformat, "HDF5");
2074  if (ncdf4_input) strcpy(input.oformat, "netCDF4");
2075  }
2076  if (strcmp(input.oformat, "HDF5") == 0) isHDF5 = 1;
2077  if (strcmp(input.oformat, "netCDF4") == 0) isHDF5 = 2;
2078  // if (H5Fis_hdf5( input.ifile)) isHDF5 = 1;
2079  // if ( ncdf4_input == 1) isHDF5 = 2;
2081 
2082  if (strcmp(input.precision, "F") == 0) {
2083  fill = (VOIDP) & fill_val_float;
2084  } else if (strcmp(input.precision, "I") == 0) {
2085  fill = (VOIDP) & fill_val_int16;
2086  } else if (strcmp(input.precision, "B") == 0) {
2087  fill = (VOIDP) & fill_val;
2088  }
2089 
2090  ptr_meta_l3b = &meta_l3b;
2091  if (isHDF5 == 1) ptr_meta_l3b = &input_binfile.meta_l3b;
2092  ptr_meta_l3b->data_bins = filled_data_bins;
2093  put_smi(input.ofile, input.prod, par_byt,
2094  dims_out_sub, &input.latnorth, &input.lonwest,
2095  (char*) measure_list[input.meas - 1], scale_type,
2096  si_used, aminmax, atype, aopt, input.ifile, dminmax,
2097  ptr_meta_l3b, (unsigned char *) input.palette, softid, proc_con,
2098  input, input.precision, qual_byt, isHDF5, fill);
2099  }
2100 
2101  free(in2out);
2102  free(input_databuf_16);
2103  free(input_databuf);
2104  free(input_qualbuf);
2105  free(out_sum);
2106  free(out_num);
2107  free(par_byt);
2108  free(qual_byt);
2109  free(best_qual);
2110 
2111  if (input.seam_lon != -180) {
2112  free(out_sum_rot);
2113  free(out_num_rot);
2114  free(best_qual_rot);
2115  }
2116 
2117  if (binlist_buf != NULL) free(binlist_buf);
2118  if (sum_buf != NULL) free(sum_buf);
2119  if (qual_buf != NULL) free(qual_buf);
2120 
2121 
2122  for (i = 0; i < L3M_PARAMS; i++) {
2123  free(parmname_list[i]);
2124  free(parmname_short[i]);
2125  free(unit_list[i]);
2126  free(scaling_list[i]);
2127  free(palette_list[i]);
2128  free(precision_list[i]);
2129  }
2130  free(parmname_list);
2131  free(parmname_short);
2132  free(unit_list);
2133  free(scaling_list);
2134  free(palette_list);
2135  free(maximum_list);
2136  free(minimum_list);
2137  free(precision_list);
2138 
2139  return SUCCEED;
2140 }
2141 
2142 int32 open_input_hdf(char *hdf_file, char *pname, int32 *fid, int32 *sdfid,
2143  int32 *vgid, int32 vdata_id[], meta_l3bType *meta_l3b) {
2144  intn i;
2145  int32 vg_ref;
2146  int32 tag;
2147  int32 ref;
2148  int32 vdid;
2149  char nam_buf[80];
2150  char cls_buf[80];
2151  char *tmp_str;
2152 
2153  if ((*fid = Hopen(hdf_file, DFACC_RDONLY, 0)) < 0) {
2154  fprintf(stderr, "Error: Cannot open input HDF file on Hopen - %s\n",
2155  hdf_file);
2156  return FAIL;
2157  }
2158 
2159  Vstart(*fid);
2160 
2161  if ((*sdfid = SDstart(hdf_file, DFACC_RDONLY)) < 0) {
2162  fprintf(stderr, "Error: Cannot open input HDF file on SDstart- %s\n",
2163  hdf_file);
2164  return FAIL;
2165  }
2166 
2167  read_l3b_meta_hdf4(*sdfid, meta_l3b);
2168 
2169  *vgid = -1;
2170  vdata_id[0] = -1;
2171  vdata_id[1] = -1;
2172  vdata_id[2] = -1;
2173  vdata_id[3] = -1;
2174 
2175  vg_ref = Vfind(*fid, "Level-3 Binned Data");
2176  // HDF4 binfile
2177  if (vg_ref > 0) {
2178  *vgid = Vattach(*fid, vg_ref, "r");
2179 
2180  tmp_str = (char *) malloc(strlen(hdf_file) + 1);
2181  strcpy(tmp_str, hdf_file);
2182 
2183  HXsetdir(dirname(tmp_str));
2184 
2185  for (i = 0; i < Vntagrefs(*vgid); i++) {
2186  Vgettagref(*vgid, i, &tag, &ref);
2187  vdid = VSattach(*fid, ref, "r");
2188  VSgetname(vdid, nam_buf);
2189  VSgetclass(vdid, cls_buf);
2190 
2191  if (strcmp(cls_buf, "DataMain") == 0) {
2192  vdata_id[0] = vdid;
2193  }
2194 
2195  if (strcmp(cls_buf, "Index") == 0) {
2196  vdata_id[1] = vdid;
2197  nrows = VSelts(vdata_id[1]);
2198  }
2199 
2200  if (strcmp(cls_buf, "DataSubordinate") == 0 &&
2201  strcmp(nam_buf, pname) == 0) {
2202  vdata_id[2] = vdid;
2203  }
2204 
2205  if (strcmp(cls_buf, "DataQuality") == 0) {
2206  vdata_id[3] = vdid;
2207  }
2208  }
2209 
2210  free(tmp_str);
2211 
2212  if (vdata_id[0] == -1) {
2213  printf("\"DataMain\" Vdata Not Found.\n");
2214  exit(-1);
2215  }
2216 
2217  if (vdata_id[1] == -1) {
2218  printf("\"Index\" Vdata Not Found.\n");
2219  exit(-1);
2220  }
2221 
2222  } else {
2223 
2224  /* land metadata */
2225 
2226  strcpy(meta_l3b->sensor_name, "SeaWiFS");
2227  strcpy(meta_l3b->sensor,
2228  "Sea-viewing Wide Field-of-view Sensor (SeaWiFS)");
2229 
2230  sprintf(meta_l3b->title, "%s%s", meta_l3b->sensor_name,
2231  " Level-3 Standard Mapped Image");
2232 
2233  strcpy(meta_l3b->mission, "SeaStar SeaWiFS");
2234 
2235  strcpy(meta_l3b->mission_char, "Nominal orbit: inclination = 98.2 (Sun-synchronous); node = 12 noon local (descending); eccentricity = <0.002; altitude = 705 km; ground speed = 6.75 km/sec");
2236 
2237  strcpy(meta_l3b->sensor, "SeaWiFS");
2238 
2239  strcpy(meta_l3b->sensor_char, "Number of bands = 8; number of active bands = 8; wavelengths per band (nm) = 412, 443, 490, 510, 555, 670, 765, 865; bits per pixel = 10; instantaneous field-of-view = 1.5835 mrad; pixels per scan = 1285; scan rate = 6/sec; sample rate = 7710/sec");
2240 
2241  }
2242 
2243  return SUCCEED;
2244 }
2245 
2246 int32 open_input_hdf5(char *hdf5_file, char *pname,
2247  Hdf::hdf5_bin *input_binfile,
2248  hid_t *bin_dataset_idx) {
2249  input_binfile->open(hdf5_file);
2250 
2251  if (strcmp(pname, "pixels") == 0)
2252  return 0;
2253 
2254  char ds_name[200];
2255  int i = 0;
2256 
2257  while (1) {
2258  hid_t dataset = input_binfile->get_data_table(i);
2259  H5Iget_name(dataset, ds_name, 200);
2260  if (strcmp(pname, &ds_name[21]) == 0) break;
2261  i++;
2262 
2263  if (i == input_binfile->nprod()) {
2264  cout << "Input product: \"" << pname
2265  << "\" not found in input binfile." << endl;
2266  exit(1);
2267  }
2268 
2269  }
2270  *bin_dataset_idx = i;
2271  return 0;
2272 }
2273 
2274 int32 open_input_ncdf4(int ncid, const char *pname,
2275  size_t *nrows, int *grpid,
2276  int *binindex_id, int *binlist_id,
2277  int *bindata_id, int *binqual_id,
2278  meta_l3bType *meta_l3b) {
2279  int status;
2280  int dimid;
2281 
2282  status = nc_inq_ncid(ncid, "level-3_binned_data", grpid);
2283  status = nc_inq_dimid(*grpid, "binIndexDim", &dimid);
2284  status = nc_inq_dimlen(*grpid, dimid, nrows);
2285 
2286  status = nc_inq_varid(*grpid, "BinIndex", binindex_id);
2287  status = nc_inq_varid(*grpid, "BinList", binlist_id);
2288 
2289  status = nc_inq_varid(*grpid, pname, bindata_id);
2290  if (status != NC_NOERR) {
2291  cout << "Product \"" << pname << "\" not found in input file" << endl;
2292  exit(1);
2293  }
2294 
2295  status = nc_inq_varid(*grpid, "qual_l3", binqual_id);
2296  if (status != NC_NOERR) *binqual_id = -1;
2297 
2298  read_l3b_meta_hdf4(-ncid, meta_l3b);
2299 
2300  int proc_ctl_grp_id;
2301  status = nc_inq_grp_ncid(ncid, "processing_control", &proc_ctl_grp_id);
2302  status = nc_get_att(proc_ctl_grp_id, NC_GLOBAL, "l2_flag_names",
2303  &meta_l3b->flag_names);
2304 
2305  return 0;
2306 }
2307 
2308 int32 close_input_hdf(int32 fid, int32 sdfid, int32 vgid, int32 vdata_id[1]) {
2309 
2310  if (vgid != -1) {
2311  Vdetach(vgid);
2312  VSdetach(vdata_id[0]);
2313  if (vdata_id[2] != -1) VSdetach(vdata_id[2]);
2314  VSdetach(vdata_id[1]);
2315  }
2316 
2317  SDend(sdfid);
2318  Vend(fid);
2319  Hclose(fid);
2320 
2321  return SUCCEED;
2322 }
2323 
2324 int get_minmax_rowcol(float32 lat_range[], float32 lon_range[],
2325  char* proj_type, int32 out_rows,
2326  int32 *min_out_row, int32 *max_out_row,
2327  int32 *min_out_col, int32 *max_out_col) {
2328  int32 n_w, n_e, s_w, s_e, w_0, e_0;
2329 
2330  *min_out_row = (int32) (out_rows * (90 - lat_range[0]) / 180);
2331  *max_out_row = (int32) (out_rows * (90 - lat_range[1]) / 180 - 1);
2332 
2333 
2334  if (strcmp(proj_type, "SIN") == 0) {
2335  n_w = (int32) ((cos(lat_range[0] * PI / 180) * out_rows) * (lon_range[0] / 180) + out_rows);
2336  n_e = (int32) ((cos(lat_range[0] * PI / 180) * out_rows) * (lon_range[1] / 180) + out_rows);
2337  s_w = (int32) ((cos(lat_range[1] * PI / 180) * out_rows) * (lon_range[0] / 180) + out_rows);
2338  s_e = (int32) ((cos(lat_range[1] * PI / 180) * out_rows) * (lon_range[1] / 180) + out_rows);
2339  w_0 = (int32) ((out_rows) * (lon_range[0] / 180) + out_rows);
2340  e_0 = (int32) ((out_rows) * (lon_range[1] / 180) + out_rows);
2341  }
2342 
2343  if (strcmp(proj_type, "RECT") == 0) {
2344  n_w = (int32) ((out_rows) * (lon_range[0] / 180) + out_rows);
2345  n_e = (int32) ((out_rows) * (lon_range[1] / 180) + out_rows);
2346  s_w = (int32) ((out_rows) * (lon_range[0] / 180) + out_rows);
2347  s_e = (int32) ((out_rows) * (lon_range[1] / 180) + out_rows);
2348  w_0 = (int32) ((out_rows) * (lon_range[0] / 180) + out_rows);
2349  e_0 = (int32) ((out_rows) * (lon_range[1] / 180) + out_rows);
2350  }
2351 
2352  if ((lat_range[0] * lat_range[1]) < 0) {
2353  if (n_w <= s_w && n_w <= w_0) *min_out_col = n_w;
2354  if (s_w <= n_w && s_w <= w_0) *min_out_col = s_w;
2355  if (w_0 <= s_w && w_0 <= n_w) *min_out_col = w_0;
2356 
2357  if (n_e >= s_e && n_e >= e_0) *max_out_col = n_e - 1;
2358  if (s_e >= n_e && s_e >= e_0) *max_out_col = s_e - 1;
2359  if (e_0 >= s_e && e_0 >= n_e) *max_out_col = e_0 - 1;
2360  } else {
2361  if (n_w <= s_w) *min_out_col = n_w;
2362  if (s_w <= n_w) *min_out_col = s_w;
2363 
2364  if (n_e >= s_e) *max_out_col = n_e - 1;
2365  if (s_e >= n_e) *max_out_col = s_e - 1;
2366  }
2367 
2368  return 1;
2369 }
2370 
char ** palette_list
Definition: smigen.cpp:49
integer, parameter int16
Definition: cubeio.f90:3
int r
Definition: decode_rs.h:73
uint8_t isHDF5
Definition: get_l3m.c:8
int j
Definition: decode_rs.h:73
char ** parmname_short
Definition: smigen.cpp:44
int status
Definition: l1_czcs_hdf.c:32
int32 open_input_ncdf4(int ncid, const char *pname, size_t *nrows, int *grpid, int *binindex_id, int *binlist_id, int *bindata_id, int *binqual_id, meta_l3bType *meta_l3b)
Definition: smigen.cpp:2274
#define VERSION
Definition: smigen.cpp:36
int32 nrows
Definition: smigen.cpp:40
int32 L3M_PARAMS
Definition: smigen.cpp:42
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
int32_t read_l3b_meta_hdf4(int32_t sdfid, meta_l3bType *meta_l3b)
char mission[SM_ATTRSZ]
Definition: meta_l3b.h:21
int main(int argc, char **argv)
Definition: smigen.cpp:284
char sensor_char[SM_ATTRSZ]
Definition: meta_l3b.h:24
int32 open_input_hdf5(char *hdf5_file, char *pname, Hdf::hdf5_bin *input_binfile, hid_t *bin_dataset_idx)
Definition: smigen.cpp:2246
float32 * maximum_list
Definition: smigen.cpp:47
#define SMI_MAX_STR
Definition: smiinc.h:18
float * lat
float tm[MODELMAX]
void usage(const char *progname)
Definition: smigen.cpp:252
char flag_names[SM_ATTRSZ]
Definition: meta_l3b.h:37
Definition: spline.h:41
#define MAX_NUM_INPUTROW
Definition: smigen.cpp:34
int32_t nobs
Definition: atrem_cor.h:93
instr * input
int endianess(void)
determine endianess
Definition: endianess.c:10
const char * measure_list[]
Definition: smi_maplists.h:6
int setlinebuf(FILE *stream)
char sensor[SM_ATTRSZ]
Definition: meta_l3b.h:23
int32 open_input_hdf(char *hdf_file, char *pname, int32 *fid, int32 *sdfid, int32 *vgid, int32 vdata_id[], meta_l3bType *meta_l3b)
Definition: smigen.cpp:2142
void get_time(char *pr_time)
Definition: get_time.c:28
hid_t get_list_table()
Definition: hdf_bin.h:349
const char * getFileFormatName(const char *str)
int32_t nrows
Definition: hdf_bin.h:119
hid_t get_index_table()
Definition: hdf_bin.h:345
int32 read_attrs(int32, meta_l3bType *)
virtual int32_t nprod()
Definition: hdf_bin.h:108
float32 slope[]
Definition: l2lists.h:30
meta_l3bType meta_l3b
Definition: hdf_bin.h:131
void set_param_string(instr *input_str)
Definition: smigen_input.c:138
float32 intercept[]
Definition: l2lists.h:44
#define PI
Definition: smigen.cpp:29
int open(const char *l3b_filename)
Definition: bin_io.cpp:1172
but the philosophy of the MODIS L1 routines is that the output granule must be if it contains even a single packet of useable data Some of the spacecraft ancillary data in L0 datasets is available only on a cycle that repeates every seconds MOD_PR01 therefore looks backwards up to for such packets If the seconds preceeding the start of an MOD_PR01 run are covered by a different L0 dataset
Definition: MOD_PR01_pr.txt:33
char title[SM_ATTRSZ]
Definition: meta_l3b.h:17
char ** precision_list
Definition: smigen.cpp:50
char ** unit_list
Definition: smigen.cpp:45
char ** scaling_list
Definition: smigen.cpp:46
data_t b[NROOTS+1]
Definition: decode_rs.h:77
int getlut_file(char *lut_file, short *rlut, short *glut, short *blut)
Definition: getlut_file.c:8
float32 * minimum_list
Definition: smigen.cpp:48
int smigen_input(int argc, char **argv, instr *input)
Definition: smigen_input.c:70
int32_t put_smi(char *l3m_path, char *l3m_name, uint8 *l3m_data, int32 *dim_sizes, float32 *lat_range, float32 *lon_range, char *measure, char *scale_type, float32 *si_used, float32 *aminmax, char *atype, char *aopt, char *infiles, float32 *l3m_dminmax, meta_l3bType *meta_l3b, unsigned char *map_palette, char *softid, char *proc_con, instr input, char *precision, uint8 *qual_byt, uint8 isHDF5, VOIDP fill)
char ** parmname_list
Definition: smigen.cpp:43
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that and then aggregated up to Resolved feature request Bug by adding three new int8 SDSs for each high resolution offsets between the high resolution geolocation and a bi linear interpolation extrapolation of the positions This can be used to reconstruct the high resolution geolocation Resolved Bug by delaying cumulation of gflags until after validation of derived products Resolved Bug by setting Latitude and Longitude to the correct fill resolving to support Near Real Time because they may be unnecessary if use of entrained ephemeris and attitude data is turned resolving bug report Corrected to filter out Aqua attitude records with missing status helping resolve bug MOD_PR03 will still correctly write scan and pixel data that does not depend upon the start time
Definition: HISTORY.txt:248
Extra metadata that will be written to the HDF4 file l2prod rank
char mission_char[SM_ATTRSZ]
Definition: meta_l3b.h:22
hid_t get_data_table(int i)
Definition: hdf_bin.h:353
#define SMI_MAX_STR_SHORT
Definition: smiinc.h:20
int16_t * nscenes
Definition: l2bin.cpp:86
float * lon
l2prod offset
int64_t data_bins
Definition: meta_l3b.h:46
int32 close_input_hdf(int32 fid, int32 sdfid, int32 vgid, int32 vdata_id[1])
Definition: smigen.cpp:2308
char sensor_name[SM_ATTRSZ]
Definition: meta_l3b.h:19
int i
Definition: decode_rs.h:71
double rint(double)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
void rotate(float **r, float **qt, int n, int i, float a, float b)
int k
Definition: decode_rs.h:73
int get_minmax_rowcol(float32 lat_range[], float32 lon_range[], char *proj_type, int32 out_rows, int32 *min_out_row, int32 *max_out_row, int32 *min_out_col, int32 *max_out_col)
Definition: smigen.cpp:2324
float32 f32
Definition: l2bin.cpp:104
int count
Definition: decode_rs.h:79