OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
fmt_rd_dim.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_dim(char *file, FILE *fid, fmt_str *fmt)
8 /*******************************************************************
9 
10  fmt_rd_dim
11 
12  purpose: read in the array dimension portion of the format description for
13  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, ifound;
34 
35  /*
36  * allocate space for the dimension descriptions
37  */
38  if ((fmt->dim_id = malloc(fmt->n_dim_defs * sizeof ( attr_str))) == NULL) {
39  printf("**************Program error\n");
40  printf("in: %s, array definition structure allocation failed\n",
41  __FILE__);
42  fmt_status = fmt_status | 1;
43  return -1;
44  }
45  /*
46  * read in each line of attribute description to the proper place
47  */
48  for (i = 0; i < fmt->n_dim_defs; i++) {
49  if (get_line(line, 500, fid, '#') == NULL) {
50  printf("**************Program error\n");
51  printf(
52  "unable to read array dimension description # %d of file:\n'%s'\n",
53  i, file);
54  printf("last line read:\n'%s'\n", line);
55  fmt_status = fmt_status | 1;
56  return -1;
57  }
58 
59  strcpy(line_sav, line); /* keep an in-tact copy of the line */
60 
61  /*
62  * use the s_parse so that any quoted strings get taken together
63  * 1st, the attrib name, then, the short name
64  */
65  if ((str = s_parse(line, '\"')) == NULL) {
66  printf("**************Program error\n");
67  printf("Unable to get <attribute name> (col 1) portion of dimension "
68  "description\n");
69  printf("line %d, fmt table: %s\n", i, file);
70  printf("last line read:\n'%s'\n", line_sav);
71  fmt_status = fmt_status | 1;
72  return -1;
73  }
74  strcpy(fmt->dim_id[i].att_nm, str);
75 
76  if ((str = s_parse(NULL, '\"')) == NULL) {
77  printf("**************Program error\n");
78  printf("Unable to get <short name> (col 2) portion of dimension "
79  "description\n");
80  printf("line %d, fmt table: %s\n", i, file);
81  printf("last line read:\n'%s'\n", line_sav);
82  fmt_status = fmt_status | 1;
83  return -1;
84  }
85  strcpy(fmt->dim_id[i].att_short, str);
86 
87  /*
88  * make sure the attribute name is one of the global attributes
89  */
90  ifound = 0;
91  for (j = 0; j < fmt->n_attr; j++) {
92  if (strcmp(fmt->att[j].obj_nm, "gbl") == 0) {
93  if (strcmp(fmt->att[j].int_nm, fmt->dim_id[i].att_nm) == 0) {
94  ifound = 1;
95  /*
96  * set the dim_index in the sttr struct to the location in here
97  */
98  fmt->att[j].dim_index = i;
99  /*
100  * also make sure the attrib is not char, read in and a single
101  * value
102  */
103  if (fmt->att[j].type == DFNT_CHAR) {
104  printf("**************Program error\n");
105  printf("dimension descriptor long name: '%s'\n",
106  fmt->dim_id[i].att_nm);
107  printf("cannot be a char type\n");
108  printf("line %d, fmt table: %s\n", i, file);
109  printf("last line read:\n'%s'\n", line_sav);
110  fmt_status = fmt_status | 1;
111  return -1;
112  }
113  if (fmt->att[j].read == ATT_RD_NOREAD) {
114  printf("**************Program error\n");
115  printf("dimension descriptor long name: '%s'\n",
116  fmt->dim_id[i].att_nm);
117  printf("must be read in in attribute section\n");
118  printf("(cannot have read keyword of NOREAD)\n");
119  printf("line %d, fmt table: %s\n", i, file);
120  printf("last line read:\n'%s'\n", line_sav);
121  fmt_status = fmt_status | 1;
122  return -1;
123  }
124  if (fmt->att[j].count != 1) {
125  printf("**************Program error\n");
126  printf("dimension descriptor long name: '%s'\n",
127  fmt->dim_id[i].att_nm);
128  printf("must be for attribute with a single value\n");
129  printf("(number of values must be 1)\n");
130  printf("line %d, fmt table: %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  if (ifound != 1) {
140  printf("**************Program error\n");
141  printf("No attribute named: '%s' was found\n", fmt->dim_id[i].att_nm);
142  printf("in the global attributes, from line %d, file %s\n", i, file);
143  printf("last line read:\n'%s'\n", line_sav);
144  fmt_status = fmt_status | 1;
145  return -1;
146  }
147  /*
148  * fill in the dimension length with -1 to show it is unfilled as of yet
149  */
150  fmt->dim_id[i].dim_size = -1;
151  }
152  return 0;
153 }
char * get_line(char *, int, FILE *, int)
Definition: get_line.c:4
@ ATT_RD_NOREAD
Definition: fmt_check.h:47
int j
Definition: decode_rs.h:73
#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, FILE *fid, fmt_str *fmt)
Definition: fmt_rd_dim.c:7
int fmt_status
Definition: fmt_check.c:7
const char * str
Definition: l1c_msi.cpp:35
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")