ocssw V2020
fmt_rd_l3vg.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "fmt_check.h"
5 extern int fmt_status; /* format check status, see fmt_check */
6 
7 int fmt_rd_l3vg(char *file, FILE *fid, fmt_str *fmt)
8 /*******************************************************************
9 
10  fmt_rd_l3vg
11 
12  purpose: read in the level 3 Vgroup description section of the format
13  description for a dataset
14 
15  Returns type: int - 0 if all went well,
16 
17  Parameters: (in calling order)
18  Type Name I/O Description
19  ---- ---- --- -----------
20  char * file I file name containing the format
21  table description
22  FILE * fid I format table file handle
23  fmt_str * fmt I/O format structure
24 
25  Modification history:
26  Programmer Date Description of change
27  ---------- ---- ---------------------
28  W. Robinson, SAIC 29 Mar 2005 Original development
29 
30  *******************************************************************/
31  {
32  char line[500], line_sav[500], *str;
33  int i, j, k, ifound, n_tot_vg, nrows;
34  int valid_resolve[5] = {1, 2, 4, 9, 36};
35  int numrows[5] = {17280, 8640, 4320, 2160, 540};
36 
37  /*
38  * allocate space for the Vgroup descriptions
39  */
40  n_tot_vg = fmt->n_vgroup + 3;
41  if ((fmt->vg_info = malloc(n_tot_vg * sizeof ( vg_info_str)))
42  == NULL) {
43  printf("**************Program error\n");
44  printf("in: %s, Vgroup description storage allocation failed\n",
45  __FILE__);
46  fmt_status = fmt_status | 1;
47  return -1;
48  }
49  /*
50  * read the # of bins short name
51  */
52  i = 1;
53  if (get_line(line, 500, fid, '#') == NULL) {
54  printf("**************Program error\n");
55  printf("unable to read Vgroup description # %d of file:\n'%s'\n",
56  i, file);
57  printf("last line read:\n'%s'\n", line);
58  fmt_status = fmt_status | 1;
59  return -1;
60  }
61  strcpy(line_sav, line);
62 
63  if ((str = s_parse(line, '\"')) == NULL) {
64  printf("**************Program error\n");
65  printf(
66  "unable to read Vgroup description, line # %d of file:\n'%s'\n",
67  i, file);
68  printf("last line read:\n'%s'\n", line);
69  fmt_status = fmt_status | 1;
70  return -1;
71  }
72 
73  ifound = 0;
74  for (k = 0; k < fmt->n_dim_defs; k++) {
75  if (strcmp(str, fmt->dim_id[k].att_short) == 0) {
76  ifound = 1;
77  fmt->vg_nbin_indx = k;
78  break;
79  }
80  }
81  if (ifound == 0) {
82  printf("**************Program error\n");
83  printf(
84  "No definition of %s was found in the array definition section\n",
85  str);
86  printf("For Vgroup 'nbins' definition, line %d of file:"
87  "\n'%s'\n", i, file);
88  printf("last line read:\n'%s'\n", line);
89  fmt_status = fmt_status | 1;
90  return -1;
91  }
92 
93  /*
94  * get the resolve and check it is a valid value
95  */
96  if ((str = s_parse(NULL, '\"')) == NULL) {
97  printf("**************Program error\n");
98  printf(
99  "unable to read Vgroup resolve value, line # %d of file:\n'%s'\n",
100  i, file);
101  printf("last line read:\n'%s'\n", line_sav);
102  fmt_status = fmt_status | 1;
103  return -1;
104  }
105 
106  if (sscanf(str, "%d", &(fmt->resolve)) == EOF) {
107  printf("**************Program error\n");
108  printf(
109  "Cannot decode Vgroup resolve value, line # %d of file:\n'%s'\n",
110  i, file);
111  printf("last line read:\n'%s'\n", line_sav);
112  fmt_status = fmt_status | 1;
113  return -1;
114  }
115 
116  ifound = 0;
117  for (i = 0; i < 5; i++) {
118  if (fmt->resolve == valid_resolve[i]) {
119  ifound = 1;
120  nrows = numrows[i];
121  break;
122  }
123  }
124  if (ifound != 1) {
125  printf("**************Program error\n");
126  printf(
127  "Vgroup resolve is not a valid value. It must be\n"
128  "1, 2, 4, 9, or 36\n");
129  printf("last line read:\n'%s'\n", line_sav);
130  fmt_status = fmt_status | 1;
131  return -1;
132  }
133 
134  /*
135  * set up the first 3 Vdatas with standard information
136  */
137  fmt->vg_info[0].n_fields = 7;
138  fmt->vg_info[0].num_typs[0] = DFNT_INT32;
139  fmt->vg_info[0].num_typs[1] = DFNT_INT32;
140  fmt->vg_info[0].num_typs[2] = DFNT_INT32;
141  fmt->vg_info[0].num_typs[3] = DFNT_FLOAT64;
142  fmt->vg_info[0].num_typs[4] = DFNT_FLOAT64;
143  fmt->vg_info[0].num_typs[5] = DFNT_FLOAT64;
144  fmt->vg_info[0].num_typs[6] = DFNT_FLOAT64;
145  fmt->vg_info[0].nrec = 1;
146  strcpy(fmt->vg_info[0].name, "SEAGrid");
147  strcpy(fmt->vg_info[0].class, "Geometry");
148  strcpy(fmt->vg_info[0].field_list,
149  "registration,straddle,bins,radius,max_north,max_south,seam_lon");
150 
151  fmt->vg_info[1].n_fields = 7;
152  fmt->vg_info[1].num_typs[0] = DFNT_INT32;
153  fmt->vg_info[1].num_typs[1] = DFNT_FLOAT64;
154  fmt->vg_info[1].num_typs[2] = DFNT_FLOAT64;
155  fmt->vg_info[1].num_typs[3] = DFNT_INT32;
156  fmt->vg_info[1].num_typs[4] = DFNT_INT32;
157  fmt->vg_info[1].num_typs[5] = DFNT_INT32;
158  fmt->vg_info[1].num_typs[6] = DFNT_INT32;
159  fmt->vg_info[1].nrec = nrows;
160  strcpy(fmt->vg_info[1].name, "BinIndex");
161  strcpy(fmt->vg_info[1].class, "Index");
162  strcpy(fmt->vg_info[1].field_list,
163  "row_num,vsize,hsize,start_num,begin,extent,max");
164 
165  fmt->vg_info[2].n_fields = 7;
166  fmt->vg_info[2].num_typs[0] = DFNT_INT32;
167  fmt->vg_info[2].num_typs[1] = DFNT_INT16;
168  fmt->vg_info[2].num_typs[2] = DFNT_INT16;
169  fmt->vg_info[2].num_typs[3] = DFNT_INT16;
170  fmt->vg_info[2].num_typs[4] = DFNT_FLOAT32;
171  fmt->vg_info[2].num_typs[5] = DFNT_INT8;
172  fmt->vg_info[2].num_typs[6] = DFNT_INT32;
173  fmt->vg_info[2].nrec = -1;
174  strcpy(fmt->vg_info[2].name, "BinList");
175  strcpy(fmt->vg_info[2].class, "DataMain");
176  strcpy(fmt->vg_info[2].field_list,
177  "bin_num,nobs,nscenes,time_rec,weights,sel_cat,flags_set");
178  /*
179  * The following lines are the names of the products in the L3
180  * set up the structures for each of those products
181  */
182  for (i = 0; i < fmt->n_vgroup; i++) {
183  j = i + 3;
184  if (get_line(line, 500, fid, '#') == NULL) {
185  printf("**************Program error\n");
186  printf("unable to read Vgroup product description # %d of file:\n'%s'\n",
187  i, file);
188  printf("last line read:\n'%s'\n", line);
189  fmt_status = fmt_status | 1;
190  return -1;
191  }
192 
193  if ((str = s_parse(line, '\"')) == NULL) {
194  printf("**************Program error\n");
195  printf(
196  "unable to read Vgroup product description, line # %d of file:\n'%s'\n",
197  i, file);
198  printf("last line read:\n'%s'\n", line);
199  fmt_status = fmt_status | 1;
200  return -1;
201  }
202  /*
203  * OK, set up the general and product-specific structure info
204  */
205  fmt->vg_info[j].n_fields = 2;
206  fmt->vg_info[j].num_typs[0] = DFNT_FLOAT32;
207  fmt->vg_info[j].num_typs[1] = DFNT_FLOAT32;
208  fmt->vg_info[j].nrec = -1;
209  strcpy(fmt->vg_info[j].name, str);
210  strcpy(fmt->vg_info[j].class, "DataSubordinate");
211  sprintf(fmt->vg_info[j].field_list, "%s_sum,%s_sum_sq", str, str);
212  }
213  return 0;
214 }
char * get_line(char *, int, FILE *, int)
Definition: get_line.c:4
int j
Definition: decode_rs.h:73
#define NULL
Definition: decode_rs.h:63
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
char * s_parse(char *, int)
Definition: s_parse.c:4
int fmt_status
Definition: fmt_check.c:7
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT16
const char * str
Definition: l1c_msi.cpp:37
int fmt_rd_l3vg(char *file, FILE *fid, fmt_str *fmt)
Definition: fmt_rd_l3vg.c:7
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
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")
int k
Definition: decode_rs.h:73