26 static int32 evalmask = 0;
49 #define NDIFFMAXv6v3 4
60 #define NDIFFMAXv6m4 4
137 static ssestabstrv6v sses_sstv6v;
138 static ssestabstrv6v3 sses_sst3v6v3;
186 static ssestabstrv6m sses_sstv6m;
187 static ssestabstrv6m4 sses_sst4v6m;
211 static ssestabstrv6a sses_sstv6a;
215 static s_array *sstq, *sst4q, *sst3q;
219 static float *treesum =
NULL;
223 static int8 *qual_sst =
NULL;
224 static int8 *qual_sst4 =
NULL;
225 static int8 *qual_sst3 =
NULL;
226 static float *bias_sst =
NULL;
227 static float *bias_sst4 =
NULL;
228 static float *bias_sst3 =
NULL;
229 static float *stdv_sst =
NULL;
230 static float *stdv_sst4 =
NULL;
231 static float *stdv_sst3 =
NULL;
232 static float *bias_mean_sst =
NULL;
233 static float *bias_mean_sst4 =
NULL;
234 static float *bias_mean_sst3 =
NULL;
238 static float *dsdi_correction =
NULL;
240 static float *d3940ref =
NULL;
243 static float *LtRED_maxmin =
NULL;
244 static float *Bt11_maxmin =
NULL;
245 static float *Bt11_max =
NULL;
246 static float *Bt11_min =
NULL;
247 static float *Bt11_stdev =
NULL;
248 static float *Bt12_maxmin =
NULL;
249 static float *Bt12_min =
NULL;
250 static float *Bt37_maxmin =
NULL;
251 static float *Bt37_stdev =
NULL;
252 static float *Bt39_maxmin =
NULL;
253 static float *Bt40_maxmin =
NULL;
255 static float *Bt40_stdev =
NULL;
256 static float *Bt85_min =
NULL;
257 static float *Bt73_max =
NULL;
258 static float *rhoCirrus_maxmin =
NULL;
259 static float *rhoCirrus_min =
NULL;
260 static float *rhoCirrus_max =
NULL;
261 static float *rhotRED_maxmin =
NULL;
262 static float *rhotRED_min =
NULL;
263 static float *rhotRED_max =
NULL;
264 static float *rhotNIR7_min =
NULL;
265 static float *rhot16_min =
NULL;
266 static float *rhotRED =
NULL;
267 static float *rhotNIR7 =
NULL;
268 static float *rhot16 =
NULL;
269 static float *sst_stdev =
NULL;
272 static int32_t recnumSST = -1;
273 static int haveSST4 = 0;
274 static int haveSST = 0;
275 static int haveSSES = 1;
276 static int haveRed = 0;
277 static int ib07 = -1;
278 static int ib08 = -1;
279 static int ib16 = -1;
280 static int ib37 = -1;
281 static int ib39 = -1;
282 static int ib40 = -1;
283 static int ib67 = -1;
284 static int ib73 = -1;
285 static int ib85 = -1;
286 static int ib11 = -1;
287 static int ib12 = -1;
288 static int ibred = -1;
289 static int nbvis = -1;
290 static int nbir = -1;
295 static int fullscanpix = 1354;
296 static int32_t cldbox = 3;
297 static int32_t cldboxv = 5;
298 static int sstboxcscan = -1;
299 static float cldthresh = 0.01;
300 static float cldthreshv = 0.04;
302 static int32_t btbox = 3;
306 static int32_t btboxv = 5;
307 static int32_t csstbox = -1;
308 static float hisenz = 55.0;
309 static float hisenza = 45.0;
310 static float vhisenz = 75.0;
311 static float vhisenza = 55.0;
312 static float vhisenzv2 = 65.0;
314 static float Btmin = -4.0;
315 static float Btmina = -10.0;
317 static float Btmax = 37.0;
318 static float Btmaxa = 37.0;
320 static float Btmax40 = 35.0;
322 static float SSTmin = -1.8;
323 static float SSTmax = 40.0;
324 static float SSTmaxa = 40.0;
325 static float SSTmaxn = 37.0;
326 static float glintmax = 0.005;
327 static float dBtmin = 0.0;
328 static float dBtmax = 3.6;
329 static float dBt4min = 0.0;
330 static float dBt4max = 8.0;
331 static float SSTdiffa = 2.0;
332 static float SSTdiff = 3.0;
341 static float SSTvdiff = 5.0;
342 static float SST4diff1 = -0.8;
343 static float SST4diff2 = -1.0;
344 static float SST3diff1 = 0.8;
345 static float SST3diff2 = 1.0;
347 static float Bt11unif1 = 0.7;
348 static float Bt12unif1 = 0.7;
349 static float Bt11unif2 = 1.2;
350 static float Bt12unif2 = 1.2;
351 static float Bt37unif1 = 0.7;
352 static float Bt37unif2 = 1.2;
353 static float Bt39unif1 = 0.7;
354 static float Bt40unif1 = 0.7;
355 static float Bt39unif2 = 1.2;
356 static float Bt40unif2 = 1.2;
357 static float dBtrefmin = -1.1;
358 static float dBtrefmax = 10.0;
360 static float equatorialNorth = 30.0;
361 static float equatorialSouth = -10.0;
362 static float equatorialWest = -105.0;
363 static float equatorialEast = 105.0;
368 static float latwin = 2.5;
370 static int32 tmonth = -1;
372 static int StartOfMonth[2][12] = {
373 { 0, 31, 59, 90, 120, 151, 181, 212, 243,
375 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
384 float btrefdiffv6(int32_t ip,
float BT39,
float BT40, l2str *l2rec) {
396 satzdir = (l2rec->l1rec->pixnum[ip] < fullscanpix / 2) ? -1.0 : 1.0;
397 senz = l2rec->l1rec->senz[ip] * satzdir;
418 char name[H4_MAX_NC_NAME] =
"";
419 char sdsname[H4_MAX_NC_NAME] =
"";
423 if (strcmp(
file,
"") == 0) {
424 printf(
"\nNo SSES data provided for this sensor.\n");
429 printf(
"\nLoading SSES table from %s\n",
file);
432 sd_id = SDstart(
file, DFACC_RDONLY);
434 printf(
"-E- %s line %d: Error opening file %s.\n", __FILE__, __LINE__,
442 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
446 "-E- %s line %d: Table dimensions for %s do not match expectation. got: %d expected %d\n",
455 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
456 __FILE__, __LINE__, sdsname);
461 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
462 __LINE__, sdsname,
file);
465 status = SDendaccess(sds_id);
468 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
472 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
473 __FILE__, __LINE__, sdsname);
481 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
482 __FILE__, __LINE__, sdsname);
487 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
488 __LINE__, sdsname,
file);
491 status = SDendaccess(sds_id);
495 strcpy(sdsname,
"bias_mean");
496 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
500 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
501 __FILE__, __LINE__, sdsname);
509 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
510 __FILE__, __LINE__, sdsname);
513 status = SDreaddata(sds_id,
start,
NULL, dims, (VOIDP) sses->bias_mean);
515 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
516 __LINE__, sdsname,
file);
519 status = SDendaccess(sds_id);
521 strcpy(sdsname,
"counts");
522 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
526 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
527 __FILE__, __LINE__, sdsname);
535 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
536 __FILE__, __LINE__, sdsname);
541 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
542 __LINE__, sdsname,
file);
545 status = SDendaccess(sds_id);
548 sses->nqual = dims[0];
549 sses->nlat = dims[1];
550 sses->ndiff = dims[2];
551 sses->nsenz = dims[3];
552 sses->nquar = dims[4];
553 sses->nday = dims[5];
554 sses->nsst = dims[6];
559 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
563 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
564 __LINE__, sdsname,
file);
567 status = SDendaccess(sds_id);
568 sses->nsst = dims[0];
571 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
575 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
576 __LINE__, sdsname,
file);
579 status = SDendaccess(sds_id);
580 sses->nsenz = dims[0];
582 strcpy(sdsname,
"BTdiff");
583 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
587 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
588 __LINE__, sdsname,
file);
591 status = SDendaccess(sds_id);
592 sses->ndiff = dims[0];
595 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
599 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
600 __LINE__, sdsname,
file);
603 status = SDendaccess(sds_id);
604 sses->nlat = dims[0];
624 char name[H4_MAX_NC_NAME] =
"";
625 char sdsname[H4_MAX_NC_NAME] =
"";
629 if (strcmp(
file,
"") == 0) {
630 printf(
"\nNo SSES data provided for this sensor.\n");
635 printf(
"\nLoading SSES table from %s\n",
file);
638 sd_id = SDstart(
file, DFACC_RDONLY);
640 printf(
"-E- %s line %d: Error opening file %s.\n", __FILE__, __LINE__,
648 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
652 "-E- %s line %d: Table dimensions for %s do not match expectation. got: %d expected %d\n",
661 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
662 __FILE__, __LINE__, sdsname);
667 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
668 __LINE__, sdsname,
file);
671 status = SDendaccess(sds_id);
674 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
678 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
679 __FILE__, __LINE__, sdsname);
687 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
688 __FILE__, __LINE__, sdsname);
693 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
694 __LINE__, sdsname,
file);
697 status = SDendaccess(sds_id);
701 strcpy(sdsname,
"bias_mean");
702 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
706 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
707 __FILE__, __LINE__, sdsname);
715 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
716 __FILE__, __LINE__, sdsname);
719 status = SDreaddata(sds_id,
start,
NULL, dims, (VOIDP) sses->bias_mean);
721 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
722 __LINE__, sdsname,
file);
725 status = SDendaccess(sds_id);
727 strcpy(sdsname,
"counts");
728 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
732 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
733 __FILE__, __LINE__, sdsname);
741 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
742 __FILE__, __LINE__, sdsname);
747 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
748 __LINE__, sdsname,
file);
751 status = SDendaccess(sds_id);
754 sses->nqual = dims[0];
755 sses->nlat = dims[1];
756 sses->ndiff = dims[2];
757 sses->nsenz = dims[3];
758 sses->nquar = dims[4];
759 sses->nday = dims[5];
760 sses->nsst = dims[6];
765 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
769 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
770 __LINE__, sdsname,
file);
773 status = SDendaccess(sds_id);
774 sses->nsst = dims[0];
777 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
781 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
782 __LINE__, sdsname,
file);
785 status = SDendaccess(sds_id);
786 sses->nsenz = dims[0];
788 strcpy(sdsname,
"BTdiff");
789 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
793 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
794 __LINE__, sdsname,
file);
797 status = SDendaccess(sds_id);
798 sses->ndiff = dims[0];
801 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
805 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
806 __LINE__, sdsname,
file);
809 status = SDendaccess(sds_id);
810 sses->nlat = dims[0];
830 char name[H4_MAX_NC_NAME] =
"";
831 char sdsname[H4_MAX_NC_NAME] =
"";
835 if (strcmp(
file,
"") == 0) {
836 printf(
"\nNo SSES data provided for this sensor.\n");
841 printf(
"\nLoading SSES table from %s\n",
file);
844 sd_id = SDstart(
file, DFACC_RDONLY);
846 printf(
"-E- %s line %d: Error opening file %s.\n", __FILE__, __LINE__,
854 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
858 "-E- %s line %d: Table dimensions for %s do not match expectation. got: %d expected %d\n",
866 printf(
"%d,%d,%d,%d,%d,%d,%d\n",dims[0],dims[1],dims[2],dims[3],dims[4],dims[5],dims[6]);
868 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
869 __FILE__, __LINE__, sdsname);
874 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
875 __LINE__, sdsname,
file);
878 status = SDendaccess(sds_id);
881 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
885 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
886 __FILE__, __LINE__, sdsname);
894 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
895 __FILE__, __LINE__, sdsname);
900 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
901 __LINE__, sdsname,
file);
904 status = SDendaccess(sds_id);
908 strcpy(sdsname,
"bias_mean");
909 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
913 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
914 __FILE__, __LINE__, sdsname);
922 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
923 __FILE__, __LINE__, sdsname);
958 status = SDendaccess(sds_id);
961 sses->nqual = dims[0];
962 sses->nlat = dims[1];
963 sses->ndiff = dims[2];
964 sses->nsenz = dims[3];
965 sses->nquar = dims[4];
966 sses->nday = dims[5];
967 sses->nsst = dims[6];
972 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
976 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
977 __LINE__, sdsname,
file);
980 status = SDendaccess(sds_id);
981 sses->nsst = dims[0];
984 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
988 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
989 __LINE__, sdsname,
file);
992 status = SDendaccess(sds_id);
993 sses->nsenz = dims[0];
995 strcpy(sdsname,
"BTdiff");
996 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1000 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1001 __LINE__, sdsname,
file);
1004 status = SDendaccess(sds_id);
1005 sses->ndiff = dims[0];
1008 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1012 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1013 __LINE__, sdsname,
file);
1016 status = SDendaccess(sds_id);
1017 sses->nlat = dims[0];
1020 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1024 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1025 __LINE__, sdsname,
file);
1028 status = SDendaccess(sds_id);
1029 sses->nlat = dims[0];
1049 char name[H4_MAX_NC_NAME] =
"";
1050 char sdsname[H4_MAX_NC_NAME] =
"";
1054 if (strcmp(
file,
"") == 0) {
1055 printf(
"\nNo SSES data provided for this sensor.\n");
1060 printf(
"\nLoading SSES table from %s\n",
file);
1063 sd_id = SDstart(
file, DFACC_RDONLY);
1065 printf(
"-E- %s line %d: Error opening file %s.\n", __FILE__, __LINE__,
1073 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1077 "-E- %s line %d: Table dimensions for %s do not match expectation. got: %d expected %d\n",
1085 printf(
"%d,%d,%d,%d,%d,%d,%d\n",dims[0],dims[1],dims[2],dims[3],dims[4],dims[5],dims[6]);
1087 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1088 __FILE__, __LINE__, sdsname);
1093 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1094 __LINE__, sdsname,
file);
1097 status = SDendaccess(sds_id);
1100 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1104 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1105 __FILE__, __LINE__, sdsname);
1113 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1114 __FILE__, __LINE__, sdsname);
1119 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1120 __LINE__, sdsname,
file);
1123 status = SDendaccess(sds_id);
1127 strcpy(sdsname,
"bias_mean");
1128 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1132 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1133 __FILE__, __LINE__, sdsname);
1141 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1142 __FILE__, __LINE__, sdsname);
1177 status = SDendaccess(sds_id);
1180 sses->nqual = dims[0];
1181 sses->nlat = dims[1];
1182 sses->ndiff = dims[2];
1183 sses->nsenz = dims[3];
1184 sses->nquar = dims[4];
1185 sses->nday = dims[5];
1186 sses->nsst = dims[6];
1191 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1195 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1196 __LINE__, sdsname,
file);
1199 status = SDendaccess(sds_id);
1200 sses->nsst = dims[0];
1203 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1207 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1208 __LINE__, sdsname,
file);
1211 status = SDendaccess(sds_id);
1212 sses->nsenz = dims[0];
1214 strcpy(sdsname,
"BTdiff");
1215 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1219 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1220 __LINE__, sdsname,
file);
1223 status = SDendaccess(sds_id);
1224 sses->ndiff = dims[0];
1227 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1231 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1232 __LINE__, sdsname,
file);
1235 status = SDendaccess(sds_id);
1236 sses->nlat = dims[0];
1239 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1243 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1244 __LINE__, sdsname,
file);
1247 status = SDendaccess(sds_id);
1248 sses->nlat = dims[0];
1268 char name[H4_MAX_NC_NAME] =
"";
1269 char sdsname[H4_MAX_NC_NAME] =
"";
1273 if (strcmp(
file,
"") == 0) {
1274 printf(
"\nNo SSES data provided for this sensor.\n");
1279 printf(
"\nLoading SSES table from %s\n",
file);
1282 sd_id = SDstart(
file, DFACC_RDONLY);
1284 printf(
"-E- %s line %d: Error opening file %s.\n", __FILE__, __LINE__,
1292 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1296 "-E- %s line %d: Table dimensions for %s do not match expectation. got: %d expected %d\n",
1304 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1305 __FILE__, __LINE__, sdsname);
1310 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1311 __LINE__, sdsname,
file);
1314 status = SDendaccess(sds_id);
1317 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1321 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1322 __FILE__, __LINE__, sdsname);
1329 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1330 __FILE__, __LINE__, sdsname);
1335 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1336 __LINE__, sdsname,
file);
1339 status = SDendaccess(sds_id);
1343 strcpy(sdsname,
"bias_mean");
1344 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1348 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1349 __FILE__, __LINE__, sdsname);
1356 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1357 __FILE__, __LINE__, sdsname);
1360 status = SDreaddata(sds_id,
start,
NULL, dims, (VOIDP) sses->bias_mean);
1362 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1363 __LINE__, sdsname,
file);
1366 status = SDendaccess(sds_id);
1368 strcpy(sdsname,
"counts");
1369 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1373 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1374 __FILE__, __LINE__, sdsname);
1381 "-E- %s line %d: Table dimensions for %s do not match expectation.\n",
1382 __FILE__, __LINE__, sdsname);
1387 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1388 __LINE__, sdsname,
file);
1391 status = SDendaccess(sds_id);
1394 sses->nqual = dims[0];
1395 sses->nlat = dims[1];
1396 sses->ndiff = dims[2];
1397 sses->nsenz = dims[3];
1398 sses->nquar = dims[4];
1399 sses->nsst = dims[5];
1404 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1408 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1409 __LINE__, sdsname,
file);
1412 status = SDendaccess(sds_id);
1413 sses->nsst = dims[0];
1416 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1420 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1421 __LINE__, sdsname,
file);
1424 status = SDendaccess(sds_id);
1425 sses->nsenz = dims[0];
1427 strcpy(sdsname,
"BTdiff");
1428 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1432 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1433 __LINE__, sdsname,
file);
1436 status = SDendaccess(sds_id);
1437 sses->ndiff = dims[0];
1440 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1444 printf(
"-E- %s line %d: Error reading SDS %s from %s.\n", __FILE__,
1445 __LINE__, sdsname,
file);
1448 status = SDendaccess(sds_id);
1449 sses->nlat = dims[0];
1457 char line [200] =
"";
1463 if (nc_open(
input->sstcoeffile, NC_NOWRITE, &ncid) != NC_NOERR) {
1465 if ((fp = fopen(
input->sstcoeffile,
"r")) ==
NULL) {
1467 "-E- %s line %d: unable to open sst coef file %s for reading\n",
1468 __FILE__, __LINE__,
input->sstcoeffile);
1472 while (fgets(
line, 200, fp)) {
1473 if (
line[0] ==
'#') {
1476 sscanf(
line,
"%4s %d", mission, &datechk);
1486 if ((strcmp(mission,
"VIIR") != 0) && (datechk > 1000)) {
1489 printf(
"Using V5 coefficients to compute SST\n");
1502 extern l1qstr
l1que;
1503 int32_t
npix = l2rec->l1rec->npix;
1507 nbvis = l2rec->l1rec->l1file->nbands;
1516 ib37 =
bindex_get(3750) - l2rec->l1rec->l1file->nbands;
1517 ib39 =
bindex_get(3959) - l2rec->l1rec->l1file->nbands;
1518 ib40 =
bindex_get(4050) - l2rec->l1rec->l1file->nbands;
1519 ib67 =
bindex_get(6715) - l2rec->l1rec->l1file->nbands;
1520 ib73 =
bindex_get(7325) - l2rec->l1rec->l1file->nbands;
1521 ib85 =
bindex_get(8550) - l2rec->l1rec->l1file->nbands;
1522 ib11 =
bindex_get(11000) - l2rec->l1rec->l1file->nbands;
1523 ib12 =
bindex_get(12000) - l2rec->l1rec->l1file->nbands;
1525 if (l2rec->l1rec->l1file->sensorID ==
AVHRR) {
1526 if (strncmp(l2rec->l1rec->l1file->spatialResolution,
"4.6km", 5) == 0) {
1549 switch (l2rec->l1rec->l1file->subsensorID) {
1565 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
1576 cldthresh = cldthreshv;
1583 if (l2rec->l1rec->l1file->sensorID ==
MODIST || l2rec->l1rec->l1file->sensorID ==
MODISA) {
1586 }
else if (
l1_input->resolution == 500) {
1591 if (ib11 < 0 || ib12 < 0)
1596 if (ib39 < 0 || ib40 < 0)
1601 if (!haveSST && !haveSST4) {
1602 fprintf(
stderr,
"-E- %s line %d: no SST bands found.\n",
1603 __FILE__, __LINE__);
1613 satred = 1000.0 - 1.0;
1616 if (
l1que.nq < btbox) {
1617 fprintf(
stderr,
"-E- %s line %d: filter queue (l1que) is too small. Have %d need %d.\n",
1618 __FILE__, __LINE__,
l1que.nq, btbox);
1626 qual_sst = (int8*) calloc(
npix,
sizeof (int8));
1627 bias_sst = (
float*) calloc(
npix,
sizeof (
float));
1628 stdv_sst = (
float*) calloc(
npix,
sizeof (
float));
1629 bias_mean_sst = (
float*) calloc(
npix,
sizeof (
float));
1631 dsdi_correction = (
float*) calloc(
npix,
sizeof (
float));
1633 treesum = (
float*) calloc(
npix,
sizeof (
float));
1635 if (l2rec->l1rec->l1file->sensorID ==
AVHRR) {
1639 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
1650 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
1653 qual_sst3 = (int8*) calloc(
npix,
sizeof (int8));
1654 bias_sst3 = (
float*) calloc(
npix,
sizeof (
float));
1655 stdv_sst3 = (
float*) calloc(
npix,
sizeof (
float));
1656 bias_mean_sst3 = (
float*) calloc(
npix,
sizeof (
float));
1667 qual_sst4 = (int8*) calloc(
npix,
sizeof (int8));
1668 bias_sst4 = (
float*) calloc(
npix,
sizeof (
float));
1669 stdv_sst4 = (
float*) calloc(
npix,
sizeof (
float));
1670 bias_mean_sst4 = (
float*) calloc(
npix,
sizeof (
float));
1675 d3940ref = (
float*) calloc(
npix,
sizeof (
float));
1677 rhoCirrus_maxmin = (
float*) calloc(
npix,
sizeof (
float));
1678 rhoCirrus_min = (
float*) calloc(
npix,
sizeof (
float));
1679 rhoCirrus_max = (
float*) calloc(
npix,
sizeof (
float));
1682 LtRED_maxmin = (
float*) calloc(
npix,
sizeof (
float));
1683 rhotRED_maxmin = (
float*) calloc(
npix,
sizeof (
float));
1684 rhotRED_min = (
float*) calloc(
npix,
sizeof (
float));
1685 rhotRED_max = (
float*) calloc(
npix,
sizeof (
float));
1686 rhotRED = (
float*) calloc(
npix,
sizeof (
float));
1689 Bt11_maxmin = (
float*) calloc(
npix,
sizeof (
float));
1690 Bt11_max = (
float*) calloc(
npix,
sizeof (
float));
1691 Bt11_min = (
float*) calloc(
npix,
sizeof (
float));
1692 Bt11_stdev = (
float*) calloc(
npix,
sizeof (
float));
1695 Bt12_maxmin = (
float*) calloc(
npix,
sizeof (
float));
1696 Bt12_min = (
float*) calloc(
npix,
sizeof (
float));
1699 Bt37_maxmin = (
float*) calloc(
npix,
sizeof (
float));
1700 Bt37_stdev = (
float*) calloc(
npix,
sizeof (
float));
1703 Bt73_max = (
float*) calloc(
npix,
sizeof (
float));
1706 Bt85_min = (
float*) calloc(
npix,
sizeof (
float));
1709 rhotNIR7_min = (
float*) calloc(
npix,
sizeof (
float));
1710 rhotNIR7 = (
float*) calloc(
npix,
sizeof (
float));
1713 rhot16_min = (
float*) calloc(
npix,
sizeof (
float));
1714 rhot16 = (
float*) calloc(
npix,
sizeof (
float));
1717 Bt39_maxmin = (
float*) calloc(
npix,
sizeof (
float));
1720 Bt40_maxmin = (
float*) calloc(
npix,
sizeof (
float));
1721 Bt40_stdev = (
float*) calloc(
npix,
sizeof (
float));
1726 sst_stdev = (
float*) calloc(
npix,
sizeof (
float));
1728 csstbox =
l1que.nq / 2;
1750 char mission[5] =
"";
1751 char mission2[5] =
"";
1754 char line [200] =
"";
1755 char odates [8] =
"";
1756 char sdates [8] =
"";
1757 char edates [8] =
"";
1766 int32
sensorID = l2rec->l1rec->l1file->sensorID;
1767 double pasutime = l2rec->l1rec->scantime;
1788 fp = fopen(
input->sstcoeffile,
"r");
1792 sprintf(odates,
"%4d%03d",
year,
day);
1797 while (fgets(
line, 200, fp)) {
1798 if (
line[0] ==
'#') {
1800 if (!(
p = strchr(
line,
'=')))
1810 name[p2 -
p1 + 1] =
'\0';
1829 if (strncmp(
line, mission, 4) == 0) {
1830 sscanf(
line,
"%4s %7s %7s %f %f %f %f",
1831 mission2, sdates, edates, &coef[indx][0], &coef[indx][1], &coef[indx][2], &coef[indx][3]);
1832 coef[indx][4] = 0.0;
1833 if (strcmp(odates, sdates) >= 0 && (strcmp(odates, edates) <= 0
1834 || strcmp(edates,
"0000000") == 0
1835 || strcmp(edates,
"") == 0)) {
1846 if (found == 0 &&
year > 2004) {
1847 printf(
"Warning: No SST coefficients available for %s, reverting to previous year.\n", odates);
1857 printf(
"Loading SST coefficients from %s:\n",
input->sstcoeffile);
1858 printf(
"%s %s %6.3f %6.3f %6.3f %6.3f %6.3f\n", sdates, edates, coef[0][0], coef[0][1], coef[0][2], coef[0][3], coef[0][4]);
1859 printf(
"%s %s %6.3f %6.3f %6.3f %6.3f %6.3f\n\n", sdates, edates, coef[1][0], coef[1][1], coef[1][2], coef[1][3], coef[1][4]);
1861 printf(
" sst reference day offset = %f\n", *sstrefoffday);
1862 printf(
" sst reference night offset = %f\n", *sstrefoffnight);
1865 "-E- %s line %d: unable to locate valid SST coefficients for %s in %s\n",
1866 __FILE__, __LINE__, odates,
input->sstcoeffile);
1880 float *sstrefoffday,
float *sstrefoffnight) {
1881 char mission[5] =
"";
1882 char mission2[5] =
"";
1885 char line[200] =
"";
1886 char odatel[14] =
"";
1887 char sdatel[14] =
"";
1888 char edatel[14] =
"";
1889 char odates[8] =
"";
1890 char sdates[8] =
"";
1891 char edates[8] =
"";
1894 char *coeflabel[] ={
"day dry ",
"day moist ",
"night dry ",
"night moist "};
1902 int32 gotsstrefoffday = 0;
1903 int32 gotsstrefoffnight = 0;
1909 int32
sensorID = l2rec->l1rec->l1file->sensorID;
1910 double pasutime = l2rec->l1rec->scantime;
1942 if ((fp = fopen(
input->sstcoeffile,
"r")) ==
NULL) {
1944 "-E- %s line %d: unable to open sst coef file %s for reading\n",
1945 __FILE__, __LINE__,
input->sstcoeffile);
1951 for (tmonth = 11; tmonth >= 0; tmonth--) {
1953 if (
day > StartOfMonth[
leap][tmonth]) {
1970 ztime =
ydhmsf(pasutime,
'G');
1978 while (fgets(
line, 200, fp)) {
1979 if (
line[0] ==
'#') {
1981 if (!(
p = strchr(
line,
'=')))
1991 name[p2 -
p1 + 1] =
'\0';
2010 if (strcmp(
name,
"sstref_day_offset") == 0) {
2012 gotsstrefoffday = 1;
2014 if (strcmp(
name,
"sstref_night_offset") == 0) {
2016 gotsstrefoffnight = 1;
2021 if (strncmp(
line, mission, 4) == 0) {
2022 if (
input->viirsnosisaf == 1) {
2023 sscanf(
line,
"%4s %7s %7s %1s %f %f %f %f %f %f %f",
2024 mission2, sdates, edates, dorn,
2025 &coef[indx][0], &coef[indx][1], &coef[indx][2],
2026 &coef[indx][3], &coef[indx][4], &coef[indx][5],
2028 }
else if (
input->viirsnv7 >= 0) {
2031 "%4s %7s %6s %7s %6s %f %f %f %f %f %f %f %f %f",
2032 mission2, sdates, stime, edates, etime,
2034 &coef[indx][0], &coef[indx][1], &coef[indx][2],
2035 &coef[indx][3], &coef[indx][4], &coef[indx][5],
2037 sprintf(sdatel,
"%s%s", sdates, stime);
2038 sprintf(edatel,
"%s%s", edates, etime);
2039 if (strcmp(odatel, sdatel) >= 0
2040 && (strcmp(odatel, edatel) <= 0
2041 || strcmp(edates,
"0000000") == 0
2042 || strcmp(edates,
"") == 0)) {
2052 sscanf(
line,
"%4s %d %f %f %f %f %f %f %f %f",
2054 &coef[indx][0], &coef[indx][1], &coef[indx][2],
2055 &coef[indx][3], &coef[indx][5], &coef[indx][6]);
2057 coef[indx][4] = 0.0;
2058 if (month == tmonth + 1) {
2076 while (fgets(
line, 200, fp)) {
2077 if (
line[0] ==
'#') {
2079 if (!(
p = strchr(
line,
'=')))
2089 name[p2 -
p1 + 1] =
'\0';
2108 if (strcmp(
name,
"sstref_day_offset") == 0) {
2110 gotsstrefoffday = 1;
2112 if (strcmp(
name,
"sstref_night_offset") == 0) {
2114 gotsstrefoffnight = 1;
2119 if (strncmp(
line, mission, 4) == 0) {
2120 if (l2rec->l1rec->l1file->sensorID ==
MODIST || l2rec->l1rec->l1file->sensorID ==
MODISA) {
2123 "%4s %d %f %f %f %f %f %f %f %f %f %d %f %f",
2124 mission2, &month, &
bounds[indx][0],
2125 &
bounds[indx][1], &coef[indx][0],
2126 &coef[indx][1], &coef[indx][2], &coef[indx][3],
2127 &coef[indx][4], &coef[indx][5], &coef[indx][6],
2128 &tmp1, &tmp2, &tmp3);
2131 sscanf(
line,
"%4s %d %f %f %f %f %f %f", mission2,
2133 &coef[indx][0], &coef[indx][1], &coef[indx][2],
2135 coef[indx][4] = 0.0;
2136 coef[indx][5] = 0.0;
2137 coef[indx][6] = 0.0;
2139 if (month == tmonth + 1) {
2156 && (gotsstrefoffday == 0 || gotsstrefoffnight == 0)) {
2158 "-E- %s line %d: Day and night sst reference offsets not found in %s\n",
2159 __FILE__, __LINE__,
input->sstcoeffile);
2163 printf(
"Loading SST lat band coefficients from %s:\n",
2164 input->sstcoeffile);
2168 for (indx = 0; indx < 4; indx++) {
2169 printf(
"%s %s %s %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
2170 coeflabel[indx], sdates, edates, coef[indx][0], coef[indx][1], coef[indx][2],
2171 coef[indx][3], coef[indx][4], coef[indx][5], coef[indx][6]);
2174 for (indx = 0; indx < 7; indx++) {
2178 "%s %s %s %s %6.1f %6.1f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
2179 sdates, stime, edates, etime,
bounds[indx][0],
bounds[indx][1],
2180 coef[indx][0], coef[indx][1], coef[indx][2], coef[indx][3],
2181 coef[indx][4], coef[indx][5], coef[indx][6]);
2185 "%d %6.1f %6.1f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
2186 month,
bounds[indx][0],
bounds[indx][1], coef[indx][0],
2187 coef[indx][1], coef[indx][2], coef[indx][3],
2188 coef[indx][4], coef[indx][5], coef[indx][6]);
2192 printf(
" sst reference day offset = %f\n", *sstrefoffday);
2193 printf(
" sst reference night offset = %f\n", *sstrefoffnight);
2197 "-E- %s line %d: unable to locate valid SST coefficients for %s in %s\n",
2198 __FILE__, __LINE__, odates,
input->sstcoeffile);
2212 float **
bounds,
float **coef) {
2218 line = (
char *) calloc(200,
sizeof (
char));
2249 fprintf(
stderr,
"-E- %s line %d: unable to open %s for reading\n",
2254 sprintf(odate,
"%4d%03d",
year,
day);
2259 for (tmonth = 11; tmonth >= 0; tmonth--) {
2260 if (
day > StartOfMonth[
leap][tmonth]) {
2267 fprintf(
stderr,
" looking for month %d mission %s\n", tmonth + 1, mission);
2268 while (fgets(
line, 200, fp)) {
2270 if (strncmp(
line, mission, 4) == 0) {
2271 sscanf(
line,
"%4s %d %f %f %f %f %f %f %f %f %f", &mission2[0],
2272 &month, &
bounds[indx][0], &
bounds[indx][1], &coef[indx][0],
2273 &coef[indx][1], &coef[indx][2], &coef[indx][3],
2274 &coef[indx][4], &coef[indx][5], &coef[indx][6]);
2275 if (month == tmonth + 1) {
2289 printf(
"Loading SST4 lat band coefficients from %s:\n",
filename);
2290 for (indx = 0; indx < 7; indx++) {
2291 printf(
"%d %6.1f %6.1f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
2292 month,
bounds[indx][0],
bounds[indx][1], coef[indx][0], coef[indx][1], coef[indx][2],
2293 coef[indx][3], coef[indx][4], coef[indx][5], coef[indx][6]);
2298 "-E- %s line %d: unable to locate valid SST4 coefficients for %s in %s\n",
2299 __FILE__, __LINE__, odate,
filename);
2313 int sstcloud(int32_t ip, int32_t nx, int32_t ny,
float thresh) {
2314 extern l1qstr
l1que;
2335 "-E- %s line %d: L1 queue size of %d is too small for requested homogeneity test of %d x %d.\n",
2336 __FILE__, __LINE__,
l1que.nq, nx, ny);
2341 if (
l1que.r[
is].solz[ip] >= solznight
2342 ||
l1que.r[
is].glint_coef[ip] > glintmax)
2371 for (
j = is1;
j <= is2;
j++)
2372 for (
i = ip1;
i <= ip2;
i++) {
2373 ipb =
i * nbvis + ibred;
2374 if (
l1que.r[
j].Lt[ipb] > 0.0 &&
l1que.r[
j].Lt[ipb] < satred) {
2379 maxv =
MAX(maxv, rhot);
2380 minv =
MIN(minv, rhot);
2386 if (cnt < 2 || (maxv - minv) > thresh) {
2397 int32_t
rhoCboxstats(int32_t ip, int32_t nx, int32_t ny, statstr *statrec) {
2398 extern l1qstr
l1que;
2400 static int32_t len = 0;
2405 int32_t
is,
i,
j, ix;
2407 static float *
x =
NULL;
2412 printf(
"-E- %s line %d: L1 queue size of %d is too small for %d x %d box stats.\n",
2413 __FILE__, __LINE__,
l1que.nq, nx, ny);
2418 if (
x ==
NULL || len < nx * ny) {
2421 if ((
x = (
float *) malloc(len *
sizeof (
float))) ==
NULL) {
2422 printf(
"-E- %s line %d: Unable to allocate workspace for median and stdev\n",
2423 __FILE__, __LINE__);
2452 statrec->min = -1.0 *
BAD_FLT;
2460 for (ix = 0; ix < len; ix++) {
2465 for (
j = is1;
j <= is2;
j++)
for (
i = ip1;
i <= ip2;
i++) {
2466 Bt =
l1que.r[
j].rho_cirrus[
i];
2468 statrec->max =
MAX(statrec->max, Bt);
2469 statrec->min =
MIN(statrec->min, Bt);
2470 if (statrec->cnt == 0) {
2475 statrec->sqr += Bt * Bt;
2476 x[statrec->cnt] = Bt;
2480 if (statrec->cnt > 2) {
2481 qsort(
x, statrec->cnt, sizeof (
float), (
int (*)(
const void *,
const void *))
compfloat);
2482 statrec->max =
x[statrec->cnt - 1];
2483 statrec->min =
x[0];
2484 if (statrec->cnt > 1) {
2485 statrec->sd = (statrec->sqr - statrec->avg * statrec->avg / statrec->cnt) / (statrec->cnt - 1);
2486 if (statrec->sd > 0.0) {
2487 statrec->sd = sqrt(statrec->sd);
2493 statrec->med =
x[statrec->cnt / 2];
2495 if (statrec->cnt > 0)
2496 statrec->avg /= statrec->cnt;
2498 return (statrec->cnt);
2508 extern l1qstr
l1que;
2510 static int32_t len = 0;
2515 int32_t
is,
i,
j, ix;
2519 static float *
x =
NULL;
2524 "-E- %s line %d: L1 queue size of %d is too small for %d x %d box stats.\n",
2525 __FILE__, __LINE__,
l1que.nq, nx, ny);
2530 if (
x ==
NULL || len < nx * ny) {
2533 if ((
x = (
float *) malloc(len *
sizeof (
float))) ==
NULL) {
2534 printf(
"-E- %s line %d: Unable to allocate workspace for median and stdev\n",
2535 __FILE__, __LINE__);
2564 statrec->min = -1.0 *
BAD_FLT;
2572 for (ix = 0; ix < len; ix++) {
2577 for (
j = is1;
j <= is2;
j++)
2578 for (
i = ip1;
i <= ip2;
i++) {
2581 if (
l1que.r[
j].Lt[ipb] > sstbad + 1.0 &&
l1que.r[
j].Lt[ipb] < 1000.0 - 1.0) {
2583 statrec->max =
MAX(statrec->max, rhot);
2584 statrec->min =
MIN(statrec->min, rhot);
2585 if (statrec->cnt == 0) {
2589 statrec->avg += rhot;
2590 statrec->sqr += rhot * rhot;
2591 x[statrec->cnt] = rhot;
2595 if (statrec->cnt > 2) {
2596 qsort(
x, statrec->cnt, sizeof (
float), (
int (*)(
const void *,
const void *))
compfloat);
2597 statrec->max =
x[statrec->cnt - 1];
2598 statrec->min =
x[0];
2599 if (statrec->cnt > 1) {
2600 statrec->sd = (statrec->sqr - statrec->avg * statrec->avg / statrec->cnt) / (statrec->cnt - 1);
2601 if (statrec->sd > 0.0) {
2602 statrec->sd = sqrt(statrec->sd);
2608 statrec->med =
x[statrec->cnt / 2];
2610 if (statrec->cnt > 0)
2611 statrec->avg /= statrec->cnt;
2613 return (statrec->cnt);
2624 extern l1qstr
l1que;
2626 static int32_t len = 0;
2631 int32_t
is,
i,
j, ix;
2634 static float *
x =
NULL;
2639 "-E- %s line %d: L1 queue size of %d is too small for %d x %d box stats.\n",
2640 __FILE__, __LINE__,
l1que.nq, nx, ny);
2645 if (
x ==
NULL || len < nx * ny) {
2648 if ((
x = (
float *) malloc(len *
sizeof (
float))) ==
NULL) {
2649 printf(
"-E- %s line %d: Unable to allocate workspace for median and stdev\n",
2650 __FILE__, __LINE__);
2679 statrec->min = -1.0 *
BAD_FLT;
2687 for (ix = 0; ix < len; ix++) {
2692 for (
j = is1;
j <= is2;
j++) {
2697 || (
l1que.r[
j].detnum != 0)) {
2699 for (
i = ip1;
i <= ip2;
i++) {
2703 statrec->max =
MAX(statrec->max, Bt);
2704 statrec->min =
MIN(statrec->min, Bt);
2705 if (statrec->cnt == 0) {
2711 statrec->sqr += Bt * Bt;
2712 x[statrec->cnt] = Bt;
2718 if (statrec->cnt > 2) {
2719 qsort(
x, statrec->cnt, sizeof (
float), (
int (*)(
const void *,
const void *))
compfloat);
2720 statrec->max =
x[statrec->cnt - 1];
2721 statrec->min =
x[0];
2722 if (statrec->cnt > 1) {
2723 statrec->sd = (statrec->sqr - statrec->avg * statrec->avg / statrec->cnt) / (statrec->cnt - 1);
2724 if (statrec->sd > 0.0) {
2725 statrec->sd = sqrt(statrec->sd);
2731 statrec->med =
x[statrec->cnt / 2];
2733 if (statrec->cnt > 0) {
2734 statrec->avg /= statrec->cnt;
2737 return (statrec->cnt);
2746 int32_t
sstboxstats(int32_t ip, int32_t nx, int32_t ny, statstr *statrec) {
2747 extern l1qstr
l1que;
2749 static int32_t len = 0;
2754 int32_t
is,
i,
j, ix;
2757 static float *
x =
NULL;
2762 "-E- %s line %d: sst queue size of %d is too small for %d x %d box stats.\n",
2763 __FILE__, __LINE__,
nscan, nx, ny);
2768 if (
x ==
NULL || len < nx * ny) {
2771 if ((
x = (
float *) malloc(len *
sizeof (
float))) ==
NULL) {
2772 printf(
"-E- %s line %d: Unable to allocate workspace for median and stdev\n",
2773 __FILE__, __LINE__);
2802 statrec->min = -1.0 *
BAD_FLT;
2810 for (ix = 0; ix < len; ix++) {
2815 for (
j = is1;
j <= is2;
j++) {
2816 for (
i = ip1;
i <= ip2;
i++) {
2818 if (sst >= SSTmin && sst <= SSTmax) {
2819 statrec->max =
MAX(statrec->max, sst);
2820 statrec->min =
MIN(statrec->min, sst);
2821 if (statrec->cnt == 0) {
2826 statrec->avg += sst;
2827 statrec->sqr += sst * sst;
2828 x[statrec->cnt] = sst;
2833 if (statrec->cnt > 2) {
2834 qsort(
x, statrec->cnt, sizeof (
float), (
int (*)(
const void *,
const void *))
compfloat);
2835 statrec->max =
x[statrec->cnt - 1];
2836 statrec->min =
x[0];
2837 if (statrec->cnt > 1) {
2838 statrec->sd = (statrec->sqr - statrec->avg * statrec->avg / statrec->cnt) / (statrec->cnt - 1);
2839 if (statrec->sd > 0.0) {
2840 statrec->sd = sqrt(statrec->sd);
2846 statrec->med =
x[statrec->cnt / 2];
2848 if (statrec->cnt > 0) {
2849 statrec->avg /= statrec->cnt;
2852 return (statrec->cnt);
2862 for (ip = 0; ip <
npix; ip++) {
2863 sst_stdev[ip] = sstbad;
2864 if (
sstboxstats(ip, btbox, btbox, &statrec) > 0) {
2865 sst_stdev[ip] = statrec.sd;
2878 for (ip = 0; ip <
npix; ip++) {
2879 minarr[ip] = sstbad;
2881 minarr[ip] = statrec.min;
2894 for (ip = 0; ip <
npix; ip++) {
2895 maxminarr[ip] = sstbad;
2896 maxarr[ip] = sstbad;
2898 maxminarr[ip] = statrec.max - statrec.min;
2899 maxarr[ip] = statrec.max;
2912 for (ip = 0; ip <
npix; ip++) {
2913 avgarr[ip] = sstbad;
2915 avgarr[ip] = statrec.avg;
2928 for (ip = 0; ip <
npix; ip++) {
2929 maxminarr[ip] = sstbad;
2931 maxminarr[ip] = statrec.max - statrec.min;
2943 for (ip = 0; ip <
npix; ip++) {
2944 minarr[ip] = sstbad;
2946 minarr[ip] = statrec.min;
2958 for (ip = 0; ip <
npix; ip++) {
2959 maxarr[ip] = sstbad;
2961 maxarr[ip] = statrec.max;
2970 for (ip = 0; ip <
npix; ip++) {
2971 maxminarr[ip] = sstbad;
2972 minarr[ip] = sstbad;
2973 maxarr[ip] = sstbad;
2975 maxminarr[ip] = statrec.max - statrec.min;
2976 minarr[ip] = statrec.min;
2977 maxarr[ip] = statrec.max;
2985 for (ip = 0; ip <
npix; ip++) {
2986 stdevarr[ip] = sstbad;
2988 stdevarr[ip] = statrec.sd;
2999 extern l1qstr
l1que;
3010 || (
l1que.r[
is].detnum != 0)) {
3012 "-E- %s line %d: btavg should only be used for AQUA detector zero Bt40.\n",
3013 __FILE__, __LINE__);
3023 if ((
nscan < (btbox + 2)) && (
is == 0 ||
is == btbox)) {
3025 "-E- %s line %d: L1 queue size of %d is too small for 3 line Bt40 average around line %d.\n",
3026 __FILE__, __LINE__,
l1que.nq,
is);
3035 statrec->min = -1.0 *
BAD_FLT;
3045 for (
j = is1;
j <= is2;
j += 2) {
3051 if (statrec->cnt == 0) {
3060 if (statrec->cnt > 0)
3061 statrec->avg /= statrec->cnt;
3063 return (statrec->cnt);
3083 extern l1qstr
l1que;
3094 "-E- %s line %d: L1 queue size of %d is too small for %d line box stats.\n",
3095 __FILE__, __LINE__,
l1que.nq, ny);
3106 cpix = (fullscanpix - 1) / 2;
3120 for (jj = 0; jj <
nscan - 1; jj++) {
3121 diflats[jj] =
l1que.r[jj].lat[cpix] -
l1que.r[jj + 1].lat[cpix];
3124 if ((diflats[
is - 1] > 0.0 && diflats[
is] > 0.0) ||
3125 (diflats[
is - 1] < 0.0 && diflats[
is] < 0.0)) {
3126 *diflat = diflats[
is];
3130 if ((diflats[
is] > 0.0 && diflats[
is + 1] > 0.0) ||
3131 (diflats[
is] < 0.0 && diflats[
is + 1] < 0.0)) {
3132 *diflat = diflats[
is];
3135 *diflat = diflats[
is - 1];
3142 if (*diflat < 0.0) {
3159 extern l1qstr
l1que;
3160 int32_t
npix = l2rec->l1rec->npix;
3162 int32_t ip, ipb, ipbir;
3181 float dBt_11_12, dBt_37_11, dBt_37_12, dBt_11_37, dBt_67_11;
3182 float dBt_40_11, dBt_85_11;
3184 float subsolar, xdoy, xrad;
3189 cpix = (fullscanpix - 1) / 2;
3196 for (ip = 0; ip <
npix; ip++) {
3199 if (
sstmasked(l2rec->l1rec->flags, ip)) {
3204 ipb = ip * l2rec->l1rec->l1file->nbands;
3209 Bt37 = l2rec->l1rec->Bt[ipbir + ib37];
3210 Bt85 = l2rec->l1rec->Bt[ipbir + ib85];
3211 Bt11 = l2rec->l1rec->Bt[ipbir + ib11];
3212 Bt12 = l2rec->l1rec->Bt[ipbir + ib12];
3214 LtRED = l2rec->l1rec->Lt[ipb + ibred];
3217 if (l2rec->l1rec->l1file->sensorID ==
AVHRR) {
3218 LtNIR8 = l2rec->l1rec->Lt[ipb + ib08];
3220 rhoCirrus = l2rec->l1rec->rho_cirrus[ip];
3221 if (l2rec->l1rec->l1file->sensorID ==
MODIST || l2rec->l1rec->l1file->sensorID ==
MODISA) {
3222 Bt39 = l2rec->l1rec->Bt[ipbir + ib39];
3224 if (l2rec->l1rec->l1file->sensorID ==
MODISA && l2rec->l1rec->detnum == 0) {
3232 Bt40 = l2rec->l1rec->Bt[ipbir + ib40];
3233 Bt67 = l2rec->l1rec->Bt[ipbir + ib67];
3234 }
else if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
3235 Bt40 = l2rec->l1rec->Bt[ipbir + ib40];
3236 LtNIR7 = l2rec->l1rec->Lt[ipb + ib07];
3237 Lt16 = l2rec->l1rec->Lt[ipb + ib16];
3242 if (Bt11 < BT_LO + 0.1 || Bt11 >
BT_HI - 0.1 || Bt12 <
BT_LO + 0.1
3243 || Bt12 >
BT_HI - 0.1) {
3249 if (Bt11 < Btmin || Bt11 > Btmax || Bt12 < Btmin || Bt12 > Btmax)
3252 if (l2rec->l1rec->l1file->sensorID ==
AVHRR) {
3257 if (l2rec->l1rec->solz[ip] < solznight) {
3258 if (l2rec->l1rec->glint_coef[ip] > glintmax)
3274 if ((l2rec->l1rec->l1file->subsensorID ==
NO07
3275 || l2rec->l1rec->l1file->subsensorID ==
NO09
3276 || l2rec->l1rec->l1file->subsensorID ==
NO10
3277 || l2rec->l1rec->l1file->subsensorID ==
NO11
3278 || l2rec->l1rec->l1file->subsensorID ==
NO12
3279 || l2rec->l1rec->l1file->subsensorID ==
NO14
3280 || l2rec->l1rec->l1file->subsensorID ==
NO15)
3281 && (l2rec->l1rec->solz[ip] >= solznight
3282 || (l2rec->l1rec->solz[ip] < solznight
3283 && l2rec->l1rec->glint_coef[ip] <= glintmax))) {
3284 if (Bt37 < Btmin || Bt37 > Btmax) {
3290 if ((l2rec->l1rec->l1file->subsensorID ==
NO16
3291 || l2rec->l1rec->l1file->subsensorID ==
NO17
3292 || l2rec->l1rec->l1file->subsensorID ==
NO18
3293 || l2rec->l1rec->l1file->subsensorID ==
NO19)
3294 && l2rec->l1rec->solz[ip] >= solznight) {
3295 if (Bt37 < Btmin || Bt37 > Btmax) {
3308 if ((l2rec->l1rec->l1file->sensorID ==
MODIST || l2rec->l1rec->l1file->sensorID ==
MODISA)) {
3311 if (l2rec->l1rec->solz[ip] >= solznight
3312 && (Bt37 < Btmin || Bt37 > Btmax || Bt39 < Btmin
3313 || Bt39 > Btmax || Bt40 < Btmin || Bt40 > Btmax40)) {
3317 if ((l2rec->l1rec->solz[ip] < solznight
3318 && l2rec->l1rec->glint_coef[ip] <= glintmax)
3319 && (Bt37 < Btmin || Bt39 < Btmin || Bt40 < Btmin)) {
3324 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
3326 if (l2rec->l1rec->solz[ip] >= solznight
3327 && (Bt37 < Btmin || Bt37 > Btmax || Bt40 < Btmin
3328 || Bt40 > Btmax40)) {
3333 if ((l2rec->l1rec->solz[ip] < solznight
3334 && l2rec->l1rec->glint_coef[ip] <= glintmax)
3335 && (Bt37 < Btmin || Bt40 < Btmin)) {
3341 dBt_11_12 = Bt11 - Bt12;
3342 if (dBt_11_12 < dBtmin || dBt_11_12 > dBtmax)
3346 if ((sstq[csstbox][ip] < SSTmin)
3347 || (l2rec->l1rec->solz[ip] < solznight && sstq[csstbox][ip] > SSTmax)
3348 || (l2rec->l1rec->solz[ip] >= solznight && sstq[csstbox][ip] > SSTmaxn)) {
3356 dSST_ref = sstq[csstbox][ip] - l2rec->l1rec->sstref[ip];
3358 if ((evalmask &
SSTMODS) == 0) {
3361 if (dSST_ref < -SSTdiff || l2rec->
l1rec->sstref[ip] < sstbad + 1.0)
3363 if (dSST_ref < -input->sstrefdif &&
3364 l2rec->l1rec->lat[ip] >= equatorialSouth && l2rec->l1rec->lat[ip] <= equatorialNorth &&
3365 l2rec->l1rec->lon[ip] >= equatorialWest && l2rec->l1rec->lon[ip] <= equatorialEast) {
3371 if (l2rec->l1rec->solz[ip] >= solznight) {
3372 if (
fabs(dSST_ref) > SSTdiff)
3376 if (dSST_ref < -SSTvdiff || l2rec->
l1rec->sstref[ip] < sstbad + 1.0)
3379 if (l2rec->l1rec->solz[ip] >= solznight) {
3380 if (
fabs(dSST_ref) > SSTvdiff)
3384 if (l2rec->l1rec->solz[ip] >=
SOLZNIGHT) {
3385 if (
fabs(dSST_ref) > SSTdiff)
3388 if (dSST_ref < -SSTdiff || dSST_ref > (SSTdiff + 1))
3391 if (
fabs(dSST_ref) > SSTvdiff)
3398 dSST_SST4 = sstq[csstbox][ip] - sst4q[csstbox][ip];
3399 if (sst4q[csstbox][ip] > sstbad + 1.0 && l2rec->l1rec->solz[ip] >=
SOLZNIGHT) {
3400 if (
fabs(dSST_SST4) < SST4diff1)
3402 if (
fabs(dSST_SST4) < SST4diff2)
3409 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
3410 dSST_SST3 = sstq[csstbox][ip]-sst3q[csstbox][ip];
3411 if (sst3q[csstbox][ip] > sstbad+1.0 && l2rec->l1rec->solz[ip] >=
SOLZNIGHT) {
3412 if (
fabs(dSST_SST3) > SST3diff1)
3414 if (
fabs(dSST_SST3) > SST3diff2)
3420 if (l2rec->l1rec->senz[ip] > hisenz)
3422 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
3423 if (l2rec->l1rec->senz[ip] > vhisenzv2) {
3429 if (l2rec->l1rec->senz[ip] > vhisenz)
3434 if (l2rec->l1rec->pixnum[ip] < 2 || l2rec->l1rec->pixnum[ip] > (fullscanpix - 3))
3438 if ((l2rec->l1rec->l1file->sensorID ==
MODIST) && (l2rec->l1rec->pixnum[ip] > 1349))
3445 if (sstq[csstbox][ip] > sstbad + 1.0 && l2rec->l1rec->sstref[ip] > sstbad + 1.0
3446 && sstq[csstbox][ip] - l2rec->l1rec->sstref[ip] <= -1.0)
3447 if (
sstcloud(ip, cldbox, cldbox, cldthresh) == 1)
3451 if (Bt11_maxmin[ip] > Bt11unif1)
3453 if (Bt11_maxmin[ip] > Bt11unif2)
3456 if (Bt12_maxmin[ip] > Bt12unif1)
3458 if (Bt12_maxmin[ip] > Bt12unif2)
3463 dBt_37_11 = Bt37 - Bt11;
3464 dBt_37_12 = Bt37 - Bt12;
3465 dBt_11_37 = Bt11 - Bt37;
3466 dBt_67_11 = Bt67 - Bt11;
3467 dBt_40_11 = Bt40 - Bt11;
3468 dBt_85_11 = Bt85 - Bt11;
3474 Tdeflong = (Bt11 - Bt12) / Bt11;
3476 Tdeflong = (Bt11 - Bt12) / (Bt11 + 0.00001);
3478 double pasutime = l2rec->l1rec->scantime;
3492 switch (l2rec->l1rec->l1file->subsensorID) {
3497 if (yyyyddd < 1994001) {
3499 if ((l2rec->l1rec->solz[ip] >= solznight
3500 || (l2rec->l1rec->solz[ip] < solznight
3501 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3502 && dBt_37_12 < -0.4805) {
3503 if (dBt_37_12 < -1.249) {
3505 }
else if (dBt_11_12 >= 0.239) {
3507 }
else if (Bt37_maxmin[ip] >= 0.7975
3508 && dBt_11_12 >= -0.1805) {
3512 if (dBt_11_12 < 0.307
3513 && ((l2rec->l1rec->solz[ip] >= solznight
3514 || (l2rec->l1rec->solz[ip] < solznight
3515 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3516 && Bt37_maxmin[ip] >= 1.6215)) {
3522 if ((l2rec->l1rec->solz[ip] >= solznight
3523 || (l2rec->l1rec->solz[ip] < solznight
3524 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3525 && dBt_37_12 < 0.62) {
3527 }
else if (dBt_11_12 < 0.5055
3528 && ((l2rec->l1rec->solz[ip] >= solznight
3529 || (l2rec->l1rec->solz[ip] < solznight
3530 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3531 && Bt37_maxmin[ip] >= 1.033)
3532 && Bt11_maxmin[ip] >= 0.2435) {
3540 if ((l2rec->l1rec->solz[ip] >= solznight
3541 || (l2rec->l1rec->solz[ip] < solznight && l2rec->l1rec->glint_coef[ip] <= glintmax))
3542 && dBt_37_12 < -0.581) {
3545 if (dBt_11_12 < 0.315) {
3546 if ((l2rec->l1rec->solz[ip] >= solznight
3547 || (l2rec->l1rec->solz[ip] < solznight
3548 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3549 && dBt_11_37 < -0.1855) {
3551 }
else if ((l2rec->l1rec->solz[ip] >= solznight
3552 || (l2rec->l1rec->solz[ip] < solznight
3553 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3554 && Bt37_maxmin[ip] >= 0.9555) {
3557 }
else if ((l2rec->l1rec->solz[ip] >= solznight
3558 || (l2rec->l1rec->solz[ip] < solznight
3559 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3560 && dBt_11_37 >= 0.86 && Bt37_maxmin[ip] >= 0.5035) {
3568 if (yyyyddd >= 1995001 && yyyyddd < 1996001) {
3569 if ((l2rec->l1rec->solz[ip] >= solznight
3570 || (l2rec->l1rec->solz[ip] < solznight
3571 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3572 && dBt_11_37 >= 0.8015) {
3574 }
else if ((l2rec->l1rec->solz[ip] >= solznight
3575 || (l2rec->l1rec->solz[ip] < solznight
3576 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3577 && Bt37_maxmin[ip] >= 1.216) {
3578 if (dBt_11_12 < 1.342) {
3581 }
else if (dBt_11_12 < 1.3225
3582 && ((l2rec->l1rec->solz[ip] >= solznight
3583 || (l2rec->l1rec->solz[ip] < solznight
3584 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3585 && dBt_11_37 < 0.994)) {
3588 }
else if (yyyyddd >= 1996001) {
3589 if (dBt_11_12 >= 0.755) {
3590 if ((l2rec->l1rec->solz[ip] >= solznight
3591 || (l2rec->l1rec->solz[ip] < solznight
3592 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3593 && (dBt_11_37 >= 0.7995 || LtNIR8 >= 0.7225)) {
3597 if ((l2rec->l1rec->solz[ip] >= solznight
3598 || (l2rec->l1rec->solz[ip] < solznight
3599 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3600 && (dBt_11_37 >= 1.1475 || LtNIR8 >= 1.2645
3601 || Bt37_maxmin[ip] >= 0.966)) {
3604 if (((l2rec->l1rec->solz[ip] >= solznight
3605 || (l2rec->l1rec->solz[ip] < solznight
3606 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3607 && dBt_11_37 >= 0.869)
3608 || (dBt_11_12 < 0.462
3609 && ((l2rec->l1rec->solz[ip] >= solznight
3610 || (l2rec->l1rec->solz[ip] < solznight
3611 && l2rec->l1rec->glint_coef[ip] <= glintmax))
3612 && LtNIR8 >= 0.4865))) {
3624 if (l2rec->l1rec->solz[ip] < solznight) {
3626 if ((l2rec->l1rec->glint_coef[ip] <= glintmax && LtRED >= 0.7315)
3627 || dBt_11_12 < 0.5375) {
3632 if (dBt_37_11 < -0.1025 || Bt37_maxmin[ip] >= 1.035
3633 || dBt_11_12 < 0.7385) {
3635 }
else if (Bt37_maxmin[ip] < 0.7145) {
3636 if (dBt_11_12 < 1.454) {
3639 }
else if (dBt_11_12 < 1.271) {
3640 if (dBt_37_11 >= 0.9195) {
3643 }
else if (dBt_37_11 >= 2.408 && dBt_11_12 < 2.272) {
3651 if (l2rec->l1rec->solz[ip] < solznight) {
3653 if (l2rec->l1rec->glint_coef[ip] <= glintmax && LtRED >= 0.7045) {
3655 }
else if (l2rec->l1rec->lat[ip] >= -20.0 && dBt_11_12 < 0.4355) {
3660 if (dBt_37_12 < 0.0355 || Bt37_maxmin[ip] >= 0.9035
3661 || dBt_11_12 < 0.4565 || dBt_37_11 < -0.5515) {
3663 }
else if (dBt_37_11 >= 1.635 && dBt_11_12 < 1.693) {
3670 if (l2rec->l1rec->solz[ip] < solznight) {
3673 if (l2rec->l1rec->glint_coef[ip] <= glintmax && LtRED >= 0.7045) {
3675 }
else if (dBt_11_12 < 0.4995) {
3681 if (dBt_37_12 < 0.3185) {
3683 }
else if (Bt37_maxmin[ip] >= 0.8455) {
3684 if (dBt_11_12 < 1.477) {
3687 }
else if (dBt_11_12 < 0.6605) {
3689 }
else if (dBt_37_11 < -0.5745) {
3691 }
else if (dBt_37_11 >= 2.1015 && dBt_11_12 < 2.206) {
3697 if (l2rec->l1rec->solz[ip] < solznight) {
3699 if ((l2rec->l1rec->glint_coef[ip] <= glintmax && LtRED >= 0.84648)
3700 || dBt_11_12 < 0.168655
3701 || fabsf(sstq[csstbox][ip] - l2rec->l1rec->sstref[ip]) >= 1.237905) {
3706 if (dBt_11_12 < 0.99571) {
3707 if (dBt_37_12 < -0.26932 || dBt_11_12 < 0.126555
3708 || Bt37_maxmin[ip] >= 1.02994
3709 || fabsf(sstq[csstbox][ip] - l2rec->l1rec->sstref[ip]) >= 0.758065) {
3712 }
else if (dBt_37_11 < -0.387815
3713 || fabsf(sstq[csstbox][ip] - l2rec->l1rec->sstref[ip]) >= 0.857825) {
3724 if (l2rec->l1rec->l1file->sensorID ==
MODIST) {
3725 if (l2rec->l1rec->solz[ip] < solznight
3726 && l2rec->l1rec->glint_coef[ip] <= glintmax) {
3733 if (rhotRED[ip] < 0.206 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
3734 treesum[ip] += 0.894;
3735 if (rhotRED[ip] < 0.051 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
3736 treesum[ip] += 0.540;
3737 if (l2rec->l1rec->senz[ip] < 64.915) {
3738 treesum[ip] += -0.057;
3739 if (rhoCirrus_max[ip] < 0.003 && rhoCirrus_max[ip] > (
BAD_FLT + 0.1)) {
3740 treesum[ip] += 0.087;
3741 if (l2rec->l1rec->senz[ip] < 54.529) {
3742 treesum[ip] += 0.030;
3744 treesum[ip] += -0.573;
3747 treesum[ip] += -0.828;
3750 treesum[ip] += -2.700;
3753 treesum[ip] += -0.490;
3756 if (rhoCirrus_min[ip] < 0.004 && rhoCirrus_min[ip] > (
BAD_FLT + 0.1)) {
3757 treesum[ip] += 0.210;
3758 if (rhotRED[ip] < 0.073 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
3759 treesum[ip] += 0.074;
3761 treesum[ip] += -0.467;
3764 treesum[ip] += -1.008;
3767 treesum[ip] += -1.402;
3772 if (rhotRED_min[ip] < 0.239 && rhotRED_min[ip] > (
BAD_FLT + 0.1)) {
3773 treesum[ip] += 0.821;
3775 treesum[ip] += -0.033;
3776 if (dBt_67_11 < -42.423) {
3777 treesum[ip] += 0.283;
3779 treesum[ip] += -0.184;
3783 if (dBt_37_11 < 3.493) {
3784 treesum[ip] += 0.530;
3785 if (dBt_11_12 < 0.178) {
3786 treesum[ip] += -0.589;
3788 treesum[ip] += 0.174;
3791 treesum[ip] += -0.169;
3793 if (rhoCirrus_min[ip] < 0.008 && rhoCirrus_min[ip] > (
BAD_FLT + 0.1)) {
3794 treesum[ip] += 0.097;
3796 treesum[ip] += -0.761;
3799 if (sst_stdev[ip] < 0.273 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
3800 treesum[ip] += 0.258;
3802 treesum[ip] += -0.194;
3804 if (sst_stdev[ip] < 0.119 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
3805 treesum[ip] += 0.459;
3807 treesum[ip] += -0.037;
3808 if (sstq[csstbox][ip] < 27.293) {
3809 treesum[ip] += -0.054;
3811 treesum[ip] += 0.411;
3814 }
else if (l2rec->l1rec->solz[ip] < solznight) {
3816 if (LtRED < (1000.0 - 0.1)) {
3826 if (rhotRED[ip] < 0.098 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
3827 treesum[ip] += 1.026;
3828 if (rhotRED[ip] < 0.069 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
3829 treesum[ip] += 0.290;
3831 treesum[ip] += -0.312;
3834 if (rhoCirrus < 0.002 && rhoCirrus > (
BAD_FLT + 0.1)) {
3835 treesum[ip] += 0.154;
3837 treesum[ip] += -0.574;
3840 if (Bt73_max[ip] < -10.303) {
3841 treesum[ip] += -0.150;
3843 treesum[ip] += 0.393;
3846 treesum[ip] += -0.761;
3847 if (Bt11 < 16.122) {
3848 treesum[ip] += -0.538;
3850 treesum[ip] += 0.707;
3854 if (rhoCirrus_max[ip] < 0.005 && rhoCirrus_max[ip] > (
BAD_FLT + 0.1)) {
3855 treesum[ip] += 0.357;
3856 if (Tdeflong < 0.037) {
3857 treesum[ip] += -0.450;
3858 if (l2rec->l1rec->lat[ip] < 28.270) {
3859 treesum[ip] += -0.383;
3861 treesum[ip] += 0.560;
3864 treesum[ip] += 0.134;
3866 if (l2rec->l1rec->senz[ip] < 34.756) {
3867 treesum[ip] += 0.098;
3869 treesum[ip] += -0.424;
3872 treesum[ip] += -1.399;
3874 if (rhoCirrus_min[ip] < 0.01 && rhoCirrus_min[ip] > (
BAD_FLT + 0.1)) {
3875 treesum[ip] += 0.326;
3877 treesum[ip] += -1.404;
3881 if (sst_stdev[ip] < 0.382 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
3882 treesum[ip] += 0.130;
3883 if (l2rec->l1rec->lat[ip] < -5.005) {
3884 treesum[ip] += 0.400;
3886 treesum[ip] += -0.107;
3889 if (sst_stdev[ip] < 0.224 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
3890 treesum[ip] += 0.182;
3892 treesum[ip] += -0.216;
3895 treesum[ip] += -0.632;
3897 if (dBt_85_11 < -1.641) {
3898 treesum[ip] += 0.268;
3900 treesum[ip] += -0.201;
3901 if (sstq[csstbox][ip] < 27.723) {
3902 treesum[ip] += -0.069;
3904 treesum[ip] += 0.903;
3912 if (Bt12_min[ip] < 15.376) {
3913 treesum[ip] += -0.908;
3914 if (dBt_11_12 < 0.27) {
3915 treesum[ip] += -0.446;
3917 treesum[ip] += 0.568;
3920 if (rhoCirrus_min[ip] < -0.001) {
3921 treesum[ip] += -0.981;
3923 treesum[ip] += 0.137;
3926 treesum[ip] += 0.819;
3927 if (Tdeflong < 0.031) {
3928 treesum[ip] += -0.969;
3930 treesum[ip] += 0.025;
3933 if (Bt73_max[ip] < -9.485) {
3934 treesum[ip] += -0.208;
3936 treesum[ip] += 0.428;
3939 if (rhoCirrus_max[ip] < 0.005 && rhoCirrus_max[ip] > (
BAD_FLT + 0.1)) {
3940 treesum[ip] += 0.235;
3941 if (rhoCirrus < 0.002 && rhoCirrus > (
BAD_FLT + 0.1)) {
3942 treesum[ip] += 0.100;
3944 treesum[ip] += -0.506;
3947 treesum[ip] += -1.176;
3949 if (sst_stdev[ip] < 0.36 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
3950 treesum[ip] += 0.222;
3952 treesum[ip] += -0.657;
3954 if (sstq[csstbox][ip] < 27.443) {
3955 treesum[ip] += -0.077;
3956 if (sst_stdev[ip] < 0.36 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
3957 treesum[ip] += 0.355;
3959 treesum[ip] += -0.179;
3962 if (rhoCirrus_min[ip] < 0.01 && rhoCirrus_min[ip] > (
BAD_FLT + 0.1)) {
3963 treesum[ip] += 0.022;
3964 if (l2rec->l1rec->lat[ip] < 29.775) {
3965 treesum[ip] += -0.128;
3966 if (l2rec->l1rec->lat[ip] < -15.305) {
3967 treesum[ip] += 0.431;
3969 treesum[ip] += -0.202;
3971 if (Bt11_max[ip] < 14.722) {
3972 treesum[ip] += -1.906;
3974 treesum[ip] += 0.087;
3977 if (Tdeflong < 0.04) {
3978 treesum[ip] += -0.336;
3980 treesum[ip] += 0.156;
3983 treesum[ip] += 0.379;
3986 treesum[ip] += -1.948;
3989 treesum[ip] += 0.688;
3995 if (dBt_37_12 < -0.053) {
3996 treesum[ip] += -1.257;
3997 if (l2rec->l1rec->lat[ip] < 33.195) {
3998 treesum[ip] += -0.278;
3999 if (l2rec->l1rec->lat[ip] < -40.185) {
4000 treesum[ip] += 0.619;
4002 treesum[ip] += -0.711;
4004 treesum[ip] += -3.733;
4006 treesum[ip] += -0.111;
4010 treesum[ip] += 0.333;
4013 treesum[ip] += -0.292;
4015 treesum[ip] += 0.764;
4018 treesum[ip] += 0.430;
4019 if (Bt11_maxmin[ip] < 0.486 && Bt11_maxmin[ip] > (
BAD_FLT + 0.1)) {
4020 treesum[ip] += 0.628;
4021 if (Bt40_stdev[ip] < 0.146 && Bt40_stdev[ip] > (
BAD_FLT + 0.1)) {
4022 treesum[ip] += 0.177;
4024 treesum[ip] += -0.723;
4027 treesum[ip] += -0.450;
4029 if (dSST_SST4 < -0.878) {
4030 treesum[ip] += -1.353;
4031 if (dSST_SST4 < -1.533) {
4032 treesum[ip] += -1.439;
4034 treesum[ip] += 0.346;
4037 treesum[ip] += 0.219;
4038 if (Bt37_stdev[ip] < 0.448 && Bt37_stdev[ip] > (
BAD_FLT + 0.1)) {
4039 treesum[ip] += 0.290;
4040 if (dSST_SST4 < -0.422) {
4041 treesum[ip] += -0.504;
4043 treesum[ip] += 0.268;
4046 treesum[ip] += -0.484;
4048 if (Bt12 < 16.736) {
4049 treesum[ip] += -0.285;
4050 if (dBt_40_11 < -2.199) {
4051 treesum[ip] += 0.518;
4053 treesum[ip] += -0.316;
4054 if (Bt12 < 11.896) {
4055 treesum[ip] += -0.527;
4057 treesum[ip] += 0.400;
4061 treesum[ip] += 0.500;
4063 if (dSST_SST4 < 1.183) {
4064 treesum[ip] += 0.051;
4066 treesum[ip] += -0.898;
4071 if (treesum[ip] <= 0.0) {
4075 else if (l2rec->l1rec->l1file->sensorID ==
MODISA) {
4076 if (l2rec->l1rec->solz[ip] < solznight && l2rec->l1rec->glint_coef[ip] <= glintmax) {
4083 if (rhotRED[ip] < 0.204 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
4084 treesum[ip] += 0.982;
4085 if (rhotRED[ip] < 0.056 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
4086 treesum[ip] += 0.328;
4088 if (rhoCirrus_max[ip] < 0.006 && rhoCirrus_max[ip] > (
BAD_FLT + 0.1)) {
4089 treesum[ip] += 0.151;
4090 if (l2rec->l1rec->senz[ip] < 59.043) {
4091 treesum[ip] += 0.029;
4093 treesum[ip] += -0.618;
4096 treesum[ip] += -1.071;
4099 treesum[ip] += -0.565;
4102 treesum[ip] += -1.325;
4105 if (rhotRED_min[ip] < 0.251 && rhotRED_min[ip] > (
BAD_FLT + 0.1)) {
4106 treesum[ip] += 0.81;
4108 treesum[ip] += -0.021;
4109 if (l2rec->l1rec->lat[ip] < 48.685) {
4110 treesum[ip] += 0.605;
4112 treesum[ip] += -0.088;
4113 if (l2rec->l1rec->lat[ip] < 37.755) {
4114 treesum[ip] += -0.311;
4116 treesum[ip] += 0.189;
4118 if (dBt_11_12 < 0.752) {
4119 treesum[ip] += -0.091;
4121 treesum[ip] += 0.581;
4126 if (dBt_67_11 < -38.023) {
4127 treesum[ip] += 0.221;
4129 treesum[ip] += -0.201;
4133 if (rhoCirrus_min[ip] < 0.003 && rhoCirrus_min[ip] > (
BAD_FLT + 0.1)) {
4134 treesum[ip] += 0.22;
4135 if (rhoCirrus_max[ip] < 0.003 && rhoCirrus_max[ip] > (
BAD_FLT + 0.1)) {
4136 treesum[ip] += 0.069;
4138 treesum[ip] += -0.422;
4141 treesum[ip] += -0.891;
4143 if (dBt_37_11 < 3.577) {
4144 treesum[ip] += 0.719;
4146 treesum[ip] += -0.227;
4147 if (sstq[csstbox][ip] < 27.668) {
4148 treesum[ip] += -0.017;
4150 treesum[ip] += 0.472;
4152 if (sst_stdev[ip] < 0.481 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
4153 treesum[ip] += 0.094;
4155 treesum[ip] += -0.322;
4158 if (sst_stdev[ip] < 0.263 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
4159 treesum[ip] += 0.193;
4161 treesum[ip] += -0.276;
4163 }
else if (l2rec->l1rec->solz[ip] < solznight) {
4165 if (LtRED < (1000.0 - 0.1)) {
4172 if (rhotRED_min[ip] < 0.087 && rhotRED_min[ip] > (
BAD_FLT + 0.1)) {
4173 treesum[ip] += 1.017;
4175 treesum[ip] += -0.644;
4177 if (Bt11_min[ip] < 15.22) {
4178 treesum[ip] += -0.837;
4179 if (dBt_67_11 < -40.834) {
4180 treesum[ip] += 0.510;
4182 treesum[ip] += -0.181;
4185 treesum[ip] += 0.870;
4186 if (Tdeflong < 0.036) {
4187 treesum[ip] += -0.859;
4189 treesum[ip] += 0.215;
4192 if (l2rec->l1rec->lat[ip] < 29.675) {
4193 treesum[ip] += -0.099;
4195 treesum[ip] += 0.467;
4197 if (dBt_37_11 < 10.053) {
4198 treesum[ip] += -0.743;
4200 treesum[ip] += 0.137;
4203 if (rhoCirrus_max[ip] < 0.004 && rhoCirrus_max[ip] > (
BAD_FLT + 0.1)) {
4204 treesum[ip] += 0.227;
4205 if (rhotRED[ip] < 0.068 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
4206 treesum[ip] += 0.824;
4208 treesum[ip] += -0.113;
4210 if (rhoCirrus_maxmin[ip] < 0.001 && rhoCirrus_max[ip] > (
BAD_FLT + 0.1)) {
4211 treesum[ip] += 0.102;
4213 treesum[ip] += -0.454;
4216 treesum[ip] += -1.096;
4217 if (rhoCirrus < 0.006 && rhoCirrus > (
BAD_FLT + 0.1)) {
4218 treesum[ip] += 0.282;
4220 treesum[ip] += -0.810;
4223 if (sst_stdev[ip] < 0.397 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
4224 treesum[ip] += 0.235;
4225 if (l2rec->l1rec->lat[ip] < -0.365) {
4226 treesum[ip] += 0.240;
4228 treesum[ip] += -0.194;
4229 if (l2rec->l1rec->lon[ip] < -67.480) {
4230 treesum[ip] += 0.241;
4232 treesum[ip] += -0.229;
4235 if (sst_stdev[ip] < 0.188 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
4236 treesum[ip] += 0.187;
4238 treesum[ip] += -0.258;
4241 treesum[ip] += -0.848;
4243 if (sstq[csstbox][ip] < 27.278) {
4244 treesum[ip] += -0.066;
4246 treesum[ip] += 0.509;
4307 if (Bt12_min[ip] < 15.119) {
4308 treesum[ip] += -0.759;
4309 if (dBt_37_11 < 12.733) {
4310 treesum[ip] += 0.652;
4313 if (rhoCirrus_min[ip] < 0.001) {
4314 treesum[ip] += -1.096;
4316 treesum[ip] += 0.130;
4319 treesum[ip] += -0.288;
4321 if (Bt37_maxmin[ip] < 0.529 && Bt37_maxmin[ip] > (
BAD_FLT + 0.1)) {
4322 treesum[ip] += 0.926;
4324 treesum[ip] += 0.026;
4327 treesum[ip] += 0.794;
4328 if (dBt_37_11 < 8.37) {
4329 treesum[ip] += 0.522;
4331 treesum[ip] += -0.268;
4334 if (rhoCirrus_maxmin[ip] < 0.001 && rhoCirrus_max[ip] > (
BAD_FLT + 0.1)) {
4335 treesum[ip] += 0.381;
4336 if (rhoCirrus_max[ip] < 0.002 && rhoCirrus_max[ip] > (
BAD_FLT + 0.1)) {
4337 treesum[ip] += 0.006;
4339 treesum[ip] += -0.584;
4342 treesum[ip] += -0.619;
4344 if (sst_stdev[ip] < 0.397 && sst_stdev[ip] > (
BAD_FLT + 0.1)) {
4345 treesum[ip] += 0.101;
4347 treesum[ip] += -0.684;
4349 if (Tdeflong < 0.036) {
4350 treesum[ip] += -0.471;
4351 if (l2rec->l1rec->lat[ip] < 32.335) {
4352 treesum[ip] += -0.481;
4354 treesum[ip] += 0.684;
4357 treesum[ip] += 0.193;
4360 if (rhoCirrus_min[ip] < 0.003 && rhoCirrus_min[ip] > (
BAD_FLT + 0.1)) {
4361 treesum[ip] += 0.108;
4362 if (l2rec->l1rec->lat[ip] < -25.425) {
4363 treesum[ip] += 0.517;
4365 treesum[ip] += -0.082;
4366 if (l2rec->l1rec->lat[ip] < 27.215) {
4367 treesum[ip] += -0.077;
4368 if (Bt11 < 14.734) {
4369 treesum[ip] += -2.012;
4371 treesum[ip] += 0.089;
4374 treesum[ip] += 0.383;
4378 treesum[ip] += -0.913;
4380 if (sstq[csstbox][ip] < 27.583) {
4381 treesum[ip] += -0.074;
4383 treesum[ip] += 0.691;
4390 if (dBt_37_12 < 0.117) {
4391 treesum[ip] += -1.279;
4392 if (l2rec->l1rec->lat[ip] < 33.035) {
4393 treesum[ip] += -0.289;
4394 if (l2rec->l1rec->lat[ip] < -42.235) {
4395 treesum[ip] += 0.747;
4397 treesum[ip] += -0.564;
4398 if (Bt37 < 13.117) {
4399 treesum[ip] += -0.580;
4401 treesum[ip] += 0.638;
4405 treesum[ip] += 0.355;
4408 treesum[ip] += -0.307;
4410 treesum[ip] += 0.747;
4413 treesum[ip] += 0.470;
4414 if (Bt11_stdev[ip] < 0.155 && Bt11_stdev[ip] > (
BAD_FLT + 0.1)) {
4415 treesum[ip] += 0.690;
4416 if (Bt37_maxmin[ip] < 0.524 && Bt37_maxmin[ip] > (
BAD_FLT + 0.1)) {
4417 treesum[ip] += 0.150;
4419 treesum[ip] += -0.794;
4422 treesum[ip] += -0.430;
4424 if (dSST_SST4 < -0.787) {
4425 treesum[ip] += -1.404;
4426 if (dSST_SST4 < -1.253) {
4427 treesum[ip] += -1.086;
4429 treesum[ip] += 0.388;
4432 treesum[ip] += 0.197;
4433 if (Bt37_maxmin[ip] < 1.229 && Bt37_maxmin[ip] > (
BAD_FLT + 0.1)) {
4434 treesum[ip] += 0.287;
4435 if (dSST_SST4 < -0.383) {
4436 treesum[ip] += -0.531;
4438 treesum[ip] += 0.279;
4441 treesum[ip] += -0.497;
4443 if (Bt12 < 16.353) {
4444 treesum[ip] += -0.300;
4445 if (dBt_40_11 < -2.171) {
4446 treesum[ip] += 0.516;
4448 treesum[ip] += -0.395;
4449 if (sst4q[csstbox][ip] < 16.212) {
4450 treesum[ip] += -0.694;
4452 treesum[ip] += 0.392;
4456 treesum[ip] += 0.451;
4460 if (dBt_85_11 < -1.577) {
4461 treesum[ip] += 0.088;
4463 treesum[ip] += -0.408;
4467 if (treesum[ip] <= 0.0) {
4472 else if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
4477 if (l2rec->l1rec->solz[ip] < solznight) {
4483 if (dBt_11_12 < 0.23435 ||
4484 Bt12 < (270.78 -
CtoK)) {
4486 }
else if (Bt37_maxmin[ip] >= 0.40919 &&
4487 (Bt37_maxmin[ip] >= 1.0765 ||
4488 Bt12_maxmin[ip] >= 0.8412 ||
4489 Bt12_maxmin[ip] < 0.3193)) {
4495 if (dBt_37_11 < 0.18654) {
4497 }
else if (dSST_SST3 < -1.021674) {
4498 if (dBt_11_12 < 2.187215 || dBt_37_11 >= 5.46243) {
4501 }
else if (Bt37_maxmin[ip] >= 0.48349) {
4502 if (dBt_11_12 < 0.32251 || dSST_SST3 >= 0.4414579) {
4504 }
else if (Bt37_maxmin[ip] >= 1.012265) {
4505 if (dBt_11_12 < 0.951295 || Bt12_maxmin[ip] < 0.69827) {
4509 if (l2rec->l1rec->senz[ip] > 56.3) {
4510 if (dBt_37_11 < 1.101845 || dBt_11_12 >= 1.308475) {
4520 if (l2rec->l1rec->solz[ip] >= solznight) {
4522 treesum[ip] = 0.413;
4523 if (dBt_37_11 < 0.115) {
4524 treesum[ip] += -1.931;
4526 treesum[ip] += 0.496;
4527 if (dSST_SST3 < -0.465) {
4528 treesum[ip] += -0.942;
4529 if (dSST_SST3 < -1.102) {
4530 treesum[ip] += -0.735;
4531 if (dBt_37_11 < 1.686) {
4532 treesum[ip] += 0.651;
4534 treesum[ip] += -0.82;
4537 treesum[ip] += 0.207;
4540 treesum[ip] += 0.309;
4541 if (dSST_SST3 < 0.78) {
4542 treesum[ip] += 0.043;
4543 if (dSST_SST3 < -0.158) {
4544 treesum[ip] += -0.392;
4546 treesum[ip] += 0.194;
4549 treesum[ip] += -1.069;
4551 if (dBt_37_11 < 0.306) {
4552 treesum[ip] += -0.692;
4554 treesum[ip] += 0.077;
4557 if (Bt12 < 287.407) {
4558 treesum[ip] += -0.339;
4560 treesum[ip] += 0.426;
4563 if (sstq[csstbox][ip] < (270.414 -
CtoK)) {
4564 treesum[ip] += -3.879;
4566 treesum[ip] += 0.047;
4567 if (Bt37_stdev[ip] < 0.247 && Bt37_stdev[ip] > (
BAD_FLT + 0.1)) {
4568 treesum[ip] += 0.176;
4570 treesum[ip] += -0.187;
4573 if (treesum[ip] <= 0.0) {
4578 }
else if (l2rec->l1rec->glint_coef[ip] <= glintmax) {
4591 xrad = (360.0 / 365.0) * xdoy /
RADEG;
4592 subsolar = 23.45 * sin(xrad);
4594 if (rhotRED[ip] > 0.3 &&
4595 rhot16[ip] >= 0.006 && rhot16[ip] < 0.1 &&
4596 ((l2rec->l1rec->lat[ip] > (subsolar + 30.0)) || (l2rec->l1rec->lat[ip] < (subsolar - 30.0)))) {
4606 if (rhot16[ip] < 0.16 && Lt16 > (
BAD_FLT + 0.1) && Lt16 < (1000.0 - 0.1)) {
4607 treesum[ip] += 0.805;
4608 if (rhotNIR7[ip] < 0.062 && LtNIR7 > (
BAD_FLT + 0.1) && LtNIR7 < (1000.0 - 0.1)) {
4609 treesum[ip] += 0.393;
4610 if (rhoCirrus < 0.004 && rhoCirrus > (
BAD_FLT + 0.1)) {
4611 treesum[ip] += 0.287;
4612 if (Tdeflong < 0.002) {
4613 treesum[ip] += -0.681;
4615 treesum[ip] += 0.026;
4616 if (rhotNIR7[ip] < 0.039 && LtNIR7 > (
BAD_FLT + 0.1) && LtNIR7 < (1000.0 - 0.1)) {
4617 treesum[ip] += 0.364;
4619 treesum[ip] += -0.21;
4623 treesum[ip] += -1.244;
4626 treesum[ip] += -0.0572;
4628 if (rhot16_min[ip] < 0.032 && rhot16_min[ip] > (
BAD_FLT + 0.1)) {
4629 treesum[ip] += 0.455;
4631 treesum[ip] += -0.395;
4634 if (l2rec->l1rec->senz[ip] < 64.994) {
4635 treesum[ip] += 0.216;
4636 if (rhoCirrus < 0.007 && rhoCirrus > (
BAD_FLT + 0.1)) {
4637 treesum[ip] += 0.065;
4639 treesum[ip] += -1.077;
4642 treesum[ip] += -0.708;
4645 treesum[ip] += -1.755;
4646 if (rhot16[ip] < 0.266 && Lt16 > (
BAD_FLT + 0.1) && Lt16 < (1000.0 - 0.1)) {
4647 treesum[ip] += 0.642;
4649 treesum[ip] += -0.19;
4650 if (rhotRED_maxmin[ip] < 0.103 && rhotRED_maxmin[ip] > (
BAD_FLT + 0.1)) {
4651 treesum[ip] += 0.425;
4653 treesum[ip] += -0.195;
4656 if (dBt_11_12 < 0.235) {
4657 treesum[ip] += -0.189;
4659 treesum[ip] += 0.411;
4661 if (l2rec->l1rec->wv[ip] < 2.946) {
4662 treesum[ip] += 0.038;
4664 treesum[ip] += -1.137;
4667 if (Bt11_maxmin[ip] < 0.762 && Bt11_maxmin[ip] > (
BAD_FLT + 0.1)) {
4668 treesum[ip] += 0.156;
4670 treesum[ip] += -0.188;
4672 if (l2rec->l1rec->wv[ip] < 1.315) {
4673 treesum[ip] += 0.327;
4675 treesum[ip] += -0.054;
4676 if (sstq[csstbox][ip] < (278.171 -
CtoK)) {
4677 treesum[ip] += -0.679;
4679 treesum[ip] += 0.05;
4687 if (rhotRED[ip] > 0.065) {
4691 if (Bt85_min[ip] < (287.451 -
CtoK)) {
4692 treesum[ip] += -0.812;
4693 if (l2rec->l1rec->lat[ip] < 32.315) {
4694 treesum[ip] += -0.296;
4695 if (Tdeflong < 0.001) {
4696 treesum[ip] += -1.109;
4697 if (l2rec->l1rec->lat[ip] < -30.0) {
4698 treesum[ip] += 0.525;
4700 treesum[ip] += -1.827;
4703 treesum[ip] += 0.44;
4705 if (l2rec->l1rec->wv[ip] < 2.065) {
4706 treesum[ip] += 0.49;
4708 treesum[ip] += -1.104;
4709 if (Bt85 < (287.059 -
CtoK)) {
4710 treesum[ip] += -1.071;
4712 treesum[ip] += 0.727;
4716 treesum[ip] += 0.669;
4718 if (dBt_37_11 < 17.594) {
4719 treesum[ip] += 0.452;
4721 treesum[ip] += -0.76;
4724 treesum[ip] += 0.858;
4725 if (l2rec->l1rec->lon[ip] < -69.475) {
4726 treesum[ip] += 0.512;
4728 treesum[ip] += -0.176;
4729 if (l2rec->l1rec->lat[ip] < 1.01) {
4730 treesum[ip] += 0.64;
4732 treesum[ip] += -0.176;
4734 treesum[ip] += 0.69;
4736 treesum[ip] += -0.305;
4740 if (dBt_37_11 < 9.655) {
4741 treesum[ip] += 0.562;
4743 treesum[ip] += -0.173;
4745 if (Bt85 < (290.343 -
CtoK)) {
4746 treesum[ip] += -0.39;
4748 treesum[ip] += 0.243;
4749 if (Tdeflong < 0.003) {
4750 treesum[ip] += -0.817;
4752 treesum[ip] += 0.267;
4755 if (l2rec->l1rec->lat[ip] < 22.465) {
4756 treesum[ip] += -0.206;
4758 treesum[ip] += 0.523;
4761 if (Bt11_maxmin[ip] < 1.189 && Bt11_maxmin[ip] > (
BAD_FLT + 0.1)) {
4762 treesum[ip] += 0.059;
4764 treesum[ip] += -1.22;
4770 if (rhotNIR7_min[ip] < 0.104 && rhotNIR7_min[ip] > (
BAD_FLT + 0.1)) {
4771 treesum[ip] += 0.91;
4772 if (rhotRED[ip] < 0.086 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
4773 treesum[ip] += 0.518;
4775 if (rhotRED_min[ip] < 0.067 && rhotRED_min[ip] > (
BAD_FLT + 0.1)) {
4776 treesum[ip] += 0.558;
4778 treesum[ip] += -0.263;
4780 if (rhot16[ip] < 0.06 || Lt16 > (1000.0 - 0.1)) {
4781 treesum[ip] += -0.231;
4783 treesum[ip] += 1.712;
4786 if (rhot16[ip] < 0.046 || Lt16 > (1000.0 - 0.1)) {
4787 treesum[ip] += -1.353;
4789 treesum[ip] += 0.352;
4793 treesum[ip] += -0.585;
4794 if (dBt_37_12 < 12.951) {
4795 treesum[ip] += -0.905;
4797 treesum[ip] += 0.187;
4798 if (rhotRED[ip] < 0.098 && LtRED > (
BAD_FLT + 0.1) && LtRED < (1000.0 - 0.1)) {
4799 treesum[ip] += 0.549;
4801 treesum[ip] += -0.484;
4806 treesum[ip] += -1.819;
4808 if (rhotRED_min[ip] < 0.206 && rhotRED_min[ip] > (
BAD_FLT + 0.1)) {
4809 treesum[ip] += 0.467;
4811 treesum[ip] += -1.18;
4812 if (rhotRED_maxmin[ip] < 0.037 && rhotRED_maxmin[ip] > (
BAD_FLT + 0.1)) {
4813 treesum[ip] += 1.747;
4815 treesum[ip] += -1.79;
4818 if (l2rec->l1rec->wv[ip] < 1.705) {
4819 treesum[ip] += 0.434;
4821 treesum[ip] += -0.645;
4824 if (rhoCirrus < 0.002 && rhoCirrus > (
BAD_FLT + 0.1)) {
4825 treesum[ip] += 0.23;
4826 if (l2rec->l1rec->lat[ip] < 32.13) {
4827 treesum[ip] += -0.067;
4828 if (sstq[csstbox][ip] < (300.034 -
CtoK)) {
4829 treesum[ip] += -0.146;
4831 treesum[ip] += 0.824;
4834 treesum[ip] += 0.758;
4837 treesum[ip] += -1.153;
4839 if (rhoCirrus_min[ip] < 0.005 && rhoCirrus_min[ip] > (
BAD_FLT + 0.1)) {
4840 treesum[ip] += 0.28;
4842 treesum[ip] += -0.939;
4845 if (l2rec->l1rec->senz[ip] < 33.204) {
4848 treesum[ip] += -0.331;
4852 if (treesum[ip] <= 0.0) {
4862 if (l2rec->l1rec->l1file->sensorID ==
AVHRR) {
4866 if (l2rec->l1rec->lat[ip] < 0.0
4867 && ((ASCEND == 1 && l2rec->l1rec->pixnum[ip] <= cpix)
4868 || (ASCEND == 0 && l2rec->l1rec->pixnum[ip] > cpix))
4869 && l2rec->l1rec->senz[ip] > 45.00) {
4886 extern l1qstr
l1que;
4887 int32_t
npix = l2rec->l1rec->npix;
4889 float Bt37, Bt39, Bt40, Bt85;
4891 float dBt_37_12, dBt_40_11, dBt_85_11;
4898 for (ip = 0; ip <
npix; ip++) {
4900 d3940ref[ip] = sstbad;
4903 if (
sstmasked(l2rec->l1rec->flags, ip)) {
4910 Bt37 = l2rec->l1rec->Bt[ipbir + ib37];
4911 Bt39 = l2rec->l1rec->Bt[ipbir + ib39];
4912 Bt40 = l2rec->l1rec->Bt[ipbir + ib40];
4913 Bt85 = l2rec->l1rec->Bt[ipbir + ib85];
4914 Bt11 = l2rec->l1rec->Bt[ipbir + ib11];
4915 Bt12 = l2rec->l1rec->Bt[ipbir + ib12];
4918 if ((l2rec->l1rec->l1file->sensorID ==
MODISA)
4919 && l2rec->l1rec->detnum == 0) {
4926 dBt_37_12 = Bt37 - Bt12;
4927 dBt_40_11 = Bt40 - Bt11;
4928 dBt_85_11 = Bt85 - Bt11;
4931 if (Bt39 < BT_LO + 0.1 || Bt39 >
BT_HI - 0.1 || Bt40 <
BT_LO + 0.1
4932 || Bt40 >
BT_HI - 0.1) {
4938 if (Bt39 < Btmin || Bt39 > Btmax || Bt40 < Btmin || Bt40 > Btmax40)
4942 dBt_34 = Bt39 - Bt40;
4943 if (dBt_34 < dBt4min || dBt_34 > dBt4max)
4949 d3940ref[ip] =
btrefdiffv6(ip, Bt39, Bt40, l2rec);
4951 if (d3940ref[ip] < dBtrefmin || d3940ref[ip] > dBtrefmax)
4955 if (sst4q[csstbox][ip] < SSTmin || sst4q[csstbox][ip] > SSTmaxn)
4959 if (sst4q[csstbox][ip] < sstbad + 1.0 || l2rec->l1rec->sstref[ip] < sstbad + 1.0) {
4962 dSST4_ref = sst4q[csstbox][ip] - l2rec->l1rec->sstref[ip];
4965 if ((evalmask &
SSTMODS) == 0) {
4968 if (dSST4_ref < -SSTdiff || l2rec->
l1rec->sstref[ip] < sstbad + 1.0)
4970 if (dSST4_ref < -input->sstrefdif &&
4971 l2rec->l1rec->lat[ip] >= equatorialSouth && l2rec->l1rec->lat[ip] <= equatorialNorth &&
4972 l2rec->l1rec->lon[ip] >= equatorialWest && l2rec->l1rec->lon[ip] <= equatorialEast) {
4978 if (l2rec->l1rec->solz[ip] >= solznight) {
4979 if (
fabs(dSST4_ref) > SSTdiff)
4981 if (
fabs(dSST4_ref) > SSTvdiff)
4985 if (dSST4_ref < -SSTvdiff || l2rec->
l1rec->sstref[ip] < sstbad + 1.0)
4988 if (l2rec->l1rec->solz[ip] >=
SOLZNIGHT) {
4989 if (
fabs(dSST4_ref) > SSTdiff)
4992 if (dSST4_ref < -SSTdiff || dSST4_ref > (SSTdiff + 1))
4995 if (
fabs(dSST4_ref) > SSTvdiff)
4999 dSST_SST4 = sstq[csstbox][ip] - sst4q[csstbox][ip];
5000 if (sstq[csstbox][ip] > sstbad + 1.0) {
5001 if (
fabs(dSST_SST4) < SST4diff1)
5003 if (
fabs(dSST_SST4) < SST4diff2)
5008 if (l2rec->l1rec->senz[ip] > hisenz)
5010 if (l2rec->l1rec->senz[ip] > vhisenz)
5013 if (l2rec->l1rec->pixnum[ip] < 2 || l2rec->l1rec->pixnum[ip] > (fullscanpix - 3))
5017 if ((l2rec->l1rec->l1file->sensorID ==
MODIST) && (l2rec->l1rec->pixnum[ip] > 1349))
5029 if (Bt39_maxmin[ip] > Bt39unif1)
5031 if (Bt39_maxmin[ip] > Bt39unif2)
5034 if (Bt40_maxmin[ip] > Bt40unif1)
5036 if (Bt40_maxmin[ip] > Bt40unif2)
5040 if (l2rec->l1rec->solz[ip] >= solznight) {
5041 if (l2rec->l1rec->l1file->sensorID ==
MODIST) {
5044 if (dBt_37_12 < -0.053) {
5045 treesum[ip] += -1.257;
5046 if (l2rec->l1rec->lat[ip] < 33.195) {
5047 treesum[ip] += -0.278;
5048 if (l2rec->l1rec->lat[ip] < -40.185) {
5049 treesum[ip] += 0.619;
5051 treesum[ip] += -0.711;
5053 treesum[ip] += -3.733;
5055 treesum[ip] += -0.111;
5059 treesum[ip] += 0.333;
5062 treesum[ip] += -0.292;
5064 treesum[ip] += 0.764;
5067 treesum[ip] += 0.430;
5068 if (Bt11_maxmin[ip] < 0.486 && Bt11_maxmin[ip] > (
BAD_FLT + 0.1)) {
5069 treesum[ip] += 0.628;
5070 if (Bt40_stdev[ip] < 0.146) {
5071 treesum[ip] += 0.177;
5073 treesum[ip] += -0.723;
5076 treesum[ip] += -0.450;
5078 if (dSST_SST4 < -0.878) {
5079 treesum[ip] += -1.353;
5080 if (dSST_SST4 < -1.533) {
5081 treesum[ip] += -1.439;
5083 treesum[ip] += 0.346;
5086 treesum[ip] += 0.219;
5087 if (Bt37_stdev[ip] < 0.448) {
5088 treesum[ip] += 0.290;
5089 if (dSST_SST4 < -0.422) {
5090 treesum[ip] += -0.504;
5092 treesum[ip] += 0.268;
5095 treesum[ip] += -0.484;
5097 if (Bt12 < 16.736) {
5098 treesum[ip] += -0.285;
5099 if (dBt_40_11 < -2.199) {
5100 treesum[ip] += 0.518;
5102 treesum[ip] += -0.316;
5103 if (Bt12 < 11.896) {
5104 treesum[ip] += -0.527;
5106 treesum[ip] += 0.400;
5110 treesum[ip] += 0.500;
5112 if (dSST_SST4 < 1.183) {
5113 treesum[ip] += 0.051;
5115 treesum[ip] += -0.898;
5120 }
else if (l2rec->l1rec->l1file->sensorID ==
MODISA) {
5125 if (dBt_37_12 < 0.117) {
5126 treesum[ip] += -1.279;
5127 if (l2rec->l1rec->lat[ip] < 33.035) {
5128 treesum[ip] += -0.289;
5129 if (l2rec->l1rec->lat[ip] < -42.235) {
5130 treesum[ip] += 0.747;
5132 treesum[ip] += -0.564;
5133 if (Bt37 < 13.117) {
5134 treesum[ip] += -0.580;
5136 treesum[ip] += 0.638;
5140 treesum[ip] += 0.355;
5143 treesum[ip] += -0.307;
5145 treesum[ip] += 0.747;
5148 treesum[ip] += 0.470;
5149 if (Bt11_stdev[ip] < 0.155) {
5150 treesum[ip] += 0.690;
5151 if (Bt37_maxmin[ip] < 0.524 && Bt37_maxmin[ip] > (
BAD_FLT + 0.1)) {
5152 treesum[ip] += 0.150;
5154 treesum[ip] += -0.794;
5157 treesum[ip] += -0.430;
5159 if (dSST_SST4 < -0.787) {
5160 treesum[ip] += -1.404;
5161 if (dSST_SST4 < -1.253) {
5162 treesum[ip] += -1.086;
5164 treesum[ip] += 0.388;
5167 treesum[ip] += 0.197;
5168 if (Bt37_maxmin[ip] < 1.229 && Bt37_maxmin[ip] > (
BAD_FLT + 0.1)) {
5169 treesum[ip] += 0.287;
5170 if (dSST_SST4 < -0.383) {
5171 treesum[ip] += -0.531;
5173 treesum[ip] += 0.279;
5176 treesum[ip] += -0.497;
5178 if (Bt12 < 16.353) {
5179 treesum[ip] += -0.300;
5180 if (dBt_40_11 < -2.171) {
5181 treesum[ip] += 0.516;
5183 treesum[ip] += -0.395;
5184 if (sst4q[csstbox][ip] < 16.212) {
5185 treesum[ip] += -0.694;
5187 treesum[ip] += 0.392;
5191 treesum[ip] += 0.451;
5195 if (dBt_85_11 < -1.577) {
5196 treesum[ip] += 0.088;
5198 treesum[ip] += -0.408;
5202 if (treesum[ip] <= 0.0) {
5220 for (ip = 0; ip < l2rec->l1rec->npix; ip++) {
5222 if (l2rec->l1rec->l1file->sensorID ==
AVHRR) {
5261 if (l2rec->l1rec->ssttype[ip] == 0 && qual_sst[ip] < 4) {
5269 if (l2rec->l1rec->solz[ip] < solznight) {
5284 || l2rec->l1rec->ssttype[ip] == 0) {
5288 }
else if (((
input->viirsnv7 >= 1)
5295 }
else if (((
input->viirsnv7 <= 0)
5297 || (l2rec->l1rec->glint_coef[ip] > glintmax)
5314 if (haveRed && l2rec->
l1rec->glint_coef[ip] <= glintmax) {
5315 ipb = ip * nbvis + ibred;
5320 rhot =
PI * l2rec->l1rec->Lt[ipb] / l2rec->l1rec->Fo[ibred];
5321 if (qual_sst[ip] < 3 && sstq[csstbox][ip] - l2rec->l1rec->sstref[ip] < -1.0
5324 if ((
input->viirsnv7 >= 1)
5325 && (qual_sst[ip] == 1)) {
5355 || ((
input->viirsnv7 >= 1)
5357 || ((
input->viirsnv7 >= 1)
5359 || ((
input->viirsnv7 >= 1)
5367 }
else if (((
input->viirsnv7 <= 0)
5369 || ((
input->viirsnv7 <= 0)
5371 || ((
input->viirsnv7 <= 0)
5384 if (haveSST4 && sst4q[csstbox][ip] > sstbad + 1.0) {
5385 if (qual_sst[ip] < 3
5388 if ((
input->viirsnv7 >= 1) && (qual_sst[ip] == 1)) {
5410 for (ip = 0; ip < l2rec->l1rec->npix; ip++) {
5412 if (l2rec->l1rec->solz[ip] < solznight) {
5475 float nlsst(
float Bt11,
float Bt12, int32_t
is,
float sstref,
5476 float **
bounds,
float **coef,
float sstrefoffday,
5477 float sstrefoffnight, int32_t ip, int32_t xsatid,
5478 size_t nlatbands,
size_t ncoefficients) {
5479 extern l1qstr
l1que;
5480 static float dBtlo = 0.5;
5481 static float dBthi = 0.9;
5489 float dBt = Bt11 - Bt12;
5490 float sstlo, ssthi, lsst;
5497 int ic = nlatbands - 1;
5498 while ((ic > 0) && (
lat <=
bounds[ic - 1][1] + latwin)) {
5503 if (
l1que.r[
is].solz[ip] >= solznight)
5504 sstref = sstref + sstrefoffnight;
5506 sstref = sstref + sstrefoffday;
5519 satzdir = (
l1que.r[
is].pixnum[ip] < fullscanpix / 2) ? -1.0 : 1.0;
5523 if (xsatid ==
NO16) {
5528 printf(
"ERROR - need nlatbands >= 2, found %ld\n", nlatbands);
5531 if(ncoefficients < 4) {
5532 printf(
"ERROR - need ncoefficients >= 4, found %ld\n", ncoefficients);
5536 lsst = coef[0][0] + coef[0][1] * Bt11 + coef[0][2] * dBt * sstref + coef[0][3] * dBt * ((1.0 /
mu) - 1.0);
5537 else if (dBt >= dBthi)
5538 lsst = coef[1][0] + coef[1][1] * Bt11 + coef[1][2] * dBt * sstref + coef[1][3] * dBt * ((1.0 /
mu) - 1.0);
5540 sstlo = coef[0][0] + coef[0][1] * Bt11 + coef[0][2] * dBt * sstref + coef[0][3] * dBt * ((1.0 /
mu) - 1.0);
5541 ssthi = coef[1][0] + coef[1][1] * Bt11 + coef[1][2] * dBt * sstref + coef[1][3] * dBt * ((1.0 /
mu) - 1.0);
5542 lsst = sstlo + ((dBt - dBtlo) / (dBthi - dBtlo))*(ssthi - sstlo);
5545 }
else if (
input->viirsnosisaf == 1) {
5546 if (
l1que.r[
is].solz[ip] >= solznight)
5553 if(ncoefficients < 7) {
5554 printf(
"ERROR - need ncoefficients >= 7, found %ld\n", ncoefficients);
5558 + (coef[ic][1] + coef[ic][2] * ((1.0 /
mu) - 1.0)) * Bt11
5559 + (coef[ic][3] + coef[ic][4] * sstref + coef[ic][5] * ((1.0 /
mu) - 1.0)) * dBt
5560 + coef[ic][6] * ((1.0 /
mu) - 1.0);
5562 }
else if (
input->viirsnv7 >= 1) {
5566 if (ncoefficients < 7) {
5567 printf(
"ERROR - need ncoefficients >= 7, found %ld\n", ncoefficients);
5570 if (
lat <
bounds[ic][1] - latwin || ic == (nlatbands - 1)) {
5571 lsst = coef[ic][0] + coef[ic][1] * Bt11 + coef[ic][2] * dBt * sstref
5572 + coef[ic][3] * dBt * ((1.0 /
mu) - 1.0)
5573 + coef[ic][4] * ((1.0 /
mu) - 1.0)
5574 + coef[ic][5] * pow(((1.0 /
mu) - 1.0), coef[ic][6]);
5577 dBtlo =
bounds[ic][1] - latwin;
5578 dBthi =
bounds[ic][1] + latwin;
5579 sstlo = coef[ic][0] + coef[ic][1] * Bt11 + coef[ic][2] * dBt * sstref
5580 + coef[ic][3] * dBt * ((1.0 /
mu) - 1.0)
5581 + coef[ic][4] * ((1.0 /
mu) - 1.0)
5582 + coef[ic][5] * pow(((1.0 /
mu) - 1.0), coef[ic][6]);
5583 ssthi = coef[ic + 1][0] + coef[ic + 1][1] * Bt11
5584 + coef[ic + 1][2] * dBt * sstref
5585 + coef[ic + 1][3] * dBt * ((1.0 /
mu) - 1.0)
5586 + coef[ic + 1][4] * ((1.0 /
mu) - 1.0)
5587 + coef[ic + 1][5] * pow(((1.0 /
mu) - 1.0), coef[ic + 1][6]);
5589 lsst = sstlo + ((
lat - dBtlo) / (dBthi - dBtlo)) * (ssthi - sstlo);
5600 static int last_ic = -1;
5603 C0 = (
float *) calloc(7,
sizeof(
float));
5604 C1 = (
float *) calloc(7,
sizeof(
float));
5606 if (last_ic != ic) {
5607 for (
i = 0;
i < ncoefficients;
i++){
5612 C0[
j] = coef[ic][
i];
5613 if (ic < nlatbands -1)
5614 C1[
j] = coef[ic + 1][
i];
5617 if (
lat <
bounds[ic][1] - latwin || ic == (nlatbands - 1)) {
5620 + C0[2] * dBt * sstref
5621 + C0[3] * dBt * ((1.0 /
mu) - 1.0)
5623 + C0[5] * (
l1que.r[
is].senz[ip] * satzdir)
5624 + C0[6] * pow((
l1que.r[
is].senz[ip] * satzdir), 2);
5626 dBtlo =
bounds[ic][1] - latwin;
5627 dBthi =
bounds[ic][1] + latwin;
5630 + C0[2] * dBt * sstref
5631 + C0[3] * dBt * ((1.0 /
mu) - 1.0)
5633 + C0[5] * (
l1que.r[
is].senz[ip] * satzdir)
5634 + C0[6] * pow((
l1que.r[
is].senz[ip] * satzdir), 2);
5637 +
C1[2] * dBt * sstref
5638 +
C1[3] * dBt * ((1.0 /
mu) - 1.0)
5640 +
C1[5] * (
l1que.r[
is].senz[ip] * satzdir)
5641 +
C1[6] * pow((
l1que.r[
is].senz[ip] * satzdir), 2);
5643 lsst = sstlo + ((
lat - dBtlo) / (dBthi - dBtlo)) * (ssthi - sstlo);
5659 float nlsst4(
float Bt39,
float Bt40, int32_t
is,
float **
bounds,
float **coef, int32_t ip,
size_t nlatbands) {
5660 extern l1qstr
l1que;
5666 float dBt = Bt39 - Bt40;
5680 while ((ic > 0) &&
lat <= (
bounds[ic - 1][1] + latwin)) {
5685 satzdir = (
l1que.r[
is].pixnum[ip] < fullscanpix / 2) ? -1.0 : 1.0;
5688 if (
lat <
bounds[ic][1] - latwin || ic == (nlatbands - 1)) {
5689 lsst4 = coef[ic][0] + coef[ic][1] * Bt39 + coef[ic][2] * dBt
5690 + coef[ic][3] * ((1.0 /
mu) - 1.0) + coef[ic][4] *
mside
5691 + coef[ic][5] * (
senz * satzdir)
5692 + coef[ic][6] * pow((
senz * satzdir), 2);
5695 dBtlo =
bounds[ic][1] - latwin;
5696 dBthi =
bounds[ic][1] + latwin;
5697 sst4lo = coef[ic][0] + coef[ic][1] * Bt39 + coef[ic][2] * dBt
5698 + coef[ic][3] * ((1.0 /
mu) - 1.0) + coef[ic][4] *
mside
5699 + coef[ic][5] * (
l1que.r[
is].senz[ip] * satzdir)
5700 + coef[ic][6] * pow((
l1que.r[
is].senz[ip] * satzdir), 2);
5701 sst4hi = coef[ic + 1][0] + coef[ic + 1][1] * Bt39 + coef[ic + 1][2] * dBt
5702 + coef[ic + 1][3] * ((1.0 /
mu) - 1.0) + coef[ic + 1][4] *
mside
5703 + coef[ic + 1][5] * (
l1que.r[
is].senz[ip] * satzdir)
5704 + coef[ic + 1][6] * pow((
l1que.r[
is].senz[ip] * satzdir), 2);
5706 lsst4 = sst4lo + ((
lat - dBtlo) / (dBthi - dBtlo)) * (sst4hi - sst4lo);
5721 extern l1qstr
l1que;
5722 static int firstCall = 1;
5724 static float **coef;
5726 static size_t nlatbands = 0;
5727 static size_t ncoefficients = 0;
5731 int32_t
i,
j, ip, ipb;
5737 if (
input->proc_sst != 1) {
5739 "-E- %s line %d: SST processing must be enabled (proc_sst=1) to make sst4.\n",
5740 __FILE__, __LINE__);
5744 if (
input->sst4coeffile[0]) {
5747 int32_t latbandDimID, coeffDimID, boundsID, coefficientID;
5749 if (nc_open(
input->sst4coeffile, NC_NOWRITE, &ncid) == NC_NOERR) {
5750 printf(
"Loading SST4 lat band coefficients from %s:\n",
input->sst4coeffile);
5752 if (nc_inq_dimid(ncid,
"latband", &latbandDimID) != NC_NOERR){
5753 printf(
"Whoops! something is wrong reading the SST algorithm coefficient file: %s\n",
input->sst4coeffile);
5756 nc_inq_dimlen(ncid, latbandDimID, &nlatbands);
5758 if (nc_inq_dimid(ncid,
"coefficient", &coeffDimID) != NC_NOERR){
5759 printf(
"Whoops! something is wrong reading the SST algorithm coefficient file: %s\n",
input->sst4coeffile);
5762 nc_inq_dimlen(ncid, coeffDimID, &ncoefficients);
5763 if(ncoefficients < 7) {
5764 printf(
"ERROR - need ncoefficients >= 7 for sst4, found %ld\n", ncoefficients);
5769 if (nc_inq_varid (ncid,
"latbands", &boundsID) == NC_NOERR){
5770 nc_get_var_float(ncid, boundsID,
bounds[0]);
5779 if (nc_inq_varid (ncid,
"coefficients", &coefficientID) == NC_NOERR){
5780 size_t start[] = {month, 0, 0};
5781 size_t count[] = {nmonth, nlatbands, ncoefficients};
5782 nc_get_vara_float(ncid, coefficientID,
start,
count, coef[0]);
5787 for (
i = 0;
i < nlatbands;
i++){
5789 for (
j = 0;
j < ncoefficients;
j++){
5790 printf(
"%9.6f ", coef[
i][
j]);
5805 printf(
"SST4 algorithm coefficient file not specified.");
5811 for (ip = 0; ip < l2rec->l1rec->npix; ip++) {
5813 sst4q[
is][ip] = sstbad;
5821 Bt39 =
l1que.r[
is].Bt[ipb + ib39];
5822 Bt40 =
l1que.r[
is].Bt[ipb + ib40];
5825 if ((l2rec->l1rec->l1file->sensorID ==
MODISA)
5834 if (Bt39 < BT_LO + 0.1 || Bt39 >
BT_HI - 0.1 || Bt40 <
BT_LO + 0.1
5835 || Bt40 >
BT_HI - 0.1) {
5841 if (l2rec->l1rec->l1file->sensorID ==
MODIST) {
5843 if (l2rec->l1rec->scantime <= 972777600) {
5846 }
else if (l2rec->l1rec->scantime <= 993945600) {
5852 sst4q[
is][ip] += elecor;
5868 extern l1qstr
l1que;
5869 static int firstCall = 1;
5871 static size_t ncoefficients = 0;
5872 static size_t nlatbands = 0;
5873 static float **coef;
5876 static float sstrefoffday;
5877 static float sstrefoffnight;
5879 int32_t
i,
j, ip, ipb;
5886 if (
input->proc_sst != 1) {
5888 "-E- %s line %d: SST processing must be enabled (proc_sst=1) to make sst.\n",
5889 __FILE__, __LINE__);
5892 if (
input->sstcoeffile[0]) {
5895 int32_t latbandDimID, coeffDimID, boundsID, coefficientID;
5897 if (nc_open(
input->sstcoeffile, NC_NOWRITE, &ncid) == NC_NOERR) {
5898 printf(
"Loading SST lat band coefficients from %s:\n",
input->sstcoeffile);
5900 if (nc_inq_dimid(ncid,
"latband", &latbandDimID) != NC_NOERR){
5901 printf(
"Whoops! something is wrong reading the SST algorithm coefficient file: %s\n",
input->sstcoeffile);
5904 nc_inq_dimlen(ncid, latbandDimID, &nlatbands);
5905 if (nc_inq_dimid(ncid,
"coefficient", &coeffDimID) != NC_NOERR){
5906 printf(
"Whoops! something is wrong reading the SST algorithm coefficient file: %s\n",
input->sstcoeffile);
5909 nc_inq_dimlen(ncid, coeffDimID, &ncoefficients);
5912 if (nc_inq_varid (ncid,
"latbands", &boundsID) == NC_NOERR){
5913 nc_get_var_float(ncid, boundsID,
bounds[0]);
5922 if (nc_inq_varid (ncid,
"coefficients", &coefficientID) == NC_NOERR){
5923 size_t start[] = {month, 0, 0};
5924 size_t count[] = {nmonth, nlatbands, ncoefficients};
5925 nc_get_vara_float(ncid, coefficientID,
start,
count, coef[0]);
5930 for (
i = 0;
i < nlatbands;
i++){
5932 for (
j = 0;
j < ncoefficients;
j++){
5933 printf(
"%9.6f ", coef[
i][
j]);
5940 sstrefoffnight = 0.0;
5958 printf(
"SST algorithm coefficient file not specified.");
5965 for (ip = 0; ip < l2rec->l1rec->npix; ip++) {
5967 sstq[
is][ip] = sstbad;
5975 Bt11 =
l1que.r[
is].Bt[ipb + ib11];
5976 Bt12 =
l1que.r[
is].Bt[ipb + ib12];
5977 Bt39 =
l1que.r[
is].Bt[ipb + ib39];
5978 Bt85 =
l1que.r[
is].Bt[ipb + ib85];
5981 if (Bt11 < BT_LO + 0.1 || Bt11 >
BT_HI - 0.1 || Bt12 <
BT_LO + 0.1
5982 || Bt12 >
BT_HI - 0.1) {
5987 if (haveSST4 &&
l1que.r[
is].solz[ip] >= solznight && sst4q[
is][ip] > sstbad + 1.0)
5988 sstref = sst4q[
is][ip];
5990 sstref =
l1que.r[
is].sstref[ip];
5993 if (sstref < sstbad + 1.0) {
5998 sstq[
is][ip] =
nlsst(Bt11, Bt12,
is, sstref,
bounds, coef, sstrefoffday,
5999 sstrefoffnight, ip, l2rec->l1rec->l1file->subsensorID,
6000 nlatbands, ncoefficients);
6001 if (
l1que.r[
is].l1file->sensorID ==
AVHRR && isV5 == 1) {
6002 sstq[
is][ip] -= 0.17;
6006 if (l2rec->l1rec->anc_aerosol && strlen(
input->dsdicoeffile) &&
6007 l1que.r[
is].solz[ip] >= solznight &&
6011 float dustExtinction =
l1que.r[
is].anc_aerosol->dust_ext[ip];
6012 float csenz =
l1que.r[
is].csenz[ip];
6013 dsdi_correction[ip] =
dust_correction(dustExtinction, csenz, Bt39, Bt85, Bt11, Bt12,
l1que.r[
is].l1file->sensorID);
6014 sstq[
is][ip] += dsdi_correction[ip];
6026 float senz,
int doy,
float lat, int8 iqual,
int16 iflags,
float glintv,
6027 int iviirsnv7,
float *
bias,
float *
stdv,
float *bias_mean,
6028 int16 *bias_counts) {
6029 int i, iday, isst, idiff, isenz, iquar, ilat;
6038 if (iqual == 1 && glintv > glintmax
6046 if (
solz >= solznight)
6051 for (
i = 1;
i < sses->nlat;
i++)
6052 if (lat < sses->
lat[
i])
6055 for (
i = 1;
i < sses->nsenz;
i++)
6056 if (senz < sses->
senz[
i])
6059 for (
i = 1;
i < sses->nsst;
i++)
6060 if (lsst < sses->sst[
i])
6063 for (
i = 1;
i < sses->ndiff;
i++)
6064 if (diff <= sses->
diff[
i])
6069 if (iqual < sses->nqual) {
6070 *
bias = sses->bias[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6071 *
stdv = sses->stdv[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6073 sses->bias_mean[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6075 sses->counts[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6090 float senz,
int doy,
float lat, int8 iqual,
int16 iflags,
float glintv,
6091 int iviirsnv7,
float *
bias,
float *
stdv,
float *bias_mean,
6092 int16 *bias_counts) {
6093 int i, iday, isst, idiff, isenz, iquar, ilat;
6102 if (iqual == 1 && glintv > glintmax
6104 || (iviirsnv7 >= 1)) && (iflags &
SSTF_HISENZ) == 0) {
6110 if (
solz >= solznight)
6116 for (
i = 1;
i < sses->nlat;
i++)
6117 if (lat < sses->
lat[
i])
6120 for (
i = 1;
i < sses->nsenz;
i++)
6121 if (senz < sses->
senz[
i])
6124 for (
i = 1;
i < sses->nsst;
i++)
6125 if (lsst < sses->sst[
i])
6128 for (
i = 1;
i < sses->ndiff;
i++)
6129 if (diff <= sses->
diff[
i])
6134 if (iqual < sses->nqual) {
6135 *
bias = sses->bias[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6136 *
stdv = sses->stdv[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6138 sses->bias_mean[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6140 sses->counts[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6154 float senz,
int doy,
float lat, int8 iqual,
int16 iflags,
float glintv,
6155 int iviirsnv7,
float *
bias,
float *
stdv,
float *bias_mean,
6156 int16 *bias_counts) {
6157 int i, iday, isst, idiff, isenz, iquar, ilat;
6166 if (iqual == 1 && glintv > glintmax
6168 || (iviirsnv7 >= 1)) && (iflags &
SSTF_HISENZ) == 0) {
6174 if (
solz >= solznight)
6179 for (
i = 1;
i < sses->nlat;
i++)
6180 if (lat < sses->
lat[
i])
6183 for (
i = 1;
i < sses->nsenz;
i++)
6184 if (senz < sses->
senz[
i])
6187 for (
i = 1;
i < sses->nsst;
i++)
6188 if (lsst < sses->sst[
i])
6191 for (
i = 1;
i < sses->ndiff;
i++)
6192 if (diff < sses->
diff[
i])
6197 if (iqual < sses->nqual) {
6198 *
bias = sses->bias[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6199 *
stdv = sses->stdv[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6201 sses->bias_mean[(
int) iqual][ilat][idiff][isenz][iquar][isst];
6203 sses->counts[(
int) iqual][ilat][idiff][isenz][iquar][isst];
6217 float senz,
int doy,
float lat, int8 iqual,
int16 iflags,
float glintv,
6218 int iviirsnv7,
float *
bias,
float *
stdv,
float *bias_mean,
6219 int16 *bias_counts) {
6220 int i, iday, isst, idiff, isenz, iquar, ilat;
6229 if (iqual == 1 && glintv > glintmax
6231 || (iviirsnv7 >= 1)) && (iflags &
SSTF_HISENZ) == 0) {
6237 if (
solz >= solznight)
6243 for (
i = 1;
i < sses->nlat;
i++)
6244 if (lat < sses->
lat[
i])
6247 for (
i = 1;
i < sses->nsenz;
i++)
6248 if (senz < sses->
senz[
i])
6251 for (
i = 1;
i < sses->nsst;
i++)
6252 if (lsst < sses->sst[
i])
6255 for (
i = 1;
i < sses->ndiff;
i++)
6256 if (diff <= sses->
diff[
i])
6261 if (iqual < sses->nqual) {
6262 *
bias = sses->bias[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6263 *
stdv = sses->stdv[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6265 sses->bias_mean[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6267 sses->counts[(
int) iqual][ilat][idiff][isenz][iquar][iday][isst];
6283 float *
stdv,
float *bias_mean,
int16 *bias_counts) {
6284 int i, isst, idiff, isenz, iquar, ilat;
6291 if (iqual == 1 && ((iflags &
SSTF_GLINT) > 0)
6298 for (
i = 1;
i < sses->nlat;
i++)
6299 if (lat < sses->
lat[
i])
6302 for (
i = 1;
i < sses->nsenz;
i++)
6303 if (senz < sses->
senz[
i])
6306 for (
i = 1;
i < sses->nsst;
i++)
6307 if (lsst < sses->sst[
i])
6310 for (
i = 1;
i < sses->ndiff;
i++)
6311 if (diff < sses->
diff[
i])
6316 if (iqual < sses->nqual) {
6317 *
bias = sses->bias[(
int) iqual][ilat][idiff][isenz][iquar][isst];
6318 *
stdv = sses->stdv[(
int) iqual][ilat][idiff][isenz][iquar][isst];
6320 sses->bias_mean[(
int) iqual][ilat][idiff][isenz][iquar][isst];
6322 sses->counts[(
int) iqual][ilat][idiff][isenz][iquar][isst];
6340 int32_t
npix = l2rec->l1rec->npix;
6345 double pasutime = l2rec->l1rec->scantime;
6350 for (ip = 0; ip <
npix; ip++) {
6352 Bt37 = l2rec->l1rec->Bt[ipb + ib37];
6353 Bt12 = l2rec->l1rec->Bt[ipb + ib12];
6357 comp_sses_sstv6v3(&sses_sst3v6v3, dBt, sst3q[csstbox][ip], l2rec->l1rec->solz[ip],
6358 l2rec->l1rec->senz[ip],
day, l2rec->l1rec->lat[ip], qual_sst3[ip],
6359 flags_sst3[ip], l2rec->l1rec->glint_coef[ip],
input->viirsnv7,
6360 &bias_sst3[ip], &stdv_sst3[ip], &bias_mean_sst3[ip],
6361 &bias_counts_sst3[ip]);
6373 int32_t
npix = l2rec->l1rec->npix;
6375 double pasutime = l2rec->l1rec->scantime;
6380 for (ip = 0; ip <
npix; ip++) {
6383 l2rec->l1rec->solz[ip], l2rec->l1rec->senz[ip],
day, l2rec->l1rec->lat[ip],
6384 qual_sst4[ip], flags_sst4[ip], l2rec->l1rec->glint_coef[ip],
6385 input->viirsnv7, &bias_sst4[ip], &stdv_sst4[ip],
6386 &bias_mean_sst4[ip], &bias_counts_sst4[ip]);
6398 int32_t
npix = l2rec->l1rec->npix;
6403 double pasutime = l2rec->l1rec->scantime;
6408 for (ip = 0; ip <
npix; ip++) {
6410 Bt11 = l2rec->l1rec->Bt[ipb + ib11];
6411 Bt12 = l2rec->l1rec->Bt[ipb + ib12];
6415 if (l2rec->l1rec->l1file->sensorID ==
AVHRR) {
6416 comp_sses_sstv6a(&sses_sstv6a, dBt, sstq[csstbox][ip], l2rec->l1rec->solz[ip],
6417 l2rec->l1rec->senz[ip],
day, l2rec->l1rec->lat[ip], qual_sst[ip],
6418 flags_sst[ip], &bias_sst[ip], &stdv_sst[ip],
6419 &bias_mean_sst[ip], &bias_counts_sst[ip]);
6421 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
6422 comp_sses_sstv6v(&sses_sstv6v, dBt, sstq[csstbox][ip], l2rec->l1rec->solz[ip],
6423 l2rec->l1rec->senz[ip],
day, l2rec->l1rec->lat[ip], qual_sst[ip],
6424 flags_sst[ip], l2rec->l1rec->glint_coef[ip],
6425 input->viirsnv7, &bias_sst[ip], &stdv_sst[ip],
6426 &bias_mean_sst[ip], &bias_counts_sst[ip]);
6428 comp_sses_sstv6m(&sses_sstv6m, dBt, sstq[csstbox][ip], l2rec->l1rec->solz[ip],
6429 l2rec->l1rec->senz[ip],
day, l2rec->l1rec->lat[ip], qual_sst[ip],
6430 flags_sst[ip], l2rec->l1rec->glint_coef[ip],
6431 input->viirsnv7, &bias_sst[ip], &stdv_sst[ip],
6432 &bias_mean_sst[ip], &bias_counts_sst[ip]);
6445 int32_t
npix = l2rec->l1rec->npix;
6453 float dBt_37_11, dBt_11_12;
6456 for (ip = 0; ip <
npix; ip++) {
6459 if (
sstmasked(l2rec->l1rec->flags, ip)) {
6465 Bt37 = l2rec->l1rec->Bt[ipbir + ib37];
6466 Bt40 = l2rec->l1rec->Bt[ipbir + ib40];
6467 Bt11 = l2rec->l1rec->Bt[ipbir + ib11];
6468 Bt12 = l2rec->l1rec->Bt[ipbir + ib12];
6472 if (Bt11 < BT_LO + 0.1 || Bt11 >
BT_HI - 0.1 || Bt12 <
BT_LO + 0.1
6474 || Bt37 >
BT_HI - 0.1) {
6480 if (Bt11 < Btmin || Bt11 > Btmax || Bt12 < Btmin || Bt12 > Btmax
6481 || Bt37 < Btmin || Bt37 > Btmax || Bt40 < Btmin
6482 || Bt40 > Btmax40) {
6487 dBt_11_12 = Bt11 - Bt12;
6488 if (dBt_11_12 < dBtmin || dBt_11_12 > dBtmax)
6492 if (sst3q[csstbox][ip] < SSTmin || sst3q[csstbox][ip] > SSTmaxn)
6496 dSST3_ref = sst3q[csstbox][ip] - l2rec->l1rec->sstref[ip];
6499 if (dSST3_ref < -SSTdiff || l2rec->
l1rec->sstref[ip] < sstbad + 1.0) {
6503 if ((evalmask &
SSTMODS) == 0) {
6504 if (dSST3_ref < -input->sstrefdif &&
6505 l2rec->l1rec->lat[ip] >= equatorialSouth && l2rec->l1rec->lat[ip] <= equatorialNorth &&
6506 l2rec->l1rec->lon[ip] >= equatorialWest && l2rec->l1rec->lon[ip] <= equatorialEast) {
6513 if (l2rec->l1rec->solz[ip] >= solznight) {
6514 if (
fabs(dSST3_ref) > SSTdiff)
6518 if (dSST3_ref < -SSTvdiff || l2rec->
l1rec->sstref[ip] < sstbad + 1.0)
6522 if (l2rec->l1rec->solz[ip] >= solznight) {
6523 if (
fabs(dSST3_ref) > SSTvdiff)
6528 dSST_SST3 = sstq[csstbox][ip] - sst3q[csstbox][ip];
6529 if (sstq[csstbox][ip] > sstbad + 1.0) {
6530 if (
fabs(dSST_SST3) > SST3diff1)
6532 if (
fabs(dSST_SST3) > SST3diff2)
6537 if (l2rec->l1rec->senz[ip] > hisenz)
6539 if (l2rec->l1rec->senz[ip] > vhisenz)
6542 if (l2rec->l1rec->pixnum[ip] < 2 || l2rec->l1rec->pixnum[ip] > (fullscanpix - 3))
6546 if (Bt37_maxmin[ip] > Bt37unif1)
6548 if (Bt37_maxmin[ip] > Bt37unif2)
6551 if (Bt11_maxmin[ip] > Bt11unif1)
6553 if (Bt11_maxmin[ip] > Bt11unif2)
6556 if (Bt12_maxmin[ip] > Bt12unif1)
6558 if (Bt12_maxmin[ip] > Bt12unif2)
6563 dBt_37_11 = Bt37 - Bt11;
6576 treesum[ip] = 0.466;
6578 if (!((Bt37 > Bt11) && (Bt11 > Bt12))) {
6579 treesum[ip] += -1.995;
6581 treesum[ip] += 0.55;
6582 if (sstq[csstbox][ip] < (292.504 -
CtoK)) {
6583 treesum[ip] += -0.368;
6584 if (dBt_37_11 < 1.898) {
6585 treesum[ip] += 0.091;
6587 treesum[ip] += -0.787;
6589 if (sstq[csstbox][ip] < (276.138 -
CtoK)) {
6590 treesum[ip] += -0.505;
6592 treesum[ip] += 0.09;
6595 treesum[ip] += 0.441;
6597 if (dSST_SST3 < -0.567) {
6598 treesum[ip] += -0.841;
6600 treesum[ip] += 0.177;
6601 if (dSST_SST3 < 0.484) {
6602 treesum[ip] += 0.067;
6603 if (dSST_SST3 < -0.216) {
6604 treesum[ip] += -0.313;
6606 treesum[ip] += 0.085;
6609 treesum[ip] += -0.516;
6611 if (dBt_37_11 < 0.289) {
6612 treesum[ip] += -0.705;
6614 treesum[ip] += 0.066;
6618 if (sst3q[csstbox][ip] < (270.023 -
CtoK)) {
6619 treesum[ip] += -4.116;
6621 treesum[ip] += 0.047;
6623 if (Bt37_stdev[ip] < 0.266) {
6624 treesum[ip] += 0.191;
6626 treesum[ip] += -0.255;
6628 if (treesum[ip] <= 0.0) {
6645 for (ip = 0; ip < l2rec->l1rec->npix; ip++) {
6647 if (l2rec->l1rec->solz[ip] < solznight) {
6683 }
else if (((
input->viirsnv7 >= 1)
6685 || ((
input->viirsnv7 >= 1)
6693 }
else if (((
input->viirsnv7 <= 0)
6695 || ((
input->viirsnv7 <= 0)
6719 float sstrefoff,
size_t *numbands) {
6730 char odatel[14] =
"";
6731 char sdatel[14] =
"";
6732 char edatel[14] =
"";
6743 int32 gotsstrefoff = 0;
6745 double pasutime = l2rec->l1rec->scantime;
6753 if ((fp = fopen(
input->sst3coeffile,
"r")) ==
NULL) {
6754 fprintf(
stderr,
"-E- %s line %d: unable to open %s for reading\n",
6755 __FILE__, __LINE__,
input->sst3coeffile);
6761 printf(
"ERROR - number_of_latbands is too big, reading %d into %ld\n", 6, *numbands);
6778 if (
input->viirsnv7 == -1) {
6782 for (tmonth = 11; tmonth >= 0; tmonth--) {
6784 if (
day > StartOfMonth[
leap][tmonth]) {
6795 ztime =
ydhmsf(pasutime,
'G');
6803 while (fgets(
line, 200, fp)) {
6804 if (
line[0] ==
'#') {
6806 if (!(
p = strchr(
line,
'=')))
6816 name[p2 -
p1 + 1] =
'\0';
6835 if (strcmp(
name,
"sstref_offset") == 0
6836 || strcmp(
name,
"sstref_night_offset") == 0) {
6839 }
else if (strcmp(
name,
"number_of_latbands") == 0) {
6842 printf(
"ERROR - number_of_latbands is too big, reading %ld into %ld\n",
nbands, *numbands);
6849 if (strncmp(
line, mission, 4) == 0) {
6850 if (
input->viirsnv7 < 0) {
6852 if (strncmp(
line, mission, 4) == 0) {
6853 sscanf(
line,
"%4s %d %f %f %f %f %f %f %f %f",
6855 &coef[indx][0], &coef[indx][1], &coef[indx][2],
6856 &coef[indx][3], &coef[indx][4], &coef[indx][5]);
6859 if (month == tmonth + 1) {
6861 if (indx == *numbands) {
6868 if (
input->viirsnosisaf == 1) {
6869 sscanf(
line,
"%4s %7s %7s %1s %f %f %f %f %f %f %f",
6870 mission2, sdates, edates, dorn,
6871 &coef[0][0], &coef[0][1], &coef[0][2], &coef[0][3],
6872 &coef[0][4], &coef[0][5], &coef[0][6]);
6873 sprintf(sdatel,
"%s%s", sdates,
"000000");
6874 sprintf(edatel,
"%s%s", edates,
"000000");
6876 if (
input->viirsnv7 >= 1) {
6877 sscanf(
line,
"%4s %7s %6s %7s %6s %f %f %f %f %f %f %f %f",
6878 mission2, sdates, stime, edates, etime,
6880 &coef[indx][1], &coef[indx][2], &coef[indx][3],
6881 &coef[indx][4], &coef[indx][5]);
6882 coef[indx][6] = 0.0;
6884 sscanf(
line,
"%4s %7s %6s %7s %6s %f %f %f %f %f %f",
6885 mission2, sdates, stime, edates, etime,
6887 &coef[indx][1], &coef[indx][2], &coef[indx][3]);
6888 coef[indx][4] = 0.0;
6889 coef[indx][5] = 0.0;
6890 coef[indx][6] = 0.0;
6893 sprintf(sdatel,
"%s%s", sdates, stime);
6894 sprintf(edatel,
"%s%s", edates, etime);
6895 if (strcmp(odatel, sdatel) >= 0
6896 && (strcmp(odatel, edatel) <= 0
6897 || strcmp(edates,
"0000000") == 0
6898 || strcmp(edates,
"") == 0)) {
6900 if (indx == *numbands) {
6914 if (gotsstrefoff == 0) {
6916 "-E- %s line %d: No sst reference offset found in %s\n",
6917 __FILE__, __LINE__,
input->sst3coeffile);
6921 printf(
"Loading SST3 lat band coefficients from %s:\n",
6922 input->sst3coeffile);
6924 if (
input->viirsnosisaf == 1) {
6925 printf(
"%s %s %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
6927 coef[0][0], coef[0][1], coef[0][2],
6928 coef[0][3], coef[0][4], coef[0][5]);
6930 for (indx = 0; indx<*numbands; indx++) {
6931 if (
input->viirsnv7 < 0) {
6932 printf(
"%d %6.1f %6.1f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
6935 coef[indx][0], coef[indx][1], coef[indx][2], coef[indx][3],
6936 coef[indx][4], coef[indx][5]);
6938 printf(
"%s %s %s %s %6.1f %6.1f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n",
6939 sdates, stime, edates, etime,
6941 coef[indx][0], coef[indx][1], coef[indx][2], coef[indx][3],
6942 coef[indx][4], coef[indx][5]);
6946 printf(
" sst reference offset = %f\n", sstrefoff);
6950 "-E- %s line %d: unable to locate valid SST3 coefficients for %s in %s\n",
6951 __FILE__, __LINE__, odatel,
input->sst3coeffile);
6965 float nlsst3(
float Bt37,
float Bt11,
float Bt12, int32_t
is,
float sstref,
6966 float **
bounds,
float **coef,
float sstrefoff,
size_t numbands,
6969 extern l1qstr
l1que;
6975 float dBt_37_12 = Bt37 - Bt12;
6987 sstref = sstref + sstrefoff;
6999 while ((ic > 0) && (
lat <=
bounds[ic - 1][1] + latwin)) {
7003 if (
input->viirsnv7 == 2) {
7007 latpow = (4.018114e-04 * pow(
lat, 2))+ (1.968591e-18 *
lat)
7009 if (
lat <
bounds[ic][1] - latwin || ic == (numbands-1)) {
7010 lsst3 = coef[ic][0] + coef[ic][1] * Bt11 + coef[ic][2] * dBt_37_12 * sstref
7011 + coef[ic][3] * ((1.0 /
mu) - 1.0)
7012 + coef[ic][4] * pow(((1.0 /
mu) - 1.0), latpow)
7013 + coef[ic][5] *
lat * ((1.0 /
mu) - 1.0);
7015 dBtlo =
bounds[ic][1] - latwin;
7016 dBthi =
bounds[ic][1] + latwin;
7017 sstlo = coef[ic][0] + coef[ic][1] * Bt11 + coef[ic][2] * dBt_37_12 * sstref
7018 + coef[ic][3] * ((1.0 /
mu) - 1.0)
7019 + coef[ic][4] * pow(((1.0 /
mu) - 1.0), latpow)
7020 + coef[ic][5] *
lat * ((1.0 /
mu) - 1.0);
7021 ssthi = coef[ic + 1][0] + coef[ic + 1][1] * Bt11
7022 + coef[ic + 1][2] * dBt_37_12 * sstref
7023 + coef[ic + 1][3] * ((1.0 /
mu) - 1.0)
7024 + coef[ic + 1][4] * pow(((1.0 /
mu) - 1.0), latpow)
7025 + coef[ic + 1][5] *
lat * ((1.0 /
mu) - 1.0);
7026 lsst3 = sstlo + ((
lat - dBtlo) / (dBthi - dBtlo)) * (ssthi - sstlo);
7029 }
else if (
input->viirsnv7 == 1) {
7033 if (
lat <
bounds[ic][1] - latwin || ic == (numbands-1)) {
7034 lsst3 = coef[ic][0] + coef[ic][1] * Bt11 + coef[ic][2] * dBt_37_12 * sstref
7035 + coef[ic][3] * ((1.0 /
mu) - 1.0)
7036 + coef[ic][4] * pow(((1.0 /
mu) - 1.0), coef[ic][5]);
7038 dBtlo =
bounds[ic][1] - latwin;
7039 dBthi =
bounds[ic][1] + latwin;
7040 sstlo = coef[ic][0] + coef[ic][1] * Bt11 + coef[ic][2] * dBt_37_12 * sstref
7041 + coef[ic][3] * ((1.0 /
mu) - 1.0)
7042 + coef[ic][4] * pow(((1.0 /
mu) - 1.0), coef[ic][5]);
7043 ssthi = coef[ic + 1][0] + coef[ic + 1][1] * Bt11
7044 + coef[ic + 1][2] * dBt_37_12 * sstref
7045 + coef[ic + 1][3] * ((1.0 /
mu) - 1.0)
7046 + coef[ic + 1][4] * pow(((1.0 /
mu) - 1.0), coef[ic + 1][5]);
7047 lsst3 = sstlo + ((
lat - dBtlo) / (dBthi - dBtlo)) * (ssthi - sstlo);
7050 }
else if (
input->viirsnosisaf == 1) {
7053 + (coef[0][1] + coef[0][2]*((1.0 /
mu) - 1.0)) * Bt37
7054 + (coef[0][3]* + coef[0][4]*((1.0 /
mu) - 1.0)) * dBt_37_12
7055 + coef[0][5]*((1.0 /
mu) - 1.0);
7062 satzdir = (
l1que.r[
is].pixnum[ip] < fullscanpix / 2) ? -1.0 : 1.0;
7064 if (
lat <
bounds[ic][1] - latwin || ic == (numbands-1)) {
7065 lsst3 = coef[ic][0] + coef[ic][1] * Bt11 + coef[ic][2] * dBt_37_12 * sstref
7066 + coef[ic][3]*((1.0 /
mu) - 1.0)
7067 + coef[ic][4]*(
senz * satzdir)
7068 + coef[ic][5] * pow((
senz * satzdir), 2);
7070 dBtlo =
bounds[ic][1] - latwin;
7071 dBthi =
bounds[ic][1] + latwin;
7072 sstlo = coef[ic][0] + coef[ic][1] * Bt11 + coef[ic][2] * dBt_37_12 * sstref
7073 + coef[ic][3]*((1.0 /
mu) - 1.0)
7074 + coef[ic][4]*(
senz * satzdir)
7075 + coef[ic][5] * pow((
senz * satzdir), 2);
7076 ssthi = coef[ic + 1][0] + coef[ic + 1][1] * Bt11 + coef[ic + 1][2] * dBt_37_12 * sstref
7077 + coef[ic + 1][3]*((1.0 /
mu) - 1.0) +
7078 + coef[ic + 1][4]*(
senz * satzdir) +
7079 + coef[ic + 1][5] * pow((
senz * satzdir), 2);
7080 lsst3 = sstlo + ((
lat - dBtlo) / (dBthi - dBtlo)) * (ssthi - sstlo);
7098 extern l1qstr
l1que;
7099 static int firstCall = 1;
7101 static float **coef;
7103 static size_t nlatbands = 0;
7104 static size_t ncoefficients = 0;
7105 static float sstrefoff;
7107 int32_t
i,
j, ip, ipb;
7114 if (
input->proc_sst != 1) {
7116 "-E- %s line %d: SST processing must be enabled (proc_sst=1) to make sst3.\n",
7117 __FILE__, __LINE__);
7120 if (
input->sst3coeffile[0]) {
7124 int32_t latbandDimID, coeffDimID, boundsID, coefficientID;
7126 if (nc_open(
input->sst3coeffile, NC_NOWRITE, &ncid) == NC_NOERR) {
7127 printf(
"Loading SST3 lat band coefficients from %s:\n",
input->sst3coeffile);
7129 if (nc_inq_dimid(ncid,
"latband", &latbandDimID) != NC_NOERR){
7130 printf(
"Whoops! something is wrong reading the SST algorithm coefficient file: %s\n",
input->sst3coeffile);
7133 nc_inq_dimlen(ncid, latbandDimID, &nlatbands);
7134 if (nc_inq_dimid(ncid,
"coefficient", &coeffDimID) != NC_NOERR){
7135 printf(
"Whoops! something is wrong reading the SST algorithm coefficient file: %s\n",
input->sst3coeffile);
7138 nc_inq_dimlen(ncid, coeffDimID, &ncoefficients);
7141 if (nc_inq_varid (ncid,
"latbands", &boundsID) == NC_NOERR){
7142 nc_get_var_float(ncid, boundsID,
bounds[0]);
7151 if (nc_inq_varid (ncid,
"coefficients", &coefficientID) == NC_NOERR){
7152 size_t start[] = {month, 0, 0};
7153 size_t count[] = {nmonth, nlatbands, ncoefficients};
7154 nc_get_vara_float(ncid, coefficientID,
start,
count, coef[0]);
7159 for (
i = 0;
i < nlatbands;
i++){
7161 for (
j = 0;
j < ncoefficients;
j++){
7162 printf(
"%9.6f ", coef[
i][
j]);
7176 printf(
"SST3 coefficient file not specified.");
7182 for (ip = 0; ip < l2rec->l1rec->npix; ip++) {
7184 sst3q[
is][ip] = sstbad;
7192 sstref =
l1que.r[
is].sstref[ip];
7193 Bt37 =
l1que.r[
is].Bt[ipb + ib37];
7194 Bt11 =
l1que.r[
is].Bt[ipb + ib11];
7195 Bt12 =
l1que.r[
is].Bt[ipb + ib12];
7198 if (sstref < sstbad + 1.0) {
7203 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
7205 if (Bt37 < BT_LO + 0.1 || Bt37 >
BT_HI - 0.1 || Bt11 <
BT_LO + 0.1
7207 || Bt12 >
BT_HI - 0.1) {
7210 if(ncoefficients < 6) {
7211 printf(
"ERROR - nlsst3 needs ncoefficients >= 6, we found %ld\n", ncoefficients);
7215 sstrefoff, nlatbands, ip);
7233 static int firstCall = 1;
7234 extern l1qstr
l1que;
7236 int32_t is1, is2, iq;
7251 run_rhoCboxmaxmin(l2rec->l1rec->npix, rhoCirrus_maxmin, rhoCirrus_min, rhoCirrus_max);
7255 run_rhotboxmaxmin(l2rec->l1rec->npix, ibred, l2rec->l1rec->l1file->nbands, rhotRED_maxmin, rhotRED_max);
7256 run_rhotboxmin(l2rec->l1rec->npix, ibred, l2rec->l1rec->l1file->nbands, rhotRED_min);
7260 run_rhotboxmin(l2rec->l1rec->npix, ib07, l2rec->l1rec->l1file->nbands, rhotNIR7_min);
7264 run_rhotboxmin(l2rec->l1rec->npix, ib16, l2rec->l1rec->l1file->nbands, rhot16_min);
7303 if (sstboxcscan == -1 || sstboxcscan != l2rec->l1rec->iscan - 1) {
7306 for (ij = is1; ij <= is2; ij++) {
7311 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
7320 for (iq = is1 + 1; iq <= is2; iq++)
7321 memcpy(&sst4q[iq - 1][0], &sst4q[iq][0],
sizeof (
s_array));
7326 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
7327 for (iq = is1 + 1; iq <= is2; iq++)
7328 memcpy(&sst3q[iq - 1][0], &sst3q[iq][0],
sizeof (
s_array));
7332 for (iq = is1 + 1; iq <= is2; iq++) {
7333 memcpy(&sstq[iq - 1][0], &sstq[iq][0],
sizeof (
s_array));
7339 sstboxcscan = l2rec->l1rec->iscan;
7346 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1)
7354 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1)
7365 if (l2rec->l1rec->l1file->sensorID ==
VIIRSN || l2rec->l1rec->l1file->sensorID ==
VIIRSJ1) {
7373 recnumSST = l2rec->l1rec->iscan;
7381 if (!
sst_ran(l2rec->l1rec->iscan))
7384 return (dsdi_correction);
7393 if (!
sst_ran(l2rec->l1rec->iscan))
7406 if (!
sst_ran(l2rec->l1rec->iscan))
7410 printf(
"short-wave SST is not available for this sensor.\n");
7424 if (!
sst_ran(l2rec->l1rec->iscan))
7438 if (!
sst_ran(l2rec->l1rec->iscan))
7451 if (!
sst_ran(l2rec->l1rec->iscan))
7453 return (bias_counts_sst);
7463 if (!
sst_ran(l2rec->l1rec->iscan))
7466 return (bias_counts_sst4);
7476 if (!
sst_ran(l2rec->l1rec->iscan))
7479 return (bias_counts_sst3);
7489 if (!
sst_ran(l2rec->l1rec->iscan))
7493 printf(
"short-wave SST is not available for this sensor.\n");
7506 if (!
sst_ran(l2rec->l1rec->iscan))
7519 if (!
sst_ran(l2rec->l1rec->iscan))
7532 if (!
sst_ran(l2rec->l1rec->iscan))
7536 printf(
"short-wave SST is not available for this sensor.\n");
7550 if (!
sst_ran(l2rec->l1rec->iscan))
7563 if (!
sst_ran(l2rec->l1rec->iscan))
7576 if (!
sst_ran(l2rec->l1rec->iscan))
7580 printf(
"short-wave SST is not available for this sensor.\n");
7584 return (flags_sst4);
7594 if (!
sst_ran(l2rec->l1rec->iscan))
7597 return (flags_sst3);
7608 if (!
sst_ran(l2rec->l1rec->iscan))
7612 printf(
"long-wave SST is not available for this sensor.\n");
7616 return (sstq[csstbox]);
7627 if (!
sst_ran(l2rec->l1rec->iscan))
7631 printf(
"short-wave SST is not available for this sensor.\n");
7635 return (sst4q[csstbox]);
7646 if (!
sst_ran(l2rec->l1rec->iscan))
7649 return (sst3q[csstbox]);
7659 if (!
sst_ran(l2rec->l1rec->iscan))
7662 return (bias_mean_sst);
7672 if (!
sst_ran(l2rec->l1rec->iscan))
7676 printf(
"short-wave SST is not available for this sensor.\n");
7680 return (bias_mean_sst4);
7690 if (!
sst_ran(l2rec->l1rec->iscan))
7693 return (bias_mean_sst3);
7701 if (!
sst_ran(l2rec->l1rec->iscan))