OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
windex.c
Go to the documentation of this file.
1 #include "l1.h"
2 
3 #include <math.h>
4 
5 #define WAVE_INDEX_NUM 13000
6 #define WAVE_INDEX_MIN 300
7 #define WAVE_INDEX_MAX (WAVE_INDEX_MIN + WAVE_INDEX_NUM)
8 
9 static int band_index[WAVE_INDEX_NUM + 1];
10 
11 /* ---------------------------------------------------------------------------------------- */
12 /* windex_set() - load direct access wavelength index */
13 
14 /* ---------------------------------------------------------------------------------------- */
15 void bindex_set(int32_t wave[], int nwave, int dwave_vswir) {
16  int iw, iw1, iw2, i;
17  int dwave;
18 
19  for (i = 0; i < WAVE_INDEX_NUM; i++) {
20  band_index[i] = -1;
21  }
22 
23  for (iw = 0; iw < nwave; iw++) {
24  if (wave[iw] > 3000)
25  dwave = 1000;
26  else
27  dwave = dwave_vswir;
28  iw1 = MAX(wave[iw] - dwave / 2, WAVE_INDEX_MIN) - WAVE_INDEX_MIN;
29  iw2 = MIN(wave[iw] + dwave / 2, WAVE_INDEX_MAX) - WAVE_INDEX_MIN;
30  if (band_index[iw1] != -1) {
31  /* adjust for overlapping band-passes */
32  iw1 = MAX(wave[iw]-(wave[iw] - wave[iw - 1]) / 2, WAVE_INDEX_MIN) - WAVE_INDEX_MIN;
33  }
34  for (i = iw1; i <= iw2; i++) {
35  band_index[i] = iw; // eliminated bindx
36  }
37  }
38 }
39 
40 
41 /* ---------------------------------------------------------------------------------------- */
42 /* bindex_get() - retrieve direct access wavelength index */
43 
44 /* ---------------------------------------------------------------------------------------- */
45 int bindex_get(int32_t wave) {
46  if (wave >= WAVE_INDEX_MIN && wave < WAVE_INDEX_MAX)
47  return (band_index[wave - WAVE_INDEX_MIN]);
48  else
49  return (-1);
50 }
51 
52 
53 /* ---------------------------------------------------------------------------------------- */
54 /* bindex_get_555() - retrieve direct access wavelength index of band nearest to 555nm */
55 
56 /* ---------------------------------------------------------------------------------------- */
57 int bindex_get_555(void) {
58  int ib = bindex_get(547); /* note: we want 547 for MODIS, not 555, hence the order */
59 
60  if (ib < 0) ib = bindex_get(550);
61  if (ib < 0) ib = bindex_get(555);
62  if (ib < 0) ib = bindex_get(560);
63  if (ib < 0) ib = bindex_get(565);
64 
65  return (ib);
66 }
67 
68 
69 /* ---------------------------------------------------------------------------------------- */
70 /* windex() - return wavelength index of table which is closest to sensor wavelength */
71 
72 /* ---------------------------------------------------------------------------------------- */
73 int windex(float wave, float twave[], int ntwave) {
74  int iw, index;
75  float wdiff;
76  float wdiffmin = 99999.;
77 
78  for (iw = 0; iw < ntwave; iw++) {
79 
80  /* break on exact match */
81  if (twave[iw] == wave) {
82  index = iw;
83  break;
84  }
85 
86  /* look for closest */
87  wdiff = fabs(twave[iw] - wave);
88  if (wdiff < wdiffmin) {
89  wdiffmin = wdiff;
90  index = iw;
91  }
92  }
93 
94  return (index);
95 }
96 
97 int windex_(float *wave, float twave[], int *ntwave) {
98  return (windex(*wave, twave, *ntwave));
99 }
100 
101 
102 /* ---------------------------------------------------------------------------------------- */
103 /* invbindex() - invert the band index, given a wavelength index (oy vey!) */
104 
105 /* ---------------------------------------------------------------------------------------- */
106 int invbindx(int band, int32_t *bindx, int nbands) {
107  int i;
108 
109  for (i = 0; i < nbands; i++)
110  if (band == bindx[i])
111  return (i);
112 
113  return (-1);
114 }
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
#define MAX(A, B)
Definition: swl0_utils.h:26
const int bindx[3]
Definition: DbLutNetcdf.cpp:28
#define MIN(x, y)
Definition: rice.h:169
int bindex_get_555(void)
Definition: windex.c:57
int windex_(float *wave, float twave[], int *ntwave)
Definition: windex.c:97
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 band
#define WAVE_INDEX_MIN
Definition: windex.c:6
#define WAVE_INDEX_MAX
Definition: windex.c:7
int windex(float wave, float twave[], int ntwave)
Definition: windex.c:73
int32_t nbands
#define fabs(a)
Definition: misc.h:93
#define WAVE_INDEX_NUM
Definition: windex.c:5
int invbindx(int band, int32_t *bindx, int nbands)
Definition: windex.c:106
void bindex_set(int32_t wave[], int nwave, int dwave_vswir)
Definition: windex.c:15
int i
Definition: decode_rs.h:71
int bindex_get(int32_t wave)
Definition: windex.c:45