OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
flags_iop.c
Go to the documentation of this file.
1 #include "l12_proto.h"
2 
3 /* --------------------------------------------------------------------- */
4 
5 /* --------------------------------------------------------------------- */
6 void init_iop_flag(float32 wave[], int32 nwave, iopfstr *f) {
7  float32 *aw;
8  float32 *bbw;
9  float32 a_hi = 5.0;
10  float32 b_hi = 0.05;
11  float32 w_hi = 600;
12 
13  int iw;
14 
15  if ((aw = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
16  printf("-E- %s line %d : error allocating memory for aw in flags_iop.\n",
17  __FILE__, __LINE__);
18  exit(1);
19  }
20  if ((bbw = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
21  printf("-E- %s line %d : error allocating memory for bbw in flags_iop.\n",
22  __FILE__, __LINE__);
23  exit(1);
24  }
25 
26  for (iw = 0; iw < nwave; iw++) {
27  if (wave[iw] > w_hi) break;
28  aw [iw] = aw_spectra(wave[iw], BANDW);
29  bbw[iw] = bbw_spectra(wave[iw], BANDW);
30  }
31  f->nwave = iw;
32 
33  if ((f->a_lo = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
34  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
35  __FILE__, __LINE__);
36  exit(1);
37  }
38  if ((f->a_hi = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
39  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
40  __FILE__, __LINE__);
41  exit(1);
42  }
43  if ((f->a_on = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
44  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
45  __FILE__, __LINE__);
46  exit(1);
47  }
48 
49  if ((f->aph_lo = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
50  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
51  __FILE__, __LINE__);
52  exit(1);
53  }
54  if ((f->aph_hi = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
55  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
56  __FILE__, __LINE__);
57  exit(1);
58  }
59  if ((f->aph_on = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
60  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
61  __FILE__, __LINE__);
62  exit(1);
63  }
64 
65  if ((f->adg_lo = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
66  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
67  __FILE__, __LINE__);
68  exit(1);
69  }
70  if ((f->adg_hi = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
71  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
72  __FILE__, __LINE__);
73  exit(1);
74  }
75  if ((f->adg_on = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
76  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
77  __FILE__, __LINE__);
78  exit(1);
79  }
80 
81  if ((f->bb_lo = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
82  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
83  __FILE__, __LINE__);
84  exit(1);
85  }
86  if ((f->bb_hi = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
87  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
88  __FILE__, __LINE__);
89  exit(1);
90  }
91  if ((f->bb_on = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
92  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
93  __FILE__, __LINE__);
94  exit(1);
95  }
96 
97  if ((f->bbp_lo = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
98  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
99  __FILE__, __LINE__);
100  exit(1);
101  }
102  if ((f->bbp_hi = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
103  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
104  __FILE__, __LINE__);
105  exit(1);
106  }
107  if ((f->bbp_on = (float32 *) calloc(nwave, sizeof (float32))) == NULL) {
108  printf("-E- %s line %d : error allocating memory in init_iop_flag.\n",
109  __FILE__, __LINE__);
110  exit(1);
111  }
112 
113 
114  for (iw = 0; iw < f->nwave; iw++) {
115 
116  f->a_lo[iw] = 0.95 * aw[iw];
117  f->a_hi[iw] = a_hi;
118  f->a_on[iw] = 1;
119 
120  f->aph_lo[iw] = -0.05 * aw[iw];
121  f->aph_hi[iw] = a_hi;
122  f->aph_on[iw] = 1;
123 
124  f->adg_lo[iw] = -0.05 * aw[iw];
125  f->adg_hi[iw] = a_hi;
126  f->adg_on[iw] = 1;
127 
128  f->bb_lo[iw] = 0.95 * bbw[iw];
129  f->bb_hi[iw] = b_hi;
130  f->bb_on[iw] = 1;
131 
132  f->bbp_lo[iw] = -0.05 * bbw[iw];
133  f->bbp_hi[iw] = b_hi;
134  f->bbp_on[iw] = 1;
135  }
136 
137  for (iw = f->nwave; iw < nwave; iw++) {
138  f->a_on [iw] = 0;
139  f->aph_on [iw] = 0;
140  f->adg_on [iw] = 0;
141  f->bb_on [iw] = 0;
142  f->bbp_on [iw] = 0;
143  }
144  free(aw);
145  free(bbw);
146 }
147 
148 
149 /* --------------------------------------------------------------------- */
150 
151 /* --------------------------------------------------------------------- */
152 void set_iop_flag(float wave[], int32_t nwave,
153  float a[], float aph[], float adg[],
154  float bb[], float32 bbp[], int16_t *flag) {
155  static int firstCall = 1;
156  static iopfstr iopf;
157 
158  int iw;
159 
160  if (firstCall) {
161  firstCall = 0;
162  init_iop_flag(wave, nwave, &iopf);
163  }
164 
165  for (iw = 0; iw < iopf.nwave; iw++) {
166 
167  if (iopf.a_on[iw] && a != NULL) {
168  if (a[iw] < iopf.a_lo[iw])
169  *flag |= IOPF_ALO;
170  if (a[iw] > iopf.a_hi[iw])
171  *flag |= IOPF_AHI;
172  }
173 
174  if (iopf.aph_on[iw] && aph != NULL) {
175  if (aph[iw] < iopf.aph_lo[iw])
176  *flag |= IOPF_APHLO;
177  if (aph[iw] > iopf.aph_hi[iw])
178  *flag |= IOPF_APHHI;
179  }
180 
181  if (iopf.adg_on[iw] && adg != NULL) {
182  if (adg[iw] < iopf.adg_lo[iw])
183  *flag |= IOPF_ADGLO;
184  if (adg[iw] > iopf.adg_hi[iw])
185  *flag |= IOPF_ADGHI;
186  }
187 
188  if (iopf.bb_on[iw] && bb != NULL) {
189  if (bb[iw] < iopf.bb_lo[iw])
190  *flag |= IOPF_BBLO;
191  if (bb[iw] > iopf.bb_hi[iw])
192  *flag |= IOPF_BBHI;
193  }
194 
195  if (iopf.bbp_on[iw] && bbp != NULL) {
196  if (bbp[iw] < iopf.bbp_lo[iw])
197  *flag |= IOPF_BBPLO;
198  if (bbp[iw] > iopf.bbp_hi[iw])
199  *flag |= IOPF_BBPHI;
200  }
201  }
202 }
#define IOPF_ADGLO
Definition: flags_iop.h:18
#define IOPF_AHI
Definition: flags_iop.h:15
#define NULL
Definition: decode_rs.h:63
#define IOPF_APHLO
Definition: flags_iop.h:16
#define IOPF_APHHI
Definition: flags_iop.h:17
#define IOPF_BBHI
Definition: flags_iop.h:21
#define IOPF_BBLO
Definition: flags_iop.h:20
#define IOPF_ALO
Definition: flags_iop.h:14
void init_iop_flag(float32 wave[], int32 nwave, iopfstr *f)
Definition: flags_iop.c:6
#define IOPF_ADGHI
Definition: flags_iop.h:19
double precision function f(R1)
Definition: tmd.lp.f:1454
#define IOPF_BBPLO
Definition: flags_iop.h:22
#define IOPF_BBPHI
Definition: flags_iop.h:23
float aw_spectra(int32_t wl, int32_t width)
float bbw_spectra(int32_t wl, int32_t width)
void set_iop_flag(float wave[], int32_t nwave, float a[], float aph[], float adg[], float bb[], float32 bbp[], int16_t *flag)
Definition: flags_iop.c:152
#define BANDW
Definition: l1.h:52
PGE01 indicating that PGE02 PGE01 V6 for and PGE01 V2 for MOD03 were used to produce the granule By convention adopted in all MODIS Terra PGE02 code versions are The fourth digit of the PGE02 version denotes the LUT version used to produce the granule The source of the metadata environment variable ProcessingCenter was changed from a QA LUT value to the Process Configuration A sign used in error in the second order term was changed to a
Definition: HISTORY.txt:424