NASA Logo
Ocean Color Science Software

ocssw V2022
get_poc.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <math.h>
3 #include "l12_proto.h"
4 
5 static float badval = BAD_FLT;
6 static float minval = 0.0;
7 static float maxval = 10.0 * 1000;
8 
9 float poc_stramski_443(float *Rrs, float *wave) {
10  static int firstCall = 1;
11  static float a = 203.2;
12  static float b = -1.034;
13  static int ib1 = -1;
14  static int ib2 = -1;
15 
16  float poc = badval;
17  float Rrs1 = 0.0;
18  float Rrs2 = 0.0;
19 
20  if (firstCall) {
21  firstCall = 0;
22  ib1 = bindex_get(443);
23  ib2 = bindex_get(545);
24  if (ib2 < 0) ib2 = bindex_get(550);
25  if (ib2 < 0) ib2 = bindex_get(555);
26  if (ib2 < 0) ib2 = bindex_get(560);
27  if (ib1 < 0 || ib2 < 0) {
28  printf("-E- %s line %d: required bands not available for Stramski POC\n",
29  __FILE__, __LINE__);
30  exit(1);
31  }
32  }
33 
34  Rrs1 = Rrs[ib1];
35  Rrs2 = Rrs[ib2];
36 
37  if (Rrs1 >= 0.0 && Rrs2 > 0.0) {
38  Rrs2 = conv_rrs_to_555(Rrs2, wave[ib2],-99,NULL);
39  poc = a * pow(Rrs1 / Rrs2, b);
40  }
41 
42  return (poc);
43 }
44 
45 /*------------------------------------------------*/
46 /*Standard uncertainty for poc_stramksi_443 */
47 /*esimated using analytical propagation */
48 /*------------------------------------------------*/
49 
50 float unc_poc_stramski_443(l2str *l2rec, int ipb) {
51 
52  l1str *l1rec = l2rec->l1rec;
53  uncertainty_t *uncertainty=l1rec->uncertainty;
54  float *wave = l2rec->l1rec->l1file->fwave;
55 
56  static int firstCall = 1;
57  static float a = 203.2;
58  static float b = -1.034;
59  static int ib1 = -1;
60  static int ib2 = -1;
61 
62  float upoc = badval;
63 
64  float Rrs1 = 0.0;
65  float Rrs2 = 0.0;
66  float uRrs1 = 0.0;
67  float uRrs2 = 0.0;
68  float *uRrs2_new;
69  uRrs2_new = calloc(1, sizeof(float));
70  float dRatdRrs1;
71  float dRatdRrs2;
72  float dPocdRat;
73  float dPocdRrs1;
74  float dPocdRrs2;
75  float rat;
76 
77  if (firstCall) {
78  firstCall = 0;
79  ib1 = bindex_get(443);
80  ib2 = bindex_get(545);
81  if (ib2 < 0) ib2 = bindex_get(550);
82  if (ib2 < 0) ib2 = bindex_get(555);
83  if (ib2 < 0) ib2 = bindex_get(560);
84  if (ib1 < 0 || ib2 < 0) {
85  printf("-E- %s line %d: required bands not available for Stramski POC\n",
86  __FILE__, __LINE__);
87  exit(1);
88  }
89  }
90 
91  if (uncertainty) {
92  Rrs1 = l2rec->Rrs[ipb + ib1];
93  Rrs2 = l2rec->Rrs[ipb + ib2];
94  uRrs1 = l2rec->Rrs_unc[ipb + ib1];
95  uRrs2 = l2rec->Rrs_unc[ipb + ib2];
96  }
97 
98 
99  if (Rrs1 >= 0.0 && Rrs2 > 0.0) {
100  Rrs2 = conv_rrs_to_555(Rrs2, wave[ib2],uRrs2,uRrs2_new);
101  rat = Rrs1/Rrs2;
102  dPocdRat = a*b*pow(rat,b-1.);
103  dRatdRrs1 = 1./Rrs2;
104  dRatdRrs2 = -Rrs1/pow(Rrs2,2.);
105  dPocdRrs1 = dPocdRat * dRatdRrs1;
106  dPocdRrs2 = dPocdRat * dRatdRrs2;
107 
108  upoc = sqrt ( pow(dPocdRrs1*uRrs1,2) + pow(dPocdRrs2*(*uRrs2_new),2));
109 
110  }
111 
112  free(uRrs2_new);
113  return (upoc);
114 }
115 
116 
117 
118 float poc_stramski_490(float *Rrs, float *wave) {
119  static int firstCall = 1;
120  static float a = 308.3;
121  static float b = -1.639;
122  static int ib1 = -1;
123  static int ib2 = -1;
124 
125  float poc = badval;
126  float Rrs1 = 0.0;
127  float Rrs2 = 0.0;
128 
129  if (firstCall) {
130  firstCall = 0;
131  ib1 = bindex_get(490);
132  ib2 = bindex_get(545);
133  if (ib2 < 0) ib2 = bindex_get(550);
134  if (ib2 < 0) ib2 = bindex_get(555);
135  if (ib2 < 0) ib2 = bindex_get(560);
136  if (ib1 < 0 || ib2 < 0) {
137  printf("-E- %s line %d: required bands not available for Stramski POC\n",
138  __FILE__, __LINE__);
139  exit(1);
140  }
141  }
142 
143  Rrs1 = Rrs[ib1];
144  Rrs2 = Rrs[ib2];
145 
146  if (Rrs1 >= 0.0 && Rrs2 > 0.0) {
147  Rrs2 = conv_rrs_to_555(Rrs2, wave[ib2],-99,NULL);
148  poc = a * pow(Rrs1 / Rrs2, b);
149  }
150 
151  return (poc);
152 }
153 
154 /*------------------------------------------------*/
155 /*Standard uncertainty for poc_stramksi_490 */
156 /*esimated using analytical propagation */
157 /*------------------------------------------------*/
158 
159 float unc_poc_stramski_490(l2str *l2rec, int ipb) {
160 
161  l1str *l1rec = l2rec->l1rec;
162  uncertainty_t *uncertainty=l1rec->uncertainty;
163  float *wave = l2rec->l1rec->l1file->fwave;
164 
165  static int firstCall = 1;
166  static float a = 308.3;
167  static float b = -1.639;
168  static int ib1 = -1;
169  static int ib2 = -1;
170 
171  float upoc = badval;
172  float Rrs1 = 0.0;
173  float Rrs2 = 0.0;
174  float uRrs1 = 0.0;
175  float uRrs2 = 0.0;
176  float *uRrs2_new;
177  uRrs2_new = (float*) calloc(1, sizeof(float));
178  float dRatdRrs1;
179  float dRatdRrs2;
180  float dPocdRat;
181  float dPocdRrs1;
182  float dPocdRrs2;
183  float rat;
184 
185 
186  if (firstCall) {
187  firstCall = 0;
188  ib1 = bindex_get(490);
189  ib2 = bindex_get(545);
190  if (ib2 < 0) ib2 = bindex_get(550);
191  if (ib2 < 0) ib2 = bindex_get(555);
192  if (ib2 < 0) ib2 = bindex_get(560);
193  if (ib1 < 0 || ib2 < 0) {
194  printf("-E- %s line %d: required bands not available for Stramski POC\n",
195  __FILE__, __LINE__);
196  exit(1);
197  }
198  }
199 
200  if (uncertainty) {
201  Rrs1 = l2rec->Rrs[ipb + ib1];
202  Rrs2 = l2rec->Rrs[ipb + ib2];
203  uRrs1 = l2rec->Rrs_unc[ipb + ib1];
204  uRrs2 = l2rec->Rrs_unc[ipb + ib2];
205  }
206 
207  if (Rrs1 >= 0.0 && Rrs2 > 0.0) {
208  Rrs2 = conv_rrs_to_555(Rrs2, wave[ib2],uRrs2,uRrs2_new);
209 
210  rat = Rrs1/Rrs2;
211  dPocdRat = a*b*pow(rat,b-1.);
212  dRatdRrs1 = 1./Rrs2;
213  dRatdRrs2 = -Rrs1/pow(Rrs2,2.);
214  dPocdRrs1 = dPocdRat * dRatdRrs1;
215  dPocdRrs2 = dPocdRat * dRatdRrs2;
216 
217  upoc = sqrt ( pow(dPocdRrs1*uRrs1,2) + pow(dPocdRrs2*(*uRrs2_new),2));
218  }
219 
220  free(uRrs2_new);
221  return (upoc);
222 }
223 
224 
225 void get_poc(l2str *l2rec, l2prodstr *p, float prod[]) {
226  int32_t ip, ipb;
227  l1str *l1rec = l2rec->l1rec;
228  int32_t nbands = l1rec->l1file->nbands;
229 
230  for (ip = 0; ip < l1rec->npix; ip++) {
231 
232  prod[ip] = badval;
233  ipb = nbands * ip;
234 
235  switch (p->cat_ix) {
236 
238  prod[ip] = poc_stramski_443(&l2rec->Rrs[ip * nbands], l1rec->l1file->fwave);
239  break;
240 
242  prod[ip] = poc_stramski_490(&l2rec->Rrs[ip * nbands], l1rec->l1file->fwave);
243  break;
244 
246  prod[ip] = unc_poc_stramski_443(l2rec,ipb);
247  break;
248 
250  prod[ip] = unc_poc_stramski_490(l2rec,ipb);
251  break;
253  prod[ip] = poc_stramski_hybrid(&l2rec->Rrs[ip * nbands], l1rec->l1file->sensorID);
254  if (prod[ip]<p->min || prod[ip]>p->max)
255  prod[ip]=BAD_FLT;
256  break;
257  default:
258  printf("Error: %s : Unknown product specifier: %d\n", __FILE__, p->cat_ix);
259  exit(1);
260  break;
261  };
262 
263  if (prod[ip] == badval)
264  l1rec->flags[ip] |= PRODFAIL;
265  else if (prod[ip] < minval || prod[ip] > maxval)
266  l1rec->flags[ip] |= PRODWARN;
267 
268  }
269 
270 }
271 
#define NULL
Definition: decode_rs.h:63
read l1rec
#define PRODWARN
Definition: l2_flags.h:13
#define PRODFAIL
Definition: l2_flags.h:41
#define CAT_poc_stramski_490
Definition: l2prod.h:173
int bindex_get(int32_t wave)
Definition: windex.c:45
#define CAT_poc_unc_stramski_443
Definition: l2prod.h:166
float conv_rrs_to_555(float Rrs, float wave, float uRrs_in, float *uRrs_out)
Definition: convert_band.c:17
void get_poc(l2str *l2rec, l2prodstr *p, float prod[])
Definition: get_poc.c:225
#define CAT_poc_unc_stramski_490
Definition: l2prod.h:167
float poc_stramski_443(float *Rrs, float *wave)
Definition: get_poc.c:9
float poc_stramski_490(float *Rrs, float *wave)
Definition: get_poc.c:118
data_t b[NROOTS+1]
Definition: decode_rs.h:77
#define BAD_FLT
Definition: jplaeriallib.h:19
#define CAT_poc_stramski_443
Definition: l2prod.h:172
int32_t nbands
#define CAT_poc_stramski_hybrid
Definition: l2prod.h:421
float unc_poc_stramski_443(l2str *l2rec, int ipb)
Definition: get_poc.c:50
float unc_poc_stramski_490(l2str *l2rec, int ipb)
Definition: get_poc.c:159
float poc_stramski_hybrid(float *Rrs, int32_t sensorID)
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
float p[MODELMAX]
Definition: atrem_corl1.h:131