OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
ck_v_l3.c
Go to the documentation of this file.
1 #include "fmt_check.h"
2 #include <math.h>
3 #include <hdf4utils.h>
4 
5 extern int fmt_status; /* format checking status, see fmt_check */
6 extern int verbose; /* 0 - don't print info on each vgroup, 1 do */
7 static l3_org_str l3_org; /* info on l3 organization */
8 
9 void ck_v_l3(int32 file_id, fmt_str *fmt)
10 /*******************************************************************
11 
12  ck_v_l3
13 
14  purpose: Check the format of the Vdatas in Vgroup 'Level-3 Binned Data'
15  for a level 3 dataset
16 
17  Returns type: none
18 
19  Parameters: (in calling order)
20  Type Name I/O Description
21  ---- ---- --- -----------
22  int32 file_id I ID returned from Hopen
23  fmt_str * fmt I Format expected information
24 
25  Modification history:
26  Programmer Date Description of change
27  ---------- ---- ---------------------
28  W. Robinson 4-Apr-2005 Original development
29 
30  *******************************************************************/ {
31  int32 nbins, tot_vgroup;
32  int32 num_vgroups, dummy_i32, *ref_array, i, iret, ifound;
33 
34  /*
35  * set up # bins locally
36  */
37  nbins = fmt->dim_id[ fmt->vg_nbin_indx ].dim_size;
38 
39  /*
40  * set up organization based on the resolve
41  */
42  l3_get_org(fmt->resolve, &l3_org);
43  /*
44  * open the thing for Vgroups
45  */
46  printf("\n\nChecking the 'Level-3 Binned Data' Vgroup...\n\n");
47 
48  Vstart(file_id);
49 
50  /* get the ID for the top Vgroups
51  * ref man says to first use max_size = 0 to just get the #,
52  * so, we'll do this first too
53  */
54  if ((num_vgroups = Vlone(file_id, &dummy_i32, 0)) == -1) {
55  printf("********************Program problem:\n");
56  printf("Vgroup check: The Vlone #1 failed\n");
57  fmt_status = fmt_status | 2;
58  } else {
59  if (verbose == 1)
60  printf("the # of 'lone' Vgroups is %d\n", num_vgroups);
61  /*
62  * allocate space for the groups and get the IDs
63  */
64  ref_array = (int32 *) malloc(num_vgroups * sizeof ( int32));
65  if ((num_vgroups = Vlone(file_id, ref_array, num_vgroups)) == -1) {
66  printf("********************Program problem:\n");
67  printf("Vgroup check: The Vlone #2 failed\n");
68  fmt_status = fmt_status | 2;
69  } else {
70  /*
71  * next, loop thru the Vgroups and get class, name and # entries,
72  * = # of Vdatas in this case
73  */
74  ifound = 0;
75  tot_vgroup = fmt->n_vgroup + 3;
76  for (i = 0; i < num_vgroups; i++) {
77  if ((iret = group_fnd(file_id, ref_array[i], nbins, tot_vgroup,
78  fmt->vg_info)) == 0) {
79  ifound = 1;
80  }
81  }
82  if (ifound != 1) {
83  printf("**** the Vgroup: 'Level-3 Binned Data' was not found\n");
84  fmt_status = fmt_status | 2;
85  }
86  }
87  }
88  /* close the file */
89  Vend(file_id);
90 }
91 
92 int32 group_fnd(int32 file_id, int32 vgroup_ref, int32 nbins, int32 n_vgroup,
93  vg_info_str *vd_check)
94 /*******************************************************************
95 
96  group_fnd
97 
98  purpose: Check the format of the Vdatas in Vgroup 'Level-3 Binned Data'
99  for a level 3 dataset, archive version 2.6
100 
101  Returns type: int32
102 
103  Parameters: (in calling order)
104  Type Name I/O Description
105  ---- ---- --- -----------
106  int32 file_id I file id from Hopen
107  int32 vgroup_ref I current group ref #
108  int32 nbins I # bins from attributes
109  to check
110  int32 n_vgroup I # of vgroups (3 + # prod)
111  struct vd_check_str * vd_check I array of definitions of each
112  Vdata
113 
114  Modification history:
115  Programmer Date Description of change
116  ---------- ---- ---------------------
117  W. Robinson 16-Mar-1995 Original development
118  W. Robinson, SAIC 6 Apr 2005 uogrades for table driven version
119 
120  *******************************************************************/ {
121  int32 v_id, n_vgroup_entries;
122  int32 vd_id, i, n_vd_fields, vdata_size, interlace;
123  int32 n_rec, j, vd_typ, vd_ref;
124  int32 *begin, *extent;
125  char vgroup_class[VGNAMELENMAX], vgroup_name[VGNAMELENMAX];
126  char vd_name[VSNAMELENMAX], vd_class[VSNAMELENMAX];
127  char field_list[500];
128 
129  /*
130  * set up storage for start bin and # in each row
131  */
132  begin = (int32 *) malloc(l3_org.numrows * sizeof (int32));
133  extent = (int32 *) malloc(l3_org.numrows * sizeof (int32));
134  /*
135  * attach to the Vgroup first
136  */
137  if ((v_id = Vattach(file_id, vgroup_ref, "r")) == -1) {
138  printf("******************** Probable Program Error\n");
139  printf("Problem on attaching to group with ref # %d\n", vgroup_ref);
140  fmt_status = fmt_status | 2;
141  return -1;
142  }
143  /*
144  * get the name and check with the desired name
145  */
146  if (Vinquire(v_id, &n_vgroup_entries, vgroup_name) == -1) {
147  printf("******************** Probable Program Error\n");
148  printf("Vinquire failed on group ref # %d\n",
149  vgroup_ref);
150  fmt_status = fmt_status | 2;
151  return -1;
152  }
153 
154  if (verbose == 1)
155  printf("The group name being checked is:\n'%s'\n", vgroup_name);
156  if (strcmp(vgroup_name, "Level-3 Binned Data") != 0) {
157  return 1;
158  }
159  /*
160  * OK, if the name has passed, assume we have the right Vgroup
161  * and check the class and # entries
162  */
163  Vgetclass(v_id, vgroup_class);
164  if (verbose == 1) {
165  printf("For target Vgroup of '%s'\n# entries = %d and class = '%s'\n",
166  vgroup_name, n_vgroup_entries, vgroup_class);
167  }
168  if (n_vgroup_entries != n_vgroup) {
169  printf("**** Error, # entries (%d) is not = %d\n", n_vgroup_entries,
170  n_vgroup);
171  fmt_status = fmt_status | 2;
172  }
173  if (strcmp(vgroup_class, "PlanetaryGrid") != 0) {
174  printf("**** Error, Vgroup class ('%s') is incorrect\n", vgroup_class);
175  fmt_status = fmt_status | 2;
176  }
177  /*
178  * Go on to the Vdatas themselvs
179  */
180  printf("\n\nChecking Vdatas inside the Vgroup\n\n");
181 
182  for (i = 0; i < n_vgroup_entries; i++) {
183  /*
184  * try to find each Vdata
185  */
186  if ((vd_ref = VSfind(file_id, vd_check[i].name)) < 0) {
187  printf("**** Unable to locate Vdata with name '%s'\n",
188  vd_check[i].name);
189  fmt_status = fmt_status | 2;
190  } else {
191  /*
192  * attach to this Vdata
193  */
194  if ((vd_id = VSattach(file_id, vd_ref, "r")) == -1) {
195  printf(
196  "*************** Program Error: Unable to attach to Vdata name: '%s'\n",
197  vd_check[i].name);
198  printf(" and vd_ref # %d\n", vd_ref);
199  fmt_status = fmt_status | 2;
200  } else {
201  /*
202  * get and check class
203  */
204  VSgetclass(vd_id, vd_class);
205  if (verbose == 1)
206  printf("Vdata: '%s' has class '%s'\n", vd_check[i].name, vd_class);
207  if (strcmp(vd_class, vd_check[i].class) != 0) {
208  printf("****for Vdata: '%s', mismatch in the class\n",
209  vd_check[i].name);
210  printf("expected class: '%s'\n", vd_check[i].class);
211  printf("read class: '%s'\n", vd_class);
212  fmt_status = fmt_status | 2;
213  }
214  /*
215  * get and check the # records and field names
216  */
217  if (VSinquire(vd_id, &n_rec, &interlace, field_list,
218  &vdata_size, vd_name) == -1) {
219  printf(
220  "******************* Program Error, VSinquire failed\n");
221  fmt_status = fmt_status | 2;
222  } else {
223  if (verbose == 1)
224  printf("Vdata: '%s' has #records = %d, field list:\n'%s'\n",
225  vd_check[i].name, n_rec, field_list);
226  if (strcmp(field_list, vd_check[i].field_list) != 0) {
227  printf("****for Vdata: '%s', mismatch in the field list\n",
228  vd_check[i].name);
229  printf("expected list: '%s'\n", vd_check[i].field_list);
230  printf("read list: '%s'\n", field_list);
231  fmt_status = fmt_status | 2;
232  }
233  if (vd_check[i].nrec == -1) {
234  /*
235  * a note here, the # records in one of these Vdatas
236  * can actually be >= the attribute 'Data Bins'.
237  * Thus, the following check
238  */
239  if (n_rec < nbins) {
240  printf("****for Vdata: '%s', # records < # bins\n",
241  vd_check[i].name);
242  printf("expected: %d, read: %d\n", nbins, n_rec);
243  fmt_status = fmt_status | 2;
244  }
245  } else {
246  if (n_rec != vd_check[i].nrec) {
247  printf("****for Vdata: '%s', mismatch in the # records\n",
248  vd_check[i].name);
249  printf("expected: %d, read: %d\n",
250  vd_check[i].nrec, n_rec);
251  fmt_status = fmt_status | 2;
252  }
253  }
254  }
255  /*
256  * get and check # fields and their types
257  */
258  if ((n_vd_fields = VSgetfields(vd_id, field_list)) == -1) {
259  printf("*************** Program error, VSgetfields failed.\n");
260  fmt_status = fmt_status | 2;
261  } else {
262  if (verbose == 1)
263  printf("Vdata: '%s', has %d fields\n",
264  vd_check[i].name, n_vd_fields);
265  if (n_vd_fields != vd_check[i].n_fields) {
266  printf("****for Vdata: '%s', mismatch in the # fields\n",
267  vd_check[i].name);
268  printf("expected: %d, read: %d\n", vd_check[i].n_fields,
269  n_vd_fields);
270  fmt_status = fmt_status | 2;
271  } else {
272  for (j = 0; j < n_vd_fields; j++) {
273  vd_typ = VFfieldtype(vd_id, j);
274  if (verbose == 1)
275  printf("Vdata: '%s', field # %d has num type %d\n",
276  vd_check[i].name, j, vd_typ);
277  /* WDR - don't check type of field 5 of bin list
278  if( vd_typ != vd_check[i].num_typs[j] )
279  */
280  if ((j != 5) && (i != 2) &&
281  (vd_typ != vd_check[i].num_typs[j])) {
282  printf(
283  "****for Vdata: '%s', field # %d has incorrect number type\n",
284  vd_check[i].name, j);
285  printf("expected: %d, read: %d\n",
286  vd_check[i].num_typs[j], vd_typ);
287  fmt_status = fmt_status | 2;
288  }
289  }
290  }
291  }
292  /*
293  * Vdata has been attached to. any extra checking can be added
294  * here
295  */
296  if (i == 0) /* Check constant values in the SEAGrid */ {
297  chk_sea_grid(vd_id);
298  } /* Check all the BinIndex field values except for "begin" and
299  * "extent" fields. Save the begin and extent buffers until
300  * Vdata BinList is read then cross verify the information
301  * written in these fields against "binno" of BinList vdata.
302  */
303  else if (i == 1) {
304  chk_bin_index(vd_id, begin, extent);
305  } else if (i == 2) /* Check binno of BinList */ {
306  chk_bin_list(vd_id, nbins, begin, extent);
307  } else /* look through the products*/ {
308  chk_l3_prod(vd_id, nbins, vd_check[i].name, field_list);
309  }
310  /*
311  * remember to detach from the Vdata
312  */
313  VSdetach(vd_id);
314  }
315  }
316  }
317  free(begin);
318  free(extent);
319  /*
320  * If we got here, all was well
321  */
322  return 0;
323 }
324 
325 void chk_sea_grid(int32 vd_id)
326 /*******************************************************************
327 
328  chk_sea_grid
329 
330  purpose: Check the SEAGrid Vdata in Vgroup 'Level-3 Binned Data'
331  to make sure its constant values are correct
332 
333  Returns type: none
334 
335  Parameters: (in calling order)
336  Type Name I/O Description
337  ---- ---- --- -----------
338  int32 vd_id I ID of the Vdata
339 
340  Modification history:
341  Programmer Date Description of change
342  ---------- ---- ---------------------
343  W. Robinson 25-Apr-1995 Original development
344  W. Robinson 1-Sep-2009 They finally fixed the value of
345  l3_org.bins_eq to be # bins around
346  equator - so remove fix in this check
347 
348  *******************************************************************/ {
349  int32 n_vd_rec;
350 
351  /*
352  * This structure / union deserves some explaination.
353  * the Vdata record gets read in as a contiguous set of 3
354  * floats and 4 doubles. the buffer for VSread should be a
355  * uint8, so it is 1 part of the union. The sea_grid_str
356  * holds the actual values. The array align makes sure that
357  * this whole thing starts at a double alignment. The
358  * extra int32 dummy will assure that the float64 data
359  * starts at an aligned double boundary. When reading in,
360  * the read starts at the location buf + 4 so that the data starts
361  * at the right place.
362  */
363  union sea_gr_u {
364 
365  struct sea_grid_str {
366  int32 dummy;
367  int32 registration;
368  int32 straddle;
369  int32 bins;
370  float64 radius;
371  float64 max_north;
372  float64 max_south;
373  float64 seam_lon;
374  } str;
375  uint8 buf[48];
376  double align[6];
377  } sea_grid;
378 
379  /*
380  * set to read the first record and all fields
381  */
382  if (VSsetfields(vd_id,
383  "registration,straddle,bins,radius,max_north,max_south,seam_lon"
384  ) == -1) {
385  printf(
386  "*************** Program Error: For Vdata: 'SEAGrid',\n"
387  "Cannot do VSsetfields\n");
388  fmt_status = fmt_status | 2;
389  return;
390  }
391 
392  if (VSseek(vd_id, 0) == -1) {
393  printf(
394  "*************** Program Error: For Vdata: 'SEAGrid',\n"
395  "Cannot do VSseek\n");
396  fmt_status = fmt_status | 2;
397  }
398 
399  if ((n_vd_rec = VSread(vd_id, (sea_grid.buf + 4), 1, 0)) != 1) {
400  printf(
401  "**** For Vdata: 'SEAGrid', data read failed to read the 1 record \n"
402  " with return: %d\n", n_vd_rec);
403  fmt_status = fmt_status | 2;
404  } else {
405  if (verbose == 1)
406  printf("For Vdata 'SEAGrid', registration = %d\n",
407  sea_grid.str.registration);
408  if (sea_grid.str.registration != 5) {
409  printf("**** For Vdata 'SEAGrid', mismatch in registration\n");
410  printf(" expected: 5, read: %d\n", sea_grid.str.registration);
411  fmt_status = fmt_status | 2;
412  }
413  if (verbose == 1)
414  printf("For Vdata 'SEAGrid', straddle = %d\n",
415  sea_grid.str.straddle);
416  if (sea_grid.str.straddle != 0) {
417  printf("**** For Vdata 'SEAGrid', mismatch in straddle\n");
418  printf(" expected: 0, read: %d\n", sea_grid.str.straddle);
419  fmt_status = fmt_status | 2;
420  }
421  if (verbose == 1)
422  printf("For Vdata 'SEAGrid', bins = %d\n",
423  sea_grid.str.bins);
424  /* The # bins around equator was finally corrected in reprocessing 09
425  if( sea_grid.str.bins != l3_org.numrows )
426  */
427  if (sea_grid.str.bins != l3_org.bins_eq) {
428  printf("**** For Vdata 'SEAGrid', mismatch in bins\n");
429  printf(" expected: %d, read: %d\n", l3_org.bins_eq,
430  sea_grid.str.bins);
431  fmt_status = fmt_status | 2;
432  }
433  if (verbose == 1)
434  printf("For Vdata 'SEAGrid', radius = %f\n",
435  sea_grid.str.radius);
436  if (sea_grid.str.radius != 6378.137) {
437  printf("**** For Vdata 'SEAGrid', mismatch in radius\n");
438  printf(" expected: 6378.137, read: %f\n", sea_grid.str.radius);
439  fmt_status = fmt_status | 2;
440  }
441  if (verbose == 1)
442  printf("For Vdata 'SEAGrid', max_north = %f\n",
443  sea_grid.str.max_north);
444  if (sea_grid.str.max_north != 90.0) {
445  printf("**** For Vdata 'SEAGrid', mismatch in max_north/n");
446  printf(" expected: 90.0, read: %f\n", sea_grid.str.max_north);
447  fmt_status = fmt_status | 2;
448  }
449  if (verbose == 1)
450  printf("For Vdata 'SEAGrid', max_south = %f\n",
451  sea_grid.str.max_south);
452  if (sea_grid.str.max_south != -90.0) {
453  printf("**** For Vdata 'SEAGrid', mismatch in max_south/n");
454  printf(" expected: -90.0, read: %f\n", sea_grid.str.max_south);
455  fmt_status = fmt_status | 2;
456  }
457  if (verbose == 1)
458  printf("For Vdata 'SEAGrid', seam_lon = %f\n",
459  sea_grid.str.seam_lon);
460  if (sea_grid.str.seam_lon != -180.0) {
461  printf("**** For Vdata 'SEAGrid', mismatch in seam_lon/n");
462  printf(" expected: -180.0, read: %f\n", sea_grid.str.seam_lon);
463  fmt_status = fmt_status | 2;
464  }
465  }
466 }
467 
468 void chk_bin_index(int32 vd_id, int32 *begin, int32 *extent)
469 /*******************************************************************
470 
471  chk_bin_index
472 
473  purpose: Check the BinIndex Vdata in Vgroup 'Level-3 Binned Data'
474  to make sure its values are correct. The values in fields
475  begin and extent will not be checked in this routine.
476 
477  Returns type: none
478 
479  Parameters: (in calling order)
480  Type Name I/O Description
481  ---- ---- --- -----------
482  int32 vd_id I ID of the Vdata
483  int32* begin O # of 1st data containing bin
484  int32* extent O # of bins stored in eh. row
485 
486  Modification history:
487  Programmer Date Description of change
488  ---------- ---- ---------------------
489  L. Kumar 23-Feb-1996 Original development
490  W. Robinson 25 Jul 1996 correct hsize check so it fails on
491  difference > 1/1000
492 
493  *******************************************************************/ {
494  int32 i, status, row;
495  int32 *int32buf;
496  float64 *ft64buf, vsz;
497 
498  /*
499  * set up space needed
500  */
501  int32buf = (int32 *) malloc(l3_org.numrows * sizeof (int32));
502  ft64buf = (float64 *) malloc(l3_org.numrows * sizeof (float64));
503 
504  vsz = l3_org.vsize; /* Note that all values pre-computed in l3_get_org */
505 
506  /*
507  * read and verify the row numbers from vdata BinIndex
508  */
509  if ((status = (rdvdata(vd_id, "row_num", 0, l3_org.numrows,
510  (unsigned char *) &int32buf[0]))) >= 0) {
511  if (verbose == 1)
512  printf("For Vdata 'BinIndex', checking row_num \n");
513  for (i = 0; i < l3_org.numrows; i++)
514  if (int32buf[i] != i) {
515  printf("***** For Vdata 'BinIndex', mismatch in row_num\n");
516  printf(" expected: %d, read: %d\n", i, int32buf[i]);
517  fmt_status = fmt_status | 2;
518  }
519  }
520 
521  /*
522  * read and verify the vsize from vdata BinIndex
523  */
524  if ((status = (rdvdata(vd_id, "vsize", 0, l3_org.numrows,
525  (unsigned char *) ft64buf))) >= 0) {
526  if (verbose == 1)
527  printf("For Vdata 'BinIndex', checking vsize \n");
528  for (i = 0; i < l3_org.numrows; i++)
529  if (ft64buf[i] != vsz) {
530  printf("***** For Vdata 'BinIndex', mismatch in vsize\n");
531  printf(" expected: %15.10f, read: %15.10f\n", vsz, ft64buf[i]);
532  fmt_status = fmt_status | 2;
533  }
534  }
535 
536  /*
537  * read and verify the hsize from vdata BinIndex
538  */
539  if ((status = (rdvdata(vd_id, "hsize", 0, l3_org.numrows,
540  (unsigned char *) ft64buf))) >= 0) {
541  if (verbose == 1)
542  printf("For Vdata 'BinIndex', checking hsize \n");
543  for (row = 0; row < l3_org.numrows; row++) {
544  if ((fabs(ft64buf[row] - l3_org.hsize[row])) > 1.0 / 1000.0) {
545  printf("***** For Vdata 'BinIndex', mismatch in hsize\n");
546  printf(" expected: %10.8g, read: %10.8g\n", l3_org.hsize[row],
547  ft64buf[row]);
548  printf(" for index %d\n", row);
549  fmt_status = fmt_status | 2;
550  }
551  }
552  }
553 
554  /*
555  * read and verify the start_num from vdata BinIndex
556  */
557  if ((status = (rdvdata(vd_id, "start_num", 0, l3_org.numrows,
558  (unsigned char *) int32buf))) >= 0) {
559  if (verbose == 1)
560  printf("For Vdata 'BinIndex', checking start_num \n");
561  for (i = 0; i < l3_org.numrows; i++) {
562  if (int32buf[i] != l3_org.start_bin[i]) {
563  printf("***** For Vdata 'BinIndex', mismatch in start_num\n");
564  printf(" expected: %d, read: %d\n", l3_org.start_bin[i + 1],
565  int32buf[i]);
566  fmt_status = fmt_status | 2;
567  }
568  }
569  }
570 
571  /*
572  * read and verify the "max" (maximum no. of bins/row) from vdata BinIndex
573  */
574  if ((status = (rdvdata(vd_id, "max", 0, l3_org.numrows,
575  (unsigned char *) int32buf))) >= 0) {
576  if (verbose == 1)
577  printf("For Vdata 'BinIndex', checking max \n");
578  for (i = 0; i < l3_org.numrows; i++) {
579  if (int32buf[i] != l3_org.max_bin[i]) {
580  printf("***** For Vdata 'BinIndex', mismatch in max\n");
581  printf(" expected: %d, read: %d\n", l3_org.max_bin[i],
582  int32buf[i]);
583  fmt_status = fmt_status | 2;
584  }
585  }
586  }
587 
588  /*
589  * read and verify the begin from vdata BinIndex
590  */
591  rdvdata(vd_id, "begin", 0, l3_org.numrows, (unsigned char *) begin);
592 
593  /*
594  * read and verify the extent from vdata BinIndex
595  */
596  rdvdata(vd_id, "extent", 0, l3_org.numrows, (unsigned char *) extent);
597 
598  free(int32buf);
599  free(ft64buf);
600 }
601 
602 void chk_bin_list(int32 vd_id, int32 nbins, int32 *begin, int32 *extent)
603 /*******************************************************************
604 
605  chk_bin_list
606 
607  purpose: Read the BinList Vdata in Vgroup 'Level-3 Binned Data' for
608  field 'binno' to make sure begin and extent values stored in Vdata
609  'BinIndex' are correct. Also, verifies whether global attribute
610  'Data Bins' is correct.
611 
612  Returns type: none
613 
614  Parameters: (in calling order)
615  Type Name I/O Description
616  ---- ---- --- -----------
617  int32 vd_id I ID of the Vdata
618  int32 nbins I # of bins
619  int32* begin I # of 1st data containing bin
620  int32* extent I # of bins stored in eh. row
621 
622  Modification history:
623  Programmer Date Description of change
624  ---------- ---- ---------------------
625  L. Kumar 07-Mar-1996 Original development
626 
627  *******************************************************************/ {
628  int32 i, binno[512], row = 0, rowcount = 0;
629  int32 *loc_extent, *loc_begin, nrec;
630  int32 start, nelts, rec, recsleft, lastbin;
631  static int32 prev_bin = 0;
632 
633  /*
634  * set up storage needed
635  */
636  loc_extent = (int32 *) calloc(l3_org.numrows, sizeof ( int32));
637  loc_begin = (int32 *) calloc(l3_org.numrows, sizeof ( int32));
638 
639  lastbin = l3_org.start_bin[0] + l3_org.max_bin[0] - 1;
640  /*
641  * set # of records to read = 512
642  */
643  nelts = nrec = 512;
644  /*
645  * Read binno field of vdata 'BinList', 512 bins at a time,
646  * create begin and extent and compare the begin and extent with
647  * the input begin and extent
648  */
649 
650  printf("\n nbins = %d", nbins);
651  for (rec = 0; rec < nbins; rec += 512) {
652  if ((recsleft = nbins - rec) < 512)
653  nelts = nrec = recsleft;
654  start = rec;
655  if ((rdvdata(vd_id, "bin_num", start, nelts,
656  (unsigned char *) binno)) >= 0) {
657  /*
658  * Check the bin #s to see they are in ascending order
659  */
660  if (prev_bin >= binno[0]) {
661  printf("****For Vdata 'BinList', discrepancy in bin numbers\n");
662  printf(" expected bin# greater than %d, but read: %d\n",
663  prev_bin, binno[0]);
664  fmt_status = fmt_status | 2;
665  }
666  /*
667  * Generate begins and extents for the bin numbers read
668  */
669  for (i = 0; i < nrec; i++) {
670  if (i < nrec - 1 && binno[i] > binno[i + 1]) {
671  printf("***For Vdata 'BinList', discrepancy in bin numbers");
672  printf(" expected bin# greater than %d, but read: %d\n",
673  prev_bin, binno[0]);
674  fmt_status = fmt_status | 2;
675  }
676  if (binno[i] > lastbin) { /* next row */
677  loc_extent[row] = rowcount;
678  while (binno[i] > lastbin) {
679  row++;
680  lastbin = l3_org.start_bin[row] + l3_org.max_bin[row] - 1;
681  }
682  rowcount = 1;
683  loc_begin[row] = binno[i];
684  }
685  else { /* add bin to rowcount */
686  rowcount++;
687  }
688  }
689  prev_bin = binno[nrec - 1];
690  }
691  }
692 
693  /* don't forget to count the last [partial] row of bins */
694  loc_extent[row] = rowcount;
695 
696  if (verbose == 1) {
697  printf("\nFor Vdata 'BinIndex', checking begin ");
698  printf("\nFor Vdata 'BinIndex', checking extent \n");
699  }
700  for (i = 0; i < l3_org.numrows; i++) {
701  /*
702  printf("\n[%d]\t%d\t%d", i, loc_begin[i+1], begin[i]);
703  printf("\n[%d]\t%d\t%d", i, loc_extent[i+1], extent[i]);
704  */
705  if (loc_begin[i] != begin[i]) {
706  printf("***** For Vdata 'BinIndex', mismatch in 'begin'\n");
707  printf(" expected: %d for row %d, read: %d\n",
708  loc_begin[i], i, begin[i]);
709  fmt_status = fmt_status | 2;
710  }
711  if (loc_extent[i] != extent[i]) {
712  printf("***** For Vdata 'BinIndex', mismatch in 'extent'\n");
713  printf(" expected: %d for row %d, read: %d\n",
714  loc_extent[i], i, extent[i]);
715  fmt_status = fmt_status | 2;
716  }
717  }
718  free(loc_extent);
719  free(loc_begin);
720 }
721 
722 void chk_l3_prod(int32 vd_id, int32 nbins, char *name, char *field_list)
723 /*******************************************************************
724 
725  ck_v_l3_v2p6
726 
727  purpose: Check the SEAGrid Vdata in Vgroup 'Level-3 Binned Data'
728  to make sure its constant values are correct
729 
730  Returns type: none
731 
732  Parameters: (in calling order)
733  Type Name I/O Description
734  ---- ---- --- -----------
735  int32 vd_id I ID of the Vdata
736  int32 nbins I # of bins
737  char * name I name of Vdata
738  char * field_list I field list in Vdata
739 
740  Modification history:
741  Programmer Date Description of change
742  ---------- ---- ---------------------
743  W. Robinson 25-Apr-1995 Original development
744  W. Robinson, SAIC 5 Apr 2005 adapt to check any product
745 
746  *******************************************************************/ {
747  int32 n_vd_rec, i;
748  float32 *p_data;
749  float32 sum, sum_sq;
750 
751  /*
752  * make space for the sum and sum ^2 (such as they are)
753  */
754  p_data = (float32 *) malloc(2 * nbins * sizeof ( float32));
755 
756  /*
757  * set to read the sum and sum sq as INTERLACED
758  */
759  if (VSsetfields(vd_id, field_list) == -1) {
760  printf(
761  "*************** Program Error: For Vdata: '%s',\nCannot do VSsetfields\n",
762  name);
763  return;
764  }
765 
766  if (VSseek(vd_id, 0) == -1) {
767  printf(
768  "*************** Program Error: For Vdata: '%s',\nCannot do VSseek\n",
769  name);
770  }
771  if ((n_vd_rec = VSread(vd_id, (uint8 *) p_data, nbins, FULL_INTERLACE))
772  != nbins) {
773  printf(
774  "**** For Vdata: '%s', data read failed to read the %d record \n"
775  " with return: %d\n", name, nbins, n_vd_rec);
776  } else {
777  /*
778  * get the mean of both ~sum and ~sum_sq
779  */
780  sum = 0;
781  sum_sq = 0;
782  for (i = 0; i < nbins; i++) {
783  /* this debug printout is voluminous
784  printf( "i: %d, ~sum: %f, ~sum_sq: %f\n", i,
785  *( p_data + 2 * i ), *( p_data + 2 * i + 1 ) );
786  */
787  sum += *(p_data + 2 * i);
788  sum_sq += *(p_data + 2 * i + 1);
789  }
790  sum = sum / nbins;
791  sum_sq = sum_sq / nbins;
792 
793  if (verbose == 1)
794  printf("For Vdata: '%s', mean of sum: %f, sum_sq: %f\n",
795  name, sum, sum_sq);
796  }
797 
798  free(p_data);
799 }
800 
801 
int j
Definition: decode_rs.h:73
void chk_sea_grid(int32 vd_id)
Definition: ck_v_l3.c:325
int status
Definition: l1_czcs_hdf.c:32
void chk_bin_index(int32 vd_id, int32 *begin, int32 *extent)
Definition: ck_v_l3.c:468
int verbose
Definition: fmt_check.c:6
void chk_l3_prod(int32 vd_id, int32 nbins, char *name, char *field_list)
Definition: ck_v_l3.c:722
void chk_bin_list(int32 vd_id, int32 nbins, int32 *begin, int32 *extent)
Definition: ck_v_l3.c:602
int rdvdata(int32_t vskey, const char *fields, int32_t start, int32_t nelt, unsigned char *databuf)
int fmt_status
Definition: fmt_check.c:7
const char * str
Definition: l1c_msi.cpp:35
int32 group_fnd(int32 file_id, int32 vgroup_ref, int32 nbins, int32 n_vgroup, vg_info_str *vd_check)
Definition: ck_v_l3.c:92
#define fabs(a)
Definition: misc.h:93
void l3_get_org(int, l3_org_str *)
Definition: l3_get_org.c:9
void ck_v_l3(int32 file_id, fmt_str *fmt)
Definition: ck_v_l3.c:9
void radius(double A)
Definition: proj_report.c:132
int i
Definition: decode_rs.h:71