NASA Logo
Ocean Color Science Software

ocssw V2022
sensorInfo.c
Go to the documentation of this file.
1 #include <sensorInfo.h>
2 
3 #include <stddef.h>
4 #include <string.h>
5 #include <stdlib.h>
6 
7 #include <genutils.h>
8 
9 // sensor name indexed by sensorId
10 static const char* sensorName[] = {
11  "SeaWiFS", // 0
12  "MOS", // 1
13  "OCTS", // 2
14  "AVHRR", // 3
15  "OSMI", // 4
16  "CZCS", // 5
17  "MODIST", // 6
18  "MODISA", // 7
19  "OCM1", // 8
20  "OCM2", // 9
21  "MERIS", // 10
22  "VIIRSN", // 11
23  "OCRVC", // 12
24  "HICO", // 13
25  "GOCI", // 14
26  "OLIL8", // 15
27  "Aquarius", // 16
28  "OCIA", // 17
29  "AVIRIS", // 18
30  "PRISM", // 19
31  "OLCIS3A", // 20
32  "SGLI", // 21
33  "MSIS2A", // 22
34  "L5TM", // 23
35  "L7ETMP", // 24
36  "VIIRSJ1", // 25
37  "MSIS2B", // 26
38  "HAWKEYE", // 27
39  "MISR", // 28
40  "OLCIS3B", // 29
41  "OCI", // 30
42  "OCIS", // 31
43  "VIIRSJ2", // 32
44  "OLIL9", // 33
45  "SPEXONE", // 34
46  "HARP2", // 35
47  "HARP" // 36
48 };
49 
50 // instrument name indexed by sensorId
51 static const char *instrumentName[] = {
52  "SeaWiFS", // 0
53  "MOS", // 1
54  "OCTS", // 2
55  "AVHRR", // 3
56  "OSMI", // 4
57  "CZCS", // 5
58  "MODIS", // 6
59  "MODIS", // 7
60  "OCM", // 8
61  "OCM-2", // 9
62  "MERIS", // 10
63  "VIIRS", // 11
64  "OCRVC", // 12
65  "HICO", // 13
66  "GOCI", // 14
67  "OLI", // 15
68  "Aquarius", // 16
69  "OCIA", // 17
70  "AVIRIS", // 18
71  "PRISM", // 19
72  "OLCI", // 20
73  "SGLI", // 21
74  "MSI", // 22
75  "L5TM", // 23
76  "L7ETMP", // 24
77  "VIIRS", // 25
78  "MSI", // 26
79  "HAWKEYE", // 27
80  "MISR", // 28
81  "OLCI", // 29
82  "OCI", // 30
83  "OCIS", // 31
84  "VIIRS", // 32
85  "OLI", // 33
86  "SPEXONE", // 34
87  "HARP2", // 35
88  "HARP" // 36
89 };
90 
91 // platform name indexed by sensorId
92 static const char *platformName[] = {
93  "Orbview-2", // 0
94  "IRS-P3", // 1
95  "ADEOS", // 2
96  "AVHRR", // 3
97  "KOMPSAT", // 4
98  "Nimbus-7", // 5
99  "Terra", // 6
100  "Aqua", // 7
101  "IRS-P4", // 8
102  "Oceansat-2", // 9
103  "Envisat", // 10
104  "Suomi-NPP", // 11
105  "OCRVC", // 12
106  "ISS", // 13
107  "COMS", // 14
108  "Landsat-8", // 15
109  "SAC-D", // 16
110  "PACE", // 17
111  "AVIRIS", // 18
112  "PRISM", // 19
113  "Sentinel-3A", // 20
114  "GCOM_C", // 21
115  "Sentinel-2A", // 22
116  "L5TM", // 23
117  "L7ETMP", // 24
118  "JPSS-1", // 25
119  "Sentinel-2B", // 26
120  "Seahawk1", // 27
121  "Terra", // 28
122  "Sentinel-3B", // 29
123  "PACE", // 30
124  "PACE", // 31
125  "JPSS-2", // 32
126  "Landsat-9", // 33
127  "PACE", // 34
128  "PACE", // 35
129  "Air-HARP" // 36
130 };
131 
132 // sensor directory indexed by sensorId
133 static const char *sensorDir[] = {
134  "seawifs", // 0
135  "mos", // 1
136  "octs", // 2
137  "avhrr", // 3
138  "osmi", // 4
139  "czcs", // 5
140  "modis", // 6
141  "modis", // 7
142  "ocm1", // 8
143  "ocm2", // 9
144  "meris", // 10
145  "viirs", // 11
146  "ocrvc", // 12
147  "hico", // 13
148  "goci", // 14
149  "oli", // 15
150  "aquarius", // 16
151  "ocia", // 17
152  "aviris", // 18
153  "prism", // 19
154  "olci", // 20
155  "sgli", // 21
156  "msi", // 22
157  "l5tm", // 23
158  "l7etmp", // 24
159  "viirs", // 25
160  "msi", // 26
161  "hawkeye", // 27
162  "misr", // 28
163  "olci", // 29
164  "oci", // 30
165  "ocis", // 31
166  "viirs", // 32
167  "oli", // 33
168  "spexone", // 34
169  "harp2", // 35
170  "harp" // 36
171 };
172 
173 // subsensor directory indexed by subsensorId
174 static const char *subsensorDir[] = {
175  "gac", // 0
176  "lac", // 1
177  "terra", // 2
178  "aqua", // 3
179  "npp", // 4
180  "j1", // 5
181  "s2a", // 6
182  "s2b", // 7
183  "s3a", // 8
184  "s3b", // 9
185  "j2", // 10
186  "l8", // 11
187  "l9" // 12
188 };
189 
190 // instrument ID indexed by sensorId
191 static const int instrumentId[] = {
192  INSTRUMENT_SEAWIFS, // 0
193  INSTRUMENT_MOS, // 1
194  INSTRUMENT_OCTS, // 2
195  INSTRUMENT_AVHRR, // 3
196  INSTRUMENT_OSMI, // 4
197  INSTRUMENT_CZCS, // 5
198  INSTRUMENT_MODIS, // 6
199  INSTRUMENT_MODIS, // 7
200  INSTRUMENT_OCM, // 8
201  INSTRUMENT_OCM2, // 9
202  INSTRUMENT_MERIS, // 10
203  INSTRUMENT_VIIRS, // 11
204  INSTRUMENT_OCRVC, // 12
205  INSTRUMENT_HICO, // 13
206  INSTRUMENT_GOCI, // 14
207  INSTRUMENT_OLI, // 15
208  INSTRUMENT_AQUARIUS,// 16
209  INSTRUMENT_OCIA, // 17
210  INSTRUMENT_AVIRIS, // 18
211  INSTRUMENT_PRISM, // 19
212  INSTRUMENT_OLCI, // 20
213  INSTRUMENT_SGLI, // 21
214  INSTRUMENT_MSI, // 22
215  INSTRUMENT_L5TM, // 23
216  INSTRUMENT_L7ETMP, // 24
217  INSTRUMENT_VIIRS, // 25
218  INSTRUMENT_MSI, // 26
219  INSTRUMENT_HAWKEYE, // 27
220  INSTRUMENT_MISR, // 28
221  INSTRUMENT_OLCI, // 29
222  INSTRUMENT_OCI, // 30
223  INSTRUMENT_OCIS, // 31
224  INSTRUMENT_VIIRS, // 32
225  INSTRUMENT_OLI, // 33
226  INSTRUMENT_SPEXONE, // 34
227  INSTRUMENT_HARP2, // 35
228  INSTRUMENT_HARP // 36
229 };
230 
231 // instrument name indexed by instrumentId
232 static const char *instrumentNameByInstrumentId[] = {
233  "SeaWiFS", // 0
234  "MOS", // 1
235  "OCTS", // 2
236  "AVHRR", // 3
237  "OSMI", // 4
238  "CZCS", // 5
239  "MODIS", // 6
240  "OCM", // 7
241  "OCM-2", // 8
242  "MERIS", // 9
243  "VIIRS", // 10
244  "OCRVC", // 11
245  "HICO", // 12
246  "GOCI", // 13
247  "OLI", // 14
248  "Aquarius", // 15
249  "OCIA", // 16
250  "AVIRIS", // 17
251  "PRISM", // 18
252  "OLCI", // 19
253  "SGLI", // 20
254  "MSI", // 21
255  "L5TM", // 22
256  "L7ETMP", // 23
257  "HAWKEYE", // 24
258  "MISR", // 25
259  "OCI", // 26
260  "OCIS", // 27
261  "SPEXONE", // 28
262  "HARP2", // 29
263  "HARP" // 30
264 };
265 
266 
273 const char* sensorId2SensorName(int sensorId) {
274  if(sensorId < 0)
275  return NULL;
276  if(sensorId >= SENSOR_NUM)
277  return NULL;
278  return sensorName[sensorId];
279 }
280 
287 const char* sensorId2InstrumentName(int sensorId) {
288  if(sensorId < 0)
289  return NULL;
290  if(sensorId >= SENSOR_NUM)
291  return NULL;
292  return instrumentName[sensorId];
293 }
294 
301 const char* sensorId2PlatformName(int sensorId) {
302  if(sensorId < 0)
303  return NULL;
304  if(sensorId >= SENSOR_NUM)
305  return NULL;
306  return platformName[sensorId];
307 }
308 
315 const char* sensorId2SensorDir(int sensorId) {
316  if(sensorId < 0)
317  return NULL;
318  if(sensorId >= SENSOR_NUM)
319  return NULL;
320  return sensorDir[sensorId];
321 }
322 
329 const char* subsensorId2SubsensorDir(int subsensorId) {
330  if(subsensorId < 0)
331  return NULL;
332  if(subsensorId >= SENSOR_NUM)
333  return NULL;
334  return subsensorDir[subsensorId];
335 }
336 
343 int sensorId2InstrumentId(int sensorId) {
344  if(sensorId < 0)
345  return -1;
346  if(sensorId >= SENSOR_NUM)
347  return -1;
348  return instrumentId[sensorId];
349 }
350 
357 const char* instrumentId2InstrumentName(int instrumentId) {
358  if(instrumentId < 0)
359  return NULL;
360  if(instrumentId >= INSTRUMENT_NUM)
361  return NULL;
362  return instrumentNameByInstrumentId[instrumentId];
363 }
364 
371 int sensorName2SensorId(const char* name) {
372  int i;
373 
374  if(name == NULL)
375  return -1;
376 
377  // convert the number if an int was sent in
378  if (isValidInt(name)) {
379  i = atoi(name);
380  if (i >= 0 && i < SENSOR_NUM) {
381  return i;
382  }
383  }
384 
385  if (strcasecmp(name, "hmodisa") == 0)
386  return MODISA;
387  if (strcasecmp(name, "hmodist") == 0)
388  return MODIST;
389 
390  for (i = 0; i < SENSOR_NUM; i++) {
391  if (strcasecmp(sensorName[i], name) == 0)
392  return i;
393  }
394 
395  return -1;
396 }
397 
405 int instrumentPlatform2SensorId(const char* instrument, const char* platform) {
406  int i;
407 
408  if(instrument == NULL || platform == NULL)
409  return -1;
410 
411  // if multiple platforms, look up the first one
412  char *tmpInstrument = strdup(instrument);
413  char* ptr = strchr(tmpInstrument, ',');
414  if(ptr) *ptr = '\0';
415 
416  char *tmpPlatform = strdup(platform);
417  ptr = strchr(tmpPlatform, ',');
418  if(ptr) *ptr = '\0';
419 
420  for (i = 0; i < SENSOR_NUM; i++) {
421  if (strcasecmp(instrumentName[i], tmpInstrument) == 0)
422  if (strcasecmp(platformName[i], tmpPlatform) == 0) {
423  free(tmpInstrument);
424  free(tmpPlatform);
425  return i;
426  }
427  }
428  free(tmpInstrument);
429  free(tmpPlatform);
430  return -1;
431 }
432 
438 int sensorId2SubsensorId(int sensorId) {
439  switch(sensorId) {
440  case MODIST:
441  return MODIS_TERRA;
442  case MODISA:
443  return MODIS_AQUA;
444  case VIIRSN:
445  return VIIRS_NPP;
446  case VIIRSJ1:
447  return VIIRS_J1;
448  case MSIS2A:
449  return MSI_S2A;
450  case MSIS2B:
451  return MSI_S2B;
452  case OLCIS3A:
453  return OLCI_S3A;
454  case OLCIS3B:
455  return OLCI_S3B;
456  case VIIRSJ2:
457  return VIIRS_J2;
458  case OLIL8:
459  return OLI_L8;
460  case OLIL9:
461  return OLI_L9;
462  default:
463  return -1;
464  }
465 }
466 
473 const char* instrumentPlatform2SensorName(const char* instrument, const char* platform) {
475 }
const char * sensorId2SensorDir(int sensorId)
Definition: sensorInfo.c:315
#define OLCIS3A
Definition: sensorDefs.h:32
#define INSTRUMENT_OLI
Definition: sensorDefs.h:85
#define MODIS_AQUA
Definition: sensorDefs.h:58
int instrumentPlatform2SensorId(const char *instrument, const char *platform)
Definition: sensorInfo.c:405
#define MSI_S2B
Definition: sensorDefs.h:62
#define INSTRUMENT_SPEXONE
Definition: sensorDefs.h:99
#define INSTRUMENT_MOS
Definition: sensorDefs.h:72
#define INSTRUMENT_PRISM
Definition: sensorDefs.h:89
#define INSTRUMENT_VIIRS
Definition: sensorDefs.h:81
#define INSTRUMENT_OCM
Definition: sensorDefs.h:78
#define MSIS2B
Definition: sensorDefs.h:38
#define NULL
Definition: decode_rs.h:63
#define OLIL9
Definition: sensorDefs.h:45
#define INSTRUMENT_MSI
Definition: sensorDefs.h:92
#define VIIRSN
Definition: sensorDefs.h:23
#define INSTRUMENT_OCRVC
Definition: sensorDefs.h:82
#define INSTRUMENT_HARP2
Definition: sensorDefs.h:100
#define MSI_S2A
Definition: sensorDefs.h:61
int isValidInt(const char *str)
Definition: isValidInt.c:9
#define INSTRUMENT_L5TM
Definition: sensorDefs.h:93
int sensorName2SensorId(const char *name)
Definition: sensorInfo.c:371
const char * sensorId2PlatformName(int sensorId)
Definition: sensorInfo.c:301
const char * instrumentId2InstrumentName(int instrumentId)
Definition: sensorInfo.c:357
#define MODIST
Definition: sensorDefs.h:18
#define INSTRUMENT_MERIS
Definition: sensorDefs.h:80
int sensorId2SubsensorId(int sensorId)
Definition: sensorInfo.c:438
#define VIIRS_NPP
Definition: sensorDefs.h:59
#define OLIL8
Definition: sensorDefs.h:27
#define INSTRUMENT_OSMI
Definition: sensorDefs.h:75
#define INSTRUMENT_OCIS
Definition: sensorDefs.h:98
#define INSTRUMENT_SGLI
Definition: sensorDefs.h:91
#define INSTRUMENT_HAWKEYE
Definition: sensorDefs.h:95
#define INSTRUMENT_OCI
Definition: sensorDefs.h:97
#define INSTRUMENT_SEAWIFS
Definition: sensorDefs.h:71
char * strdup(const char *)
#define INSTRUMENT_GOCI
Definition: sensorDefs.h:84
#define INSTRUMENT_HICO
Definition: sensorDefs.h:83
#define INSTRUMENT_AVIRIS
Definition: sensorDefs.h:88
#define OLI_L8
Definition: sensorDefs.h:66
#define INSTRUMENT_L7ETMP
Definition: sensorDefs.h:94
#define INSTRUMENT_OCTS
Definition: sensorDefs.h:73
#define INSTRUMENT_CZCS
Definition: sensorDefs.h:76
#define INSTRUMENT_OCIA
Definition: sensorDefs.h:87
#define OLI_L9
Definition: sensorDefs.h:67
#define INSTRUMENT_MISR
Definition: sensorDefs.h:96
#define VIIRS_J1
Definition: sensorDefs.h:60
#define INSTRUMENT_AVHRR
Definition: sensorDefs.h:74
#define MSIS2A
Definition: sensorDefs.h:34
#define MODIS_TERRA
Definition: sensorDefs.h:57
const char * sensorId2SensorName(int sensorId)
Definition: sensorInfo.c:273
#define INSTRUMENT_MODIS
Definition: sensorDefs.h:77
const char * sensorId2InstrumentName(int sensorId)
Definition: sensorInfo.c:287
#define INSTRUMENT_AQUARIUS
Definition: sensorDefs.h:86
#define VIIRSJ2
Definition: sensorDefs.h:44
const char * subsensorId2SubsensorDir(int subsensorId)
Definition: sensorInfo.c:329
#define OLCIS3B
Definition: sensorDefs.h:41
#define VIIRS_J2
Definition: sensorDefs.h:65
#define INSTRUMENT_OLCI
Definition: sensorDefs.h:90
int i
Definition: decode_rs.h:71
#define SENSOR_NUM
const char * instrumentPlatform2SensorName(const char *instrument, const char *platform)
Definition: sensorInfo.c:473
#define MODISA
Definition: sensorDefs.h:19
#define VIIRSJ1
Definition: sensorDefs.h:37
#define OLCI_S3A
Definition: sensorDefs.h:63
#define INSTRUMENT_HARP
Definition: sensorDefs.h:101
#define INSTRUMENT_OCM2
Definition: sensorDefs.h:79
#define OLCI_S3B
Definition: sensorDefs.h:64
#define INSTRUMENT_NUM
Definition: sensorDefs.h:102
int sensorId2InstrumentId(int sensorId)
Definition: sensorInfo.c:343