OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
fmt_read.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_read(char *file, fmt_str *fmt)
8 /*******************************************************************
9 
10  fmt_read
11 
12  purpose: read in the format description for a dataset
13  from a file
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  fmt_str * fmt O format structure
23 
24  Modification history:
25  Programmer Date Description of change
26  ---------- ---- ---------------------
27  W. Robinson 21-Feb-1995 Original development
28  W. Robinson 13-Mar-1995 adapt to use the s_parse routine
29  W. Robinson 8-May-1995 take fmt files from $SWFTBL/fmt_check
30  W. Robinson 7-Jun-1995 add code to handle UINT8 - unsigned
31  8-bit bytes
32  W. Robinson 30-Jun-1995 set fmt_status if problems
33  W. Robinson 26-Sep-1996 add logic for new attribute read
34  flag of 2: read in the minimum and
35  maximum. Also, read in min, max
36  range for sds range checking
37  W. Robinson 31-Oct-1996 upgrade to handle float64 data
38  W. Robinson 18-Feb-1997 changed call to var_decode
39  W. Robinson, SAIC 29 Mar 2005 update to fully table driven model
40  and call I/O for sections from here
41 
42  *******************************************************************/
43  {
44  FILE *fid;
45  char line[500], *str;
46  int ival, isec;
47  char *sec_ids[] = {"**ATTR", "**ARR_DIM", "**SDS", "**RASTER", "**VGROUP"};
48 
49  enum sec_code {
50  SEC_CODE_ATTR, SEC_CODE_ARR_DIM, SEC_CODE_SDS,
51  SEC_CODE_RASTER, SEC_CODE_VGROUP
52  };
53  int nsec = 5; /* # of sections in fmt table and identifiers (above) */
54 
55  /*
56  * Open the file
57  */
58  if ((fid = fopen(file, "r")) == NULL) {
59  printf("**************Program error\n");
60  printf("unable to open format file:\n'%s'\n", file);
61  fmt_status = fmt_status | 1;
62  return -1;
63  }
64 
65  /*
66  * process each section description, each must be there in order
67  */
68  for (isec = 0; isec < nsec; isec++) {
69  if (get_line(line, 500, fid, '#') == (char *) NULL) {
70  printf("**************Format table read error\n");
71  printf("table: %s\n", file);
72  printf("for section # %d, name: %s\n", isec, sec_ids[isec]);
73  printf("unable to read section description line\n");
74  fmt_status = fmt_status | 1;
75  return -1;
76  }
77  /*
78  * extract the section keyword and # following entries
79  */
80  if ((str = s_parse(line, '\"')) == NULL) {
81  printf("**************Format table read error\n");
82  printf("table: %s\n", file);
83  printf("for section # %d, name: %s\n", isec, sec_ids[isec]);
84  printf("unable to find section keyword\n");
85  fmt_status = fmt_status | 1;
86  return -1;
87  }
88  if (strcmp(str, sec_ids[isec]) != 0) {
89  printf("**************Format table read error\n");
90  printf("table: %s\n", file);
91  printf("for section # %d, name: %s\n", isec, sec_ids[isec]);
92  printf("improper section name: %s, found\n", str);
93  fmt_status = fmt_status | 1;
94  return -1;
95  }
96  if ((str = s_parse(NULL, '\"')) == NULL) {
97  printf("**************Format table read error\n");
98  printf("table: %s\n", file);
99  printf("for section # %d, name: %s\n", isec, sec_ids[isec]);
100  printf("no # of section descriptions found\n");
101  fmt_status = fmt_status | 1;
102  return -1;
103  }
104  if (sscanf(str, "%d", &ival) == EOF) {
105  printf("**************Format table read error\n");
106  printf("table: %s\n", file);
107  printf("for section # %d, name: %s\n", isec, sec_ids[isec]);
108  printf("could not read # description lines\n");
109  fmt_status = fmt_status | 1;
110  return -1;
111  }
112  /*
113  * for each section, call a reader
114  */
115  switch (isec) {
116  case SEC_CODE_ATTR:
117  printf("%s - fmt_rd call for %s\n", __FILE__, sec_ids[isec]);
118  fmt->n_attr = ival;
119  if (fmt_rd_attr(file, fid, fmt) != 0) return -1;
120  break;
121 
122  case SEC_CODE_ARR_DIM:
123  printf("%s - fmt_rd call for %s\n", __FILE__, sec_ids[isec]);
124  fmt->n_dim_defs = ival;
125  if (fmt_rd_dim(file, fid, fmt) != 0) return -1;
126  break;
127 
128  case SEC_CODE_SDS:
129  printf("%s - fmt_rd call for %s\n", __FILE__, sec_ids[isec]);
130  fmt->n_sds = ival;
131  if (fmt_rd_sds(file, fid, fmt) != 0) return -1;
132  break;
133 
134  case SEC_CODE_RASTER:
135  printf("%s - fmt_rd call for %s\n", __FILE__, sec_ids[isec]);
136  fmt->n_raster = ival;
137  if (fmt_rd_ras(file, fid, fmt) != 0) return -1;
138  break;
139 
140  case SEC_CODE_VGROUP:
141  printf("%s - fmt_rd call for %s\n", __FILE__, sec_ids[isec]);
142  fmt->n_vgroup = ival;
143  if (ival > 0)
144  if (fmt_rd_l3vg(file, fid, fmt) != 0) return -1;
145  break;
146 
147  default:
148  printf("************** Program error\n");
149  printf("%s - This shouldn't happen, isec = %d\n", __FILE__, isec);
150  fmt_status = fmt_status | 1;
151  return -1;
152  break;
153  }
154  }
155  /*
156  * some verification: array dimension section info
157  */
158  /*
159  printf( "list of the array dimension descriptors, # = %d\n",
160  fmt->n_dim_defs );
161  printf( "'attribute name' 'short name'\n" );
162  for( i = 0; i < fmt->n_dim_defs; i++ )
163  {
164  printf( "%s %s\n", fmt->dim_id[i].att_nm, fmt->dim_id[i].att_short );
165  }
166  */
167  /*
168  * SDS description section info
169  */
170  /*
171  printf( "\n\nList of SDS section info, # entries: %d\n", fmt->n_sds );
172  printf( "SDS name type # attr rank dim 1 code, size dim 2 dim 3 flg_rng\n" );
173  for( i = 0; i < fmt->n_sds; i++ )
174  {
175  printf( "%s %d %d %d %d %d %d %d\n",
176  fmt->sds_info[i].name, fmt->sds_info[i].type, fmt->sds_info[i].n_attr,
177  fmt->sds_info[i].rank, fmt->sds_info[i].e_ranges[0],
178  fmt->sds_info[i].e_ranges[1], fmt->sds_info[i].e_ranges[2],
179  fmt->sds_info[i].flg_rng );
180  }
181  */
182 
183  fclose(fid);
184  return 0;
185 }
char * get_line(char *, int, FILE *, int)
Definition: get_line.c:4
int fmt_rd_ras(char *, FILE *, fmt_str *)
Definition: fmt_rd_ras.c:7
#define NULL
Definition: decode_rs.h:63
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_rd_dim(char *, FILE *, fmt_str *)
Definition: fmt_rd_dim.c:7
int fmt_read(char *file, fmt_str *fmt)
Definition: fmt_read.c:7
int fmt_rd_l3vg(char *, FILE *, fmt_str *)
Definition: fmt_rd_l3vg.c:7
int fmt_rd_attr(char *, FILE *, fmt_str *)
Definition: fmt_rd_attr.c:10
int fmt_rd_sds(char *, FILE *, fmt_str *)
Definition: fmt_rd_sds.c:7
const char * str
Definition: l1c_msi.cpp:35
int fmt_status
Definition: fmt_check.c:7