OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
fmt_rd_attr.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 static char *att_rd_str[] = {"NOREAD", "READ_NOCK", "READ_ONE_VAL",
8  "READ_INCLUSIVE"};
9 
10 int fmt_rd_attr(char *file, FILE *fid, fmt_str *fmt)
11 /*******************************************************************
12 
13  fmt_rd_attr
14 
15  purpose: read in the attribute portion of the format description for
16  a dataset
17 
18  Returns type: int - 0 if all went well,
19 
20  Parameters: (in calling order)
21  Type Name I/O Description
22  ---- ---- --- -----------
23  char * file I file name containing the format
24  table description
25  FILE * fid I format table file handle
26  fmt_str * fmt I/O format structure
27 
28  Modification history:
29  Programmer Date Description of change
30  ---------- ---- ---------------------
31  W. Robinson, SAIC 29 Mar 2005 Original development
32  (a portion of the old fmt_read)
33 
34  *******************************************************************/
35  {
36  char line[500], line_sav[500], str_typ[200], *str;
37  int i, j, k, ifound, ndata, ierr;
38 
39  /*
40  * allocate space for the attribute descriptions
41  */
42  if ((fmt->att = malloc(fmt->n_attr * sizeof ( attr_str))) == NULL) {
43  printf("**************Program error\n");
44  printf("in: %s, attrib allocation failed\n", __FILE__);
45  fmt_status = fmt_status | 1;
46  return -1;
47  }
48  /*
49  * read in each line of attribute description to the proper place
50  */
51  for (i = 0; i < fmt->n_attr; i++) {
52  if (get_line(line, 500, fid, '#') == NULL) {
53  printf("**************Program error\n");
54  printf("unable to read attribute description # %d of file:\n'%s'\n",
55  i, file);
56  printf("last line read:\n'%s'\n", line);
57  fmt_status = fmt_status | 1;
58  return -1;
59  }
60 
61  strcpy(line_sav, line); /* save an in-tact copy of line */
62  fmt->att[i].dim_index = -1;
63 
64  /*
65  * use the s_parse so that any quoted strings get taken together
66  */
67  if ((str = s_parse(line, '\"')) == NULL) {
68  printf("**************Program error\n");
69  printf(
70  "unable to read attr ctl value 1 of description # %d of file:\n'%s'\n",
71  i, file);
72  printf("last line read:\n'%s'\n", line_sav);
73  fmt_status = fmt_status | 1;
74  return -1;
75  }
76  strcpy(fmt->att[i].obj_nm, str);
77 
78  for (j = 0; j < 5; j++) {
79  if ((str = s_parse(NULL, '\"')) == NULL) {
80  printf("**************Program error\n");
81  printf(
82  "unable to read attr ctl value %d of description # %d of file:\n'%s'\n",
83  j + 2, i, file);
84  printf("last line read:\n'%s'\n", line_sav);
85  fmt_status = fmt_status | 1;
86  return -1;
87  }
88  switch (j) {
89  case 0:
90  {
91  strcpy(fmt->att[i].access_nm, str);
92  break;
93  }
94  case 1:
95  {
96  strcpy(fmt->att[i].int_nm, str);
97  break;
98  }
99  case 2:
100  {
101  strcpy(str_typ, str);
102  break;
103  }
104  case 3:
105  {
106  if (sscanf(str, "%d", &(fmt->att[i].count)) == EOF) {
107  printf("**************Program error\n");
108  printf(
109  "unable to decode att ctl value count in desc # %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  break;
116  }
117  case 4:
118  {
119  ifound = 0;
120  for (k = 0; k < 4; k++) {
121  if (strcmp(str, att_rd_str[k]) == 0) {
122  fmt->att[i].read = k;
123  ifound = 1;
124  break;
125  }
126  }
127  if (ifound == 0) {
128  printf("**************Program error\n");
129  printf("Improper read code for the attribute\n");
130  printf("desc # %d of file:\n'%s'\n", i, file);
131  printf("last line read:\n'%s'\n", line_sav);
132  fmt_status = fmt_status | 1;
133  return -1;
134  }
135  break;
136  }
137  }
138  }
139  /*
140  * we are still left with the data to be read. As it can have
141  * multiple formats and variable # values
142  *
143  * set up the # of attribute values that need to be read. This is
144  * the count for read flag!= 2 (a set value for each attribute) and
145  * 2 for read flag = 2 (min and max)
146  */
147  ndata = fmt->att[i].count;
148  if (fmt->att[i].read == ATT_RD_READ_INCLUSIVE) ndata = 2;
149 
150  if (strcmp(str_typ, "DFNT_CHAR") == 0) {
151  fmt->att[i].type = DFNT_CHAR;
152  ndata = 1;
153  } else if (strcmp(str_typ, "DFNT_INT8") == 0) {
154  fmt->att[i].type = DFNT_INT8;
155  } else if (strcmp(str_typ, "DFNT_UINT8") == 0) {
156  fmt->att[i].type = DFNT_UINT8;
157  } else if (strcmp(str_typ, "DFNT_INT16") == 0) {
158  fmt->att[i].type = DFNT_INT16;
159  } else if (strcmp(str_typ, "DFNT_INT32") == 0) {
160  fmt->att[i].type = DFNT_INT32;
161  } else if (strcmp(str_typ, "DFNT_FLOAT32") == 0) {
162  fmt->att[i].type = DFNT_FLOAT32;
163  } else if (strcmp(str_typ, "DFNT_FLOAT64") == 0) {
164  fmt->att[i].type = DFNT_FLOAT64;
165  } else {
166  fmt->att[i].type = -9999; /* unhandled, checked later on in var_decode */
167  }
168  /*
169  * in the case where no read or no check is done, no more arguments
170  * reqquired on a line (ndata can be 0 for these cases)
171  */
172  if ((fmt->att[i].read != ATT_RD_NOREAD) &
173  (fmt->att[i].read != ATT_RD_READ_NOCK)) {
174  for (j = 0; j < ndata; j++) {
175  if ((str = s_parse(NULL, '\"')) == NULL) {
176  printf("**************Program error\n");
177  printf("unable to find data #%d in desc # %d of file:\n'%s'\n",
178  j, i, file);
179  printf("last line read:\n'%s'\n", line_sav);
180  fmt_status = fmt_status | 1;
181  return -1;
182  }
183  if ((ierr = var_decode(str, fmt->att[i].type,
184  (void *) fmt->att[i].data.i32, j, 0)) != 0) {
185  if (ierr == -1) {
186  printf("**************Program error\n");
187  printf(
188  "unable to decode #%d in attribute description # %d of file:\n'%s'\n",
189  j, i, file);
190  printf("last line read:\n'%s'\n", line_sav);
191  fmt_status = fmt_status | 1;
192  return -1;
193  }
194  if (ierr == -2) {
195  printf("**************Program error\n");
196  printf(
197  "Value # %d is out of range in attr descrip # %d of file:\n'%s'\n",
198  j, i, file);
199  printf("last line read:\n'%s'\n", line_sav);
200  fmt_status = fmt_status | 1;
201  return -1;
202  }
203  if (ierr == -3) {
204  printf("**************Program error\n");
205  printf(
206  "data type of: %d is not handled by fmt_read currently\n",
207  fmt->att[i].type);
208  printf(
209  "In attr descrip # %d of file:\n'%s'\n", i, file);
210  fmt_status = fmt_status | 1;
211  return -1;
212  }
213  }
214  }
215  }
216  }
217  return 0;
218 }
int fmt_status
Definition: fmt_check.c:7
char * get_line(char *, int, FILE *, int)
Definition: get_line.c:4
@ ATT_RD_NOREAD
Definition: fmt_check.h:47
int fmt_rd_attr(char *file, FILE *fid, fmt_str *fmt)
Definition: fmt_rd_attr.c:10
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
int var_decode(char *, int32, void *, int32, int32)
Definition: var_decode.c:8
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
@ ATT_RD_READ_NOCK
Definition: fmt_check.h:47
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT16
@ ATT_RD_READ_INCLUSIVE
Definition: fmt_check.h:48
const char * str
Definition: l1c_msi.cpp:35
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