OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
fmt_check.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "mfhdf.h"
5 #include "fmt_check.h"
6 int verbose; /* switch to write the global attrib info: 0 no, 1 yes */
7 int fmt_status; /* status of format checking: 0 all good, 1 program problem,
8  2 format problem, 3 both problems */
9 
10 int main(int argc, char **argv)
11 /*******************************************************************
12 
13  fmt_check
14 
15  purpose: open the SeaWiFS dataset and check the format
16 
17  Returns type: none
18 
19  Parameters: (in calling order)
20  Type Name I/O Description
21  ---- ---- --- -----------
22  int argc I count of input args
23  char * argv[] I args: [1] hdf file to check
24  [2] table to check against
25  [3] verbose switch - 0 or
26  blank, none, 1 - be more
27  verbose
28 
29  Modification history:
30  Programmer Date Description of change
31  ---------- ---- ---------------------
32  W. Robinson 16-Feb-1995 Original development
33  W. Robinson 9-Mar-1995 update to v2.6
34  1 - Title is now a constant
35  2 - new fields added: Scene Center
36  Solar Zenith, csol_z, entry_year,
37  entry_day
38  W. Robinson 16-Mar-1995 run the checking of all levels
39  and all versions
40  W. Robinson 18-Apr-1995 add the level 2 and 3
41  W. Robinson 30-Jun-1995 add verbose switch to call args
42  W. Robinson 29-Aug-1995 update for added v2.7 formats
43  W. Robinson 20-Nov-1995 update for added v2.8 formats
44  L. Kumar 19-Dec-1995 add nrt met and ozone
45  W. Robinson 21-Oct-1996 update for v3.0 formats
46  W. Robinson 3-Mar-1997 update for v3.1 met format
47  W. Robinson 9-Dec-1999 update for new repro 3 formats
48  W. Robinson 15-Mar-2001 update argv for linux use
49  W. Robinson, SAIC 29 Mar 2005 update to fully table driven model
50  and call I/O for sections from here
51 
52  *******************************************************************/
53  {
54  int i, j, ierr, num, a_count, index;
55  l1info_struct l1info;
56  void fmt_exit(int);
57  char file[400], table[400];
58  fmt_str fmt; /* master format structure */
59  u_data value;
60 
61  fmt_status = 0;
62  /*
63  * Start check the input line arguments
64  */
65  if (argc != 3 && argc != 4) {
66  printf("*** format: fmt_check <file> <table> <verbose>\n");
67  printf(" <file> is the hdf file to check\n");
68  printf(" <table> is the table to use in the format checking\n");
69  printf(" <verbose> is blank or 0 to list attributes 1 to omit\n");
70  fmt_status = 1;
72  }
73  /*
74  * set global to activate attr_disp if 4th arg is 1 (verbose output)
75  */
76  verbose = (argc == 4 && argv[3][0] == '1') ? 0 : 1;
77  strcpy(file, argv[1]);
78  strcpy(table, argv[2]);
79 
80  printf("Format Check of Dataset: '%s'\n", file);
81  printf("with control table: \n '%s'\n\n", table);
82  /*
83  * hopen will open the file and read data descriptor blocks
84  * to memory
85  */
86  if ((l1info.fid = Hopen(file, DFACC_RDONLY, 0)) < 0) {
87  printf("fmt_check: Failed on the Hopen of \n'%s'\n", file);
88  fmt_status = 1;
90  }
91 
92  /*
93  * SDstart opens the hdf interface and inits the SD interface, wierd.
94  * apparently, if both SD and HDF are used, both these need to
95  * be called.
96  */
97  if ((l1info.sdfid = SDstart(file, DFACC_RDONLY)) < 0) {
98  printf("fmt_check: Failure at SDstart of \n'%s'\n", file);
99  l1io_close(l1info);
100  fmt_status = 2;
102  }
103 
104  /*
105  * ok, it's open. Get the format descriptions fromthe table
106  */
107  if (fmt_read(table, &fmt) != 0) {
108  printf("**** Exiting due to failure in control file read\n");
109  printf(" control file: '%s'\n", table);
110  fmt_status = fmt_status | 1;
112  }
113  printf("\n\nChecking Global Attributes...\n\n");
114 
115  for (i = 0; i < fmt.n_attr; i++) {
116  if (strcmp(fmt.att[i].obj_nm, "gbl") == 0) {
117  ierr = get_attr(l1info.sdfid, fmt.att[i], &value, &a_count);
118  if (ierr == 0) {
119  /*
120  * display the attribute
121  */
122  attr_disp(fmt.att[i], value, a_count);
123 
124  /*
125  * also, save the dimension sizes desired
126  */
127  if ((index = fmt.att[i].dim_index) >= 0) {
128  switch (fmt.att[i].type) {
129  case DFNT_FLOAT32:
130  fmt.dim_id[ index ].dim_size = (int) value.f32[0];
131  break;
132  case DFNT_FLOAT64:
133  fmt.dim_id[ index ].dim_size = (int) value.f64[0];
134  break;
135  case DFNT_INT8:
136  fmt.dim_id[ index ].dim_size = (int) value.i8[0];
137  break;
138  case DFNT_UINT8:
139  fmt.dim_id[ index ].dim_size = (int) value.ui8[0];
140  break;
141  case DFNT_INT16:
142  fmt.dim_id[ index ].dim_size = (int) value.i16[0];
143  break;
144  case DFNT_INT32:
145  fmt.dim_id[ index ].dim_size = (int) value.i32[0];
146  break;
147  default:
148  printf(
149  "****Program error, dimension getting reached impossible condition,\n");
150  printf("routine %s\n", __FILE__);
151  fmt_status = fmt_status | 1;
153  break;
154  }
155  }
156  }
157  }
158  }
159  /* temporary, list the dim_id stuff */
160  printf("\n\ndimension structure info:\n");
161  printf("attrib name, short name, dim size, # entries: %d\n", fmt.n_dim_defs);
162  for (i = 0; i < fmt.n_dim_defs; i++) {
163  printf("%s %s %d\n", fmt.dim_id[i].att_nm, fmt.dim_id[i].att_short, fmt.dim_id[i].dim_size);
164  }
165  /*
166  * next, proceed to check the science datasets
167  */
168  printf("\n\nChecking Science datasets...\n\n");
169 
170  /*
171  * loop through the sds's
172  */
173  for (i = 0; i < fmt.n_sds; i++) {
174  /*
175  * Find the indixes of the attributes for this sds
176  */
177  num = 0;
178  for (j = 0; j < fmt.n_attr; j++) {
179  if (strcmp(fmt.att[j].obj_nm, fmt.sds_info[i].name) == 0) {
180  fmt.sds_info[i].attr_ind[ num++ ] = j;
181  }
182  }
183  if (num != fmt.sds_info[i].n_attr) {
184  printf("********************\n");
185  printf("Problem with fmt_check, for SDS: '%s',\n",
186  fmt.sds_info[i].name);
187  printf(" mismatch in # attributes in list and expected #\n");
188  fmt_status = fmt_status | 2;
189  }
190  /*
191  * Do most of the checking of the sds size and its attributes
192  */
193  if ((ierr = chk_sds(l1info.sdfid, &fmt, i)) == 0) {
194  /*
195  * code for checking the ranges that could not be done above
196  */
197  }
198  }
199 
200  /*
201  * check the raster data if requested
202  */
203  if (fmt.n_raster > 0) {
204  printf("\n\nChecking Raster data...\n\n");
205  for (i = 0; i < fmt.n_raster; i++) {
206  hdf_ras_chk(file, fmt.ras[i].lbl_ras, fmt.ras[i].lbl_pal,
207  fmt.dim_id[ fmt.ras[i].npix_indx ].dim_size,
208  fmt.dim_id[ fmt.ras[i].nlin_indx ].dim_size);
209  }
210  }
211 
212  /*
213  * check the L3 Vgroups if needed
214  */
215  if (fmt.n_vgroup > 0) {
216  ck_v_l3(l1info.fid, &fmt);
217  }
218 
219  l1io_close(l1info);
221  return 0;
222 }
223 
224 void fmt_exit(int status)
225 /*******************************************************************
226 
227  fmt_exit
228 
229  purpose: provide a common exit from the fmt_check program and
230  error summary info.
231 
232  Returns type: none
233 
234  Parameters: (in calling order)
235  Type Name I/O Description
236  ---- ---- --- -----------
237  int status I format check status
238 
239  Modification history:
240  Programmer Date Description of change
241  ---------- ---- ---------------------
242  W. Robinson 30-jun-1995 Original development
243 
244  *******************************************************************/ {
245  if (status == 0)
246  printf("\n\nSuccessfull format check, no format errors\n");
247  else {
248  if (status & 1)
249  printf("\n\nFailure of format check due to program error\n");
250  if (status & 2)
251  printf("\n\nFailure of format check due to dataset format error\n");
252  }
253  exit(status);
254 }
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
int32 value
Definition: Granule.c:1235
int j
Definition: decode_rs.h:73
int status
Definition: l1_czcs_hdf.c:32
int fmt_read(char *, fmt_str *)
Definition: fmt_read.c:7
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 table(e.g. m1) to be used for interpolation. The table values will be linearly interpolated using the tables corresponding to the node times bracketing the granule time. If the granule time falls before the time of the first node or after the time of the last node
int hdf_ras_chk(char *, char *, char *, int, int)
Definition: hdf_ras_chk.c:6
int verbose
Definition: fmt_check.c:6
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
Definition: HISTORY.txt:413
int chk_sds(int32 fid, fmt_str *fmt, int isds)
Definition: chk_sds.c:11
int fmt_status
Definition: fmt_check.c:7
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT16
void fmt_exit(int status)
Definition: fmt_check.c:224
void ck_v_l3(int32 file_id, fmt_str *fmt)
Definition: ck_v_l3.c:9
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
void l1io_close(l1info_struct)
Definition: l1io_close.c:4
int get_attr(int32, attr_str, u_data *, int *)
Definition: get_attr.c:10
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
void attr_disp(attr_str attr, u_data value, int a_count)
Definition: attr_disp.c:5
int main(int argc, char **argv)
Definition: fmt_check.c:10