00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #include <dsclim.h>
00063
00065 int
00066 read_large_scale_eof(data_struct *data) {
00073 int istat;
00074 int i;
00075 int cat;
00076 double *buf = NULL;
00077 double *lat = NULL;
00078 double *lon = NULL;
00079 int nlon;
00080 int nlat;
00081 int nlon_file;
00082 int nlat_file;
00083 int neof_file;
00084 proj_struct proj_eof;
00085
00086 proj_eof.eof_coords = (char *) NULL;
00087 proj_eof.name = (char *) NULL;
00088 proj_eof.grid_mapping_name = (char *) NULL;
00089
00090
00091 for (cat=0; cat<2; cat++) {
00092
00093 for (i=0; i<data->field[cat].n_ls; i++) {
00094
00095
00096 if (data->field[cat].data[i].eof_info->eof_project == TRUE) {
00097
00098 if (data->field[cat].lon_eof_ls == NULL) {
00099
00100 istat = read_netcdf_dims_eof(&lon, &lat, &nlon, &nlat, &neof_file,
00101 data->field[cat].data[i].eof_info->eof_coords,
00102 data->conf->lonname_eof, data->conf->latname_eof,
00103 data->conf->dimxname_eof, data->conf->dimyname_eof,
00104 data->conf->eofname,
00105 data->field[cat].data[i].eof_info->eof_filein_ls);
00106 if (istat < 0) {
00107
00108 (void) free(lon);
00109 (void) free(lat);
00110 return istat;
00111 }
00112
00113
00114 proj_eof.eof_coords = strdup(data->field[cat].proj[i].coords);
00115 proj_eof.name = strdup(data->field[cat].proj[i].name);
00116 proj_eof.grid_mapping_name = strdup(data->field[cat].proj[i].grid_mapping_name);
00117 }
00118
00119
00120 istat = read_netcdf_var_3d(&buf, data->field[cat].data[i].eof_info->info, &proj_eof,
00121 data->field[cat].data[i].eof_info->eof_filein_ls,
00122 data->field[cat].data[i].eof_data->eof_nomvar_ls,
00123 data->conf->dimxname_eof, data->conf->dimyname_eof,
00124 data->conf->eofname, &nlon_file, &nlat_file, &neof_file, TRUE);
00125 if (nlon != nlon_file || nlat != nlat_file) {
00126 (void) fprintf(stderr, "%s: Problems in dimensions! nlat=%d nlat_file=%d nlon=%d nlon_file=%d\n",
00127 __FILE__, nlat, nlat_file, nlon, nlon_file);
00128 istat = -1;
00129 }
00130 if (data->field[cat].data[i].eof_info->neof_ls != neof_file) {
00131 (void) fprintf(stderr, "%s: ERROR: Number of EOFs (%d) for %s field from large-scale fields file (%s) is not equal to number of EOFs specified in XML configuration file for large-scale fields (%d)!\n", __FILE__, neof_file,
00132 data->field[cat].data[i].eof_data->eof_nomvar_ls,
00133 data->field[cat].data[i].eof_info->eof_filein_ls,
00134 data->field[cat].data[i].eof_info->neof_ls);
00135 istat = -1;
00136 }
00137 if (istat != 0) {
00138
00139 (void) free(buf);
00140 (void) free(lon);
00141 (void) free(lat);
00142 if (proj_eof.eof_coords != NULL)
00143 (void) free(proj_eof.eof_coords);
00144 if (proj_eof.name != NULL)
00145 (void) free(proj_eof.name);
00146 if (proj_eof.grid_mapping_name != NULL)
00147 (void) free(proj_eof.grid_mapping_name);
00148 return istat;
00149 }
00150
00152
00153 if (data->field[cat].lon_eof_ls != NULL) {
00154 (void) free(data->field[cat].lon_eof_ls);
00155 data->field[cat].lon_eof_ls = NULL;
00156 }
00157 if (data->field[cat].lat_eof_ls != NULL) {
00158 (void) free(data->field[cat].lat_eof_ls);
00159 data->field[cat].lat_eof_ls = NULL;
00160 }
00161 if (data->field[cat].data[i].eof_data->eof_ls != NULL) {
00162 (void) free(data->field[cat].data[i].eof_data->eof_ls);
00163 data->field[cat].data[i].eof_data->eof_ls = NULL;
00164 }
00165
00166 (void) extract_subdomain(&(data->field[cat].data[i].eof_data->eof_ls), &(data->field[cat].lon_eof_ls),
00167 &(data->field[cat].lat_eof_ls),
00168 &(data->field[cat].nlon_eof_ls), &(data->field[cat].nlat_eof_ls), buf, lon, lat,
00169 data->conf->longitude_min, data->conf->longitude_max, data->conf->latitude_min, data->conf->latitude_max,
00170 nlon, nlat, data->field[cat].data[i].eof_info->neof_ls);
00171 (void) free(buf);
00172
00173
00174 printf("%s: EOF missing_value = %lf\n", __FILE__, (double) data->field[cat].data[i].eof_info->info->fillvalue);
00175
00176
00177 istat = read_netcdf_var_1d(&(data->field[cat].data[i].eof_data->sing_ls), (info_field_struct *) NULL,
00178 data->field[cat].data[i].eof_info->eof_filein_ls, data->field[cat].data[i].eof_data->sing_nomvar_ls,
00179 data->conf->eofname, &neof_file, TRUE);
00180 if (data->field[cat].data[i].eof_info->neof_ls != neof_file) {
00181 (void) fprintf(stderr, "%s: ERROR: Number of EOFs (%d) for %s singular values from large-scale fields file (%s) is not equal to number of EOFs specified in XML configuration file for large-scale fields (%d)!\n", __FILE__, neof_file,
00182 data->field[cat].data[i].eof_data->sing_nomvar_ls, data->field[cat].data[i].eof_info->eof_filein_ls,
00183 data->field[cat].data[i].eof_info->neof_ls);
00184 istat = -1;
00185 }
00186 if (istat != 0) {
00187
00188 (void) free(lon);
00189 (void) free(lat);
00190 if (proj_eof.eof_coords != NULL)
00191 (void) free(proj_eof.eof_coords);
00192 if (proj_eof.name != NULL)
00193 (void) free(proj_eof.name);
00194 if (proj_eof.grid_mapping_name != NULL)
00195 (void) free(proj_eof.grid_mapping_name);
00196 return istat;
00197 }
00198 }
00199
00200 if (lon != NULL) (void) free(lon);
00201 lon = NULL;
00202 if (lat != NULL) (void) free(lat);
00203 lat = NULL;
00204
00205 if (proj_eof.eof_coords != NULL) {
00206 (void) free(proj_eof.eof_coords);
00207 proj_eof.eof_coords = (char *) NULL;
00208 }
00209 if (proj_eof.name != NULL) {
00210 (void) free(proj_eof.name);
00211 proj_eof.name = (char *) NULL;
00212 }
00213 if (proj_eof.grid_mapping_name != NULL) {
00214 (void) free(proj_eof.grid_mapping_name);
00215 proj_eof.grid_mapping_name = NULL;
00216 }
00217 }
00218 }
00219
00220
00221 return 0;
00222 }