OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l2stat_chk.c
Go to the documentation of this file.
1 /*
2  * W. Robinson, GSC, 13 Dec 1999 update for version 4.0 - the new format
3  * from MSL12
4  */
5 #include <time.h>
6 #include "l2stat.h"
7 #include "l2lists.h"
8 #include "l2stat_proto.h"
9 
10 #define MAX_NAME 255
11 #define SET 1
12 
13 char err_msg[1024];
14 static int32 stat_status = 0; /* status of statistical checking: 0 all good,
15  1 program problem, 2 statistical problem,
16  3 both problems */
17 
18 int main(int argc, char *argv[])
19 /*******************************************************************
20 
21  l2stat_chk
22 
23  purpose: open the SeaWiFS level 2 dataset and checks the data values
24  against given thresholds
25 
26  Returns type: none
27 
28  Parameters: (in calling order)
29  Type Name I/O Description
30  ---- ---- --- -----------
31  int argc I count of input args
32  char * argv[] I args: [1] hdf file
33  [2] controls file
34 
35  Modification history:
36  Programmer Date Description of change
37  ---------- ---- ---------------------
38  L. Kumar 04-Apr-1996 Original development
39  L. Kumar 06-Jun-1996 Removed '#ifdef PROTOTYPE' defns. and
40  '\t' (tabs) from the printf statements
41  W. Robinson, GSC 5-Nov-1997 add extra argument for extra flags to
42  exclude
43  W. Robinson, GSC 10-Dec-1999 update for version 4.0 of L2 format,
44  (different parameters and 32 bit flags)
45  W. Robinson, SAIC, 27jun2002 update for chlor_a stored as a float
46  for REPRO 4
47  *******************************************************************/ {
48  char dtype[255], extra_flags[200];
49  int32 fid, sdfid;
50  int32 nsamp, nscans;
51  cntl_str grschk[NPARAMS], statchk[NPARAMS];
52  flag_str flgchk[NFLAGS];
53 
54  clock_t val = 0, val2 = 0;
55 
56  val = (float) clock() / CLOCKS_PER_SEC;
57 
58  /*
59  * Check input arguments
60  */
61 
62  /* WDR chg:if (argc != 3) { */
63  if (argc < 3 || argc > 4) {
64  printf("\n******* Usage: l2stat_chk <hdf file> <control file> [<flg>]\n");
65  printf(" <hdf file> is level 2 data file\n");
66  printf(" <control file> is the file specifying thresholds\n");
67  printf(" <flg> is any extra flag names to exclude (optional)\n");
68  printf("\nOn exit, $status will be set to: \n 0 - no problems,"
69  "\n 1 - program error, ");
70  printf("\n 2 - data problem, \n 3 - both program and data problem\n");
73  }
74 
75  printf("\n\n# Statistical Check of Dataset '%s'\n\n", argv[1]);
76 
77  /*
78  * hopen will open the file and read data descriptor blocks
79  * to memory
80  */
81 
82  if ((fid = Hopen(argv[1], DFACC_RDONLY, 0)) < 0) {
83  printf("****** l2stat_chk: Failed on the Hopen of \n '%s'\n", argv[1]);
84  stat_status = 1;
86  }
87 
88  /*
89  * SDstart opens the hdf interface and initiates SD interface
90  */
91 
92  if ((sdfid = SDstart(argv[1], DFACC_RDONLY)) < 0) {
93  printf("******* l2stat_chk: Failure at SDstart of \n'%s'\n", argv[1]);
94  Hclose(fid);
95  stat_status = 1;
97  }
98 
99  /*
100  * Read control file and save the information. If the return value
101  * is -1, it means, some prolblem with opening control data file or
102  * with some control format, close HDF file, and exit with status set
103  * to 1 indicating program error.
104  */
105 
106  if ((read_cntldata(argv[2], grschk, statchk, flgchk)) < 0) {
107  Hclose(fid);
109  }
110 
111  /*
112  * Verify if given input file is a level 2 file
113  */
114 
115  if ((l2file(sdfid, &nsamp, &nscans, dtype)) < 0) {
116  Hclose(fid);
117  printf("******* %s", err_msg);
119  }
120 
121  /*
122  * before the gross check, set up the extra flag list
123  * depending on a 4th argument
124  */
125  if (argc == 4) {
126  strcpy(extra_flags, argv[3]);
127  } else
128  strcpy(extra_flags, "none");
129 
130  /*
131  * Do a gross value check and general statistics check
132  */
133 
134  if ((chk_grsstat(sdfid, nscans, nsamp, grschk, statchk, extra_flags)) < 0)
135  printf("\n******* %s", err_msg);
136 
137  /*
138  * Verify Flag percentage
139  */
140 
141  if ((chk_flg(sdfid, flgchk)) < 0)
142  printf("\n******** %s", err_msg);
143 
144  /*
145  * Free all the allocated resources
146  */
147 
148  Hclose(fid);
149 
150  val2 = (float) clock() / CLOCKS_PER_SEC;
151  printf("\n\n# Time took for %s = %d secs\n", argv[0], (int) (val2 - val));
152 
154 
155  return 0;
156 }
157 
158 /****************************************************************************
159  read_cntldata
160 
161  purpose: Opens given control file and reads in the mnemonics and thresholds
162  given. If any error occurs, prints out an error message,
163  sets stat_status field and returns a negative 1.
164 
165  Returns type: integer
166 
167  Parameters: (in calling order)
168  Type Name I/O Description
169  ---- ---- --- -----------
170  char * cntl_file I control file path/name
171  cntl_str * grschk O structure to hold control
172  data related to gross checking
173  cntl_str * statchk O structure to hold control
174  data related to general stat
175  check
176  flag_str * flgchk O structure to hold control
177  data related to flag percentage
178 
179  Modification history:
180  Programmer Date Description of change
181  ---------- ---- ---------------------
182  L. Kumar 04-Apr-1996 Original development
183 
184  ****************************************************************************/
185 int32 read_cntldata(char *cntl_file, cntl_str *grschk, cntl_str *statchk,
186  flag_str *flgchk) {
187  FILE *fid;
188  char line[501], str[25];
189  int32 i, param, flag, nflds = 0;
190  float32 err_thresh, low_thresh, high_thresh;
191 
192  printf("\n# Reading control file '%s'\n\n", cntl_file);
193 
194  /*
195  * Open the file
196  */
197  if ((fid = fopen(cntl_file, "r")) == NULL) {
198  printf("********read_cntldata: Unable to open control file:\n '%s'\n",
199  cntl_file);
200  stat_status = stat_status | 1;
201  return FAIL;
202  }
203 
204  /*
205  * Initialize all input structrues
206  */
207  for (i = 0; i < NPARAMS; i++) {
208  grschk[i].param = statchk[i].param = 0;
209  grschk[i].err_thresh = statchk[i].err_thresh = 0;
210  grschk[i].low_thresh = statchk[i].low_thresh = 0;
211  grschk[i].high_thresh = statchk[i].high_thresh = 0;
212  }
213 
214  for (i = 0; i < NFLAGS; i++)
215  flgchk[i].flag = flgchk[i].err_low_thresh = flgchk[i].err_high_thresh = 0;
216 
217  /*
218  * Read control file one line at a time
219  */
220  while (fgets(line, 500, fid) != NULL) {
221  /* Ignore beginning blanks and tabs */
222  for (i = 0; i < 500 && (line[i] == ' ' || line[i] == '\t'); i++);
223 
224  /* If first character is '#' sign, then treat the line as comment */
225  if (i < 500 && line[i] == '#') {
226  printf("%s", line);
227  continue;
228  }
229 
230  /* If not comment, check if it is Gross CHK info */
231  printf("#%s", line);
232  if (strncmp(&line[i], "L2GCHK", 6) == 0) {
233  if ((nflds = sscanf(line, "%s %f %f %f", str, &err_thresh,
234  &low_thresh, &high_thresh)) != 4) {
235  printf("\n*********read_cntldata: expecting 4 fields");
236  printf(" but read %d field(s)", nflds);
237  stat_status = stat_status | 1;
238  return FAIL;
239  }
240  /*
241  prm[0] = str[6];
242  */
243  param = atoi(&str[6]);
244  if (param < 1 || param > NPARAMS) {
245  printf("********read_cntldata: Error in parameter number.");
246  printf(" Parameter # read = %d", param);
247  stat_status = stat_status | 1;
248  return FAIL;
249  }
250  grschk[param - 1].param = 1;
251  grschk[param - 1].err_thresh = err_thresh;
252  grschk[param - 1].low_thresh = low_thresh;
253  grschk[param - 1].high_thresh = high_thresh;
254  } else if (strncmp(&line[i], "L2STAT", 6) == 0) {
255  if ((nflds = sscanf(line, "%s", str)) != 1) {
256  printf("*********read_cntldata: expecting 1 field");
257  printf(" but read %d field(s)", nflds);
258  stat_status = stat_status | 1;
259  return FAIL;
260  }
261  param = atoi(&str[6]);
262  if (param < 1 || param > NPARAMS) {
263  printf("********read_cntldata: Error in param number.");
264  printf(" Parameter # read = %d", param);
265  stat_status = stat_status | 1;
266  return FAIL;
267  }
268  statchk[param - 1].param = 1;
269  } else if (strncmp(&line[i], "L2FLGCK", 7) == 0) {
270  if ((nflds = sscanf(line, "%s %f %f", str, &low_thresh, &high_thresh))
271  != 3) {
272  printf("*********read_cntldata: expecting 3 fields");
273  printf(" but read %d field(s)", nflds);
274  stat_status = stat_status | 1;
275  return FAIL;
276  }
277  flag = atoi(&str[7]);
278  if (flag < 1 || flag > NFLAGS) {
279  printf("*********read_cntldata: Error in flag number.");
280  printf(" Flag # read = %d", flag);
281  stat_status = stat_status | 1;
282  return FAIL;
283  }
284  flgchk[flag - 1].flag = 1;
285  flgchk[flag - 1].err_low_thresh = low_thresh;
286  flgchk[flag - 1].err_high_thresh = high_thresh;
287  }
288  }
289  return SUCCEED;
290 }
291 
292 /****************************************************************************
293  l2file
294 
295  purpose: Verifies if the given input file is level 2 data file
296 
297  Returns type: integer
298 
299  Parameters: (in calling order)
300  Type Name I/O Description
301  ---- ---- --- -----------
302  int32 sdfid I SD interface ID
303  int32 * nsamp O number of samples/pixels
304  int32 * nscans O number of scan lines
305  char * dtype O data type (GAC, LAC, ...)
306 
307  Modification history:
308  Programmer Date Description of change
309  ---------- ---- ---------------------
310  L. Kumar 04-Apr-1996 Original development
311 
312  ****************************************************************************/
313 int32 l2file(int32 sdfid, int32 *nsamp, int32 *nscans, char *dtype) {
314  char title[1024];
315 
316  /*
317  * Read title to verify if the given input file is level 1A data file
318  */
319 
320  if ((rdattr(sdfid, TITLE, &title)) < 0)
321  return FAIL;
322 
323  if (strcmp(title, "SeaWiFS Level-2 Data") != 0) {
324  sprintf(err_msg, "l2file: Data file is not level 2 file");
325  stat_status = stat_status | 1;
326  return FAIL;
327  }
328 
329  if ((rdattr(sdfid, NSAMP, (VOIDP *) nsamp)) < 0)
330  return FAIL;
331 
332  printf("\n# Number of samples = %d", *nsamp);
333 
334  if ((rdattr(sdfid, NSCANS, (VOIDP *) nscans)) < 0)
335  return FAIL;
336 
337  printf("\n# Number of scanlines = %d", *nscans);
338 
339  if ((rdattr(sdfid, DTYPE, dtype)) < 0)
340  return FAIL;
341 
342  printf("\n# Data type = %s\n", dtype);
343 
344  return SUCCEED;
345 }
346 
347 /****************************************************************************
348  chk_grsstat
349 
350  purpose: Verifies Gross value and statistical checks against the given
351  thresholds for requested parameters
352 
353  Returns type: integer
354 
355  Parameters: (in calling order)
356  Type Name I/O Description
357  ---- ---- --- -----------
358  int32 sdfid I SD interface ID
359  int32 nscans I Number of scanlines
360  int32 nsamp I Number of pixels
361  cntl_str * grschk I structure containing Gross
362  value control thresholds
363  int16 * buf I buffer for reading data
364  char * extra_flags I user-requested extra flags
365  to use in excluding data
366 
367  Modification history:
368  Programmer Date Description of change
369  ---------- ---- ---------------------
370  L. Kumar 04-Apr-1996 Original development
371  W. Robinson, GSC 5-Nov-1997 add the extra_flags argument
372  W. Robinson, GSC 13-Dec-1999 use 32 bit flag array and tau as a
373  16 bit value
374  W. Robinson, SAIC, 27jun2002 update for chlor_a stored as a float
375  for REPRO 4
376 
377  ****************************************************************************/
378 int32 chk_grsstat(int32 sdfid, int32 nscans, int32 nsamp, cntl_str *grschk,
379  cntl_str *statchk, char *extra_flags) {
380  uint8 *i8buf;
381  uint16 mask;
382  int32 *l2_flags;
383  int16 *buf, flag[NPARAMS];
384  int32 i, p, npix = (nsamp * nscans);
385  int32 edge[3], start[3];
386  int32 non_masked_pixels, low_cnt = 0, high_cnt = 0;
387  int32 minloc[NPARAMS], maxloc[NPARAMS];
388  int32 failcode = 0;
389  float32 min[NPARAMS], max[NPARAMS], *flt32buf;
390  float64 geoval, value1[NPARAMS], value2[NPARAMS];
391  float64 xbar[NPARAMS], sd[NPARAMS], sum, sumsq;
392 
393  printf("\n#Checking Gross/Statistical values ....\n");
394 
395  for (i = 0; i < NPARAMS; i++) {
396  value1[i] = value2[i] = flag[i] = 0;
397  xbar[i] = sd[i] = 0;
398  min[i] = max[i] = minloc[i] = maxloc[i] = 0;
399  }
400 
401  /*
402  * Allocate buffer for reading a line of data with 4 byte values
403  * for 4byte chlor_a values in repro4
404  */
405 
406  if ((buf = (int16 *) calloc(npix * 2, sizeof (int16))) == NULL) {
407  sprintf(err_msg, "chk_grsstat: cannot allocate memory for reading data");
408  stat_status = stat_status | 1;
409  return FAIL;
410  }
411 
412  /*
413  * Allocate buffer for reading l2_flags and set start and end dims for
414  * reading l2_flags
415  */
416 
417  if ((l2_flags = (int32 *) calloc(npix, sizeof (int32))) == NULL) {
418  sprintf(err_msg, "chk_grsstat: cannot allocate memory for reading data");
419  stat_status = stat_status | 1;
420  free(buf);
421  return FAIL;
422  }
423 
424  start[0] = start[1] = start[2] = 0;
425  edge[0] = nscans;
426  edge[1] = nsamp;
427  edge[2] = 0;
428  if ((rdslice(sdfid, L2FLAGS, start, edge, (VOIDP) l2_flags)) < 0) {
429  stat_status = stat_status | 1;
430  free(buf);
431  free(l2_flags);
432  return FAIL;
433  }
434 
435  /*
436  * Call set_mask for setting mask, and find total number of non masked values
437  */
438 
439  if (set_mask(sdfid, extra_flags, &mask) < 0) {
440  stat_status = stat_status | 1;
441  free(buf);
442  free(l2_flags);
443  return FAIL;
444  }
445 
446  start[0] = start[1] = start[2] = 0;
447  edge[0] = nscans;
448  edge[1] = nsamp;
449  edge[2] = 0;
450 
451  for (p = 0; p < NPARAMS; p++)
452  if (grschk[p].param || statchk[p].param) {
453  printf("\n#Parm-%d %s", p + 1, param_name[p]);
454  printf(" Slope = %f, Intercept = %f", slope[p], intercept[p]);
455  low_cnt = high_cnt = 0;
456  min[p] = 9999;
457  max[p] = -9999;
458  minloc[p] = maxloc[p] = 0;
459  non_masked_pixels = sum = sumsq = 0;
460  if ((rdslice(sdfid, param_name[p], start, edge, (VOIDP) buf)) < 0) {
461  stat_status = stat_status | 1;
462  free(buf);
463  free(l2_flags);
464  return FAIL;
465  }
466  if ((strcmp(param_name[p], "eps_78")) == 0) {
467  i8buf = (uint8 *) buf;
468  for (i = 0; i < npix; i++)
469  if ((l2_flags[i] & mask) == 0) {
470  geoval = (float64) i8buf[i] * slope[p] + intercept[p];
471  if (geoval < grschk[p].low_thresh)
472  low_cnt++;
473  if (geoval > grschk[p].high_thresh)
474  high_cnt++;
475  sum += geoval;
476  sumsq += geoval * geoval;
477  non_masked_pixels++;
478  if (geoval < min[p]) {
479  min[p] = geoval;
480  minloc[p] = i;
481  }
482  if (geoval > max[p]) {
483  max[p] = geoval;
484  maxloc[p] = i;
485  }
486  }
487  } else if ((strcmp(param_name[p], "chlor_a")) == 0) {
488  flt32buf = (float32 *) buf;
489  for (i = 0; i < npix; i++)
490  if ((l2_flags[i] & mask) == 0) {
491  geoval = (float64) flt32buf[i] * slope[p] + intercept[p];
492  if (geoval < grschk[p].low_thresh)
493  low_cnt++;
494  if (geoval > grschk[p].high_thresh)
495  high_cnt++;
496  sum += geoval;
497  sumsq += geoval * geoval;
498  non_masked_pixels++;
499  if (geoval < min[p]) {
500  min[p] = geoval;
501  minloc[p] = i;
502  }
503  if (geoval > max[p]) {
504  max[p] = geoval;
505  maxloc[p] = i;
506  }
507  }
508  } else {
509  for (i = 0; i < npix; i++)
510  if ((l2_flags[i] & mask) == 0) {
511  geoval = (float64) buf[i] * slope[p] + intercept[p];
512  if (geoval < grschk[p].low_thresh)
513  low_cnt++;
514  if (geoval > grschk[p].high_thresh)
515  high_cnt++;
516  sum += geoval;
517  sumsq += geoval * geoval;
518  non_masked_pixels++;
519  if (geoval < min[p]) {
520  min[p] = geoval;
521  minloc[p] = i;
522  }
523  if (geoval > max[p]) {
524  max[p] = geoval;
525  maxloc[p] = i;
526  }
527  }
528  }
529  /*
530  * calculate percentage of non-masked values < given low_threshold and
531  * values > given high threshold
532  */
533  if (low_cnt > 0)
534  value1[p] = (low_cnt / (float64) (non_masked_pixels) * 100.0);
535  if (high_cnt > 0)
536  value2[p] = (high_cnt / (float) (non_masked_pixels) * 100.0);
537  if (value2[p] > grschk[p].err_thresh)
538  flag[p] = -1;
539  if (value1[p] > grschk[p].err_thresh)
540  flag[p] = 1;
541 
542  /*
543  * Gather statistical information and output the info later
544  */
545  if (non_masked_pixels) {
546  xbar[p] = sum = sum / non_masked_pixels;
547  sumsq /= non_masked_pixels;
548  if ((sumsq - sum * sum) <= 0)
549  sd[p] = 0;
550  else
551  sd[p] = sqrt(sumsq - sum * sum);
552  } else
553  xbar[p] = sd[p] = 0;
554  }
555 
556  /*
557  * Print headers for gross check output messages
558  */
559 
560  printf("\n\n#Mnemonic Flag %%<Low %%>High Err_thr low_thr high_thr");
561  printf("\n#-------------------------------------------------------------\n");
562 
563  for (p = 0; p < NPARAMS; p++)
564  if (grschk[p].param) {
565  printf("\nL2GCHK%d %d %f %f %f %f %f", p + 1, flag[p], value1[p],
566  value2[p], grschk[p].err_thresh, grschk[p].low_thresh,
567  grschk[p].high_thresh);
568  if (flag[p] != 0)
569  failcode = 1;
570  }
571 
572  /*
573  * Print headers for statistical check output messages
574  */
575 
576  printf("\n\n");
577  printf("#Mnemonic non xbar sd min min_loc max max_loc");
578  printf("\n# masked pixels (x,y) (x,y)");
579  printf("\n#--------------------------------------------------------------------------\n");
580 
581  for (p = 0; p < NPARAMS; p++)
582  if (statchk[p].param)
583  printf("\nL2STAT%d %d %f %f %f %d,%d %f %d,%d",
584  p + 1, non_masked_pixels, xbar[p], sd[p], min[p], minloc[p] % nsamp,
585  minloc[p] / nsamp, max[p], maxloc[p] % nsamp, maxloc[p] / nsamp);
586 
587  if (failcode)
588  stat_status = stat_status | 2;
589 
590  free(l2_flags);
591  free(buf);
592  return SUCCEED;
593 }
594 
595 /****************************************************************************
596  set_mask
597 
598  purpose: Sets mask field based on masknames stored in the datafile
599 
600  Returns type: 2 byte integer <0 is fail
601 
602  Parameters: (in calling order)
603  Type Name I/O Description
604  ---- ---- --- -----------
605  int32 sdfid I SD interface ID
606  char * extra_flags I string of extra flags to mask
607  uint16 * mask O mask returned
608 
609  Modification history:
610 
611  Programmer Date Description of change
612  ---------- ---------- ---------------------
613  L. Kumar 04-Apr-1996 Original development
614  W. Robinson, GSC 5-Nov-1997 add extra_flags argument
615 
616  ****************************************************************************/
617 int16 set_mask(int32 sdfid, char *extra_flags, uint16 *mask) {
618  int32 nt, count, i;
619  char *masknames;
620 
621  /*
622  * Reads Mask Names global attribute
623  */
624  *mask = 0;
625 
626  if ((getattrsz(sdfid, MASKNAMES, &nt, &count)) < 0)
627  return FAIL;
628 
629  if ((masknames = (char *) malloc(sizeof (char)*count + 1)) == NULL) {
630  sprintf(err_msg, "set_mask: malloc error -- while alloc space for %s",
631  MASKNAMES);
632  return FAIL;
633  }
634 
635  if ((rdattr(sdfid, MASKNAMES, masknames)) < 0)
636  return FAIL;
637 
638  if (masknames != NULL)
639  for (i = 0; i < NFLAGS; i++) {
640  if ((strstr(masknames, flag_names[i]) != NULL) ||
641  (strstr(extra_flags, flag_names[i]) != NULL))
642  *mask = *mask + (int16) pow(2, i);
643  }
644 
645  printf("\n#Masknames: %s\n", masknames);
646  printf("#(note user-designated flags are: '%s')\n", extra_flags);
647 
648  free(masknames);
649  return 0;
650 }
651 
652 /****************************************************************************
653  chk_flag
654 
655  purpose: Sets mask field based on masknames stored in the datafile
656 
657  Returns type: 2 byte integer
658 
659  Parameters: (in calling order)
660  Type Name I/O Description
661  ---- ---- --- -----------
662  int32 sdfid I SD interface ID
663 
664  Modification history:
665 
666  Programmer Date Description of change
667  ---------- ---------- ---------------------
668  L. Kumar 04-Apr-1996 Original development
669 
670  ****************************************************************************/
671 int32 chk_flg(int32 sdfid, flag_str *flgchk) {
672  int32 i, flag = 0;
673  float32 perct_flags[NFLAGS];
674 
675  printf("\n\n#Checking Flag Percentages ....");
676 
677  if ((rdattr(sdfid, PERCENTFLAGS, perct_flags)) < 0)
678  return FAIL;
679 
680  printf("\n\n#Mnemonic flag flag %% err_thr_low err_thr_high");
681  printf("\n#------------------------------------------------------------------\n");
682 
683  for (i = 0; i < NFLAGS; i++)
684  if (flgchk[i].flag) {
685  flag = 0;
686  if (perct_flags[i] < flgchk[i].err_low_thresh)
687  flag = -1;
688  if (perct_flags[i] > flgchk[i].err_high_thresh)
689  flag = 1;
690  if (flag != 0)
691  stat_status = stat_status | 2;
692  printf("\nL2FLGCK%d %d %f %f %f", i + 1, flag,
693  perct_flags[i], flgchk[i].err_low_thresh,
694  flgchk[i].err_high_thresh);
695  }
696  return SUCCEED;
697 }
698 
699 void stat_exit(int status)
700 /*******************************************************************
701 
702  stat_exit
703 
704  purpose: provide a common exit from the stat_check program and
705  error summary info.
706 
707  Returns type: none
708 
709  Parameters: (in calling order)
710  Type Name I/O Description
711  ---- ---- --- -----------
712  int status I statistical check status
713 
714  Modification history:
715  Programmer Date Description of change
716  ---------- ---- ---------------------
717  W. Robinson 30-jun-1995 Original development
718 
719  *******************************************************************/ {
720  if (status == 0)
721  printf("\n\nSuccessful check, no statistical errors\n");
722  else {
723  if (status & 1)
724  printf("\n\nFailure of statistical check due to program error\n");
725  if (status & 2)
726  printf("\n\nFailure of statistical check due to data error\n");
727  }
728  exit(status);
729 }
730 
731 /*-----------------------------------------------------------------------------
732  Function: rdattr
733 
734  Returns: int32 (status)
735  The return code is a negative value if any error occurs, otherwise,
736  returns 0.
737 
738  Description:
739  The function rdattr reads the requested global attribute
740 
741  Parameters: (in calling order)
742  Type Name I/O Description
743  ---- ---- --- -----------
744  int32 sdfid I ID req to access HDF SDS interface
745  char * attr_name I attribute name
746  void * buf I/O pointer to data buffer
747 
748  Modification history:
749  Programmer Organization Date Description of change
750  -------------- ------------ -------- ---------------------
751  Lakshmi Kumar Hughes STX 11/07/94 Original development
752 
753 ----------------------------------------------------------------------------*/
754 int32 rdattr(int32 sdfid, char *attr_name, void *buf) {
755  int32 attrnum;
756 
757  if ((attrnum = SDfindattr(sdfid, attr_name)) < 0) {
758  sprintf(err_msg, "rdattr: Failure in SDfindattr while trying to read %s",
759  attr_name);
760  stat_status = stat_status | 1;
761  return FAIL;
762  }
763 
764  if ((SDreadattr(sdfid, attrnum, buf)) < 0) {
765  sprintf(err_msg, "rdattr: Failure in SDreadattr while trying to read %s",
766  attr_name);
767  stat_status = stat_status | 1;
768  return FAIL;
769  }
770 
771  return SUCCEED;
772 }
773 
774 /*-----------------------------------------------------------------------------
775  Function: rdslice
776 
777  Returns: int32 (sdsid)
778  The return code is a negative value if any error occurs, otherwise,
779  returns sdsid.
780 
781  Description:
782  The function rdslice reads requested slice of data from the
783  given named dataset
784 
785  Parameters: (in calling order)
786  Type Name I/O Description
787  ---- ---- --- -----------
788  int32 sdfid I ID req to access HDF SDS interface
789  char *name I SDS name
790  int32 *start I start data dimension
791  int32 *edge I no. of values to be read
792  void *buf O SDS data buffer
793 
794  NOTE:
795 
796  Modification history:
797  Programmer Organization Date Description of change
798  -------------- ------------ -------- ---------------------
799  Lakshmi Kumar Hughes STX 11/02/94 Original development
800 ----------------------------------------------------------------------------*/
801 int32 rdslice(int32 sdfid, char *name, int32 *start, int32 *edge, void *buf) {
802  int32 index, sdsid, rank, num_type, nattrs;
803  char sdsname[MAX_NAME];
804 
805 
806  if ((index = SDnametoindex(sdfid, name)) < 0) {
807  sprintf(err_msg, "rdslice: SDnametoindex failed for sds \"%s\" ", name);
808  return FAIL;
809  }
810  if ((sdsid = SDselect(sdfid, index)) < 0) {
811  sprintf(err_msg, "rdslice: SDselect failed for sds \"%s\" ", name);
812  return FAIL;
813  }
814 
815  if (edge[0] == 0 && edge[1] == 0 && edge[2] == 0)
816  if ((SDgetinfo(sdsid, sdsname, &rank, edge, &num_type, &nattrs)) < 0) {
817  sprintf(err_msg, "rdslice: SDgetinfo failed for sds \"%s\" ", name);
818  return FAIL;
819  }
820 
821  if ((SDreaddata(sdsid, start, NULL, edge, buf)) < 0) {
822  sprintf(err_msg,
823  "rdslice: SDreaddata error while reading \"%s\" ", name);
824  return FAIL;
825  }
826 
827 
828  SDendaccess(sdsid);
829  return SUCCEED;
830 }
831 
832 /*-----------------------------------------------------------------------------
833  Function: getattrsz
834 
835  Returns: int32 (status)
836  The return code is a negative value if any error occurs, otherwise,
837  returns 0.
838 
839  Description:
840  The function getattrsz passes the requested global attribute's
841  number type (data type) and the number of values
842 
843  Parameters: (in calling order)
844  Type Name I/O Description
845  ---- ---- --- -----------
846  int32 sdfid I ID req to access HDF SDS interface
847  char * attr_name I attribute name
848  int32 * nt O HDF data type
849  int32 * count O number of values in the specified attribute
850 
851  Modification history:
852  Programmer Organization Date Description of change
853  -------------- ------------ -------- ---------------------
854  Lakshmi Kumar Hughes STX 11/07/94 Original development
855 ----------------------------------------------------------------------------*/
856 int32 getattrsz(int32 id, char *attr_name, int32 *nt, int32 *count) {
857  int32 attrnum;
858  char name[MAX_NAME];
859 
860  attrnum = SDfindattr(id, attr_name);
861  if ((SDattrinfo(id, attrnum, name, nt, count)) < 0) {
862  sprintf(err_msg, "getattrsz: SDattrinfo failed for attribute - %s\n",
863  attr_name);
864  return FAIL;
865  }
866  return SUCCEED;
867 }
868 
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
integer, parameter int16
Definition: cubeio.f90:3
int status
Definition: l1_czcs_hdf.c:32
#define DTYPE
Definition: l1stat.h:26
These are used to scale the SD before writing it to the HDF4 file The default is and which means the product is not scaled at all Since the product is usually stored as a float inside of this is a way to write the float out as a integer l2prod min
#define MASKNAMES
Definition: l2stat.h:24
char * param_name[]
Definition: l2lists.h:16
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
int32 rdattr(int32 sdfid, char *attr_name, void *buf)
Definition: l2stat_chk.c:754
int16 set_mask(int32 sdfid, char *extra_flags, uint16 *mask)
Definition: l2stat_chk.c:617
unsigned long long sumsq(signed short *in, int cnt)
int32 read_cntldata(char *cntl_file, cntl_str *grschk, cntl_str *statchk, flag_str *flgchk)
Definition: l2stat_chk.c:185
int32 chk_grsstat(int32 sdfid, int32 nscans, int32 nsamp, cntl_str *grschk, cntl_str *statchk, char *extra_flags)
Definition: l2stat_chk.c:378
#define L2FLAGS
Definition: l2stat.h:25
int32 chk_flg(int32 sdfid, flag_str *flgchk)
Definition: l2stat_chk.c:671
int main(int argc, char *argv[])
Definition: l2stat_chk.c:18
#define NSAMP
Definition: l1stat.h:23
#define NPARAMS
Definition: l2stat.h:11
float32 slope[]
Definition: l2lists.h:30
#define PERCENTFLAGS
Definition: l2stat.h:18
int32 stat_status
Definition: l1stat_chk.c:8
char err_msg[1024]
Definition: l2stat_chk.c:13
int32 getattrsz(int32 id, char *attr_name, int32 *nt, int32 *count)
Definition: l2stat_chk.c:856
a context in which it is NOT documented to do so subscript which cannot be easily calculated when extracting TONS attitude data from the Terra L0 files Corrected several defects in extraction of entrained ephemeris and and as HDF file for both the L1A and Geolocation enabling retrieval of South Polar DEM data Resolved Bug by changing to opent the geolocation file only after a successful read of the L1A and also by checking for fatal errors from not restoring C5 and to report how many of those high resolution values were water in the new WaterPresent SDS Added valid_range attribute to Land SeaMask Changed to bilinearly interpolate the geoid_height to remove artifacts at one degree lines Made corrections to const qualification of pointers allowed by new version of M API library Removed casts that are no longer for same not the geoid Corrected off by one error in calculation of high resolution offsets Corrected parsing of maneuver list configuration parameter Corrected to set Height SDS to fill values when geolocation when for elevation and land water mask
Definition: HISTORY.txt:114
float32 intercept[]
Definition: l2lists.h:44
#define TITLE
Definition: l1stat.h:25
int32 rdslice(int32 sdfid, char *name, int32 *start, int32 *edge, void *buf)
Definition: l2stat_chk.c:801
#define MAX_NAME
Definition: l2stat_chk.c:10
const char * str
Definition: l1c_msi.cpp:35
void stat_exit(int status)
Definition: l2stat_chk.c:699
#define NFLAGS
Definition: l2stat.h:12
dtype
Definition: DDataset.hpp:31
char * flag_names[]
Definition: l2lists.h:46
Extra metadata that will be written to the HDF4 file l2prod rank
const int NSCANS
Definition: RsViirs.h:63
int i
Definition: decode_rs.h:71
int32 l2file(int32 sdfid, int32 *nsamp, int32 *nscans, char *dtype)
Definition: l2stat_chk.c:313
msiBandIdx val
Definition: l1c_msi.cpp:34
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int npix
Definition: get_cmp.c:27
float p[MODELMAX]
Definition: atrem_corl1.h:131
l2prod max
int count
Definition: decode_rs.h:79