28 #define WINDSAT3DAY 10
35 static int32_t format = -1;
37 static int MiddleOfMonth[2][12] = {
38 {15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349},
39 {15, 45, 75, 106, 136, 167, 197, 228, 259, 289, 320, 350}};
52 static int firstCall = 1;
53 static int nx =
OI4NX;
54 static int ny =
OI4NY;
55 static float dx = 360.0 /
OI4NX;
56 static float dy = 180.0 /
OI4NY;
58 typedef float sstref_t[
OI4NX + 2];
59 static sstref_t* sstref;
71 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
75 ssttmp = (ssttmp_t*) malloc(
OI4NY *
sizeof (ssttmp_t));
77 char name [H4_MAX_NC_NAME] =
"";
78 char sdsname[H4_MAX_NC_NAME] =
"";
79 int ncid, ndims, nvars, ngatts, unlimdimid;
84 int32 dims[H4_MAX_VAR_DIMS];
86 int32
start[4] = {0, 0, 0, 0};
93 printf(
"Loading Daily V2 0.25-deg OI Reynolds SST reference from %s\n", sstfile);
104 sd_id = SDstart(sstfile, DFACC_RDONLY);
110 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
112 status = SDreaddata(sds_id,
start,
NULL, dims, (VOIDP) & ssttmp[0][0]);
114 fprintf(
stderr,
"-E- %s Line %d: Error reading SDS %s from %s.\n",
115 __FILE__, __LINE__, sdsname, sstfile);
118 if (
getHDFattr(sd_id,
"scale_factor", sdsname, (VOIDP) &
slope) != 0) {
119 fprintf(
stderr,
"-E- %s line %d: error reading scale factor.\n",
124 fprintf(
stderr,
"-E- %s line %d: error reading scale offset.\n",
128 status = SDendaccess(sds_id);
133 if (nc_open(sstfile, NC_NOWRITE, &ncid) == NC_NOERR) {
135 status = nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid);
136 status = nc_inq_varid(ncid, sdsname, &sds_id);
139 if (nc_get_var(ncid, sds_id, &ssttmp[0][0]) != NC_NOERR) {
140 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
141 __FILE__, __LINE__, sdsname, sstfile);
145 if (nc_get_att_float(ncid, sds_id,
"scale_factor", &
slope) != NC_NOERR) {
146 fprintf(
stderr,
"-E- %s line %d: error reading scale factor.\n",
151 if (nc_get_att_float(ncid, sds_id,
"add_offset", &
offset) != NC_NOERR) {
152 fprintf(
stderr,
"-E- %s line %d: error reading scale offset.\n",
157 if (nc_close(ncid) != NC_NOERR) {
158 fprintf(
stderr,
"-E- %s line %d: error closing %s.\n",
159 __FILE__, __LINE__, sstfile);
164 fprintf(
stderr,
"-E- %s line %d: error reading %s.\n",
165 __FILE__, __LINE__, sstfile);
173 for (
j = 0;
j < ny;
j++) {
174 for (
i = 0;
i < nx;
i++) {
175 ii = (
i < nx / 2) ?
i + nx / 2 :
i - nx / 2;
176 if (ssttmp[
j][
i] > -999)
179 sstref[
j + 1][ii + 1] = sstbad;
181 sstref[
j + 1][0] = sstref[
j + 1][nx];
182 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
184 for (
i = 0;
i < nx + 2;
i++) {
185 sstref[0] [
i] = sstref[1][
i];
186 sstref[ny + 1][
i] = sstref[ny][
i];
198 xx =
i * dx - 180.0 - dx / 2;
199 yy =
j * dy - 90.0 - dy / 2;
207 if (sstref[
j ][
i ] > sstbad + 1) {
208 ftmp += sstref[
j ][
i ];
211 if (sstref[
j ][
i + 1] > sstbad + 1) {
212 ftmp += sstref[
j ][
i + 1];
215 if (sstref[
j + 1][
i + 1] > sstbad + 1) {
216 ftmp += sstref[
j + 1][
i + 1];
219 if (sstref[
j + 1][
i ] > sstbad + 1) {
220 ftmp += sstref[
j + 1][
i ];
225 reftmp[0][0] = (sstref[
j ][
i ] > sstbad + 1 ? sstref[
j ][
i ] : ftmp);
226 reftmp[0][1] = (sstref[
j ][
i + 1] > sstbad + 1 ? sstref[
j ][
i + 1] : ftmp);
227 reftmp[1][1] = (sstref[
j + 1][
i + 1] > sstbad + 1 ? sstref[
j + 1][
i + 1] : ftmp);
228 reftmp[1][0] = (sstref[
j + 1][
i ] > sstbad + 1 ? sstref[
j + 1][
i ] : ftmp);
230 sst = (1 -
t)*(1 -
u) * reftmp[0][0] +
t * (1 -
u) * reftmp[0][1] +
t *
u * reftmp[1][1] + (1 -
t) *
u * reftmp[1][0];
242 static int firstCall = 1;
243 static size_t nx = 0;
244 static size_t ny = 0;
245 static float dx = 0.1;
246 static float dy = 0.1;
248 static float **sstref;
249 static float *latitudes;
250 static float *longitudes;
263 char sdsname[H4_MAX_NC_NAME] =
"";
264 int32_t ncid, ndims, nvars, ngatts, unlimdimid;
265 int32_t latDimID, lonDimID;
272 printf(
"Loading Daily CMC SST reference from %s\n", sstfile);
276 if (nc_open(sstfile, NC_NOWRITE, &ncid) == NC_NOERR) {
277 nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid);
279 strcpy(sdsname,
"analysed_sst");
280 nc_inq_varid(ncid, sdsname, &sds_id);
282 if (nc_inq_dimid(ncid,
"lat", &latDimID) != NC_NOERR) {
283 printf(
"Whoops! something is wrong reading the CMC SST reference file: %s\n", sstfile);
286 nc_inq_dimlen(ncid, latDimID, &ny);
288 if (nc_inq_dimid(ncid,
"lon", &lonDimID) != NC_NOERR) {
289 printf(
"Whoops! something is wrong reading the CMC SST reference file: %s\n", sstfile);
292 nc_inq_dimlen(ncid, lonDimID, &nx);
299 latitudes = (
float *) calloc(ny,
sizeof(
float));
300 longitudes = (
float *) calloc(nx,
sizeof(
float));
303 if (nc_get_var_short(ncid, sds_id, &ssttmp[0][0]) != NC_NOERR) {
304 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
305 __FILE__, __LINE__, sdsname, sstfile);
309 if (nc_get_att_float(ncid, sds_id,
"scale_factor", &
slope) != NC_NOERR) {
310 fprintf(
stderr,
"-E- %s line %d: error reading scale factor.\n",
315 if (nc_get_att_float(ncid, sds_id,
"add_offset", &
offset) != NC_NOERR) {
316 fprintf(
stderr,
"-E- %s line %d: error reading scale offset.\n",
321 nc_inq_varid(ncid, sdsname, &sds_id);
322 if (nc_get_var_float(ncid, sds_id, latitudes) != NC_NOERR) {
323 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
324 __FILE__, __LINE__, sdsname, sstfile);
328 nc_inq_varid(ncid, sdsname, &sds_id);
329 if (nc_get_var_float(ncid, sds_id, longitudes) != NC_NOERR) {
330 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
331 __FILE__, __LINE__, sdsname, sstfile);
335 if (nc_close(ncid) != NC_NOERR) {
336 fprintf(
stderr,
"-E- %s line %d: error closing %s.\n",
337 __FILE__, __LINE__, sstfile);
341 fprintf(
stderr,
"-E- %s line %d: error opening %s.\n",
342 __FILE__, __LINE__, sstfile);
346 for (
j = ny-1;
j >= 0;
j--) {
347 for (
i = 0;
i < nx;
i++) {
348 if (ssttmp[
j][
i] > -999)
351 sstref[
j + 1][
i + 1] = sstbad;
353 sstref[
j + 1][0] = sstref[
j + 1][nx];
354 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
356 for (
i = 0;
i < nx + 2;
i++) {
357 sstref[0] [
i] = sstref[1][
i];
358 sstref[ny + 1][
i] = sstref[ny][
i];
367 for (
i=0;
i < nx;
i++){
368 float cdiff =
fabs(longitudes[
i] -
lon);
378 for (
i=0;
i < ny;
i++){
379 float cdiff =
fabs(latitudes[
i] -
lat);
389 xx = longitudes[lonidx];
390 yy = latitudes[latidx];
398 if (sstref[latidx ][lonidx ] > sstbad + 1) {
399 ftmp += sstref[latidx ][lonidx ];
402 if (sstref[latidx][lonidx + 1] > sstbad + 1) {
403 ftmp += sstref[latidx ][lonidx + 1];
406 if (sstref[latidx + 1][lonidx + 1] > sstbad + 1) {
407 ftmp += sstref[latidx + 1][lonidx + 1];
410 if (sstref[latidx + 1][lonidx ] > sstbad + 1) {
411 ftmp += sstref[latidx + 1][lonidx ];
416 reftmp[0][0] = (sstref[latidx ][lonidx ] > sstbad + 1 ? sstref[latidx ][lonidx ] : ftmp);
417 reftmp[0][1] = (sstref[latidx ][lonidx + 1] > sstbad + 1 ? sstref[latidx ][lonidx + 1] : ftmp);
418 reftmp[1][1] = (sstref[latidx + 1][lonidx + 1] > sstbad + 1 ? sstref[latidx + 1][lonidx + 1] : ftmp);
419 reftmp[1][0] = (sstref[latidx + 1][lonidx ] > sstbad + 1 ? sstref[latidx + 1][lonidx ] : ftmp);
421 sst = (1 -
t)*(1 -
u) * reftmp[0][0] +
t * (1 -
u) * reftmp[0][1] +
t *
u * reftmp[1][1] + (1 -
t) *
u * reftmp[1][0] -
CtoK;
448 static int firstCall = 1;
449 static int nx =
OINX;
450 static int ny =
OINY;
451 static float dx = 360.0 /
OINX;
452 static float dy = 180.0 /
OINY;
454 typedef float sstref_t[
OINX + 2];
455 static sstref_t* sstref;
464 sstref = (sstref_t*) malloc((
OINY + 2) *
sizeof (sstref_t));
466 typedef float ssttmp_t[
OINX];
467 ssttmp_t *ssttmp = (ssttmp_t*) malloc(
OINY *
sizeof (ssttmp_t));
478 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
479 printf(
"Error opening SST reference file %s for reading.\n", sstfile);
483 if (fseek(fp, 4, SEEK_SET) < 0) {
484 printf(
"Error reading SST reference file %s.\n", sstfile);
487 if (fread(&
syear,
sizeof (int32_t), 1, fp) != 1) {
488 printf(
"Error reading SST reference file %s.\n", sstfile);
491 fread(&smon,
sizeof (int32_t), 1, fp);
492 fread(&
sday,
sizeof (int32_t), 1, fp);
493 fread(&
eyear,
sizeof (int32_t), 1, fp);
494 fread(&emon,
sizeof (int32_t), 1, fp);
495 fread(&
eday,
sizeof (int32_t), 1, fp);
496 fread(&ndays,
sizeof (int32_t), 1, fp);
497 fread(&
version,
sizeof (int32_t), 1, fp);
498 fseek(fp, 4, SEEK_CUR);
511 printf(
"Loading Weekly 1-degree OI Reynolds SST reference from %s\n", sstfile);
512 printf(
" file start date (y/m/d): %d / %d / %d\n",
syear, smon,
sday);
513 printf(
" file end date (y/m/d): %d / %d / %d\n",
eyear, emon,
eday);
514 printf(
" days composited: %d\n", ndays);
515 printf(
" file version: %d\n",
version);
518 if (fseek(fp, 4, SEEK_CUR) < 0) {
519 printf(
"Error reading SST reference file %s.\n", sstfile);
522 if (fread(&ssttmp[0][0],
sizeof (
float), nx * ny, fp) != nx * ny) {
523 printf(
"Error reading SST reference file %s.\n", sstfile);
534 for (
j = 0;
j < ny;
j++) {
535 for (
i = 0;
i < nx;
i++) {
536 ii = (
i < nx / 2) ?
i + nx / 2 :
i - nx / 2;
537 sstref[
j + 1][ii + 1] = ssttmp[
j][
i];
539 sstref[
j + 1][0] = sstref[
j + 1][nx];
540 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
542 for (
i = 0;
i < nx + 2;
i++) {
543 sstref[0] [
i] = sstref[1][
i];
544 sstref[ny + 1][
i] = sstref[ny][
i];
555 xx =
i * dx - 180.0 - dx / 2;
556 yy =
j * dy - 90.0 - dy / 2;
562 sst = (1 -
t)*(1 -
u) * sstref[
j ][
i ]
563 +
t * (1 -
u) * sstref[
j ][
i + 1]
564 +
t *
u * sstref[
j + 1][
i + 1]
565 + (1 -
t) *
u * sstref[
j + 1][
i ];
584 static int firstCall = 1;
585 static int nx =
OI4NX;
586 static int ny =
OI4NY;
587 static float dx = 360.0 /
OI4NX;
588 static float dy = 180.0 /
OI4NY;
590 typedef float sstref_t[
OI4NX + 2];
591 static sstref_t* sstref;
606 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
608 typedef float ssttmp_t[
OI4NX];
610 ssttmp = (ssttmp_t*) malloc(
OI4NY *
sizeof (ssttmp_t));
619 if (year < 2006 || year > 2009) {
620 printf(
"ntev2 data only for years 2006 to 2009, not %d\n",
year);
623 printf(
"Loading ntev2 daily field from %s\n", sstfile);
627 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
628 printf(
"-E- %s line %d: error opening SST reference file %s for reading.\n",
629 __FILE__, __LINE__, sstfile);
633 if (fseek(fp, 4, SEEK_SET) < 0) {
634 printf(
"Error seeking SST NTEV2 reference file %s.\n", sstfile);
637 if (fread(&
syear,
sizeof (int32_t), 1, fp) != 1) {
638 printf(
"Error reading SST NTEV2 reference file %s.\n", sstfile);
641 fread(&smon,
sizeof (int32_t), 1, fp);
642 fread(&
sday,
sizeof (int32_t), 1, fp);
644 if (fread(&ssttmp[0][0],
sizeof (
float), nx * ny, fp) != nx * ny) {
645 printf(
"Error reading SST NTEV2 reference file %s.\n", sstfile);
654 swapc_bytes((
char *) &ssttmp[0][0],
sizeof (
float), nx * ny);
657 printf(
"Loading Daily 0.25 Deg NTEV2 Reynolds SST reference from %s\n", sstfile);
658 printf(
" file date (y/m/d): %d / %d / %d\n",
syear, smon,
sday);
665 for (
j = 0;
j < ny;
j++) {
666 for (
i = 0;
i < nx;
i++) {
667 ii = (
i < nx / 2) ?
i + nx / 2 :
i - nx / 2;
668 sstref[
j + 1][ii + 1] = ssttmp[
j][
i];
670 sstref[
j + 1][0] = sstref[
j + 1][nx];
671 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
673 for (
i = 0;
i < nx + 2;
i++) {
674 sstref[0] [
i] = sstref[1][
i];
675 sstref[ny + 1][
i] = sstref[ny][
i];
686 xx =
i * dx - 180.0 - dx / 2;
687 yy =
j * dy - 90.0 - dy / 2;
695 if (sstref[
j ][
i ] > sstbad + 1) {
696 ftmp += sstref[
j ][
i ];
699 if (sstref[
j ][
i + 1] > sstbad + 1) {
700 ftmp += sstref[
j ][
i + 1];
703 if (sstref[
j + 1][
i + 1] > sstbad + 1) {
704 ftmp += sstref[
j + 1][
i + 1];
707 if (sstref[
j + 1][
i ] > sstbad + 1) {
708 ftmp += sstref[
j + 1][
i ];
713 reftmp[0][0] = (sstref[
j ][
i ] > sstbad + 1 ? sstref[
j ][
i ] : ftmp);
714 reftmp[0][1] = (sstref[
j ][
i + 1] > sstbad + 1 ? sstref[
j ][
i + 1] : ftmp);
715 reftmp[1][1] = (sstref[
j + 1][
i + 1] > sstbad + 1 ? sstref[
j + 1][
i + 1] : ftmp);
716 reftmp[1][0] = (sstref[
j + 1][
i ] > sstbad + 1 ? sstref[
j + 1][
i ] : ftmp);
718 sst = (1 -
t)*(1 -
u) * reftmp[0][0] +
t * (1 -
u) * reftmp[0][1] +
t *
u * reftmp[1][1] + (1 -
t) *
u * reftmp[1][0];
736 static int firstCall = 1;
737 static int nx =
OI4NX;
738 static int ny =
OI4NY;
740 static float dx = 360.0 /
OI4NX;
741 static float dy = 180.0 /
OI4NY;
743 typedef float sstref_t[
OI4NX + 2];
744 static sstref_t* sstref;
758 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
761 ssttmp_t* ssttmpb = (ssttmp_t*) malloc(2 *
sizeof (ssttmp_t));
762 ssttmp_t* sstcnt = (ssttmp_t*) malloc(2 *
sizeof (ssttmp_t));
771 int leap, day1, day2;
783 if (year < 2006 || year > 2009) {
784 printf(
"ATSR data only for years 2006 to 2009, not %d\n",
year);
787 printf(
"Loading ATSR monthly fields from %s\n", sstfile);
790 for (month = 11; month >= 0; month--) {
791 if (
day > MiddleOfMonth[
leap][month]) {
827 endofyear = (otherleap == 1 ? 366 : 365);
828 numdays = ((endofyear - MiddleOfMonth[otherleap][11]) +
829 MiddleOfMonth[
leap][0]);
835 foff[0] = ((
year - 1 - 2006)*12 + 11) * reclen * 3;
837 }
else if (month == 11) {
846 foff[0] = ((
year - 2006)*12 + 11) * reclen * 3;
851 endofyear = (
leap == 1 ? 366 : 365);
852 numdays = ((endofyear - MiddleOfMonth[
leap][11]) +
853 MiddleOfMonth[otherleap][0]);
859 foff[0] = ((
year - 2006)*12 + 11) * reclen * 3;
863 day1 = MiddleOfMonth[
leap][month];
864 day2 = MiddleOfMonth[
leap][month + 1];
870 foff[0] = ((
year - 2006)*12 + month) * reclen * 3;
873 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
874 printf(
"-E- %s line %d: error opening SST reference file %s for reading.\n",
875 __FILE__, __LINE__, sstfile);
879 if (fseek(fp, foff[0] + 16, SEEK_SET) < 0) {
880 printf(
"Error seeking SST reference file %s.\n", sstfile);
884 if ((
status = fread(&ssttmpb[0][0][0],
sizeof (
float), nx * ny, fp)) != nx * ny) {
885 printf(
"Wrong atsr data read size: want %d got %d\n", nx*ny,
status);
889 if (fseek(fp, 4 + reclen + 16, SEEK_CUR) < 0) {
890 printf(
"Error seeking first counts from SST reference file %s.\n", sstfile);
893 if ((
status = fread(&sstcnt[0][0][0],
sizeof (
float), nx * ny, fp)) != nx * ny) {
894 printf(
"Wrong atsr counts data read size: want %d got %d\n", nx*ny,
status);
900 fseek(fp, 20, SEEK_CUR);
901 if ((
status = fread(&ssttmpb[1][0][0],
sizeof (
float), nx * ny, fp)) != nx * ny) {
902 printf(
"Wrong 2nd atsr data read size: want %d got %d\n", nx*ny,
status);
906 if (fseek(fp, 4 + reclen + 16, SEEK_CUR) < 0) {
907 printf(
"Error seek to second counts from SST reference file %s.\n", sstfile);
910 if ((
status = fread(&sstcnt[1][0][0],
sizeof (
float), nx * ny, fp)) != nx * ny) {
911 printf(
"Wrong 2nd atsr counts data read size: want %d got %d\n", nx*ny,
status);
917 swapc_bytes((
char *) &ssttmpb[0][0][0],
sizeof (
float), 2 * nx * ny);
918 swapc_bytes((
char *) &sstcnt[0][0][0],
sizeof (
float), 2 * nx * ny);
926 for (
j = 0;
j < ny;
j++) {
927 for (
i = 0;
i < nx;
i++) {
928 ii = (
i < nx / 2) ?
i + nx / 2 :
i - nx / 2;
929 if (ssttmpb[0][
j][
i] > -999.0 && ssttmpb[1][
j][
i] > -999.0 &&
930 sstcnt[0][
j][
i] >= minatsrcnt && sstcnt[1][
j][
i] >= minatsrcnt)
931 sstref[
j + 1][ii + 1] = w1 * ssttmpb[0][
j][
i] + w2 * ssttmpb[1][
j][
i];
933 if (ssttmpb[0][
j][
i] > -999.0 && sstcnt[0][
j][
i] >= minatsrcnt)
934 sstref[
j + 1][ii + 1] = ssttmpb[0][
j][
i];
935 else if (ssttmpb[1][
j][
i] > -999.0 && sstcnt[1][
j][
i] >= minatsrcnt)
936 sstref[
j + 1][ii + 1] = ssttmpb[1][
j][
i];
938 sstref[
j + 1][ii + 1] = sstbad;
941 sstref[
j + 1][0] = sstref[
j + 1][nx];
942 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
944 for (
i = 0;
i < nx + 2;
i++) {
945 sstref[0] [
i] = sstref[1][
i];
946 sstref[ny + 1][
i] = sstref[ny][
i];
958 xx =
i * dx - 180.0 - dx / 2;
959 yy =
j * dy - 90.0 - dy / 2;
967 if (sstref[
j ][
i ] > sstbad + 1) {
968 ftmp += sstref[
j ][
i ];
971 if (sstref[
j ][
i + 1] > sstbad + 1) {
972 ftmp += sstref[
j ][
i + 1];
975 if (sstref[
j + 1][
i + 1] > sstbad + 1) {
976 ftmp += sstref[
j + 1][
i + 1];
979 if (sstref[
j + 1][
i ] > sstbad + 1) {
980 ftmp += sstref[
j + 1][
i ];
985 reftmp[0][0] = (sstref[
j ][
i ] > sstbad + 1 ? sstref[
j ][
i ] : ftmp);
986 reftmp[0][1] = (sstref[
j ][
i + 1] > sstbad + 1 ? sstref[
j ][
i + 1] : ftmp);
987 reftmp[1][1] = (sstref[
j + 1][
i + 1] > sstbad + 1 ? sstref[
j + 1][
i + 1] : ftmp);
988 reftmp[1][0] = (sstref[
j + 1][
i ] > sstbad + 1 ? sstref[
j + 1][
i ] : ftmp);
990 sst = (1 -
t)*(1 -
u) * reftmp[0][0] +
t * (1 -
u) * reftmp[0][1] +
t *
u * reftmp[1][1] + (1 -
t) *
u * reftmp[1][0];
1008 static int firstCall = 1;
1009 static int nx =
OI4NX;
1010 static int ny =
OI4NY;
1011 static float dx = 360.0 /
OI4NX;
1012 static float dy = 180.0 /
OI4NY;
1014 typedef float sstref_t[
OI4NX + 2][2];
1015 static sstref_t* sstref;
1032 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
1035 unsigned char ssttmp[
OI4NX];
1041 printf(
"Loading 3-Day 0.25-deg AMSR-E SST reference from %s\n", sstfile);
1043 printf(
"Loading 3-Day Day or Night 0.25-deg AMSR-E SST reference from %s\n", sstfile);
1045 printf(
"Loading Daily 0.25-deg AMSR-E SST reference from %s\n", sstfile);
1049 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
1050 printf(
"-E- %s line %d: error opening SST reference file %s for reading.\n",
1051 __FILE__, __LINE__, sstfile);
1063 foff[1] = (int32_t) (nx * ny);
1070 foff[0] = (int32_t) (nx * ny);
1071 foff[1] = (int32_t) (nx * ny * 8);
1076 for (kk = 0; kk < kkmax; kk = kk + 1) {
1079 if (fseek(fp, foff[kk], SEEK_SET) < 0) {
1080 fprintf(
stderr,
"-E- %s line %d: error reading SST reference file %s.\n",
1081 __FILE__, __LINE__, sstfile);
1084 for (jj = 0; jj < ny; jj = jj + 1) {
1085 if ((
status = fread(&ssttmp[0],
sizeof (
char), nx, fp)) != nx) {
1086 printf(
"Wrong AMSR-E data read size: want %d got %d\n", nx,
status);
1090 for (ii = 0; ii < nx; ii = ii + 1) {
1094 ij = (ii < nx / 2) ? ii + nx / 2 : ii - nx / 2;
1095 if (ssttmp[ii] <= 250) {
1096 sstref[jj + 1][ij + 1][kk] = ssttmp[ii] * 0.15 - 3.0;
1098 sstref[jj + 1][ij + 1][kk] = sstbad;
1102 sstref[jj + 1][ij + 1][1] = sstref[jj + 1][ij + 1][0];
1107 sstref[jj + 1][0] [kk] = sstref[jj + 1][nx][kk];
1108 sstref[jj + 1][nx + 1][kk] = sstref[jj + 1][1] [kk];
1111 for (ii = 0; ii < nx + 2; ii = ii + 1) {
1112 sstref[0] [ii][kk] = sstref[1] [ii][kk];
1113 sstref[ny + 1][ii][kk] = sstref[ny][ii][kk];
1139 xsatid ==
NO10 || xsatid ==
NO12 || xsatid ==
NO15 || xsatid ==
NO17))))) {
1146 ii =
MAX(
MIN((
int) ((
lon + 180.0 + dx / 2) / dx), nx + 1), 0);
1147 jj =
MAX(
MIN((
int) ((
lat + 90.0 + dy / 2) / dy), ny + 1), 0);
1150 xx = ii * dx - 180.0 - dx / 2;
1151 yy = jj * dy - 90.0 - dy / 2;
1154 t = (
lon - xx) / dx;
1155 u = (
lat - yy) / dy;
1159 if (sstref[jj ][ii ][ad] > sstbad + 1) {
1160 ftmp += sstref[jj ][ii ][ad];
1163 if (sstref[jj ][ii + 1][ad] > sstbad + 1) {
1164 ftmp += sstref[jj ][ii + 1][ad];
1167 if (sstref[jj + 1][ii + 1][ad] > sstbad + 1) {
1168 ftmp += sstref[jj + 1][ii + 1][ad];
1171 if (sstref[jj + 1][ii ][ad] > sstbad + 1) {
1172 ftmp += sstref[jj + 1][ii ][ad];
1177 reftmp[0][0] = (sstref[jj ][ii ][ad] > sstbad + 1 ? sstref[jj ][ii ][ad] : ftmp);
1178 reftmp[0][1] = (sstref[jj ][ii + 1][ad] > sstbad + 1 ? sstref[jj ][ii + 1][ad] : ftmp);
1179 reftmp[1][1] = (sstref[jj + 1][ii + 1][ad] > sstbad + 1 ? sstref[jj + 1][ii + 1][ad] : ftmp);
1180 reftmp[1][0] = (sstref[jj + 1][ii ][ad] > sstbad + 1 ? sstref[jj + 1][ii ][ad] : ftmp);
1182 sst = (1 -
t)*(1 -
u) * reftmp[0][0] +
t * (1 -
u) * reftmp[0][1] +
t *
u * reftmp[1][1] + (1 -
t) *
u * reftmp[1][0];
1200 static int firstCall = 1;
1201 static int nx =
OI4NX;
1202 static int ny =
OI4NY;
1203 static float dx = 360.0 /
OI4NX;
1204 static float dy = 180.0 /
OI4NY;
1206 typedef float sstref_t[
OI4NX + 2][2];
1207 static sstref_t* sstref;
1224 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
1227 unsigned char ssttmp[
OI4NX];
1228 float fssttmp[
OI4NX];
1234 printf(
"Loading 3-Day 0.25-deg WindSat SST reference from %s\n", sstfile);
1236 printf(
"Loading 3-Day Day or Night 0.25-deg WindSat SST reference from %s\n", sstfile);
1238 printf(
"Loading Daily 0.25-deg WindSat SST reference from %s\n", sstfile);
1242 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
1243 printf(
"-E- %s line %d: error opening SST reference file %s for reading.\n",
1244 __FILE__, __LINE__, sstfile);
1257 foff[1] = (int32_t) (nx * ny *
sizeof (
float));
1264 foff[0] = (int32_t) (nx * ny);
1265 foff[1] = (int32_t) (nx * ny * 10);
1271 for (kk = 0; kk < kkmax; kk = kk + 1) {
1274 if (fseek(fp, foff[kk], SEEK_SET) < 0) {
1275 fprintf(
stderr,
"-E- %s line %d: error reading SST reference file %s.\n",
1276 __FILE__, __LINE__, sstfile);
1279 for (jj = 0; jj < ny; jj = jj + 1) {
1281 if ((
status = fread(&fssttmp[0],
sizeof (
float), nx, fp)) != nx) {
1282 printf(
"Wrong WINDSAT data read size: want %d got %d\n", nx,
status);
1289 swapc_bytes((
char *) &fssttmp[0],
sizeof (
float), nx);
1299 if ((
status = fread(&ssttmp[0],
sizeof (
char), nx, fp)) != nx) {
1300 printf(
"Wrong WINDSAT data read size: want %d got %d\n", nx,
status);
1305 for (ii = 0; ii < nx; ii = ii + 1) {
1309 ij = (ii < nx / 2) ? ii + nx / 2 : ii - nx / 2;
1312 if (fssttmp[ii] > -9998.0) {
1313 sstref[jj + 1][ij + 1][kk] = fssttmp[ii];
1315 sstref[jj + 1][ij + 1][kk] = sstbad;
1318 if (ssttmp[ii] <= 250) {
1319 sstref[jj + 1][ij + 1][kk] = ssttmp[ii] * 0.15 - 3.0;
1321 sstref[jj + 1][ij + 1][kk] = sstbad;
1326 sstref[jj + 1][ij + 1][1] = sstref[jj + 1][ij + 1][0];
1331 sstref[jj + 1][0] [kk] = sstref[jj + 1][nx][kk];
1332 sstref[jj + 1][nx + 1][kk] = sstref[jj + 1][1] [kk];
1335 for (ii = 0; ii < nx + 2; ii = ii + 1) {
1336 sstref[0] [ii][kk] = sstref[1] [ii][kk];
1337 sstref[ny + 1][ii][kk] = sstref[ny][ii][kk];
1368 xsatid ==
NO10 || xsatid ==
NO12 || xsatid ==
NO15 || xsatid ==
NO17))))) {
1375 ii =
MAX(
MIN((
int) ((
lon + 180.0 + dx / 2) / dx), nx + 1), 0);
1376 jj =
MAX(
MIN((
int) ((
lat + 90.0 + dy / 2) / dy), ny + 1), 0);
1379 xx = ii * dx - 180.0 - dx / 2;
1380 yy = jj * dy - 90.0 - dy / 2;
1383 t = (
lon - xx) / dx;
1384 u = (
lat - yy) / dy;
1388 if (sstref[jj ][ii ][ad] > sstbad + 1) {
1389 ftmp += sstref[jj ][ii ][ad];
1392 if (sstref[jj ][ii + 1][ad] > sstbad + 1) {
1393 ftmp += sstref[jj ][ii + 1][ad];
1396 if (sstref[jj + 1][ii + 1][ad] > sstbad + 1) {
1397 ftmp += sstref[jj + 1][ii + 1][ad];
1400 if (sstref[jj + 1][ii ][ad] > sstbad + 1) {
1401 ftmp += sstref[jj + 1][ii ][ad];
1406 reftmp[0][0] = (sstref[jj ][ii ][ad] > sstbad + 1 ? sstref[jj ][ii ][ad] : ftmp);
1407 reftmp[0][1] = (sstref[jj ][ii + 1][ad] > sstbad + 1 ? sstref[jj ][ii + 1][ad] : ftmp);
1408 reftmp[1][1] = (sstref[jj + 1][ii + 1][ad] > sstbad + 1 ? sstref[jj + 1][ii + 1][ad] : ftmp);
1409 reftmp[1][0] = (sstref[jj + 1][ii ][ad] > sstbad + 1 ? sstref[jj + 1][ii ][ad] : ftmp);
1411 sst = (1 -
t)*(1 -
u) * reftmp[0][0] +
t * (1 -
u) * reftmp[0][1] +
t *
u * reftmp[1][1] + (1 -
t) *
u * reftmp[1][0];
1429 static int firstCall = 1;
1430 static int nx =
OI1NX;
1431 static int ny =
OI1NY;
1432 static int32_t slen = 0;
1433 static float *sref =
NULL;
1434 static float dx = 360.0 /
OI1NX;
1435 static float dy = 180.0 /
OI1NY;
1447 char name [H4_MAX_NC_NAME] =
"";
1448 char sdsname[H4_MAX_NC_NAME] =
"";
1454 int32 dims[H4_MAX_VAR_DIMS];
1456 int32
start[4] = {0, 0, 0, 0};
1463 printf(
"Loading Daily 0.1-deg ATSR SST reference from %s\n", sstfile);
1468 if ((sref = (
float *) malloc(slen *
sizeof (
float))) ==
NULL) {
1469 fprintf(
stderr,
"-E- %s line %d: Unable to allocate sstref array.\n",
1470 __FILE__, __LINE__);
1475 if ((stmp = (
float *) malloc(stlen *
sizeof (
float))) ==
NULL) {
1476 fprintf(
stderr,
"-E- %s line %d: Unable to allocate ssttmp array.\n",
1477 __FILE__, __LINE__);
1482 sd_id = SDstart(sstfile, DFACC_RDONLY);
1483 if (sd_id ==
FAIL) {
1484 fprintf(
stderr,
"-E- %s line %d: error reading %s.\n",
1485 __FILE__, __LINE__, sstfile);
1489 strcpy(sdsname,
"sst_skin");
1490 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1494 fprintf(
stderr,
"-E- %s Line %d: Error reading SDS %s from %s.\n",
1495 __FILE__, __LINE__, sdsname, sstfile);
1498 status = SDendaccess(sds_id);
1506 for (
j = 0;
j < ny;
j++) {
1514 jjl = jj * (nx + 2);
1515 for (
i = 0;
i < nx;
i++) {
1516 if (stmp[jl +
i] > -998.0) {
1517 sref[jjl +
i + 1] = stmp[jl +
i];
1519 sref[jjl +
i + 1] = sstbad;
1522 sref[jl] = sref[jl + nx];
1523 sref[jl + nx + 2 + nx + 1] = sref[jl + nx + 2 + 1];
1525 ll = (ny + 1)*(nx + 2);
1527 for (
i = 0;
i < nx + 2;
i++) {
1528 sref[
i] = sref[nx + 2 +
i];
1529 sref[ll +
i] = sref[
nl +
i];
1540 xx =
i * dx - 180.0 - dx / 2;
1541 yy =
j * dy - 90.0 - dy / 2;
1544 t = (
lon - xx) / dx;
1545 u = (
lat - yy) / dy;
1549 jl = (
j - 1)*(nx + 2);
1551 if (sref[jl +
i ] > sstbad + 1) {
1552 ftmp += sref[jl +
i ];
1555 if (sref[jl +
i + 1] > sstbad + 1) {
1556 ftmp += sref[jl +
i + 1];
1559 if (sref[
nl +
i + 1] > sstbad + 1) {
1560 ftmp += sref[
nl +
i + 1];
1563 if (sref[
nl +
i ] > sstbad + 1) {
1564 ftmp += sref[
nl +
i ];
1569 reftmp[0][0] = (sref[jl +
i ] > sstbad + 1 ? sref[jl +
i ] : ftmp);
1570 reftmp[0][1] = (sref[jl +
i + 1] > sstbad + 1 ? sref[jl +
i + 1] : ftmp);
1571 reftmp[1][1] = (sref[
nl +
i + 1] > sstbad + 1 ? sref[
nl +
i + 1] : ftmp);
1572 reftmp[1][0] = (sref[
nl +
i ] > sstbad + 1 ? sref[
nl +
i ] : ftmp);
1574 sst = (1 -
t)*(1 -
u) * reftmp[0][0] +
t * (1 -
u) * reftmp[0][1] +
t *
u * reftmp[1][1] + (1 -
t) *
u * reftmp[1][0];
1596 int32_t xsatid =
l1rec->l1file->subsensorID;
1602 int32_t
year = (int32_t) yr;
1603 int32_t
day = (int32_t) dy;
1610 if (access(sstfile, F_OK) || access(sstfile, R_OK)) {
1611 printf(
"-E- %s line %d: SST input file '%s' does not exist or cannot open.\n",
1612 __FILE__, __LINE__, sstfile);
1621 }
else if (reftyp == 7) {
1625 }
else if (reftyp == 6) {
1629 }
else if (reftyp == 5) {
1633 }
else if (reftyp == 4) {
1637 }
else if (reftyp == 3) {
1641 }
else if (reftyp == 2) {
1645 }
else if (reftyp == 1) {
1651 char title[255] =
"";
1655 if (Hishdf(sstfile))
1656 sd_id = SDstart(sstfile, DFACC_RDONLY);
1660 if (sd_id !=
FAIL) {
1662 char title[255] =
"";
1663 if (SDreadattr(sd_id, SDfindattr(sd_id,
"title"), (VOIDP)
title) == 0) {
1664 if (strstr(
title,
"Daily-OI-V2") !=
NULL) {
1666 }
else if (strstr(
title,
"ARC Sea Surface Temperature") !=
NULL) {
1670 printf(
"-E- %s line %d: Unable to initialize SST file\n", __FILE__, __LINE__);
1671 printf(
"%s %d\n", sstfile,
day);
1674 }
else if (SDreadattr(sd_id, SDfindattr(sd_id,
"Title"), (VOIDP)
title) == 0) {
1675 if (strstr(
title,
"SST Climatology") !=
NULL) {
1678 printf(
"-E- %s line %d: Unable to initialize SST file\n", __FILE__, __LINE__);
1679 printf(
"%s %d\n", sstfile,
day);
1687 if (nc_open(sstfile, NC_NOWRITE, &sd_id) == NC_NOERR) {
1689 if (nc_get_att_text(sd_id, NC_GLOBAL,
"title",
title) == NC_NOERR) {
1690 if (strstr(
title,
"Daily-OI") ||
1691 strstr(
title,
"NOAA/NCEI 1/4 Degree Daily Optimum Interpolation Sea Surface Temperature (OISST) Analysis")) {
1693 }
else if (strstr(
title,
"CMC") !=
NULL) {
1696 printf(
"-E- %s : Unable to initialize SST file\n", __FILE__);
1697 printf(
"%s %d\n", sstfile,
day);
1713 char file [FILENAME_MAX] =
"";
1714 if ((tmp_str = getenv(
"OCDATAROOT")) ==
NULL) {
1715 printf(
"OCDATAROOT environment variable is not defined.\n");
1719 strcat(
file,
"/common/sst_climatology.hdf");
1721 printf(
"-E- %s line %d: Unable to initialize SST file\n", __FILE__, __LINE__);
1731 l1rec->ssttype[ip] = 0;
1736 l1rec->ssttype[ip] = 1;
1742 l1rec->ssttype[ip] = 2;
1748 l1rec->ssttype[ip] = 3;
1754 l1rec->ssttype[ip] = 4;
1760 l1rec->ssttype[ip] = 5;
1765 l1rec->ssttype[ip] = 6;
1771 l1rec->ssttype[ip] = 7;
1773 if (sst > sstbad + 1) {
1779 l1rec->ssttype[ip] = 8;
1786 l1rec->ssttype[ip] = 9;
1792 l1rec->ssttype[ip] = 10;
1798 l1rec->ssttype[ip] = 11;
1800 if (sst > sstbad + 1) {
1806 l1rec->ssttype[ip] = 12;
1811 printf(
"-E- %s line %d: unknown SST input file format for %s.\n", __FILE__, __LINE__, sstfile);
1815 if (sst < (sstbad + 1)) {
1817 l1rec->ssttype[ip] = 0;