21 static int firstCall = 1;
22 static int zx =
ZXANC;
23 static int zy =
ZYANC;
24 static float dx = 360.0 /
ZXANC;
25 static float dy = 180.0 /
ZYANC;
27 typedef float ref_t[
ZXANC + 2];
40 char sdsname[H4_MAX_NC_NAME];
41 char sdsname2[H4_MAX_NC_NAME];
42 int ncid, ndims, nvars, ngatts, unlimdimid;
45 int rh_dimids[H4_MAX_VAR_DIMS];
49 int32 lymin, lxmin, lymax, lxmax;
52 char *OCSSW_root, zclimatology_file[300];
60 if ((OCSSW_root = getenv(
"OCDATAROOT")) ==
NULL) {
62 "-E- %s: Error looking up environmental variable OCDATAROOT\n",
66 strcpy(zclimatology_file, OCSSW_root);
67 strcat(zclimatology_file,
"/common/zno3_climatology_woa2005.nc");
69 printf(
"\nOpening z climatology file %s\n\n", zclimatology_file);
79 if (nc_open(zclimatology_file, NC_NOWRITE, &ncid) == NC_NOERR) {
81 status = nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid);
83 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
84 __FILE__, __LINE__, sdsname, zclimatology_file);
88 status = nc_inq_varid(ncid, sdsname, &sds_id);
90 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
91 __FILE__, __LINE__, sdsname, zclimatology_file);
94 nc_inq_varname(ncid, sds_id, sdsname2);
95 status = nc_inq_var(ncid, sds_id, 0, &rh_type, &rh_ndims, rh_dimids,
100 printf(
"\nReading z climatology file %s ndims=%d nvars=%d sds_id=%d var=%s\n\n", zclimatology_file, ndims, nvars, sds_id, sdsname2);
102 if (nc_get_var(ncid, sds_id, &ztmp[0][0][0]) != NC_NOERR) {
103 fprintf(
stderr,
"-E- %s line %d: Error reading %s from %s.\n",
104 __FILE__, __LINE__, sdsname, zclimatology_file);
107 printf(
"\nClosing z climatology file %s\n\n", zclimatology_file);
110 if (nc_close(ncid) != NC_NOERR) {
111 fprintf(
stderr,
"-E- %s line %d: error closing %s.\n",
112 __FILE__, __LINE__, zclimatology_file);
116 fprintf(
stderr,
"-E- %s line %d: error opening %s.\n",
117 __FILE__, __LINE__, zclimatology_file);
125 for (
j = 0;
j < zy;
j++) {
126 for (
i = 0;
i < zx;
i++) {
128 if (ztmp[mon][
i][
j] >= 0) {
129 zref[jj + 1][
i + 1] = ztmp[mon][
i][
j];
131 zref[jj + 1][
i + 1] = zbad;
134 zref[jj + 1][0] = zref[jj + 1][zx];
135 zref[jj + 1][zx + 1] = zref[jj + 1][1];
138 for (
i = 0;
i < zx + 2;
i++) {
139 zref[0][
i] = zref[1][
i];
140 zref[zy + 1][
i] = zref[zy][
i];
151 for (iy = 0; iy < zy + 2; iy++) {
152 lymin = (iy == 0) ? 0 : iy - 1;
153 lymax = (iy == zy + 1) ? zy + 1 : iy + 1;
155 for (ix = 0; ix < zx + 2; ix++) {
156 if (zref[iy][ix] < zbad + 1) {
157 lxmin = (ix == 0) ? 0 : ix - 1;
158 lxmax = (ix == zx + 1) ? zx + 1 : ix + 1;
162 for (
j = lymin;
j < lymax + 1;
j++)
163 for (
i = lxmin;
i < lxmax + 1;
i++) {
164 if (z_sav[
j][
i] > zbad + 1) {
170 zref[iy][ix] = sum /
ct;
192 xx =
i * dx - 180.0 - dx / 2;
193 yy =
j * dy - 90.0 - dy / 2;
199 if ((zref[
j][
i] > zbad + 1) && (zref[
j][
i + 1] > zbad + 1)
200 && (zref[
j + 1][
i] > zbad + 1)
201 && (zref[
j + 1][
i + 1] > zbad + 1)) {
203 zno3 = (1 -
t) * (1 -
u) * zref[
j][
i] +
t * (1 -
u) * zref[
j][
i + 1]
204 +
t *
u * zref[
j + 1][
i + 1] + (1 -
t) *
u * zref[
j + 1][
i];