16 #include <gsl/gsl_fit.h>
20 #define PARWN (PARW2-PARW1)+1
22 static float fqymin = 0.0;
23 static float fqymax = 0.3;
24 static float flhmin = 0.0;
34 float mean_x=0, mean_y=0;
35 float xy_sum=0,x2_sum=0;
45 xy_sum+=(
x[
i]-mean_x)*(
y[
i]-mean_y);
46 x2_sum+=(
x[
i]-mean_x)*(
x[
i]-mean_x);
50 coef[0]=xy_sum/x2_sum;
52 coef[1]=mean_y-coef[0]*mean_x;
63 static int32_t ib665, ib680, ib709;
64 static int firstCall = 1;
73 float dbdnlw1, dbdnlw2, dbdnlw3;
76 l1str *
l1rec = l2rec->l1rec;
78 uncertainty_t *uncertainty=
l1rec->uncertainty;
87 printf(
"No fluorescence algorithm available for this sensor.\n");
92 printf(
"No fluorescence algorithm available for this sensor.\n");
100 printf(
"No fluorescence algorithm available for this sensor.\n");
106 for (ip = 0; ip <
l1rec->npix; ip++) {
110 ipb =
l1file->nbands * ip;
116 nLw1 = l2rec->nLw[ipb + ib665];
117 nLw2 = l2rec->nLw[ipb + ib680];
118 nLw3 = l2rec->nLw[ipb + ib709];
120 unLw1 = l2rec->Rrs_unc[ipb + ib665] * l2rec->l1rec->l1file->Fobar[ib665];
121 unLw2 = l2rec->Rrs_unc[ipb + ib680] * l2rec->l1rec->l1file->Fobar[ib680];
122 unLw3 = l2rec->Rrs_unc[ipb + ib709] * l2rec->l1rec->l1file->Fobar[ib709];
124 Lf1 =
l1file->fwave[ib665];
125 Lf2 =
l1file->fwave[ib680];
126 Lf3 =
l1file->fwave[ib709];
132 if (
l1rec->mask[ip] || nLw1 < -0.01 || nLw2 < -0.01 || nLw3 < -0.01) {
141 dbdnlw1 = -(Lf3- Lf2) / (Lf3 - Lf1);
143 dbdnlw3 = -1.0 + ((Lf3- Lf2) / (Lf3 - Lf1));
149 uflh[ip] = sqrt(pow(dbdnlw1*unLw1,2) + pow(dbdnlw2*unLw2,2)
150 + pow(dbdnlw3*unLw3,2) + pow(ubias,2) );
169 static int firstRun = 1;
172 l1str *
l1rec = l2rec->l1rec;
174 double c0, c1, cov00, cov01, cov11, chi_sq;
177 static double *xfit =
NULL;
178 static double *yfit =
NULL;
179 static int *baseBands;
180 static int heightBand;
186 if (
input->flh_num_base_wavelengths < 2) {
187 printf(
"-E- Need at least 2 flh_base_wavelengths to compute FLH. Only %d provided\n",
input->flh_num_base_wavelengths);
190 if (
input->flh_height_wavelength == -1.0) {
191 printf(
"-E- Missing flh_height_wavelength needed to compute FLH.\n");
197 nfit =
input->flh_num_base_wavelengths;
198 xfit = (
double *)malloc(nfit *
sizeof(
double));
199 yfit = (
double *)malloc(nfit *
sizeof(
double));
200 baseBands = (
int *)malloc(nfit *
sizeof(
int));
204 for (ib = 0; ib < nfit; ib++) {
206 xfit[ib] =
l1file->fwave[baseBands[ib]];
210 for (ip = 0; ip <
l1rec->npix; ip++) {
213 if (
l1rec->mask[ip]) {
218 ipb =
l1file->nbands * ip;
219 nLw = &l2rec->nLw[ipb];
222 for (ib = 0; ib < nfit; ib++) {
223 yfit[ib] = nLw[baseBands[ib]];
224 if (yfit[ib] < -0.01) {
233 gsl_fit_linear(xfit, 1, yfit, 1, nfit, &c0, &c1, &cov00, &cov01, &cov11, &chi_sq);
235 baseline = c0 + c1 *
input->flh_height_wavelength;
237 flh[ip] = nLw[heightBand] - baseline -
input->flh_offset;
239 if (flh[ip] < flhmin) {
260 static int firstCall = 1;
266 l1str *
l1rec = l2rec->l1rec;
272 if ((ipar = (
float *) calloc(
l1rec->npix, sizeof (
float))) ==
NULL) {
273 printf(
"-E- %s line %d: Unable to allocate space for ipar.\n",
277 if ((fsat = (
float *) calloc(
l1rec->npix, sizeof (
float))) ==
NULL) {
278 printf(
"-E- %s line %d: Unable to allocate space for fsat.\n",
291 for (ip = 0; ip <
l1rec->npix; ip++) {
295 if (!
l1rec->mask[ip] && l2rec->chl[ip] > 0.0 && fsat[ip] >= 0.0) {
298 fqy[ip] = 0.01 * fsat[ip] / (0.0302 * l2rec->chl[ip]) * ipar[ip]
301 if (!isfinite(fqy[ip])) {
304 }
else if (fqy[ip] < fqymin || fqy[ip] > fqymax) {