28 #define WINDSAT3DAY 10
36 static int32_t format = -1;
38 static int MiddleOfMonth[2][12] = {
39 {15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349},
40 {15, 45, 75, 106, 136, 167, 197, 228, 259, 289, 320, 350}};
53 static int firstCall = 1;
54 static int nx =
OI4NX;
55 static int ny =
OI4NY;
56 static float dx = 360.0 /
OI4NX;
57 static float dy = 180.0 /
OI4NY;
59 typedef float sstref_t[
OI4NX + 2];
60 static sstref_t* sstref;
72 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
76 ssttmp = (ssttmp_t*) malloc(
OI4NY *
sizeof (ssttmp_t));
78 char name [H4_MAX_NC_NAME] =
"";
79 char sdsname[H4_MAX_NC_NAME] =
"";
80 int ncid, ndims, nvars, ngatts, unlimdimid;
85 int32 dims[H4_MAX_VAR_DIMS];
87 int32
start[4] = {0, 0, 0, 0};
94 printf(
"Loading Daily V2 0.25-deg OI Reynolds SST reference from %s\n", sstfile);
105 sd_id = SDstart(sstfile, DFACC_RDONLY);
111 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
113 status = SDreaddata(sds_id,
start,
NULL, dims, (VOIDP) & ssttmp[0][0]);
115 fprintf(
stderr,
"-E- %s Line %d: Error reading SDS %s from %s.\n",
116 __FILE__, __LINE__, sdsname, sstfile);
119 if (
getHDFattr(sd_id,
"scale_factor", sdsname, (VOIDP) &
slope) != 0) {
120 fprintf(
stderr,
"-E- %s line %d: error reading scale factor.\n",
125 fprintf(
stderr,
"-E- %s line %d: error reading scale offset.\n",
129 status = SDendaccess(sds_id);
134 if (nc_open(sstfile, NC_NOWRITE, &ncid) == NC_NOERR) {
136 status = nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid);
137 status = nc_inq_varid(ncid, sdsname, &sds_id);
140 if (nc_get_var(ncid, sds_id, &ssttmp[0][0]) != NC_NOERR) {
141 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
142 __FILE__, __LINE__, sdsname, sstfile);
146 if (nc_get_att_float(ncid, sds_id,
"scale_factor", &
slope) != NC_NOERR) {
147 fprintf(
stderr,
"-E- %s line %d: error reading scale factor.\n",
152 if (nc_get_att_float(ncid, sds_id,
"add_offset", &
offset) != NC_NOERR) {
153 fprintf(
stderr,
"-E- %s line %d: error reading scale offset.\n",
158 if (nc_close(ncid) != NC_NOERR) {
159 fprintf(
stderr,
"-E- %s line %d: error closing %s.\n",
160 __FILE__, __LINE__, sstfile);
165 fprintf(
stderr,
"-E- %s line %d: error reading %s.\n",
166 __FILE__, __LINE__, sstfile);
174 for (
j = 0;
j < ny;
j++) {
175 for (
i = 0;
i < nx;
i++) {
176 ii = (
i < nx / 2) ?
i + nx / 2 :
i - nx / 2;
177 if (ssttmp[
j][
i] > -999)
180 sstref[
j + 1][ii + 1] = sstbad;
182 sstref[
j + 1][0] = sstref[
j + 1][nx];
183 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
185 for (
i = 0;
i < nx + 2;
i++) {
186 sstref[0] [
i] = sstref[1][
i];
187 sstref[ny + 1][
i] = sstref[ny][
i];
199 xx =
i * dx - 180.0 - dx / 2;
200 yy =
j * dy - 90.0 - dy / 2;
208 if (sstref[
j ][
i ] > sstbad + 1) {
209 ftmp += sstref[
j ][
i ];
212 if (sstref[
j ][
i + 1] > sstbad + 1) {
213 ftmp += sstref[
j ][
i + 1];
216 if (sstref[
j + 1][
i + 1] > sstbad + 1) {
217 ftmp += sstref[
j + 1][
i + 1];
220 if (sstref[
j + 1][
i ] > sstbad + 1) {
221 ftmp += sstref[
j + 1][
i ];
226 reftmp[0][0] = (sstref[
j ][
i ] > sstbad + 1 ? sstref[
j ][
i ] : ftmp);
227 reftmp[0][1] = (sstref[
j ][
i + 1] > sstbad + 1 ? sstref[
j ][
i + 1] : ftmp);
228 reftmp[1][1] = (sstref[
j + 1][
i + 1] > sstbad + 1 ? sstref[
j + 1][
i + 1] : ftmp);
229 reftmp[1][0] = (sstref[
j + 1][
i ] > sstbad + 1 ? sstref[
j + 1][
i ] : ftmp);
231 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];
243 static int firstCall = 1;
244 static size_t nx = 0;
245 static size_t ny = 0;
246 static float dx = 0.1;
247 static float dy = 0.1;
249 static float **sstref;
250 static float *latitudes;
251 static float *longitudes;
264 char sdsname[H4_MAX_NC_NAME] =
"";
265 int32_t ncid, ndims, nvars, ngatts, unlimdimid;
266 int32_t latDimID, lonDimID;
273 printf(
"Loading SST reference from %s\n", sstfile);
277 if (nc_open(sstfile, NC_NOWRITE, &ncid) == NC_NOERR) {
278 nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid);
280 strcpy(sdsname,
"analysed_sst");
281 if (nc_inq_varid(ncid, sdsname, &sds_id) != NC_NOERR){
283 if (nc_inq_varid(ncid, sdsname, &sds_id) != NC_NOERR){
284 printf(
"Whoops! something is wrong reading the SST reference file: %s\n", sstfile);
289 if (nc_inq_dimid(ncid,
"lat", &latDimID) != NC_NOERR) {
290 printf(
"Whoops! something is wrong reading the SST reference file: %s\n", sstfile);
293 nc_inq_dimlen(ncid, latDimID, &ny);
295 if (nc_inq_dimid(ncid,
"lon", &lonDimID) != NC_NOERR) {
296 printf(
"Whoops! something is wrong reading the SST reference file: %s\n", sstfile);
299 nc_inq_dimlen(ncid, lonDimID, &nx);
306 latitudes = (
float *) calloc(ny,
sizeof(
float));
307 longitudes = (
float *) calloc(nx,
sizeof(
float));
310 if (nc_get_var_short(ncid, sds_id, &ssttmp[0][0]) != NC_NOERR) {
311 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
312 __FILE__, __LINE__, sdsname, sstfile);
316 if (nc_get_att_float(ncid, sds_id,
"scale_factor", &
slope) != NC_NOERR) {
317 fprintf(
stderr,
"-E- %s line %d: error reading scale factor.\n",
322 if (nc_get_att_float(ncid, sds_id,
"add_offset", &
offset) != NC_NOERR) {
323 fprintf(
stderr,
"-E- %s line %d: error reading scale offset.\n",
328 nc_inq_varid(ncid, sdsname, &sds_id);
329 if (nc_get_var_float(ncid, sds_id, latitudes) != NC_NOERR) {
330 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
331 __FILE__, __LINE__, sdsname, sstfile);
335 nc_inq_varid(ncid, sdsname, &sds_id);
336 if (nc_get_var_float(ncid, sds_id, longitudes) != NC_NOERR) {
337 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
338 __FILE__, __LINE__, sdsname, sstfile);
342 if (nc_close(ncid) != NC_NOERR) {
343 fprintf(
stderr,
"-E- %s line %d: error closing %s.\n",
344 __FILE__, __LINE__, sstfile);
348 fprintf(
stderr,
"-E- %s line %d: error opening %s.\n",
349 __FILE__, __LINE__, sstfile);
353 for (
j = ny-1;
j >= 0;
j--) {
354 for (
i = 0;
i < nx;
i++) {
355 if (ssttmp[
j][
i] > -999)
358 sstref[
j + 1][
i + 1] = sstbad;
360 sstref[
j + 1][0] = sstref[
j + 1][nx];
361 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
363 for (
i = 0;
i < nx + 2;
i++) {
364 sstref[0] [
i] = sstref[1][
i];
365 sstref[ny + 1][
i] = sstref[ny][
i];
374 for (
i=0;
i < nx;
i++){
375 float cdiff =
fabs(longitudes[
i] -
lon);
385 for (
i=0;
i < ny;
i++){
386 float cdiff =
fabs(latitudes[
i] -
lat);
396 xx = longitudes[lonidx];
397 yy = latitudes[latidx];
405 if (sstref[latidx ][lonidx ] > sstbad + 1) {
406 ftmp += sstref[latidx ][lonidx ];
409 if (sstref[latidx][lonidx + 1] > sstbad + 1) {
410 ftmp += sstref[latidx ][lonidx + 1];
413 if (sstref[latidx + 1][lonidx + 1] > sstbad + 1) {
414 ftmp += sstref[latidx + 1][lonidx + 1];
417 if (sstref[latidx + 1][lonidx ] > sstbad + 1) {
418 ftmp += sstref[latidx + 1][lonidx ];
423 reftmp[0][0] = (sstref[latidx ][lonidx ] > sstbad + 1 ? sstref[latidx ][lonidx ] : ftmp);
424 reftmp[0][1] = (sstref[latidx ][lonidx + 1] > sstbad + 1 ? sstref[latidx ][lonidx + 1] : ftmp);
425 reftmp[1][1] = (sstref[latidx + 1][lonidx + 1] > sstbad + 1 ? sstref[latidx + 1][lonidx + 1] : ftmp);
426 reftmp[1][0] = (sstref[latidx + 1][lonidx ] > sstbad + 1 ? sstref[latidx + 1][lonidx ] : ftmp);
428 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];
457 static int firstCall = 1;
458 static int nx =
OINX;
459 static int ny =
OINY;
460 static float dx = 360.0 /
OINX;
461 static float dy = 180.0 /
OINY;
463 typedef float sstref_t[
OINX + 2];
464 static sstref_t* sstref;
473 sstref = (sstref_t*) malloc((
OINY + 2) *
sizeof (sstref_t));
475 typedef float ssttmp_t[
OINX];
476 ssttmp_t *ssttmp = (ssttmp_t*) malloc(
OINY *
sizeof (ssttmp_t));
487 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
488 printf(
"Error opening SST reference file %s for reading.\n", sstfile);
492 if (fseek(fp, 4, SEEK_SET) < 0) {
493 printf(
"Error reading SST reference file %s.\n", sstfile);
496 if (fread(&
syear,
sizeof (int32_t), 1, fp) != 1) {
497 printf(
"Error reading SST reference file %s.\n", sstfile);
500 fread(&smon,
sizeof (int32_t), 1, fp);
501 fread(&
sday,
sizeof (int32_t), 1, fp);
502 fread(&
eyear,
sizeof (int32_t), 1, fp);
503 fread(&emon,
sizeof (int32_t), 1, fp);
504 fread(&
eday,
sizeof (int32_t), 1, fp);
505 fread(&ndays,
sizeof (int32_t), 1, fp);
506 fread(&
version,
sizeof (int32_t), 1, fp);
507 fseek(fp, 4, SEEK_CUR);
520 printf(
"Loading Weekly 1-degree OI Reynolds SST reference from %s\n", sstfile);
521 printf(
" file start date (y/m/d): %d / %d / %d\n",
syear, smon,
sday);
522 printf(
" file end date (y/m/d): %d / %d / %d\n",
eyear, emon,
eday);
523 printf(
" days composited: %d\n", ndays);
524 printf(
" file version: %d\n",
version);
527 if (fseek(fp, 4, SEEK_CUR) < 0) {
528 printf(
"Error reading SST reference file %s.\n", sstfile);
531 if (fread(&ssttmp[0][0],
sizeof (
float), nx * ny, fp) != nx * ny) {
532 printf(
"Error reading SST reference file %s.\n", sstfile);
543 for (
j = 0;
j < ny;
j++) {
544 for (
i = 0;
i < nx;
i++) {
545 ii = (
i < nx / 2) ?
i + nx / 2 :
i - nx / 2;
546 sstref[
j + 1][ii + 1] = ssttmp[
j][
i];
548 sstref[
j + 1][0] = sstref[
j + 1][nx];
549 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
551 for (
i = 0;
i < nx + 2;
i++) {
552 sstref[0] [
i] = sstref[1][
i];
553 sstref[ny + 1][
i] = sstref[ny][
i];
564 xx =
i * dx - 180.0 - dx / 2;
565 yy =
j * dy - 90.0 - dy / 2;
571 sst = (1 -
t)*(1 -
u) * sstref[
j ][
i ]
572 +
t * (1 -
u) * sstref[
j ][
i + 1]
573 +
t *
u * sstref[
j + 1][
i + 1]
574 + (1 -
t) *
u * sstref[
j + 1][
i ];
593 static int firstCall = 1;
594 static int nx =
OI4NX;
595 static int ny =
OI4NY;
596 static float dx = 360.0 /
OI4NX;
597 static float dy = 180.0 /
OI4NY;
599 typedef float sstref_t[
OI4NX + 2];
600 static sstref_t* sstref;
615 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
617 typedef float ssttmp_t[
OI4NX];
619 ssttmp = (ssttmp_t*) malloc(
OI4NY *
sizeof (ssttmp_t));
628 if (year < 2006 || year > 2009) {
629 printf(
"ntev2 data only for years 2006 to 2009, not %d\n", year);
632 printf(
"Loading ntev2 daily field from %s\n", sstfile);
636 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
637 printf(
"-E- %s line %d: error opening SST reference file %s for reading.\n",
638 __FILE__, __LINE__, sstfile);
642 if (fseek(fp, 4, SEEK_SET) < 0) {
643 printf(
"Error seeking SST NTEV2 reference file %s.\n", sstfile);
646 if (fread(&
syear,
sizeof (int32_t), 1, fp) != 1) {
647 printf(
"Error reading SST NTEV2 reference file %s.\n", sstfile);
650 fread(&smon,
sizeof (int32_t), 1, fp);
651 fread(&
sday,
sizeof (int32_t), 1, fp);
653 if (fread(&ssttmp[0][0],
sizeof (
float), nx * ny, fp) != nx * ny) {
654 printf(
"Error reading SST NTEV2 reference file %s.\n", sstfile);
663 swapc_bytes((
char *) &ssttmp[0][0],
sizeof (
float), nx * ny);
666 printf(
"Loading Daily 0.25 Deg NTEV2 Reynolds SST reference from %s\n", sstfile);
667 printf(
" file date (y/m/d): %d / %d / %d\n",
syear, smon,
sday);
674 for (
j = 0;
j < ny;
j++) {
675 for (
i = 0;
i < nx;
i++) {
676 ii = (
i < nx / 2) ?
i + nx / 2 :
i - nx / 2;
677 sstref[
j + 1][ii + 1] = ssttmp[
j][
i];
679 sstref[
j + 1][0] = sstref[
j + 1][nx];
680 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
682 for (
i = 0;
i < nx + 2;
i++) {
683 sstref[0] [
i] = sstref[1][
i];
684 sstref[ny + 1][
i] = sstref[ny][
i];
695 xx =
i * dx - 180.0 - dx / 2;
696 yy =
j * dy - 90.0 - dy / 2;
704 if (sstref[
j ][
i ] > sstbad + 1) {
705 ftmp += sstref[
j ][
i ];
708 if (sstref[
j ][
i + 1] > sstbad + 1) {
709 ftmp += sstref[
j ][
i + 1];
712 if (sstref[
j + 1][
i + 1] > sstbad + 1) {
713 ftmp += sstref[
j + 1][
i + 1];
716 if (sstref[
j + 1][
i ] > sstbad + 1) {
717 ftmp += sstref[
j + 1][
i ];
722 reftmp[0][0] = (sstref[
j ][
i ] > sstbad + 1 ? sstref[
j ][
i ] : ftmp);
723 reftmp[0][1] = (sstref[
j ][
i + 1] > sstbad + 1 ? sstref[
j ][
i + 1] : ftmp);
724 reftmp[1][1] = (sstref[
j + 1][
i + 1] > sstbad + 1 ? sstref[
j + 1][
i + 1] : ftmp);
725 reftmp[1][0] = (sstref[
j + 1][
i ] > sstbad + 1 ? sstref[
j + 1][
i ] : ftmp);
727 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];
744 float get_atsr(
char *sstfile,
float lon,
float lat, int32_t year, int32_t
day, int32_t minatsrcnt) {
745 static int firstCall = 1;
746 static int nx =
OI4NX;
747 static int ny =
OI4NY;
749 static float dx = 360.0 /
OI4NX;
750 static float dy = 180.0 /
OI4NY;
752 typedef float sstref_t[
OI4NX + 2];
753 static sstref_t* sstref;
767 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
770 ssttmp_t* ssttmpb = (ssttmp_t*) malloc(2 *
sizeof (ssttmp_t));
771 ssttmp_t* sstcnt = (ssttmp_t*) malloc(2 *
sizeof (ssttmp_t));
780 int leap, day1, day2;
792 if (year < 2006 || year > 2009) {
793 printf(
"ATSR data only for years 2006 to 2009, not %d\n", year);
796 printf(
"Loading ATSR monthly fields from %s\n", sstfile);
799 for (month = 11; month >= 0; month--) {
800 if (
day > MiddleOfMonth[
leap][month]) {
835 otherleap = (
isleap(year - 1) ==
TRUE ? 1 : 0);
836 endofyear = (otherleap == 1 ? 366 : 365);
837 numdays = ((endofyear - MiddleOfMonth[otherleap][11]) +
838 MiddleOfMonth[
leap][0]);
844 foff[0] = ((year - 1 - 2006)*12 + 11) * reclen * 3;
846 }
else if (month == 11) {
855 foff[0] = ((year - 2006)*12 + 11) * reclen * 3;
859 otherleap = (
isleap(year + 1) ==
TRUE ? 1 : 0);
860 endofyear = (
leap == 1 ? 366 : 365);
861 numdays = ((endofyear - MiddleOfMonth[
leap][11]) +
862 MiddleOfMonth[otherleap][0]);
868 foff[0] = ((year - 2006)*12 + 11) * reclen * 3;
872 day1 = MiddleOfMonth[
leap][month];
873 day2 = MiddleOfMonth[
leap][month + 1];
879 foff[0] = ((year - 2006)*12 + month) * reclen * 3;
882 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
883 printf(
"-E- %s line %d: error opening SST reference file %s for reading.\n",
884 __FILE__, __LINE__, sstfile);
888 if (fseek(fp, foff[0] + 16, SEEK_SET) < 0) {
889 printf(
"Error seeking SST reference file %s.\n", sstfile);
893 if ((
status = fread(&ssttmpb[0][0][0],
sizeof (
float), nx * ny, fp)) != nx * ny) {
894 printf(
"Wrong atsr data read size: want %d got %d\n", nx*ny,
status);
898 if (fseek(fp, 4 + reclen + 16, SEEK_CUR) < 0) {
899 printf(
"Error seeking first counts from SST reference file %s.\n", sstfile);
902 if ((
status = fread(&sstcnt[0][0][0],
sizeof (
float), nx * ny, fp)) != nx * ny) {
903 printf(
"Wrong atsr counts data read size: want %d got %d\n", nx*ny,
status);
909 fseek(fp, 20, SEEK_CUR);
910 if ((
status = fread(&ssttmpb[1][0][0],
sizeof (
float), nx * ny, fp)) != nx * ny) {
911 printf(
"Wrong 2nd atsr data read size: want %d got %d\n", nx*ny,
status);
915 if (fseek(fp, 4 + reclen + 16, SEEK_CUR) < 0) {
916 printf(
"Error seek to second counts from SST reference file %s.\n", sstfile);
919 if ((
status = fread(&sstcnt[1][0][0],
sizeof (
float), nx * ny, fp)) != nx * ny) {
920 printf(
"Wrong 2nd atsr counts data read size: want %d got %d\n", nx*ny,
status);
926 swapc_bytes((
char *) &ssttmpb[0][0][0],
sizeof (
float), 2 * nx * ny);
927 swapc_bytes((
char *) &sstcnt[0][0][0],
sizeof (
float), 2 * nx * ny);
935 for (
j = 0;
j < ny;
j++) {
936 for (
i = 0;
i < nx;
i++) {
937 ii = (
i < nx / 2) ?
i + nx / 2 :
i - nx / 2;
938 if (ssttmpb[0][
j][
i] > -999.0 && ssttmpb[1][
j][
i] > -999.0 &&
939 sstcnt[0][
j][
i] >= minatsrcnt && sstcnt[1][
j][
i] >= minatsrcnt)
940 sstref[
j + 1][ii + 1] = w1 * ssttmpb[0][
j][
i] + w2 * ssttmpb[1][
j][
i];
942 if (ssttmpb[0][
j][
i] > -999.0 && sstcnt[0][
j][
i] >= minatsrcnt)
943 sstref[
j + 1][ii + 1] = ssttmpb[0][
j][
i];
944 else if (ssttmpb[1][
j][
i] > -999.0 && sstcnt[1][
j][
i] >= minatsrcnt)
945 sstref[
j + 1][ii + 1] = ssttmpb[1][
j][
i];
947 sstref[
j + 1][ii + 1] = sstbad;
950 sstref[
j + 1][0] = sstref[
j + 1][nx];
951 sstref[
j + 1][nx + 1] = sstref[
j + 1][1];
953 for (
i = 0;
i < nx + 2;
i++) {
954 sstref[0] [
i] = sstref[1][
i];
955 sstref[ny + 1][
i] = sstref[ny][
i];
967 xx =
i * dx - 180.0 - dx / 2;
968 yy =
j * dy - 90.0 - dy / 2;
976 if (sstref[
j ][
i ] > sstbad + 1) {
977 ftmp += sstref[
j ][
i ];
980 if (sstref[
j ][
i + 1] > sstbad + 1) {
981 ftmp += sstref[
j ][
i + 1];
984 if (sstref[
j + 1][
i + 1] > sstbad + 1) {
985 ftmp += sstref[
j + 1][
i + 1];
988 if (sstref[
j + 1][
i ] > sstbad + 1) {
989 ftmp += sstref[
j + 1][
i ];
994 reftmp[0][0] = (sstref[
j ][
i ] > sstbad + 1 ? sstref[
j ][
i ] : ftmp);
995 reftmp[0][1] = (sstref[
j ][
i + 1] > sstbad + 1 ? sstref[
j ][
i + 1] : ftmp);
996 reftmp[1][1] = (sstref[
j + 1][
i + 1] > sstbad + 1 ? sstref[
j + 1][
i + 1] : ftmp);
997 reftmp[1][0] = (sstref[
j + 1][
i ] > sstbad + 1 ? sstref[
j + 1][
i ] : ftmp);
999 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];
1017 static int firstCall = 1;
1018 static int nx =
OI4NX;
1019 static int ny =
OI4NY;
1020 static float dx = 360.0 /
OI4NX;
1021 static float dy = 180.0 /
OI4NY;
1023 typedef float sstref_t[
OI4NX + 2][2];
1024 static sstref_t* sstref;
1041 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
1044 unsigned char ssttmp[
OI4NX];
1050 printf(
"Loading 3-Day 0.25-deg AMSR-E SST reference from %s\n", sstfile);
1052 printf(
"Loading 3-Day Day or Night 0.25-deg AMSR-E SST reference from %s\n", sstfile);
1054 printf(
"Loading Daily 0.25-deg AMSR-E SST reference from %s\n", sstfile);
1058 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
1059 printf(
"-E- %s line %d: error opening SST reference file %s for reading.\n",
1060 __FILE__, __LINE__, sstfile);
1072 foff[1] = (int32_t) (nx * ny);
1079 foff[0] = (int32_t) (nx * ny);
1080 foff[1] = (int32_t) (nx * ny * 8);
1085 for (kk = 0; kk < kkmax; kk = kk + 1) {
1088 if (fseek(fp, foff[kk], SEEK_SET) < 0) {
1089 fprintf(
stderr,
"-E- %s line %d: error reading SST reference file %s.\n",
1090 __FILE__, __LINE__, sstfile);
1093 for (jj = 0; jj < ny; jj = jj + 1) {
1094 if ((
status = fread(&ssttmp[0],
sizeof (
char), nx, fp)) != nx) {
1095 printf(
"Wrong AMSR-E data read size: want %d got %d\n", nx,
status);
1099 for (ii = 0; ii < nx; ii = ii + 1) {
1103 ij = (ii < nx / 2) ? ii + nx / 2 : ii - nx / 2;
1104 if (ssttmp[ii] <= 250) {
1105 sstref[jj + 1][ij + 1][kk] = ssttmp[ii] * 0.15 - 3.0;
1107 sstref[jj + 1][ij + 1][kk] = sstbad;
1111 sstref[jj + 1][ij + 1][1] = sstref[jj + 1][ij + 1][0];
1116 sstref[jj + 1][0] [kk] = sstref[jj + 1][nx][kk];
1117 sstref[jj + 1][nx + 1][kk] = sstref[jj + 1][1] [kk];
1120 for (ii = 0; ii < nx + 2; ii = ii + 1) {
1121 sstref[0] [ii][kk] = sstref[1] [ii][kk];
1122 sstref[ny + 1][ii][kk] = sstref[ny][ii][kk];
1148 xsatid ==
NO10 || xsatid ==
NO12 || xsatid ==
NO15 || xsatid ==
NO17))))) {
1155 ii =
MAX(
MIN((
int) ((
lon + 180.0 + dx / 2) / dx), nx + 1), 0);
1156 jj =
MAX(
MIN((
int) ((
lat + 90.0 + dy / 2) / dy), ny + 1), 0);
1159 xx = ii * dx - 180.0 - dx / 2;
1160 yy = jj * dy - 90.0 - dy / 2;
1163 t = (
lon - xx) / dx;
1164 u = (
lat - yy) / dy;
1168 if (sstref[jj ][ii ][ad] > sstbad + 1) {
1169 ftmp += sstref[jj ][ii ][ad];
1172 if (sstref[jj ][ii + 1][ad] > sstbad + 1) {
1173 ftmp += sstref[jj ][ii + 1][ad];
1176 if (sstref[jj + 1][ii + 1][ad] > sstbad + 1) {
1177 ftmp += sstref[jj + 1][ii + 1][ad];
1180 if (sstref[jj + 1][ii ][ad] > sstbad + 1) {
1181 ftmp += sstref[jj + 1][ii ][ad];
1186 reftmp[0][0] = (sstref[jj ][ii ][ad] > sstbad + 1 ? sstref[jj ][ii ][ad] : ftmp);
1187 reftmp[0][1] = (sstref[jj ][ii + 1][ad] > sstbad + 1 ? sstref[jj ][ii + 1][ad] : ftmp);
1188 reftmp[1][1] = (sstref[jj + 1][ii + 1][ad] > sstbad + 1 ? sstref[jj + 1][ii + 1][ad] : ftmp);
1189 reftmp[1][0] = (sstref[jj + 1][ii ][ad] > sstbad + 1 ? sstref[jj + 1][ii ][ad] : ftmp);
1191 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];
1209 static int firstCall = 1;
1210 static int nx =
OI4NX;
1211 static int ny =
OI4NY;
1212 static float dx = 360.0 /
OI4NX;
1213 static float dy = 180.0 /
OI4NY;
1215 typedef float sstref_t[
OI4NX + 2][2];
1216 static sstref_t* sstref;
1233 sstref = (sstref_t*) malloc((
OI4NY + 2) *
sizeof (sstref_t));
1236 unsigned char ssttmp[
OI4NX];
1237 float fssttmp[
OI4NX];
1243 printf(
"Loading 3-Day 0.25-deg WindSat SST reference from %s\n", sstfile);
1245 printf(
"Loading 3-Day Day or Night 0.25-deg WindSat SST reference from %s\n", sstfile);
1247 printf(
"Loading Daily 0.25-deg WindSat SST reference from %s\n", sstfile);
1251 if ((fp = fopen(sstfile,
"r")) ==
NULL) {
1252 printf(
"-E- %s line %d: error opening SST reference file %s for reading.\n",
1253 __FILE__, __LINE__, sstfile);
1266 foff[1] = (int32_t) (nx * ny *
sizeof (
float));
1273 foff[0] = (int32_t) (nx * ny);
1274 foff[1] = (int32_t) (nx * ny * 10);
1280 for (kk = 0; kk < kkmax; kk = kk + 1) {
1283 if (fseek(fp, foff[kk], SEEK_SET) < 0) {
1284 fprintf(
stderr,
"-E- %s line %d: error reading SST reference file %s.\n",
1285 __FILE__, __LINE__, sstfile);
1288 for (jj = 0; jj < ny; jj = jj + 1) {
1290 if ((
status = fread(&fssttmp[0],
sizeof (
float), nx, fp)) != nx) {
1291 printf(
"Wrong WINDSAT data read size: want %d got %d\n", nx,
status);
1298 swapc_bytes((
char *) &fssttmp[0],
sizeof (
float), nx);
1308 if ((
status = fread(&ssttmp[0],
sizeof (
char), nx, fp)) != nx) {
1309 printf(
"Wrong WINDSAT data read size: want %d got %d\n", nx,
status);
1314 for (ii = 0; ii < nx; ii = ii + 1) {
1318 ij = (ii < nx / 2) ? ii + nx / 2 : ii - nx / 2;
1321 if (fssttmp[ii] > -9998.0) {
1322 sstref[jj + 1][ij + 1][kk] = fssttmp[ii];
1324 sstref[jj + 1][ij + 1][kk] = sstbad;
1327 if (ssttmp[ii] <= 250) {
1328 sstref[jj + 1][ij + 1][kk] = ssttmp[ii] * 0.15 - 3.0;
1330 sstref[jj + 1][ij + 1][kk] = sstbad;
1335 sstref[jj + 1][ij + 1][1] = sstref[jj + 1][ij + 1][0];
1340 sstref[jj + 1][0] [kk] = sstref[jj + 1][nx][kk];
1341 sstref[jj + 1][nx + 1][kk] = sstref[jj + 1][1] [kk];
1344 for (ii = 0; ii < nx + 2; ii = ii + 1) {
1345 sstref[0] [ii][kk] = sstref[1] [ii][kk];
1346 sstref[ny + 1][ii][kk] = sstref[ny][ii][kk];
1377 xsatid ==
NO10 || xsatid ==
NO12 || xsatid ==
NO15 || xsatid ==
NO17))))) {
1384 ii =
MAX(
MIN((
int) ((
lon + 180.0 + dx / 2) / dx), nx + 1), 0);
1385 jj =
MAX(
MIN((
int) ((
lat + 90.0 + dy / 2) / dy), ny + 1), 0);
1388 xx = ii * dx - 180.0 - dx / 2;
1389 yy = jj * dy - 90.0 - dy / 2;
1392 t = (
lon - xx) / dx;
1393 u = (
lat - yy) / dy;
1397 if (sstref[jj ][ii ][ad] > sstbad + 1) {
1398 ftmp += sstref[jj ][ii ][ad];
1401 if (sstref[jj ][ii + 1][ad] > sstbad + 1) {
1402 ftmp += sstref[jj ][ii + 1][ad];
1405 if (sstref[jj + 1][ii + 1][ad] > sstbad + 1) {
1406 ftmp += sstref[jj + 1][ii + 1][ad];
1409 if (sstref[jj + 1][ii ][ad] > sstbad + 1) {
1410 ftmp += sstref[jj + 1][ii ][ad];
1415 reftmp[0][0] = (sstref[jj ][ii ][ad] > sstbad + 1 ? sstref[jj ][ii ][ad] : ftmp);
1416 reftmp[0][1] = (sstref[jj ][ii + 1][ad] > sstbad + 1 ? sstref[jj ][ii + 1][ad] : ftmp);
1417 reftmp[1][1] = (sstref[jj + 1][ii + 1][ad] > sstbad + 1 ? sstref[jj + 1][ii + 1][ad] : ftmp);
1418 reftmp[1][0] = (sstref[jj + 1][ii ][ad] > sstbad + 1 ? sstref[jj + 1][ii ][ad] : ftmp);
1420 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];
1438 static int firstCall = 1;
1439 static int nx =
OI1NX;
1440 static int ny =
OI1NY;
1441 static int32_t slen = 0;
1442 static float *sref =
NULL;
1443 static float dx = 360.0 /
OI1NX;
1444 static float dy = 180.0 /
OI1NY;
1456 char name [H4_MAX_NC_NAME] =
"";
1457 char sdsname[H4_MAX_NC_NAME] =
"";
1463 int32 dims[H4_MAX_VAR_DIMS];
1465 int32
start[4] = {0, 0, 0, 0};
1472 printf(
"Loading Daily 0.1-deg ATSR SST reference from %s\n", sstfile);
1477 if ((sref = (
float *) malloc(slen *
sizeof (
float))) ==
NULL) {
1478 fprintf(
stderr,
"-E- %s line %d: Unable to allocate sstref array.\n",
1479 __FILE__, __LINE__);
1484 if ((stmp = (
float *) malloc(stlen *
sizeof (
float))) ==
NULL) {
1485 fprintf(
stderr,
"-E- %s line %d: Unable to allocate ssttmp array.\n",
1486 __FILE__, __LINE__);
1491 sd_id = SDstart(sstfile, DFACC_RDONLY);
1492 if (sd_id ==
FAIL) {
1493 fprintf(
stderr,
"-E- %s line %d: error reading %s.\n",
1494 __FILE__, __LINE__, sstfile);
1498 strcpy(sdsname,
"sst_skin");
1499 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
1503 fprintf(
stderr,
"-E- %s Line %d: Error reading SDS %s from %s.\n",
1504 __FILE__, __LINE__, sdsname, sstfile);
1507 status = SDendaccess(sds_id);
1515 for (
j = 0;
j < ny;
j++) {
1523 jjl = jj * (nx + 2);
1524 for (
i = 0;
i < nx;
i++) {
1525 if (stmp[jl +
i] > -998.0) {
1526 sref[jjl +
i + 1] = stmp[jl +
i];
1528 sref[jjl +
i + 1] = sstbad;
1531 sref[jl] = sref[jl + nx];
1532 sref[jl + nx + 2 + nx + 1] = sref[jl + nx + 2 + 1];
1534 ll = (ny + 1)*(nx + 2);
1536 for (
i = 0;
i < nx + 2;
i++) {
1537 sref[
i] = sref[nx + 2 +
i];
1538 sref[ll +
i] = sref[
nl +
i];
1549 xx =
i * dx - 180.0 - dx / 2;
1550 yy =
j * dy - 90.0 - dy / 2;
1553 t = (
lon - xx) / dx;
1554 u = (
lat - yy) / dy;
1558 jl = (
j - 1)*(nx + 2);
1560 if (sref[jl +
i ] > sstbad + 1) {
1561 ftmp += sref[jl +
i ];
1564 if (sref[jl +
i + 1] > sstbad + 1) {
1565 ftmp += sref[jl +
i + 1];
1568 if (sref[
nl +
i + 1] > sstbad + 1) {
1569 ftmp += sref[
nl +
i + 1];
1572 if (sref[
nl +
i ] > sstbad + 1) {
1573 ftmp += sref[
nl +
i ];
1578 reftmp[0][0] = (sref[jl +
i ] > sstbad + 1 ? sref[jl +
i ] : ftmp);
1579 reftmp[0][1] = (sref[jl +
i + 1] > sstbad + 1 ? sref[jl +
i + 1] : ftmp);
1580 reftmp[1][1] = (sref[
nl +
i + 1] > sstbad + 1 ? sref[
nl +
i + 1] : ftmp);
1581 reftmp[1][0] = (sref[
nl +
i ] > sstbad + 1 ? sref[
nl +
i ] : ftmp);
1583 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];
1605 int32_t xsatid =
l1rec->l1file->subsensorID;
1611 int32_t year = (int32_t) yr;
1612 int32_t
day = (int32_t) dy;
1619 if (access(sstfile, F_OK) || access(sstfile, R_OK)) {
1620 printf(
"-E- %s line %d: SST input file '%s' does not exist or cannot open.\n",
1621 __FILE__, __LINE__, sstfile);
1630 }
else if (reftyp == 7) {
1634 }
else if (reftyp == 6) {
1638 }
else if (reftyp == 5) {
1642 }
else if (reftyp == 4) {
1646 }
else if (reftyp == 3) {
1650 }
else if (reftyp == 2) {
1654 }
else if (reftyp == 1) {
1660 char title[255] =
"";
1664 if (Hishdf(sstfile))
1665 sd_id = SDstart(sstfile, DFACC_RDONLY);
1669 if (sd_id !=
FAIL) {
1671 char title[255] =
"";
1672 if (SDreadattr(sd_id, SDfindattr(sd_id,
"title"), (VOIDP)
title) == 0) {
1673 if (strstr(
title,
"Daily-OI-V2") !=
NULL) {
1675 }
else if (strstr(
title,
"ARC Sea Surface Temperature") !=
NULL) {
1679 printf(
"-E- %s line %d: Unable to initialize SST file\n", __FILE__, __LINE__);
1680 printf(
"%s %d\n", sstfile,
day);
1683 }
else if (SDreadattr(sd_id, SDfindattr(sd_id,
"Title"), (VOIDP)
title) == 0) {
1684 if (strstr(
title,
"SST Climatology") !=
NULL) {
1687 printf(
"-E- %s line %d: Unable to initialize SST file\n", __FILE__, __LINE__);
1688 printf(
"%s %d\n", sstfile,
day);
1696 if (nc_open(sstfile, NC_NOWRITE, &sd_id) == NC_NOERR) {
1698 if (nc_get_att_text(sd_id, NC_GLOBAL,
"title",
title) == NC_NOERR) {
1699 if (strstr(
title,
"Daily-OI") ||
1700 strstr(
title,
"NOAA/NCEI 1/4 Degree Daily Optimum Interpolation Sea Surface Temperature (OISST) Analysis")) {
1702 }
else if (strstr(
title,
"CMC") !=
NULL) {
1704 }
else if (strstr(
title,
"Standard Mapped Image") !=
NULL) {
1707 printf(
"-E- %s : Unable to initialize SST file\n", __FILE__);
1708 printf(
"%s %d\n", sstfile,
day);
1724 char file [FILENAME_MAX] =
"";
1725 if ((tmp_str = getenv(
"OCDATAROOT")) ==
NULL) {
1726 printf(
"OCDATAROOT environment variable is not defined.\n");
1730 strcat(
file,
"/common/sst_climatology.hdf");
1732 printf(
"-E- %s line %d: Unable to initialize SST file\n", __FILE__, __LINE__);
1742 l1rec->ssttype[ip] = 0;
1747 l1rec->ssttype[ip] = 1;
1753 l1rec->ssttype[ip] = 2;
1759 l1rec->ssttype[ip] = 3;
1765 l1rec->ssttype[ip] = 4;
1771 l1rec->ssttype[ip] = 5;
1776 l1rec->ssttype[ip] = 6;
1782 l1rec->ssttype[ip] = 7;
1784 if (sst > sstbad + 1) {
1790 l1rec->ssttype[ip] = 8;
1797 l1rec->ssttype[ip] = 9;
1803 l1rec->ssttype[ip] = 10;
1809 l1rec->ssttype[ip] = 11;
1811 if (sst > sstbad + 1) {
1817 l1rec->ssttype[ip] = 12;
1823 l1rec->ssttype[ip] = 13;
1826 printf(
"-E- %s line %d: unknown SST input file format for %s.\n", __FILE__, __LINE__, sstfile);
1830 if (sst < (sstbad + 1)) {
1832 l1rec->ssttype[ip] = 0;