OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
fmt_rd_ras.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_ras(char *file, FILE *fid, fmt_str *fmt)
8 /*******************************************************************
9 
10  fmt_rd_ras
11 
12  purpose: read in the raster definition 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, k, ifound;
34 
35  /*
36  * allocate space for theraster definitions
37  */
38  if ((fmt->ras = malloc(fmt->n_raster * sizeof ( ras_str)))
39  == NULL) {
40  printf("**************Program error\n");
41  printf("in: %s, raster definition storage allocation failed\n", __FILE__);
42  fmt_status = fmt_status | 1;
43  return -1;
44  }
45  /*
46  * read in each line of raster definition to the proper place
47  */
48  for (i = 0; i < fmt->n_raster; i++) {
49  if (get_line(line, 500, fid, '#') == NULL) {
50  printf("**************Program error\n");
51  printf("unable to read raster definition # %d of file:\n'%s'\n",
52  i, file);
53  printf("last line read:\n'%s'\n", line);
54  fmt_status = fmt_status | 1;
55  return -1;
56  }
57  strcpy(line_sav, line); /* save original line */
58 
59  /*
60  * raster label name
61  */
62  if ((str = s_parse(line, '\"')) == NULL) {
63  printf("**************Program error\n");
64  printf("unable to read raster label name, line %d, entry #1\n", i);
65  printf("last line read:\n'%s'\n", line_sav);
66  fmt_status = fmt_status | 1;
67  return -1;
68  }
69  strcpy(fmt->ras[i].lbl_ras, str);
70 
71  /*
72  * The next field is the palette label
73  */
74  if ((str = s_parse(NULL, '\"')) == NULL) {
75  printf("**************Program error\n");
76  printf(
77  "unable to read raster palette label, line # %d of file:\n'%s'\n",
78  i, file);
79  printf("last line read:\n'%s'\n", line_sav);
80  fmt_status = fmt_status | 1;
81  return -1;
82  }
83  strcpy(fmt->ras[i].lbl_pal, str);
84 
85  /*
86  * the next 2 fields are the dimensions of the image, they are linked
87  * to the attributes by the short name
88  */
89  if ((str = s_parse(NULL, '\"')) == NULL) {
90  printf("**************Program error\n");
91  printf(
92  "unable to read raster # pixels short name, line # %d of file:\n'%s'\n",
93  i, file);
94  printf("last line read:\n'%s'\n", line_sav);
95  fmt_status = fmt_status | 1;
96  return -1;
97  }
98  ifound = 0;
99  for (k = 0; k < fmt->n_dim_defs; k++) {
100  if (strcmp(str, fmt->dim_id[k].att_short) == 0) {
101  ifound = 1;
102  fmt->ras[i].npix_indx = k;
103  break;
104  }
105  }
106  if (ifound == 0) {
107  printf("**************Program error\n");
108  printf(
109  "No definition of %s was found in the array definition section\n",
110  str);
111  printf("For raster pixel dimension of line %d of file:"
112  "\n'%s'\n", i, file);
113  printf("last line read:\n'%s'\n", line_sav);
114  fmt_status = fmt_status | 1;
115  return -1;
116  }
117 
118  if ((str = s_parse(NULL, '\"')) == NULL) {
119  printf("**************Program error\n");
120  printf(
121  "unable to read raster # lines short name, line # %d of file:\n'%s'\n", i, file);
122  printf("last line read:\n'%s'\n", line_sav);
123  fmt_status = fmt_status | 1;
124  return -1;
125  }
126  ifound = 0;
127  for (k = 0; k < fmt->n_dim_defs; k++) {
128  if (strcmp(str, fmt->dim_id[k].att_short) == 0) {
129  ifound = 1;
130  fmt->ras[i].nlin_indx = k;
131  break;
132  }
133  }
134  if (ifound == 0) {
135  printf("**************Program error\n");
136  printf(
137  "No definition of %s was found in the array definition section\n",
138  str);
139  printf("For raster line dimension of line %d of file:"
140  "\n'%s'\n", i, file);
141  printf("last line read:\n'%s'\n", line_sav);
142  fmt_status = fmt_status | 1;
143  return -1;
144  }
145  }
146  return 0;
147 }
char * get_line(char *, int, FILE *, int)
Definition: get_line.c:4
#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
const char * str
Definition: l1c_msi.cpp:35
int fmt_status
Definition: fmt_check.c:7
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
int fmt_rd_ras(char *file, FILE *fid, fmt_str *fmt)
Definition: fmt_rd_ras.c:7