OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
prodlist.c
Go to the documentation of this file.
1 #include "l12_proto.h"
2 
3 int32 prodlist(int32 sensorID, int32 evalmask, const char *inprod, const char *defprod, char outprod[L1_MAXPROD][32]) {
4  static int32 nwave = -1;
5  static int32 nwaveIR = -1;
6  static int32 nwaveVIS = -1;
7  static int32 *wave = NULL;
8 
9  int32 tot_prod;
10  char wavestr[6];
11  char prefix[256];
12  char suffix[256];
13  char *p1, *p2;
14  int32 i, j, k, iw;
15  char *tmp_ptr;
16  char tmp_str[2048];
17 
18  if (wave == NULL) {
19  nwave = rdsensorinfo(sensorID, evalmask, "Lambda", (void **) &wave);
20  nwaveIR = rdsensorinfo(sensorID, evalmask, "NbandsIR", NULL);
21  nwaveVIS = rdsensorinfo(sensorID, evalmask, "NbandsVIS", NULL);
22  }
23 
24  // insert default products if requested or no prods specified
25 
26  if (inprod[0] == '\0') {
27  strcpy(tmp_str, defprod);
28  } else {
29  strcpy(tmp_str, inprod);
30  tmp_ptr = tmp_str;
31  while (*tmp_ptr != '\0') {
32  if (isupper(*tmp_ptr)) *tmp_ptr = tolower(*tmp_ptr);
33  tmp_ptr++;
34  }
35  if ((tmp_ptr = strstr(tmp_str, "default")) != NULL) {
36  i = strlen(tmp_ptr);
37  k = strlen(inprod);
38  strncpy(tmp_str, inprod, k - i);
39  tmp_str[k - i] = '\0';
40  strcat(tmp_str, defprod);
41  strcat(tmp_str, inprod + k - i + 7);
42  } else
43  strcpy(tmp_str, inprod);
44  }
45 
46  // count products and separate into array of strings
47 
48  tot_prod = 0;
49  if (tmp_str[0] != '\0') {
50  i = 0;
51  while (1) {
52  while (tmp_str[i] == ' ' || tmp_str[i] == ',')
53  i++;
54  if (tmp_str[i] == '\0')
55  break;
56  k = i;
57  while (tmp_str[i] != ' ' &&
58  tmp_str[i] != ',' &&
59  tmp_str[i] != '\0')
60  i++;
61 
62  // exclude l2_flags, it will be explicitly added if needed
63  if (strstr(&tmp_str[k], "l2_flags") == &tmp_str[k])
64  continue;
65  strncpy(outprod[tot_prod], &tmp_str[k], i - k);
66  outprod[tot_prod][i - k] = '\0';
67  tot_prod++;
68  if (tmp_str[i] == '\0')
69  break;
70  }
71  }
72  if (tot_prod == 0) {
73  return (tot_prod);
74  }
75 
76  // expand any nnn wavelength placeholders with sensor wavelengths
77  for (i = 0; i < tot_prod; i++) {
78  if ((tmp_ptr = strstr(outprod[i], "_nnn")) != NULL) {
79 
80  // make room
81  for (k = tot_prod - 1; k > i; k--)
82  strcpy(outprod[k + nwave - 1], outprod[k]);
83  tot_prod = tot_prod + nwave - 1;
84 
85  // replace
86  p1 = outprod[i];
87  p2 = tmp_ptr;
88  prefix[0] = '\0';
89  strncpy(prefix, p1, p2 - p1 + 1);
90  prefix[p2 - p1 + 1] = '\0';
91  suffix[0] = '\0';
92  strcpy(suffix, p2 + 4);
93  outprod[i][0] = '\0';
94 
95  for (iw = 0; iw < nwave; iw++) {
96  wavestr[0] = '\0';
97  sprintf(wavestr, "%d", (int) wave[iw]);
98  outprod[i + iw][0] = '\0';
99  strcat(outprod[i + iw], prefix);
100  strcat(outprod[i + iw], wavestr);
101  strcat(outprod[i + iw], suffix);
102  }
103  }
104  }
105 
106  // expand any vvv wavelength placeholders with visible sensor wavelengths
107 
108  for (i = 0; i < tot_prod; i++) {
109  if ((tmp_ptr = strstr(outprod[i], "_vvv")) != NULL) {
110 
111  // make room
112  for (k = tot_prod - 1; k > i; k--)
113  strcpy(outprod[k + nwaveVIS - 1], outprod[k]);
114  tot_prod = tot_prod + nwaveVIS - 1;
115 
116  // replace
117  p1 = outprod[i];
118  p2 = tmp_ptr;
119  prefix[0] = '\0';
120  strncpy(prefix, p1, p2 - p1 + 1);
121  prefix[p2 - p1 + 1] = '\0';
122  suffix[0] = '\0';
123  strcpy(suffix, p2 + 4);
124  outprod[i][0] = '\0';
125 
126  for (iw = 0; iw < nwaveVIS; iw++) {
127  wavestr[0] = '\0';
128  sprintf(wavestr, "%d", (int) wave[iw]);
129  outprod[i + iw][0] = '\0';
130  strcat(outprod[i + iw], prefix);
131  strcat(outprod[i + iw], wavestr);
132  strcat(outprod[i + iw], suffix);
133  }
134  }
135  }
136 
137  // expand any iii wavelength placeholders with IR sensor wavelengths
138  for (i = 0; i < tot_prod; i++) {
139  if ((tmp_ptr = strstr(outprod[i], "_iii")) != NULL) {
140 
141  // make room
142  for (k = tot_prod - 1; k > i; k--)
143  strcpy(outprod[k + nwaveIR - 1], outprod[k]);
144  tot_prod = tot_prod + nwaveIR - 1;
145 
146  // replace
147  p1 = outprod[i];
148  p2 = tmp_ptr;
149  prefix[0] = '\0';
150  strncpy(prefix, p1, p2 - p1 + 1);
151  prefix[p2 - p1 + 1] = '\0';
152  suffix[0] = '\0';
153  strcpy(suffix, p2 + 4);
154  outprod[i][0] = '\0';
155 
156  for (iw = 0; iw < nwaveIR; iw++) {
157  wavestr[0] = '\0';
158  sprintf(wavestr, "%d", (int) wave[iw + nwave]);
159  outprod[i + iw][0] = '\0';
160  strcat(outprod[i + iw], prefix);
161  strcat(outprod[i + iw], wavestr);
162  strcat(outprod[i + iw], suffix);
163  //printf("%d %d %d %s %d\n",iw,iw+nwave,wave[iw+nwave],outprod[i+iw],tot_prod);
164  }
165  }
166  }
167 
168  // get rid of duplicate products from output file
169  for (i = 0; i < tot_prod; i++) {
170  for (j = i + 1; j < tot_prod; j++) {
171  if (strcmp(outprod[i], outprod[j]) == 0) {
172  for (k = j + 1; k < tot_prod; k++) {
173  strcpy(outprod[k - 1], outprod[k]);
174  }
175  tot_prod--;
176  j--;
177  }
178  }
179  }
180 
181  return (tot_prod);
182 }
#define L1_MAXPROD
Definition: filehandle.h:20
int j
Definition: decode_rs.h:73
#define NULL
Definition: decode_rs.h:63
int32 prodlist(int32 sensorID, int32 evalmask, const char *inprod, const char *defprod, char outprod[L1_MAXPROD][32])
Definition: prodlist.c:3
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second and prod_ix set to PARAM_TYPE_INT name_prefix is compared with the beginning of the product name If name_suffix is not empty the it must match the end of the product name The characters right after the prefix are read as an integer and prod_ix is set to that number strncpy(l2prod->name_prefix, "myprod", UNITLEN)
int32_t rdsensorinfo(int32_t, int32_t, const char *, void **)
Definition: rdsensorinfo.c:69
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
int k
Definition: decode_rs.h:73