18 float sw, a1,
b1, a2, b2;
21 if (
fabs(wave - 555) > 2) {
22 if (
fabs(wave - 547) <= 2) {
28 }
else if (
fabs(wave - 550) <= 2) {
34 }
else if (
fabs(wave - 560) <= 2) {
40 }
else if (
fabs(wave - 565) <= 2) {
47 printf(
"-E- %s line %d: Unable to convert Rrs at %f to 555nm.\n", __FILE__, __LINE__, wave);
53 Rrs = pow(10.0, a1 * log10(
Rrs) -
b1);
55 *uRrs_out=
Rrs*a1/temp_Rrs*uRrs_in;
94 void grabBricaud(
float wvl[],
int nwvl,
float* a_bricaud,
float* b_bricaud) {
96 float bricaud_L_A_B[][17] ={
97 {410, 412, 413, 440, 443, 488, 490, 510, 530, 531, 547, 550, 555, 560, 665, 667, 670},
98 {0.0313, 0.0323, 0.032775, 0.0403, 0.0394, 0.0279, 0.0274, 0.018, 0.0117, 0.0115, 0.00845,
99 0.008, 0.007, 0.0062, 0.0152, 0.01685, 0.0189},
100 {0.283, 0.286, 0.28775, 0.332, 0.3435, 0.369, 0.361, 0.260, 0.139, 0.134, 0.0625,
101 0.052, 0.0315, 0.016, 0.134, 0.140, 0.149}
113 while (ko < nwvl && srchCounter < wvlToSrch) {
115 if (wvl[ko] == bricaud_L_A_B[0][kb]) {
116 a_bricaud[ko] = bricaud_L_A_B[1][kb];
117 b_bricaud[ko] = bricaud_L_A_B[2][kb];
120 }
else if (wvl[ko] < bricaud_L_A_B[0][kb]) {
130 void grabAwBw(
float wvl[],
int nwvl,
float aw[],
float bw[]) {
132 for (
i = 0;
i < nwvl;
i++) {
174 void calcQAA443(
float ab_surf_rrs[],
float wvl[],
int nwvl, ccstr *ctxt) {
176 float *blw_surf_rrs, *u_ptr;
177 float c1 = 0.52, c2 = 1.7;
178 float g0 = 0.089, g1 = 0.125;
179 float a0, bbp0, bbp0_exp, a0_exp;
180 float ratio_aph, slope_adg, ratio_adg;
181 static int firstCall = 1;
182 static int rIdx = -1, gIdx = -1, bgIdx = -1, refIdx = -1, purIdx = -1;
184 blw_surf_rrs = (
float*) malloc(nwvl *
sizeof (
float));
185 u_ptr = (
float*) malloc(nwvl *
sizeof (
float));
189 rIdx =
windex(670, wvl, nwvl);
190 gIdx =
windex(550, wvl, nwvl);
191 bgIdx =
windex(490, wvl, nwvl);
193 purIdx =
windex(412, wvl, nwvl);
196 float bbp[refIdx + 1],
a[refIdx + 1];
198 float up_667 = 20 * pow(ab_surf_rrs[gIdx], 1.5);
199 float lw_667 = 0.9 * pow(ab_surf_rrs[gIdx], 1.7);
200 if (ab_surf_rrs[rIdx] > up_667 || ab_surf_rrs[rIdx] < lw_667) {
201 ab_surf_rrs[rIdx] = 1.27 * pow(ab_surf_rrs[gIdx], 1.47) +
202 0.00018 * pow(ab_surf_rrs[gIdx] / (ab_surf_rrs[bgIdx]), -3.19);
207 for (ib = 0; ib < nwvl; ib++) {
209 *(blw_surf_rrs + ib) = ab_surf_rrs[ib] / (c1 + c2 * ab_surf_rrs[ib]);
210 *(u_ptr + ib) = (-g0 + pow(pow(g0, 2) + 4 * g1 *
211 *(blw_surf_rrs + ib), 0.5)) / (2 * g1);
214 (*(blw_surf_rrs + refIdx) + *(blw_surf_rrs + bgIdx)) /
215 (*(blw_surf_rrs + gIdx) + 5 * (*(blw_surf_rrs + rIdx) /
216 *(blw_surf_rrs + bgIdx)) *
217 *(blw_surf_rrs + rIdx))
219 a0 = *(ctxt->aw_i + gIdx) + pow(10.0, (-1.146 - (1.366 * a0_exp) -(0.469 * pow(a0_exp, 2))));
220 bbp0 = *(u_ptr + gIdx) * a0 / (1 - *(u_ptr + gIdx)) - *(ctxt->bbw_i + gIdx);
221 bbp0_exp = 2 * (1 - 1.2 * exp(-0.9 * *(blw_surf_rrs + refIdx) / *(blw_surf_rrs + gIdx)));
222 ratio_aph = 0.74 + (0.2 / (0.8 + *(blw_surf_rrs + refIdx) / *(blw_surf_rrs + gIdx)));
223 slope_adg = 0.015 + 0.002 / (0.6 + *(blw_surf_rrs + refIdx) / *(blw_surf_rrs + gIdx));
224 ratio_adg = exp(slope_adg * (wvl[refIdx] - wvl[purIdx]));
225 for (ib = 0; ib <= refIdx; ib++) {
227 bbp[ib] = bbp0 * pow((wvl[gIdx] / wvl[ib]), bbp0_exp);
228 a[ib] = (1 - *(u_ptr + ib)) * (bbp[ib] + *(ctxt->bbw_i + ib)) / *(u_ptr + ib);
230 *(ctxt->adgRef) = ((
a[purIdx] - ratio_aph *
a[refIdx]) - (*(ctxt->aw_i + purIdx) - ratio_aph * *(ctxt->aw_i + refIdx))) /
231 (ratio_adg - ratio_aph);
232 *(ctxt->aphRef) =
a[refIdx] - *(ctxt->aw_i + refIdx) - *(ctxt->adgRef);
233 *(ctxt->bbpRef) = bbp[refIdx];
247 for (in = 0; in<*ctxt->num_wvl_i; in++) {
248 wt = 1.0 /
fabs(ctxt->wvl_i[in] - xout);
249 prodSum += wt * ctxt->tar_rrs[in];
253 interpOut = prodSum / wtSum;
261 void idInputBand(
float inputWvl[],
float targetWvl, ccstr *ctxt,
int nin) {
271 closeIdx =
windex(targetWvl, inputWvl, nin);
272 if (((inputWvl[closeIdx] - targetWvl) >
MINWVDIFF) && (closeIdx > 0)) {
273 idx[0] = closeIdx - 1;
275 }
else if (((inputWvl[closeIdx] - targetWvl) < -
MINWVDIFF) && (closeIdx < (nin - 1))) {
277 idx[1] = closeIdx + 1;
282 ctxt->sh_strt_idx = (
int*) malloc(nout *
sizeof (
int));
283 ctxt->wvl_i = (
float*) malloc(nout *
sizeof (
float));
284 ctxt->num_wvl_i = (
int*) malloc(
sizeof (
int));
285 *(ctxt->num_wvl_i) = nout;
287 for (kb = 0; kb < nout; kb++) {
288 *(ctxt->sh_strt_idx + kb) = idx[kb];
289 *(ctxt->wvl_i + kb) = inputWvl[idx[kb]];
299 void shiftBand(
float inputWvl[],
float inputRrs[],
float chla,
int numBands,
float tarWvl, ccstr* ctxt)
302 float wvlIn, rrsIn, refwvl;
303 float s = 0.015, g0 = 0.089, g1 = 0.125, c1 = -0.52, c2 = 1.7;
304 static int gIdx = -1, refIdx = -1;
306 float ll_i, aph_i, adg_i, bbp_i;
307 float a_tot_i, bb_tot_i, qaa_fwd_i, qaa_rrs_bbw_i, qaa_rrs_aw_i;
308 float ll_o, aph_o, adg_o, bbp_o;
309 float a_tot_o, bb_tot_o, qaa_fwd_o, qaa_rrs_bbw_o, qaa_rrs_aw_o, correc_factor;
314 gIdx =
windex(550, inputWvl, numBands);
317 refwvl = inputWvl[refIdx];
319 nin = *(ctxt->num_wvl_i);
321 b2g = inputRrs[refIdx] / inputRrs[gIdx];
322 sdg =
s + 0.002 / (0.6 + b2g);
323 yy = 2 * (1 - 1.2 * exp(-0.9 * b2g));
326 for (kb = 0; kb < nin; kb++) {
327 idx = *(ctxt->sh_strt_idx + kb);
328 wvlIn = inputWvl[idx];
329 rrsIn = inputRrs[idx];
331 ll_i = wvlIn - refwvl;
333 adg_i = *(ctxt->adgRef) * exp(-sdg * ll_i);
334 bbp_i = *(ctxt->bbpRef) * pow((443 / wvlIn), yy);
335 a_tot_i = aph_i + adg_i + *(ctxt->aw_i + idx);
336 bb_tot_i = bbp_i + *(ctxt->bbw_i + idx);
337 qaa_fwd_i = bb_tot_i / (a_tot_i + bb_tot_i);
338 qaa_rrs_bbw_i = (g0 + g1 * qaa_fwd_i) * qaa_fwd_i;
339 qaa_rrs_aw_i = (c1 * qaa_rrs_bbw_i) / ((c2 * qaa_rrs_bbw_i) - 1);
343 adg_o = *(ctxt->adgRef) * exp(-sdg * ll_o);
344 bbp_o = *(ctxt->bbpRef) * pow((443 / tarWvl), yy);
345 a_tot_o = aph_o + adg_o + *(ctxt->aw_o);
346 bb_tot_o = bbp_o + *(ctxt->bbw_o);
347 qaa_fwd_o = bb_tot_o / (a_tot_o + bb_tot_o);
348 qaa_rrs_bbw_o = (g0 + g1 * qaa_fwd_o) * qaa_fwd_o;
349 qaa_rrs_aw_o = (c1 * qaa_rrs_bbw_o) / ((c2 * qaa_rrs_bbw_o) - 1);
350 correc_factor = qaa_rrs_aw_o / qaa_rrs_aw_i;
351 *(ctxt->tar_rrs + kb) = rrsIn * correc_factor;
369 free(ctxt->num_wvl_i);
371 free(ctxt->sh_strt_idx);
375 float bioBandShift(
float wvl[],
float rrs[],
float chla,
int nw,
float tarWvl) {
379 sh_ctxt.aw_i = (
float*) malloc(nw *
sizeof (
float));
380 sh_ctxt.bbw_i = (
float*) malloc(nw *
sizeof (
float));
381 sh_ctxt.aBric_i = (
float*) malloc(nw *
sizeof (
float));
382 sh_ctxt.bBric_i = (
float*) malloc(nw *
sizeof (
float));
383 sh_ctxt.aw_o = (
float*) malloc(
sizeof (
float));
384 sh_ctxt.bbw_o = (
float*) malloc(
sizeof (
float));
385 sh_ctxt.aBric_o = (
float*) malloc(
sizeof (
float));
386 sh_ctxt.bBric_o = (
float*) malloc(
sizeof (
float));
387 sh_ctxt.aphRef = (
float*) malloc(
sizeof (
float));
388 sh_ctxt.adgRef = (
float*) malloc(
sizeof (
float));
389 sh_ctxt.bbpRef = (
float*) malloc(
sizeof (
float));
390 sh_ctxt.tar_rrs = (
float*) malloc(
sizeof (
float));
392 grabAwBw(wvl, nw, sh_ctxt.aw_i, sh_ctxt.bbw_i);
393 grabAwBw(&tarWvl, 1, sh_ctxt.aw_o, sh_ctxt.bbw_o);
396 shiftBand(wvl, rrs, chla, nw, tarWvl, &sh_ctxt);
397 if (*sh_ctxt.num_wvl_i > 1)
401 result = *(sh_ctxt.tar_rrs);