Go to the documentation of this file.
7 static int32_t LastRecNum = -1;
8 static float adg_s = 0.018;
29 static int firstCall = 1;
32 static float xtab [
NTAB];
33 static float ytab [
NTAB];
36 static int ib412 = -1;
37 static int ib443 = -1;
38 static int ib490 = -1;
39 static int ib555 = -1;
50 l1str *
l1rec = l2rec->l1rec;
62 if ((
path = getenv(
"OCDATAROOT")) ==
NULL) {
63 printf(
"OCDATAROOT environment variable is not defined.\n");
77 if (ib412 < 0 || ib443 < 0 || ib490 < 0 || ib555 < 0) {
78 printf(
"cdom_morel: incompatible sensor wavelengths for this algorithm\n");
85 strcat(
filename,
"/common/morel_chl_R490_R555.dat");
88 printf(
"-E- %s line %d: error opening (%s) file", __FILE__, __LINE__,
filename);
92 printf(
"\nLoading Morel CDOM table from file %s\n",
filename);
97 tmp_str = strtok(buff, delim);
98 if (strcmp(tmp_str,
"R412/R443") == 0) {
100 while ((tmp_str = strtok(
NULL, delim)) !=
NULL) {
101 xtab[
i] = atof(tmp_str);
105 }
else if (strcmp(tmp_str,
"R490/R555") == 0) {
108 ytab[
j] = atof(tmp_str);
110 while ((tmp_str = strtok(
NULL, delim)) !=
NULL) {
111 if (strcmp(tmp_str,
"NA") != 0)
112 chltab[
i][
j] = atof(tmp_str);
118 printf(
"-E- %s line %d: error reading (%s) file", __FILE__, __LINE__,
filename);
126 printf(
"Read %d x %d entries.\n", nx, ny);
131 strcat(
filename,
"/common/morel_cdm_index.dat");
134 printf(
"-E- %s line %d: error opening (%s) file", __FILE__, __LINE__,
filename);
138 printf(
"\nLoading Morel CDOM table from file %s\n",
filename);
143 tmp_str = strtok(buff, delim);
144 if (strcmp(tmp_str,
"R412/R443") == 0) {
146 while ((tmp_str = strtok(
NULL, delim)) !=
NULL) {
147 xtab[
i] = atof(tmp_str);
151 }
else if (strcmp(tmp_str,
"R490/R555") == 0) {
154 ytab[
j] = atof(tmp_str);
156 while ((tmp_str = strtok(
NULL, delim)) !=
NULL) {
157 if (strcmp(tmp_str,
"NA") != 0)
158 idxtab[
i][
j] = atof(tmp_str);
164 printf(
"-E- %s line %d: error reading (%s) filename", __FILE__, __LINE__,
filename);
172 printf(
"Read %d x %d entries.\n", nx, ny);
176 if ((chl = calloc(
l1rec->npix, sizeof (
float))) ==
NULL) {
177 printf(
"-E- %s line %d : error allocating memory for Morel CDOM.\n",
182 if ((idx = calloc(
l1rec->npix, sizeof (
float))) ==
NULL) {
183 printf(
"-E- %s line %d : error allocating memory for Morel CDOM.\n",
191 if ((Q0 = calloc(
l1file->nbands, sizeof (
float))) ==
NULL) {
192 printf(
"-E- %s line %d : error allocating memory for Q0 Morel CDOM.\n",
199 for (ip = 0; ip <
l1rec->npix; ip++) {
200 ipb = ip *
l1file->nbands;
203 if (l2rec->chl[ip] > 0.0) {
206 R412 = l2rec->Rrs[ipb + ib412] * Q0[ib412];
207 R443 = l2rec->Rrs[ipb + ib443] * Q0[ib443];
208 R490 = l2rec->Rrs[ipb + ib490] * Q0[ib490];
210 if (R443 > 0.0 && R555 > 0.0) {
212 xrat =
MAX(
MIN(R412 / R443, xtab[nx - 1]), xtab[0]);
213 yrat =
MAX(
MIN(R490 / R555, ytab[ny - 1]), ytab[0]);
214 for (
i = 0;
i < nx - 2;
i++)
217 for (
j = 0;
j < ny - 2;
j++)
221 t = (xrat - xtab[
i]) / (xtab[
i + 1] - xtab[
i]);
222 u = (yrat - ytab[
j]) / (ytab[
j + 1] - ytab[
j]);
224 w[0] = (idxtab[
i ][
j ] > -1) * (1 -
t)*(1 -
u);
225 w[1] = (idxtab[
i ][
j + 1] > -1) *
t * (1 -
u);
226 w[2] = (idxtab[
i + 1][
j + 1] > -1) *
t*
u;
227 w[3] = (idxtab[
i + 1][
j ] > -1) * (1 -
t) *
u;
229 wt = w[0] + w[1] + w[2] + w[3];
232 idx[ip] = (idxtab[
i ][
j ] * w[0]
233 + idxtab[
i ][
j + 1] * w[1]
234 + idxtab[
i + 1][
j + 1] * w[2]
235 + idxtab[
i + 1][
j ] * w[3]) / wt;
236 chl[ip] = (chltab[
i ][
j ] * w[0]
237 + chltab[
i ][
j + 1] * w[1]
238 + chltab[
i + 1][
j + 1] * w[2]
239 + chltab[
i + 1][
j ] * w[3]) / wt;
251 LastRecNum =
l1rec->iscan;
273 if (chl > 0.0 && idx > badval + 1)
274 return (idx * 0.065 * pow(chl, 0.63) * exp(-adg_s * (wave - 400)));
288 if (chl > 0.0 && idx > badval + 1) {
289 aph = 0.03782 * pow(chl, 0.635);
291 return (100 * adg / (adg + aph));
302 float A[] = {-73.65, -35.92, 15.3, 14.8};
305 if (chl > 0.0 && idx > 0.0) {
306 idx =
MIN(
MAX(idx, 0.1), 10.0);
308 Y = X * (A[0] + X * (A[1] + X * (A[2] + X * A[3])));
309 return (chl * (1 + Y / 100));
320 int prodID =
p->cat_ix;
328 for (ip = 0; ip < l2rec->l1rec->npix; ip++) {
333 prod[ip] = (
float) idx[ip];
337 prod[ip] = (
float) chl[ip];
341 prod[ip] =
adg_morel(chl[ip], idx[ip], l2rec->l1rec->l1file->fwave[ib]);
353 printf(
"-E- %s line %d : erroneous product ID %d passed to CDOM morel.\n",
354 __FILE__, __LINE__, prodID);
int32 l1file(int32 sdfid, int32 *nsamp, int32 *nscans, int16 *dtynum)
void run_cdom_morel(l2str *l2rec)
float pcdom_morel(float chl, float idx)
float adg_morel(float chl, float idx, float wave)
void get_cdom_morel(l2str *l2rec, l2prodstr *p, float prod[])
float chl_cdomcorr_morel(float chl, float idx)
int cdom_morel_ran(int recnum)
int bindex_get(int32_t wave)
#define CAT_chl_cdomcorr_morel
char filename[FILENAME_MAX]
void qint_morel(float wave[], int32_t nwave, float solz, float chl, float Qn[])
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
float conv_rrs_to_555(float Rrs, float wave)