12 static int32_t format = -1;
23 static int firstCall = 1;
29 typedef float sssref_t[
WOASSSNX + 2];
30 static sssref_t* sssref;
31 static sssref_t* sss_sav;
41 sssref = (sssref_t*) malloc((
WOASSSNY + 2) *
sizeof (sssref_t));
42 sss_sav = (sssref_t*) malloc((
WOASSSNY + 2) *
sizeof (sssref_t));
45 char name [H4_MAX_NC_NAME] =
"";
46 char sdsname[H4_MAX_NC_NAME] =
"";
51 int32 dims[H4_MAX_VAR_DIMS];
53 int32
start[4] = {0, 0, 0, 0};
55 int32 lymin, lxmin, lymax, lxmax;
62 printf(
"Loading SSS reference from Climatology file: %s\n", sssfile);
66 sd_id = SDstart(sssfile, DFACC_RDONLY);
68 fprintf(
stderr,
"-E- %s line %d: error reading %s.\n",
69 __FILE__, __LINE__, sssfile);
74 sprintf(sdsname,
"sss%2.2i", mon);
75 sds_id = SDselect(sd_id, SDnametoindex(sd_id, sdsname));
79 fprintf(
stderr,
"-E- %s Line %d: Error reading SDS %s from %s.\n",
80 __FILE__, __LINE__, sdsname, sssfile);
83 status = SDendaccess(sds_id);
89 for (
j = 0;
j < ny;
j++) {
90 for (
i = 0;
i < nx;
i++) {
91 ii = (
i < nx / 2) ?
i + nx / 2 :
i - nx / 2;
93 sssref[
j + 1][ii + 1] = ssstmp[
j][
i];
95 sssref[
j + 1][ii + 1] = sssbad;
97 sssref[
j + 1][0] = sssref[
j + 1][nx];
98 sssref[
j + 1][nx + 1] = sssref[
j + 1][1];
100 for (
i = 0;
i < nx + 2;
i++) {
101 sssref[0] [
i] = sssref[1][
i];
102 sssref[ny + 1][
i] = sssref[ny][
i];
107 memcpy(sss_sav, sssref,
109 for (iy = 0; iy < ny + 2; iy++) {
110 lymin = (iy == 0) ? 0 : iy - 1;
111 lymax = (iy == ny + 1) ? ny + 1 : iy + 1;
113 for (ix = 0; ix < nx + 2; ix++) {
114 if (sssref[iy][ix] < sssbad + 1) {
115 lxmin = (ix == 0) ? 0 : ix - 1;
116 lxmax = (ix == nx + 1) ? nx + 1 : ix + 1;
120 for (
j = lymin;
j < lymax + 1;
j++)
121 for (
i = lxmin;
i < lxmax + 1;
i++) {
122 if (sss_sav[
j][
i] > sssbad + 1) {
123 sum += sss_sav[
j][
i];
128 sssref[iy][ix] = sum /
ct;
139 xx =
i * dx - 180.0 - dx / 2;
140 yy =
j * dy - 90.0 - dy / 2;
146 if ((sssref[
j][
i] > sssbad + 1) && (sssref[
j][
i + 1] > sssbad + 1) &&
147 (sssref[
j + 1][
i] > sssbad + 1) && (sssref[
j + 1][
i + 1] > sssbad + 1)) {
149 sss = (1 -
t)*(1 -
u) * sssref[
j ][
i ]
150 +
t * (1 -
u) * sssref[
j ][
i + 1]
151 +
t *
u * sssref[
j + 1][
i + 1]
152 + (1 -
t) *
u * sssref[
j + 1][
i ];
200 static int firstCall = 1;
203 static float dx = 360.0 /
HYCOMNX;
204 static float dy = 180.0 /
HYCOMNY;
206 typedef float sssref_t[
HYCOMNX + 2 ];
207 static sssref_t* sssref;
208 static sssref_t* sss_sav;
212 int i,
j, iter_ct, iter_max;
217 sssref = (sssref_t*) malloc((
HYCOMNY + 2) *
sizeof (sssref_t));
218 sss_sav = (sssref_t*) malloc((
HYCOMNY + 2) *
sizeof (sssref_t));
219 float ssstmp[ny][nx], sum;
220 h5io_str fid, dsid, grpid;
221 int nobj, *types, ndim, dim_siz[10], sto_len, ix, iy,
ct;
222 int lymin, lxmin, lymax, lxmax;
229 printf(
"Loading SSS reference from HYCOM file: %s\n", sssfile);
240 fprintf(
stderr,
"-E- %s, %d: Failed to set trivial group\n",
245 fprintf(
stderr,
"-E- %s, %d: Failed to find contents of sss file\n",
250 if (strcmp(o_names[0],
"salinity") != 0)
256 if (
h5io_info(&dsid,
NULL, &
class, &native_typ, &ndim, dim_siz,
258 fprintf(
stderr,
"-E- %s, %d: Failed to find info on salinity dataset\n",
263 if ((ndim != 2) || (dim_siz[0] != 720) || (dim_siz[1] != 1440))
269 if (
h5io_rd_ds(&dsid, (
void *) ssstmp) != 0) {
270 fprintf(
stderr,
"-E- %s, %d: Failed to read salinity dataset\n",
280 for (
j = 0;
j < ny;
j++) {
281 for (
i = 0;
i < nx;
i++) {
282 if ((ssstmp[
j][
i] > 0) && (ssstmp[
j][
i] <= 1000.))
283 sssref[
j + 1][
i + 1] = ssstmp[
j][
i];
285 sssref[
j + 1][
i + 1] = sssbad;
287 sssref[
j + 1][0] = sssref[
j + 1][nx];
288 sssref[
j + 1][nx + 1] = sssref[
j + 1][1];
290 for (
i = 0;
i < nx + 2;
i++) {
291 sssref[0] [
i] = sssref[1][
i];
292 sssref[ny + 1][
i] = sssref[ny][
i];
301 memcpy(sss_sav, sssref,
303 for (iy = 0; iy < ny + 2; iy++) {
304 lymin = (iy == 0) ? 0 : iy - 1;
305 lymax = (iy == ny + 1) ? ny + 1 : iy + 1;
307 for (ix = 0; ix < nx + 2; ix++) {
308 if (sssref[iy][ix] < sssbad + 1) {
309 lxmin = (ix == 0) ? 0 : ix - 1;
310 lxmax = (ix == nx + 1) ? nx + 1 : ix + 1;
314 for (
j = lymin;
j < lymax + 1;
j++)
315 for (
i = lxmin;
i < lxmax + 1;
i++) {
316 if (sss_sav[
j][
i] > sssbad + 1) {
317 sum += sss_sav[
j][
i];
322 sssref[iy][ix] = sum /
ct;
326 }
while (iter_ct < iter_max);
331 i =
MAX(
MIN((
int) ((
lon + 180.0 + dx / 2) / dx), nx + 1), 0);
332 j =
MAX(
MIN((
int) ((
lat + 90.0 + dy / 2) / dy), ny + 1), 0);
335 xx =
i * dx - 180.0 - dx / 2;
336 yy =
j * dy - 90.0 - dy / 2;
343 if ((sssref[
j][
i] > sssbad + 1) && (sssref[
j][
i + 1] > sssbad + 1) &&
344 (sssref[
j + 1][
i] > sssbad + 1) && (sssref[
j + 1][
i + 1] > sssbad + 1))
345 *sss = (1 -
t)*(1 -
u) * sssref[
j ][
i ]
346 +
t * (1 -
u) * sssref[
j ][
i + 1]
347 +
t *
u * sssref[
j + 1][
i + 1]
348 + (1 -
t) *
u * sssref[
j + 1][
i ];
367 if (access(sssfile, F_OK) || access(sssfile, R_OK)) {
368 printf(
"-E- %s: SSS input file '%s' does not exist or cannot open.\n",
374 sd_id = SDstart(sssfile, DFACC_RDONLY);
377 char title[255] =
"";
378 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Title"), (VOIDP)
title) == 0) {
379 if (strstr(
title,
"WOA Sea Surface Salinity Monthly Climatology") !=
NULL) {
383 printf(
"-E- %s: unable to read SSS input file %s.\n", __FILE__, sssfile);
402 printf(
"-E- %s: unknown SSS input file format for %s.\n", __FILE__, sssfile);