OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
metqc.c
Go to the documentation of this file.
1 /*****************************************************************
2  * FILE: metqc.c
3  *
4  * PURPOSE: QC HDF ancillary real time datafile against climatology
5  * for one of four parameters.
6  *
7  * DESCRIPTION: This program will create a HDF with:
8  *
9  * HDF Geometry Vdata of Lat/Lon limits and steps.
10  * 2-D std dev of NRT vs CLM for z_wind or,
11  * 2-D std dev of NRT vs CLM for m_wind or,
12  * 2-D std dev of NRT vs CLM for press or,
13  * 2-D std dev of NRT vs CLM for rel_hum.
14  *
15  * A ASCII text file of %points in each STD category.
16  *
17  * For MET data:
18  * The real time parameter is read into array
19  * z_windRT, m_windRT, pressRT or rel_humRT
20  *
21  * Real-time files are dimensioned 73x144. The COADS based
22  * climatology is 90x180. A regridded COADS climatology
23  * (S19461990_COADS.REGRID.MET) is therefore used by this program.
24  *
25  * The climatological averages and standard deviations for the same time
26  * period (month) are read into:
27  * z_windCLMAVG, m_windCLMAVG, pressCLMAVG or rel_humCLMAVG and
28  * z_windCLMSTD, m_windCLMAVG, pressCLMSTD or rel_humCLMSTD respectively.
29 
30  *
31  * PROCEDURE:
32  *
33  * The CLMAVG array is subtracted from the RT array and
34  * divided by the CLMSTD array to produce an array of the number
35  * of std deviations from the mean for the real-time data.
36  *
37  * An option for an array of just the differences can be run by envoking
38  * the 'd' (difference) flag on the command line.
39  *
40  * As the data is processed a tally of points falling + and - 1, 2, and 3
41  * STDs from the mean will be stored for later writing of percentages in
42  * each category (if 'difference' option not used).
43  *
44  * INPUT PARMS: command line arguments (argv[?])
45  * [1] char *nrtfile - real-time input file to process
46  * ("S199310200_NMC.MET")
47  * [2] char *climfile - regridded climatology input file to process
48  * ("S19461990_COADS.REGRID.MET")
49  * [3] char *outfile - output QC filename.
50  * Note: FNOC could be used in place of NMC.
51  * [4] char monthstr - month being processed
52  * [5] - field to compare: 'z_wind', 'm_wind', 'press', 'rel_hum' or 'p_water'
53  * [6] float32 stdlimit1 - % w/in 1 STD
54  * [7] float32 stdlimit2 - % w/in 2 STD
55  * [8] float32 stdlimit3 - % w/in 3 STD
56  * [9] int maxmissing - max num missing pts.
57  *
58  * Optional inputs: on command line
59  * (args are read in order so preceeding optionals are required in order
60  * to use succeeding ones.)
61  *
62  * [10] float32 loval - lowest allowed value
63  * [11] float32 hival - highest allowed value
64  * [12] int outmax - max num allowed outliers before error flag set.
65  * [13] char gridflag - 'S'tandard deviation [default] or 'D'ifference calc.
66  * Note, difference calculations do not product reports.
67  * [14] int ifileflag - 0 = file is NRT file [default],
68  * 1 = file in CLM file (stats on one CLM vs another)
69  *
70  * OUTPUT PARMS:
71  * prints report to standard out.
72  * returns a SUCCESS (0) or FAILURE(5) value as Standard Deviation
73  * threshold exit status. This value can be checked with a C-shell
74  * $status flag.
75  *
76  * output name is similar to the input real-time file.
77  * Example name: "S199310200_NMC.MET.'parm'.qc"
78  * ('parm' = z_wind, m_wind, press, rel_hum or p_water)
79  *
80  * RETURNS: Program returns success or failure codes to a calling
81  * 'shell' script.
82  *
83  * LOCAL VARS: variables for storing HDFs.
84  *
85  * Subs called: int rdsds - reads an HDF SDS data grid
86  * int8 check_usage - confirm args
87  * int startHDF - open HDF file for output
88  * int setupGrid - setup HDF geometry struct
89  * int writeGeom - write HDF geometry struct
90  * int wrtsds - write HDF SDS array
91  * int addAttr - add HDF SDS attributes
92  * int setSDSref - set HDF SDS reference
93  * void deattachHDFgrid - detach HDF grid struct
94  * int closeHDFstructs - close HDF files
95  * int rd_size - read field size
96  * int resize_2d - resize climatology field to match nrt
97  *
98  * HISTORY: none
99  *
100  * NOTE: This program is meant to generate HDF QC SDS data sets.
101  *
102  * AUTHOR: Brian D. Schieber, GSC, 4/93
103  *
104  * MODIFICATION HISTORY:
105  *
106  * 10/14/93 BDS - Subtantial mods to process all three MET parameters
107  * at once and to handle the NEW HDF format specs.
108  * 12/06/93 BDS - Make that all 4 parms (z_wind,m_wind,press,rel_hum).
109  * Verifying the exclusion of missings from CLM in
110  * these calcs (in NRT, 0.0's passed through).
111  * Defined VALIDMIN to -99.1 (catches CDFMINVAL (-99.9)
112  * in CLM) as min threshold for QC valid points to
113  * calculate.
114  * 3/94 BDS - prep for call from script which used SYBASE calls.
115  * Append parm type to 'qc' file name.
116  * Return pass or fail STD DEV thresholds as file status.
117  * 5/94 BDS - allow specification of output directory
118  * 8/14/95 BDS - revised for OAPS spec 2.7
119  * 11/95 BDS, add ability to sum number of values in image < or >
120  * two specified range arguments and return FAIL if > outmax.
121  * Values for LO(lower range), HI (upper range),
122  * and OUTMAX (MAX. Pts allowed outside range) hardcoded within
123  * for each of the four parameters.
124  * Also, print min and max value of data.
125  * 8/21/96 BDS - renamed 'perror' to 'pexit' to avoid HDF4.0 conflict.
126  * W. Robinson, GSC, 6 Feb 97 add p_water and make code work independently
127  * of the nrt and climatology sizes
128  *****************************************************************/
129 #include <mfhdf.h>
130 
131 #include "ancil.h"
132 #include "l1io.h"
133 #include <genutils.h>
134 
135 /*
136  * Note on all data sizes: old (pre march 97) data sizes
137  * met nrt: 73 lines, 144 pixels
138  * met climatology: 90 lines, 180 pixels
139  * met climatology gridded: 73 lines, 144 pixels - same as nrt
140  */
141 /*
142  * MET specific settings
143  */
144 
145 #define VGROUPCLASS "PlanetaryGrid" /* all inner Vgroups use same name */
146 
147 #define BIN_METH 2 /* geometry structure settings */
148 #define REGISTRATION CENTER /* " */
149 
150 /* MET file settings */
151 #define VSIZE 2.5 /* " */
152 #define HSIZE 2.5 /* " */
153 #define MAX_NORTH 89.0 /* " */
154 #define MAX_SOUTH -89.0 /* " */
155 #define MAX_WEST -179.0 /* " */
156 #define MAX_EAST 179.0 /* " */
157 
158 #define VALIDMIN -99.1 /* using '.1' to compensate float */
159 #define CLMfile 1
160 
161 int main(int argc, char *argv[]) {
162  int i, j, p;
163  int rank;
164  int result = 0;
165  int missing = 0;
166 
167  float32 minval = 1200.0; /* initial minimum value */
168  float32 maxval = -100.0; /* initial maximum value */
169 
170  float32 loZ_WIND = -30.0; /* default lo range threshold */
171  float32 hiZ_WIND = 30.0; /* default hi range threshold */
172  float32 loM_WIND = -30.0; /* default lo range threshold */
173  float32 hiM_WIND = 30.0; /* default hi range threshold */
174  float32 loPRESS = 850.0; /* default lo range threshold */
175  float32 hiPRESS = 1100.0; /* default hi range threshold */
176  float32 loREL_HUM = 5.0; /* default lo range threshold */
177  float32 hiREL_HUM = 100.0; /* default hi range threshold */
178  float32 loP_WATER = 0.; /* as above precip. water */
179  float32 hiP_WATER = 200.;
180  float32 loval; /* default actual range threshold */
181  float32 hival; /* default actual range threshold */
182  int outmax = 25; /* max num pts allowed to fall
183  outside range */
184 
185  int locnt; /* pts under lo range limit */
186  int hicnt; /* pts above hi range limit */
187  int rtmiss = 0;
188  int totalpts = 0;
189  int neg1cnt = 0;
190  int neg2cnt = 0;
191  int neg3cnt = 0;
192  int pos1cnt = 0;
193  int pos2cnt = 0;
194  int pos3cnt = 0;
195  int failed = 0;
196  int array_size = 0;
197  int32 shape_nrt[2], shape_clm[2];
198  int32 inShape[2];
199  char infileRT[MAXNAMELNG];
200  char infileCLM[MAXNAMELNG];
201  char outfile[MAXNAMELNG];
202  char gridflag[2];
203  char datalabel[MAXNAMELNG];
204  int32 datatype;
205  char *dataattr;
206  char *dataunit;
207  char vgname[MAXNAMELNG];
208  char monthstr[13];
209  char sdsname[MAXNAMELNG];
210  char vgroupname[21];
211  int32 sdsid, sdfid, fid, gridid, geomid;
212  int ifileflag = 0;
213  float32 stdlimit1, stdlimit2, stdlimit3;
214  int maxmissing;
215  /*
216  * data type array pointers
217  */
218 
219  float32 *float_SDSdataRT;
220  float32 *float_SDSdataCLMAVG;
221  float32 *float_SDSdataCLMSTD;
222  float32 *float_SDSdataQC;
223  float32 *c_avg, *c_std; /* new avg, std dev for pre-resized climatology */
224 
225  /* functions used from this file */
226 
227  int8 check_usage();
228 
229  int resize_2d(float *, int, int, int, int, float *);
230  int rd_size(char *, int *, int *);
231 
232  /*
233  * ------- check command line arguments and set args ------------------
234  */
235 
236  strcpy(gridflag, "s"); /* says: use std as default output QC field */
237  if ((check_usage(argc, argv)) != 0) pexit("insufficient args provided");
238 
239  strcpy(infileRT, argv[1]);
240  strcpy(infileCLM, argv[2]);
241  strcpy(outfile, argv[3]);
242  strcpy(monthstr, argv[4]);
243 
244  if (!strcmp(lowcase(argv[5]), "ozone"))
245  pexit("OZONE parameter type not supported by this program.");
246 
247  if (!strcmp(lowcase(argv[5]), "z_wind")) {
248  loval = loZ_WIND;
249  hival = hiZ_WIND;
250  } else if (!strcmp(lowcase(argv[5]), "m_wind")) {
251  loval = loM_WIND;
252  hival = hiM_WIND;
253  } else if (!strcmp(lowcase(argv[5]), "press")) {
254  loval = loPRESS;
255  hival = hiPRESS;
256  } else if (!strcmp(lowcase(argv[5]), "rel_hum")) {
257  loval = loREL_HUM;
258  hival = hiREL_HUM;
259  } else if (!strcmp(lowcase(argv[5]), "p_water")) {
260  loval = loP_WATER;
261  hival = hiP_WATER;
262  } else
263  pexit(
264  "parameter must be 'z_wind', 'm_wind', 'press', 'rel_hum' or 'p_water'.");
265 
266  strcpy(vgroupname, argv[5]);
267 
268  sscanf(argv[6], "%f", &stdlimit1);
269  sscanf(argv[7], "%f", &stdlimit2);
270  sscanf(argv[8], "%f", &stdlimit3);
271  sscanf(argv[9], "%d", &maxmissing);
272  if (argc >= 11) sscanf(argv[10], "%f", &loval);
273  if (argc >= 12) sscanf(argv[11], "%f", &hival);
274  if (argc >= 13) sscanf(argv[12], "%d", &outmax);
275  if (argc >= 14) {
276  strncpy(gridflag, argv[14], 1);
277  gridflag[1] = '\0';
278  }
279  if (argc >= 15) ifileflag = atoi(argv[15]);
280 
281 
282  /*
283  * ------- Read Z/M_WIND, PRESS, REL_HUM or OZONE real-time array files ---------
284  */
285 
286  if (ifileflag == CLMfile) {
287  strcpy(vgname, monthstr);
288  strcpy(sdsname, vgroupname);
289  strcat(sdsname, "_mean");
290  } else {
291  strcpy(vgname, "Geophysical Data");
292  strcpy(sdsname, vgroupname);
293  }
294  /*
295  * Read the size of the NRT field and set the size here
296  */
297  if (rd_size(infileRT, (int*) &shape_nrt[1], (int*) &shape_nrt[0]) != 0) {
298  pexit("metqc: Unable to read the data field size");
299  }
300  /*
301  * allocate the nrt-size arrays here
302  * RT - met field
303  * CLMAVG - mean climatology
304  * CLMSTD - Standard deviation of observations around the mean
305  * QC - output QC field
306  */
307  rank = 2;
308  array_size = shape_nrt[0] * shape_nrt[1];
309 
310  if ((float_SDSdataRT =
311  (float32 *) malloc(sizeof (float32) * array_size)) == NULL)
312  pexit("malloc float_SDSdataRT");
313 
314  if ((float_SDSdataCLMAVG =
315  (float32 *) malloc(sizeof (float32) * array_size)) == NULL)
316  pexit("malloc float_SDSdataCLMAVG");
317 
318  if ((float_SDSdataCLMSTD =
319  (float32 *) malloc(sizeof (float32) * array_size)) == NULL)
320  pexit("malloc float_SDSdataCLMSTD");
321 
322  if ((float_SDSdataQC =
323  (float32 *) malloc(sizeof (float32) * array_size)) == NULL)
324  pexit("malloc float_SDSdataQC");
325  /*
326  * Read Z/M_WIND, PRESS, REL_HUM, P_WATER or OZONE real-time array files
327  */
328 
329  if ((rdsds(infileRT, vgname, sdsname, inShape,
330  float_SDSdataRT)) != 0) pexit("rdsds RT");
331 
332  if ((inShape[0] != shape_nrt[0]) || (inShape[1] != shape_nrt[1])) {
333  printf("inShape[0] %d shape_nrt[0] %d inShape[1] %d shape_nrt[1] %d\n",
334  inShape[0], shape_nrt[0], inShape[1], shape_nrt[1]);
335  pexit("real-time dimensions not matching expected");
336  }
337 
338  /*
339  * ------- Determine appropriate climatology month (SDS) to match ------
340  * real time file. Get the average and std.dev. SDSs.
341  */
342 
343  /*
344  * Read the size of the CLM field and set the size here
345  */
346  if (rd_size(infileCLM, (int*) &shape_clm[1], (int*) &shape_clm[0]) != 0) {
347  pexit("metqc: Unable to read the climatology data field size");
348  }
349  /*
350  * allocate the space
351  */
352  if ((c_avg =
353  (float32 *) malloc(sizeof (float32) * shape_clm[0] * shape_clm[1]))
354  == NULL) {
355  pexit("malloc float_SDSdataCLMAVG");
356  }
357  if ((c_std =
358  (float32 *) malloc(sizeof (float32) * shape_clm[0] * shape_clm[1]))
359  == NULL) {
360  pexit("malloc float_SDSdataCLMAVG");
361  }
362 
363  strcpy(vgname, monthstr);
364  strcpy(sdsname, vgroupname);
365  strcat(sdsname, "_mean");
366 
367  if ((rdsds(infileCLM, vgname, sdsname, inShape,
368  c_avg)) != 0) pexit("rdsds CLMAVG");
369 
370  if ((inShape[0] != shape_clm[0]) || (inShape[1] != shape_clm[1])) {
371  printf("inShape[0] %d shape_clm[0] %d inShape[1] %d shape_clm[1] %d\n",
372  inShape[0], shape_clm[0], inShape[1], shape_clm[1]);
373  pexit("clim avg dimensions not matching expected");
374  }
375 
376  strcpy(sdsname, vgroupname);
377  strcat(sdsname, "_std_dev");
378 
379  if ((rdsds(infileCLM, vgname, sdsname, inShape,
380  c_std)) != 0) pexit("rdsds CLMSTD");
381 
382  if ((inShape[0] != shape_clm[0]) || (inShape[1] != shape_clm[1])) {
383  printf("inShape[0] %d shape_clm[0] %d inShape[1] %d shape_clm[1] %d\n",
384  inShape[0], shape_clm[0], inShape[1], shape_clm[1]);
385  pexit("clim std dimensions not matching expected");
386  }
387 
388  /*
389  l = 0;
390  for (i = 0; i < shape_nrt[0]; i++) {
391  printf ("\n");
392  for (j = 0; j < shape_nrt[1]; j++) {
393  printf ("%f ", float_SDSdataRT[l]);
394  l++;
395  }
396  }
397  */
398 
399  /*
400  * reconcile the climatology array size to that of the met field
401  */
402  printf("NRT field size is - pixels: %d, lines: %d\n",
403  shape_nrt[1], shape_nrt[0]);
404  if (shape_clm[0] != shape_nrt[0] || shape_clm[1] != shape_nrt[1]) {
405  printf("NOTE: Climatology field size is different\n");
406  printf(" Pixels: %d, lines: %d\n", shape_clm[1], shape_clm[0]);
407  printf(" Resizing climatology to match NRT\n");
408  }
409 
410  if ((shape_clm[0] <= 0) || (shape_clm[1] <= 0) ||
411  (shape_nrt[0] <= 0) || (shape_nrt[1] <= 0)) {
412  pexit("metqc: one of shape_clm, shape_nrt dimensions <= 0!");
413  }
414  if (resize_2d(c_avg, shape_clm[1], shape_clm[0],
415  shape_nrt[1], shape_nrt[0], float_SDSdataCLMAVG) != 0) {
416  pexit("metqc: resize_2d problem for CLMAVG, exiting");
417  }
418 
419  if (resize_2d(c_std, shape_clm[1], shape_clm[0],
420  shape_nrt[1], shape_nrt[0], float_SDSdataCLMSTD) != 0) {
421  pexit("metqc: resize_2d problem for CLMSTD, exiting");
422  }
423  free(c_avg);
424  free(c_std);
425 
426  /*
427  * ------- Compute variance of real-time from climatology -----------
428  * and tally #0s (and/or missing), #+ & - 1,2,3 std dev
429  * for writing to file for mailing.
430  */
431 
432  p = 0;
433  missing = 0;
434  locnt = 0;
435  hicnt = 0;
436  rtmiss = 0;
437  neg1cnt = 0;
438  neg2cnt = 0;
439  neg3cnt = 0;
440  pos1cnt = 0;
441  pos2cnt = 0;
442  pos3cnt = 0;
443 
444  for (i = 0; i < shape_nrt[0]; i++) {
445  for (j = 0; j < shape_nrt[1]; j++) {
446  float_SDSdataQC[p] = 0.0; /* initialize each point */
447 
448  /* pt. is missing, NRT missing, a MIN val, and counted as out of
449  lower range */
450  if ((float_SDSdataRT[p] <= VALIDMIN) ||
451  (float_SDSdataCLMAVG[p] <= VALIDMIN)) {
452  missing++;
453  if (float_SDSdataRT[p] <= VALIDMIN) rtmiss++;
454  if (float_SDSdataRT[p] < minval) minval = float_SDSdataRT[p];
455  if (float_SDSdataRT[p] < loval) locnt++;
456  } else {
457  if ((!strcmp(gridflag, "d")) || (!strcmp(gridflag, "D"))) {
458  float_SDSdataQC[p] =
459  (float32) float_SDSdataRT[p] - float_SDSdataCLMAVG[p];
460  } else {
461  if (float_SDSdataCLMSTD[p] > 0)
462  float_SDSdataQC[p] = (float32)
463  (float_SDSdataRT[p] - float_SDSdataCLMAVG[p]) /
464  float_SDSdataCLMSTD[p];
465  }
466 
467  /* find min and max of all points */
468  if (float_SDSdataRT[p] < minval) minval = float_SDSdataRT[p];
469  if (float_SDSdataRT[p] > maxval) maxval = float_SDSdataRT[p];
470 
471  /* sum up points outside lo/hi range (LO adds to missing counts)*/
472  if (float_SDSdataRT[p] < loval) locnt++;
473  if (float_SDSdataRT[p] > hival) hicnt++;
474 
475  if (float_SDSdataQC[p] < -1.0) neg1cnt++;
476  if (float_SDSdataQC[p] < -2.0) neg2cnt++;
477  if (float_SDSdataQC[p] < -3.0) neg3cnt++;
478 
479  if (float_SDSdataQC[p] > 1.0) pos1cnt++;
480  if (float_SDSdataQC[p] > 2.0) pos2cnt++;
481  if (float_SDSdataQC[p] > 3.0) pos3cnt++;
482  }
483  /*
484  if ((j > 100) && (j < 150)) {
485  printf("QC [%d][%d]: %f\n", i,j,float_SDSdataQC[p]);
486  printf("RT [%d][%d]: %f\n", i,j,float_SDSdataRT[p]);
487  printf("AVG [%d][%d]: %f\n", i,j,float_SDSdataCLMAVG[p]);
488  printf("STD [%d][%d]: %f\n", i,j,float_SDSdataCLMSTD[p]);
489  }
490  printf("[%d][%d]: %f %f %f\n", i,j,float_SDSdataRT[p],
491  float_SDSdataCLMAVG[p], float_SDSdataCLMSTD[p]);
492  */
493  p++;
494  } /* for j */
495  } /* for i */
496 
497  totalpts = array_size - missing;
498 
499  free(float_SDSdataRT);
500  free(float_SDSdataCLMAVG);
501  free(float_SDSdataCLMSTD);
502 
503 #if 0
504  p = 0;
505  for (i = 0; i < shape_nrt[0]; i++) {
506  for (j = 0; j < shape_nrt[1]; j++) {
507  float_SDSdataQC[p] = 0.0; /* initialize each point */
508  p++;
509  } /* for j */
510  } /* for i */
511 #endif
512 
513  /*
514  * ----------------- Write QC SDS ----------------------------
515  */
516 
517  /*
518  * Create HDF file
519  */
520 
521 
522  if ((startHDF(outfile, &sdfid, &fid, DFACC_CREATE)) != 0)
523  pexit("Fatal error starting output HDF file");
524 
525  /*
526  * Create grid structure
527  */
528 
529  /* gridid = setupGrid(fid, VGROUPCLASS, vgroupname); */
530  gridid = setupGrid(fid, vgroupname);
531 
532  /*
533  * Write geometry Vdata, get ref, and add to grid Vgroup (geomid not used)
534  */
535 
536  if ((geomid = writeGeom(fid, gridid, GEOMNAME, BIN_METH, REGISTRATION,
538  MAX_WEST, MAX_EAST)) == ERROR)
539  pexit("Fatal error writing geometry");
540 
541  /*
542  * Write SDS grid
543  */
544 
545  strcpy(datalabel, "QC array");
546  datatype = DFNT_FLOAT;
547  dataattr = "UNITS";
548  dataunit = "std dev diff";
549 
550  if ((sdsid = wrtsds(sdfid, rank, shape_nrt, datatype, datalabel,
551  float_SDSdataQC)) < 0) pexit("main wrtsds");
552 
553  free(float_SDSdataQC);
554 
555  /*
556  * set SDS attribute
557  */
558 
559  if ((result = addAttr(sdsid, dataattr, DFNT_CHAR, dataunit)) != 0)
560  pexit("addAttr");
561 
562  /*
563  * add SDS to Vgroup and deattach SDS
564  */
565 
566  if ((result = setSDSref(sdsid, gridid)) != 0) pexit("setSDSref");
567 
568  /*
569  * deattach HDF grid
570  */
571 
572  deattachHDFgrid(gridid);
573 
574  /*
575  * close HDF structures
576  */
577 
578  if ((result = closeHDFstructs(sdfid, fid)) != 0) pexit("closeHDFstructs");
579 
580  /*
581  * ----------------- Print stats to standard output -----------
582  */
583 
584  /* printf("gridflag [%s]\n",gridflag); */
585 
586  if (!strcmp(gridflag, "s")) {
587  printf("\n");
588  printf("-------------------------------------------------------------\n");
589  printf("Results of comparison of real-time and climatological files:\n");
590  printf("%s\n%s\n", infileRT, infileCLM);
591  printf("Month: %s\t\tParameter: %s\n", monthstr, argv[5]);
592  printf("Thresholds: %8.3f %8.3f %8.3f Max Missings: %d",
593  stdlimit1, stdlimit2, stdlimit3, maxmissing);
594  printf("\n");
595  printf("Minimum value: %8.3f Maximum: %8.3f\n", minval, maxval);
596 
597  printf("Total # non-missing values: %6d\n", totalpts);
598  printf("Total # values <%8.3f: %d >%8.3f: %d allowed: %d",
599  loval, locnt, hival, hicnt, outmax);
600 
601  /* if (locnt >= outmax) failed = 1; lo points out of range exceeded */
602  /* if (hicnt >= outmax) failed = 1; hi points out of range exceeded */
603  /*
604  * WDR if fail in either case, append a set of astrisks
605  */
606  if (locnt >= outmax || hicnt >= outmax) {
607  failed = 1;
608  printf(" ***\n");
609  } else {
610  printf("\n");
611  }
612 
613  printf("\n");
614  printf("Total # points/percentage < -1 STD: %6d (%5.2f percent)\n",
615  neg1cnt, (float) neg1cnt / totalpts * 100.0);
616  printf("Total # points/percentage +/- 1 STD: %6d (%5.2f percent)",
617  totalpts - (neg1cnt + pos1cnt),
618  (float) (totalpts - (pos1cnt + neg1cnt)) / totalpts * 100.0);
619 
620  if (((float) (totalpts - (pos1cnt + neg1cnt)) / totalpts * 100.0) <
621  stdlimit1) {
622  failed = 1;
623  printf(" ***\n");
624  } else {
625  printf("\n");
626  }
627 
628  printf("Total # points/percentage > 1 STD: %6d (%5.2f percent)\n",
629  pos1cnt, (float) pos1cnt / totalpts * 100.0);
630  printf("\n");
631 
632  printf("Total # points/percentage < -2 STD: %6d (%5.2f percent)\n",
633  neg2cnt, (float) neg2cnt / totalpts * 100.0);
634  printf("Total # points/percentage +/- 2 STD: %6d (%5.2f percent)",
635  totalpts - (neg2cnt + pos2cnt),
636  (float) (totalpts - (pos2cnt + neg2cnt)) / totalpts * 100.0);
637 
638  if (((float) (totalpts - (pos2cnt + neg2cnt)) / totalpts * 100.0) <
639  stdlimit2) {
640  failed = 1;
641  printf(" ***\n");
642  } else {
643  printf("\n");
644  }
645 
646  printf("Total # points/percentage > 2 STD: %6d (%5.2f percent)\n",
647  pos2cnt, (float) pos2cnt / totalpts * 100.0);
648  printf("\n");
649 
650  printf("Total # points/percentage < -3 STD: %6d (%5.2f percent)\n",
651  neg3cnt, (float) neg3cnt / totalpts * 100.0);
652  printf("Total # points/percentage +/- 3 STD: %6d (%5.2f percent)",
653  totalpts - (neg3cnt + pos3cnt),
654  (float) (totalpts - (pos3cnt + neg3cnt)) / totalpts * 100.0);
655 
656  if (((float) (totalpts - (pos3cnt + neg3cnt)) / totalpts * 100.0) <
657  stdlimit3) {
658  failed = 1;
659  printf(" ***\n");
660  } else {
661  printf("\n");
662  }
663 
664  printf("Total # points/percentage > 3 STD: %6d (%5.2f percent)\n",
665  pos3cnt, (float) pos3cnt / totalpts * 100.0);
666  printf("\n");
667 
668  printf("Total # missing values: %6d\n", missing);
669  printf("Total # missing real-time: %6d", rtmiss);
670  if (rtmiss > maxmissing) {
671  failed = 1;
672  printf(" ***\n");
673  } else {
674  printf("\n");
675  }
676  printf("-------------------------------------------------------------\n");
677  printf("\n\n");
678 
679  }
680 
681  /* set exit value to reflect threshold checks */
682 
683  if (failed) {
684  printf("Threshold Status: FAILED\n");
685  return (FAILURE);
686  } else {
687  printf("Threshold Status: SUCCESS\n");
688  return (SUCCESS);
689  }
690 } /* main */
691 
692 /*****************************************************************
693  *
694  * check user parameters and show example if not all parms given
695  *
696  *****************************************************************/
697 
698 int8 check_usage(int argc, char *argv[]) {
699  if (argc < 9) {
700  printf("\n\nUsage:\n");
701  printf("\t%s <file><file><outfile><monthstr><param><t1><t2><t2><maxmiss><lo><hi><outmax>[diff][type] \n", argv[0]);
702  printf("\nWhere:\n");
703  printf("\tfile: Real-time file to process\n");
704  printf("\tfile: Climatology file\n");
705  printf("\toutfile: Output QC file\n");
706  printf("\tmonthstr: Month in string form (i.e., January)\n");
707  printf("\tparam: Parameter to run: z_wind m_wind press rel_hum p_water\n");
708  printf("\tt1: Threshold percent of pts w/in 1 STD DEV of clim\n");
709  printf("\tt2: Threshold percent of pts w/in 2 STD DEV of clim\n");
710  printf("\tt3: Threshold percent of pts w/in 3 STD DEV of clim\n");
711  printf("\tmaxmiss: Max num of missing NRT points permitted\n");
712  printf("\tlo: Lowest allowed value in NRT file\n");
713  printf("\thi: Highest allowed value in NRT file\n");
714  printf("\tlo: Maximum # of NRT points allowed outside of lo/hi before returning an error flag\n");
715  printf("\t [optional] parameters follow. Preceeding args \n");
716  printf("\t are required for subsequent ones used\n");
717  printf("\tdiff: [optional] Enter 'd' to see a simple difference output\n");
718  printf("\t grid rather than the default STD variance 's'\n");
719  printf("\t Difference calculations do not product reports\n");
720  printf("\ttype [optional] Enter 1 if NRT file is actually a CLM file\n");
721  printf("\t This will allow the program to read the CLM\n");
722  printf("\t as of test of CLM to itself\n");
723  printf("\n");
724  return (ERROR);
725  }
726  return 0;
727 }
int32_t setupGrid(int32_t fid, char *grpname)
Definition: ANCroutines.c:51
#define SUCCESS
Definition: ObpgReadGrid.h:15
int j
Definition: decode_rs.h:73
#define CLMfile
Definition: metqc.c:159
char * lowcase(char *instr)
Definition: lowcase.c:10
int addAttr(int32_t sdsid, char *dataattr, int32_t datatype, char *dataunit)
Definition: ANCroutines.c:222
int8 check_usage(int argc, char *argv[])
Definition: metqc.c:698
int main(int argc, char *argv[])
Definition: metqc.c:161
#define NULL
Definition: decode_rs.h:63
int rd_size(char *file, int *npix, int *nlin)
Definition: rd_size.c:4
#define MAX_SOUTH
Definition: metqc.c:154
#define HSIZE
Definition: metqc.c:152
#define MAX_EAST
Definition: metqc.c:156
int resize_2d(float *in_arr, int inpix, int inlin, int outpix, int outlin, float *out_arr)
Definition: resize_2d.c:1
#define VALIDMIN
Definition: metqc.c:158
#define BIN_METH
Definition: metqc.c:147
int32_t wrtsds(int32_t sdfid, int rank, int32_t *shape, int32_t datatype, char *datalabel, void *data)
int deattachHDFgrid(int32_t gridid)
Definition: ANCroutines.c:267
#define VSIZE
Definition: metqc.c:151
int closeHDFstructs(int32_t sdfid, int32_t fid)
Definition: ANCroutines.c:281
void pexit(char *string)
Definition: pexit.c:10
int32_t writeGeom(int32_t fid, int32_t gridid, char *geomname, int32_t bin_meth, int32_t registration, float vsize, float hsize, float max_north, float max_south, float max_west, float max_east)
Definition: ANCroutines.c:92
#define FAILURE
Definition: ancil.h:25
Extra metadata that will be written to the HDF4 file l2prod rank
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second and prod_ix set to PARAM_TYPE_INT name_prefix is compared with the beginning of the product name If name_suffix is not empty the it must match the end of the product name The characters right after the prefix are read as an integer and prod_ix is set to that number strncpy(l2prod->name_prefix, "myprod", UNITLEN)
#define REGISTRATION
Definition: metqc.c:148
int setSDSref(int32_t sdsid, int32_t gridid)
Definition: ANCroutines.c:245
#define MAXNAMELNG
Definition: ancil.h:43
int i
Definition: decode_rs.h:71
#define GEOMNAME
Definition: ancil.h:44
#define MAX_NORTH
Definition: metqc.c:153
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
#define MAX_WEST
Definition: metqc.c:155
int rdsds(char *filename, char *vgname, char *sdsname, int32_t *dimsizes, void *inData)
float p[MODELMAX]
Definition: atrem_corl1.h:131
int startHDF(char *outfile, int32_t *sdfid, int32_t *fid, int32_t mode)
Definition: ANCroutines.c:27
#define ERROR
Definition: ancil.h:24