OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rdatreminfo.c
Go to the documentation of this file.
1 /* ========================================================== */
2 /* rdatreminfo() - reads parameters from ATREM sensor files */
3 /* */
4 /* Inputs: */
5 /* sensorID - sensor ID as defined in l12_parms.h */
6 /* pname - parameter name from sensor table */
7 /* */
8 /* Outputs: */
9 /* pval - pointer to scalar or array containing param */
10 /* */
11 /* Written By: */
12 /* R. Healy, March 2015 */
13 /* Based on rdsensorinfo.c */
14 /* */
15 /* ========================================================== */
16 
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <ctype.h>
21 #include "sensorInfo.h"
22 #include "genutils.h"
23 
24 // this is really defined in l2gen/l12_params.h
25 // but I need it here also.
26 #define NEWSENSINFO 32 /* use test sensor info file */
27 void parseline(char *line, char *name, char *value);
28 
38 int32_t rdatreminfo(int32_t sensorID, int32_t evalmask, const char *pname, void **pval) {
39  FILE *fp;
40  char *filedir;
41  char filename[FILENAME_MAX];
42  char line[80];
43  char name[80];
44  char value[80];
45  char param[80];
46  char *p;
47  int i;
48  int status;
49 
50  static int32_t sensorID_s = -999;
51  static int32_t nbands = 0;
52 
53  static float *fwhm, *fwave;
54  static int32_t h2o, co2, co, ch4, no2, n2o, o3, o2;
55  static float vrto3, sno2;
56  static float window1, window2, window3, window4, wp94c, w1p14c;
57  static int32_t nb1, nb2, nb3, nb4, nbp94, nb1p14, full_calc, dogeom;
58 
59  want_verbose = 0;
60  if (sensorID != sensorID_s) {
61 
62  if (want_verbose)
63  printf("\nLoading atrem (atmospheric removal - water vapor,etc.) information for %s\n",
65 
66  /* */
67  /* Locate atmocor datafile using environment variable */
68  /* */
69  if ((filedir = getenv("OCDATAROOT")) == NULL) {
70  printf("-E- %s: OCDATAROOT env variable undefined.\n", __FILE__);
71  return (-1);
72  }
73 
74  strcpy(filename, filedir);
75  if ((evalmask & NEWSENSINFO) != 0)
76  strcat(filename, "/eval/");
77  else
78  strcat(filename, "/");
80 
81  strcat(filename, "/msl12_atrem_info.dat");
82 
83  if (want_verbose)
84  printf("Opening atrem information file %s\n Looking for %s\n", filename, pname);
85 
86  if ((fp = fopen(filename, "r")) == NULL) {
87  fprintf(stderr, "-E- %s line %d: unable to open %s for reading\n",
88  __FILE__, __LINE__, filename);
89  return (-1);
90  }
91 
92  // read file to determine number of bands
93 
94  while (fgets(line, 80, fp)) {
95 
96  memset(name, '\0', sizeof (name));
97  memset(value, '\0', sizeof (value));
98 
99  // skip comment lines, empty lines, and lines without a name = value pair.
100 
101  if (line[0] == '#' || line[0] == '\n')
102  continue;
103  if (!(p = strchr(line, '=')))
104  continue;
105 
106  // parse parameter name and value, looking for Nbands
107 
109 
110  if (strcmp(name, "Nbands") == 0) {
111  nbands = (int32_t) atoi(value);
112  break;
113  }
114  }
115 
116  if (nbands <= 0) {
117  printf("-E- %s: error find Nbands in %s.\n", __FILE__, filename);
118  return (-1);
119  }
120 
121  // allocate space for static data
122 
123  status = 0;
124  if ((fwhm = (float*) calloc(nbands, sizeof (float))) == NULL)
125  status = 1;
126  if ((fwave = (float*) calloc(nbands, sizeof (float))) == NULL)
127  status = 1;
128  if (status == 1) {
129  printf(
130  "-E- %s: error allocating space for %d bands in sensor info.\n",
131  __FILE__, nbands);
132  return (-1);
133  }
134 
135 
136  // Loop through each line of file looking for identifiers
137 
138  while (fgets(line, 80, fp)) {
139 
140  memset(name, '\0', sizeof (name));
141  memset(value, '\0', sizeof (value));
142 
143  // skip comment lines, empty lines, and lines without a name = value pair.
144 
145  if (line[0] == '#' || line[0] == '\n')
146  continue;
147  if (!(p = strchr(line, '=')))
148  continue;
149 
150  // parse parameter name and value
151 
153 
154  // Copy value to appropriate variable
155 
156  if (strcmp(name, "Nbands") == 0)
157  nbands = (int32_t) atoi(value);
158  else if (strcmp(name, "h2o") == 0)
159  h2o = (int32_t) atoi(value);
160  else if (strcmp(name, "o2") == 0)
161  o2 = (int32_t) atoi(value);
162  else if (strcmp(name, "o3") == 0)
163  o3 = (int32_t) atoi(value);
164  else if (strcmp(name, "ch4") == 0)
165  ch4 = (int32_t) atoi(value);
166  else if (strcmp(name, "co") == 0)
167  co = (int32_t) atoi(value);
168  else if (strcmp(name, "n2o") == 0)
169  n2o = (int32_t) atoi(value);
170  else if (strcmp(name, "no2") == 0)
171  no2 = (int32_t) atoi(value);
172  else if (strcmp(name, "co2") == 0)
173  co2 = (int32_t) atoi(value);
174  else if (strcmp(name, "vrto3") == 0)
175  vrto3 = (float) atof(value);
176  else if (strcmp(name, "sno2") == 0)
177  sno2 = (float) atof(value);
178  else if (strcmp(name, "window1") == 0)
179  window1 = (float) atof(value);
180  else if (strcmp(name, "window2") == 0)
181  window2 = (float) atof(value);
182  else if (strcmp(name, "window3") == 0)
183  window3 = (float) atof(value);
184  else if (strcmp(name, "window4") == 0)
185  window4 = (float) atof(value);
186  else if (strcmp(name, "w1p14c") == 0)
187  w1p14c = (float) atof(value);
188  else if (strcmp(name, "wp94c") == 0)
189  wp94c = (float) atof(value);
190  else if (strcmp(name, "nb1") == 0)
191  nb1 = (int32_t) atoi(value);
192  else if (strcmp(name, "nb2") == 0)
193  nb2 = (int32_t) atoi(value);
194  else if (strcmp(name, "nb3") == 0)
195  nb3 = (int32_t) atoi(value);
196  else if (strcmp(name, "nb4") == 0)
197  nb4 = (int32_t) atoi(value);
198  else if (strcmp(name, "nbp94") == 0)
199  nbp94 = (int32_t) atoi(value);
200  else if (strcmp(name, "nb1p14") == 0)
201  nb1p14 = (int32_t) atoi(value);
202  else if (strcmp(name, "full_calc") == 0)
203  full_calc = (int32_t) atoi(value);
204  else if (strcmp(name, "dogeom") == 0)
205  dogeom = (int32_t) atoi(value);
206  else {
207  for (i = 0; i < nbands; i++) {
208  sprintf(param, "fwhm(%d)", i + 1);
209  if (strcmp(name, param) == 0) {
210  fwhm[i] = (float) atof(value);
211  break;
212  }
213  sprintf(param, "Lambda(%d)", i + 1);
214  if (strcmp(name, param) == 0) {
215  fwave[i] = (float) atof(value);
216  break;
217  }
218 
219  }
220  }
221 
222  }
223 
224 
225  /* */
226  /* Write-out what was read, for informational purposes */
227  /* */
228  if (want_verbose) {
229 
230  printf("window1=%f\n", window1);
231  printf(" %3s %8s\n", "Bnd",
232  "Fwhm");
233  for (i = 0; i < nbands; i++)
234  printf(
235  " %3d %8.3f\n",
236  i, fwhm[i]);
237  printf("\n");
238 
239  printf("\n");
240  } // want_verbose
241  }
242 
243  /* */
244  /* Return a pointer to the requested parameter */
245  /* */
246  if (pval != NULL) {
247  if (strcmp(pname, "Nbands") == 0)
248  *pval = (void *) &nbands;
249  else if (strcmp(pname, "fwhm") == 0)
250  *pval = (void *) fwhm;
251  else if (strcmp(pname, "Lambda") == 0)
252  *pval = (void *) fwave;
253  else if (strcmp(pname, "o2") == 0)
254  *pval = (void *) &o2;
255  else if (strcmp(pname, "o3") == 0)
256  *pval = (void *) &o3;
257  else if (strcmp(pname, "n2o") == 0)
258  *pval = (void *) &n2o;
259  else if (strcmp(pname, "ch4") == 0)
260  *pval = (void *) &ch4;
261  else if (strcmp(pname, "co") == 0)
262  *pval = (void *) &co;
263  else if (strcmp(pname, "no2") == 0)
264  *pval = (void *) &no2;
265  else if (strcmp(pname, "h2o") == 0)
266  *pval = (void *) &h2o;
267  else if (strcmp(pname, "co2") == 0)
268  *pval = (void *) &co2;
269  else if (strcmp(pname, "vrto3") == 0)
270  *pval = (void *) &vrto3;
271  else if (strcmp(pname, "sno2") == 0)
272  *pval = (void *) &sno2;
273  else if (strcmp(pname, "window1") == 0)
274  *pval = (void *) &window1;
275  else if (strcmp(pname, "window2") == 0)
276  *pval = (void *) &window2;
277  else if (strcmp(pname, "window3") == 0)
278  *pval = (void *) &window3;
279  else if (strcmp(pname, "window4") == 0)
280  *pval = (void *) &window4;
281  else if (strcmp(pname, "wp94c") == 0)
282  *pval = (void *) &wp94c;
283  else if (strcmp(pname, "w1p14c") == 0)
284  *pval = (void *) &w1p14c;
285  else if (strcmp(pname, "nb1") == 0)
286  *pval = (void *) &nb1;
287  else if (strcmp(pname, "nb2") == 0)
288  *pval = (void *) &nb2;
289  else if (strcmp(pname, "nb3") == 0)
290  *pval = (void *) &nb3;
291  else if (strcmp(pname, "nb4") == 0)
292  *pval = (void *) &nb4;
293  else if (strcmp(pname, "nbp94") == 0)
294  *pval = (void *) &nbp94;
295  else if (strcmp(pname, "nb1p14") == 0)
296  *pval = (void *) &nb1p14;
297  else if (strcmp(pname, "full_calc") == 0)
298  *pval = (void *) &full_calc;
299  else if (strcmp(pname, "dogeom") == 0)
300  *pval = (void *) &dogeom;
301 
302  else
303  return (-1);
304  }
305 
306  sensorID_s = sensorID;
307 
308  if (pname != NULL)
309  return (nbands);
310 
311  return (0);
312 }
313 
int32 value
Definition: Granule.c:1235
const char * sensorId2SensorDir(int sensorId)
Definition: sensorInfo.c:240
int32_t co
Definition: atrem_corl1.h:118
int32_t full_calc
Definition: atrem_corl1.h:148
int status
Definition: l1_czcs_hdf.c:32
int32_t o3
Definition: atrem_corl1.h:118
int32_t co2
Definition: atrem_corl1.h:118
#define NULL
Definition: decode_rs.h:63
float sno2
Definition: atrem_corl1.h:133
int32_t rdatreminfo(int32_t sensorID, int32_t evalmask, const char *pname, void **pval)
Definition: rdatreminfo.c:38
int32_t nb4
Definition: atrem_cor.h:98
int32_t nbp94
Definition: atrem_cor.h:98
float fwhm[NBANDS]
Definition: atrem_corl1.h:144
float vrto3
Definition: atrem_corl1.h:133
void parseline(char *line, char *name, char *value)
Definition: rdsensorinfo.c:32
int32_t h2o
Definition: atrem_corl1.h:118
int32_t no2
Definition: atrem_corl1.h:118
int32_t nb1
Definition: atrem_cor.h:98
int32_t nb2
Definition: atrem_cor.h:98
float w1p14c
Definition: atrem_corl1.h:153
int want_verbose
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
int32_t o2
Definition: atrem_corl1.h:118
float wp94c
Definition: atrem_corl1.h:153
#define NEWSENSINFO
Definition: rdatreminfo.c:26
int32_t nbands
const char * sensorId2SensorName(int sensorId)
Definition: sensorInfo.c:198
int32_t ch4
Definition: atrem_corl1.h:118
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")
int32_t sensorID[MAXNFILES]
Definition: l2bin.cpp:97
int32_t nb1p14
Definition: atrem_cor.h:98
int32_t nb3
Definition: atrem_cor.h:98
float p[MODELMAX]
Definition: atrem_corl1.h:131
int32_t n2o
Definition: atrem_corl1.h:118