97 static int idx410 = -1;
98 static int idx440 = -1;
99 static int idx490 = -1;
100 static int idx555 = -1;
101 static int idx670 = -1;
102 static int initialized = 0;
103 static int aph_check = 1;
104 static double S = 0.015;
105 static double acoefs[3];
132 qaa_init(
int i410,
int i440,
int i490,
int i555,
int i670) {
168 S = va_arg(ap,
double);
171 acoefs[0] = va_arg(ap,
double);
172 acoefs[1] = va_arg(ap,
double);
173 acoefs[2] = va_arg(ap,
double);
176 aph_check = va_arg(ap,
int);
201 double *rrs,
double *
u,
double *
a,
double *bb,
unsigned char *
flags) {
203 const double g0 = 0.08945;
204 const double g1 = 0.1247;
219 if ((
Rrs[idx670] > 20.0 * pow(
Rrs[idx555], 1.5)) ||
220 (
Rrs[idx670] < 0.9 * pow(
Rrs[idx555], 1.7))) {
221 Rrs[idx670] = 1.27 * pow(
Rrs[idx555], 1.47) + 0.00018 * pow(
Rrs[idx490] /
Rrs[idx555], -3.19);
234 u[
i] = (sqrt(g0 * g0 + 4.0 * g1 * rrs[
i]) - g0) / (2.0 * g1);
237 if (
Rrs[idx670] >= 0.0015) {
238 aref = aw[idx670] + 0.39*powf(
Rrs[idx670]/(
Rrs[idx440]+
Rrs[idx490]),1.14);
241 numer = rrs[idx440] + rrs[idx490];
242 denom = rrs[idx555] + 5.0 * rrs[idx670]*(rrs[idx670] / rrs[idx490]);
244 rho = acoefs[0] + acoefs[1] * rho + acoefs[2] * rho*rho;
245 aref = aw[idx555] + pow(10.0, rho);
250 bbpref = ((
u[idxref] * aref) / (1.0 -
u[idxref])) - bbw[idxref];
253 rat = rrs[idx440] / rrs[idx555];
254 Y = 2.0 * (1.0 - 1.2 * exp(-0.9 * rat));
258 bb[
i] = bbpref * pow((wavel[idxref] / wavel[
i]), Y) + bbw[
i];
265 a[
i] = ((1.0 -
u[
i]) * bb[
i]) /
u[
i];
280 float *rrs,
float *
u,
float *
a,
float *bb,
281 unsigned char *
flags) {
283 const float g0 = 0.08945;
284 const float g1 = 0.1247;
301 if (
Rrs[idx555] <= 0.0)
305 if ((
Rrs[idx670] > 20.0 * powf(
Rrs[idx555], 1.5)) ||
306 (
Rrs[idx670] < 0.9 * powf(
Rrs[idx555], 1.7))) {
307 Rrs[idx670] = 1.27 * powf(
Rrs[idx555], 1.47) + 0.00018 * powf(
Rrs[idx490] /
Rrs[idx555], -3.19);
320 u[
i] = (sqrt(g0 * g0 + 4.0 * g1 * rrs[
i]) - g0) / (2.0 * g1);
323 if (
Rrs[idx670] >= 0.0015) {
324 aref = aw[idx670] + 0.39*powf(
Rrs[idx670]/(
Rrs[idx440]+
Rrs[idx490]),1.14);
327 numer = rrs[idx440] + rrs[idx490];
328 denom = rrs[idx555] + 5.0 * rrs[idx670]*(rrs[idx670] / rrs[idx490]);
330 rho = acoefs[0] + acoefs[1] * rho + acoefs[2] * rho*rho;
331 aref = aw[idx555] + powf(10.0, rho);
336 bbpref = ((
u[idxref] * aref) / (1.0 -
u[idxref])) - bbw[idxref];
339 rat = rrs[idx440] / rrs[idx555];
340 Y = 2.0 * (1.0 - 1.2 * expf(-0.9 * rat));
344 bb[
i] = bbpref * pow((wavel[idxref] / wavel[
i]), Y) + bbw[
i];
351 a[
i] = ((1.0 -
u[
i]) * bb[
i]) /
u[
i];
381 double *adg,
double *aph,
unsigned char *
flags) {
383 double symbol, x1, x2;
384 double zeta,
denom, dif1, dif2;
394 rat = rrs[idx440] / rrs[idx555];
395 symbol = 0.74 + (0.2 / (0.8 + rat));
398 Sr = S + 0.002 / (0.6 + rat);
399 zeta = exp(Sr * (wavel[idx440] - wavel[idx410]));
402 denom = zeta - symbol;
403 dif1 =
a[idx410] - symbol *
a[idx440];
404 dif2 = aw[idx410] - symbol * aw[idx440];
405 adg440 = (dif1 - dif2) /
denom;
408 adg[
i] = adg440 * exp(Sr * (wavel[idx440] - wavel[
i]));
409 aph[
i] =
a[
i] - adg[
i] - aw[
i];
416 x1 = aph[idx440] /
a[idx440];
417 if (x1 < 0.15 || x1 > 0.6) {
421 x2 = -0.8 + 1.4 * (
a[idx440] - aw[idx440]) / (
a[idx410] - aw[idx410]);
431 aph[idx440] =
a[idx440] * x2;
432 adg440 =
a[idx440] - aph[idx440] - aw[idx440];
435 adg[
i] = adg440 * exp(Sr * (wavel[idx440] - wavel[
i]));
436 aph[
i] =
a[
i] - adg[
i] - aw[
i];
451 float *adg,
float *aph,
unsigned char *
flags) {
453 float symbol, x1, x2;
454 float zeta,
denom, dif1, dif2;
464 rat = rrs[idx440] / rrs[idx555];
465 symbol = 0.74 + (0.2 / (0.8 + rat));
468 Sr = S + 0.002 / (0.6 + rat);
469 zeta = expf(Sr * (wavel[idx440] - wavel[idx410]));
472 denom = zeta - symbol;
473 dif1 =
a[idx410] - symbol *
a[idx440];
474 dif2 = aw[idx410] - symbol * aw[idx440];
475 adg440 = (dif1 - dif2) /
denom;
478 adg[
i] = adg440 * expf(Sr * (wavel[idx440] - wavel[
i]));
479 aph[
i] =
a[
i] - adg[
i] - aw[
i];
486 x1 = aph[idx440] /
a[idx440];
487 if (x1 < 0.15 || x1 > 0.6) {
491 x2 = -0.8 + 1.4 * (
a[idx440] - aw[idx440]) / (
a[idx410] - aw[idx410]);
501 aph[idx440] =
a[idx440] * x2;
502 adg440 =
a[idx440] - aph[idx440] - aw[idx440];
505 adg[
i] = adg440 * expf(Sr * (wavel[idx440] - wavel[
i]));
506 aph[
i] =
a[
i] - adg[
i] - aw[
i];
528 static void print_out(
int n,
float *fwl,
float *
Rrs,
float *rrs,
float *
u,
529 float *
a,
float *aph,
float *adg,
float *aw,
float *bb,
float *bbw) {
534 for (
i = 0;
i < n;
i++)
535 printf(
"%9.0f ", fwl[
i]);
539 for (
i = 0;
i < n;
i++)
540 printf(
"%9.6f ",
Rrs[
i]);
544 for (
i = 0;
i < n;
i++)
545 printf(
"%9.6f ", rrs[
i]);
549 for (
i = 0;
i < n;
i++)
550 printf(
"%9.6f ",
u[
i]);
554 for (
i = 0;
i < n;
i++)
555 printf(
"%9.6f ",
a[
i]);
559 for (
i = 0;
i < n;
i++)
560 printf(
"%9.6f ", aph[
i]);
564 for (
i = 0;
i < n;
i++)
565 printf(
"%9.6f ", adg[
i]);
569 for (
i = 0;
i < n;
i++)
570 printf(
"%9.6f ", aw[
i]);
574 for (
i = 0;
i < n;
i++)
575 printf(
"%9.6f ", bb[
i]);
579 for (
i = 0;
i < n;
i++)
580 printf(
"%9.6f ", bbw[
i]);
586 main(
int argc,
char *argv[]) {
591 #define NUM_SPECTRA 24
592 float Rrs_insitu[NUM_SPECTRA][
NBANDS] = {
594 { 0.001919, 0.002297, 0.004420, 0.005547, 0.009138, 0.004110},
595 { 0.001753, 0.002657, 0.004348, 0.005212, 0.007641, 0.003950},
596 { 0.003968, 0.003374, 0.002932, 0.002142, 0.001214, 0.000136},
597 { 0.001332, 0.001414, 0.002116, 0.002464, 0.003891, 0.001669},
598 { 0.001572, 0.001537, 0.002132, 0.002504, 0.004157, 0.001909},
599 { 0.004830, 0.004084, 0.003540, 0.002648, 0.001584, 0.000194},
600 { 0.001145, 0.001457, 0.002501, 0.002945, 0.004180, 0.001524},
601 { 0.000921, 0.001004, 0.001465, 0.001456, 0.001363, 0.000252},
602 { 0.003120, 0.003226, 0.003530, 0.002857, 0.001882, 0.000196},
603 { 0.005170, 0.004682, 0.003794, 0.002535, 0.001343, 0.000131},
604 { 0.004718, 0.004378, 0.003763, 0.002627, 0.001472, 0.000151},
605 { 0.003503, 0.003394, 0.003358, 0.002510, 0.001507, 0.000181},
606 { 0.001005, 0.001131, 0.001879, 0.002219, 0.003316, 0.001100},
607 { 0.007704, 0.006917, 0.005540, 0.003721, 0.002129, 0.000389},
608 { 0.003311, 0.003071, 0.002920, 0.002315, 0.001508, 0.000285},
609 { 0.003476, 0.003285, 0.003073, 0.002347, 0.001436, 0.000200},
610 { 0.004661, 0.005739, 0.008028, 0.007809, 0.006632, 0.001035},
611 { 0.004212, 0.004859, 0.006455, 0.006117, 0.004895, 0.000676},
612 { 0.002090, 0.002280, 0.003091, 0.002780, 0.002177, 0.000444},
613 { 0.003237, 0.003042, 0.002947, 0.002317, 0.001440, 0.000166},
614 { 0.003125, 0.003444, 0.004119, 0.003777, 0.002875, 0.000413},
615 { 0.002637, 0.002896, 0.003477, 0.002987, 0.002085, 0.000251},
616 { 0.003472, 0.003596, 0.003834, 0.003067, 0.001969, 0.000331},
617 { 0.004554, 0.003772, 0.002074, 0.002082, 0.001338, 0.000120}
620 float fwl[
NBANDS] = {412, 443, 490, 510, 555, 670};
621 float aw[
NBANDS] = {0.004994, 0.007512, 0.025010, 0.040020, 0.077080, 0.445600};
622 float bbw[
NBANDS] = {0.003271, 0.002421, 0.001568, 0.001339, 0.000939, 0.000426};
645 qaa_init(idx410, idx440, idx490, idx555, idx670);
649 for (
j = 0;
j < NUM_SPECTRA;
j++) {
655 Rrs[
i] = Rrs_insitu[
j][
i];
660 for (
i = 0;
i < 6;
i++)
664 for (
i = 0;
i < 6;
i++)
668 print_out(
nbands, fwl,
Rrs, rrs,
u,
a, aph, adg, aw, bb, bbw);
671 printf(
"original aph/a ratio was out of range (0.15 to 0.6)\n");
673 printf(
" and was forced to minimum (0.15)\n");
675 printf(
" and was forced to maximum (0.6)\n");