read_large_scale_eof.c File Reference

Read Large-Scale EOFs from input files. Currently only NetCDF is implemented. More...

#include <dsclim.h>
Include dependency graph for read_large_scale_eof.c:

Go to the source code of this file.

Functions

int read_large_scale_eof (data_struct *data)
 Read Large-Scale EOFs from input files.

Detailed Description

Read Large-Scale EOFs from input files. Currently only NetCDF is implemented.

Definition in file read_large_scale_eof.c.


Function Documentation

int read_large_scale_eof ( data_struct data  ) 

Read Large-Scale EOFs from input files.

Currently only NetCDF is implemented.

Parameters:
[in] data MASTER data structure.
Returns:
Status.

Extract subdomain

Definition at line 66 of file read_large_scale_eof.c.

References data_struct::conf, proj_struct::coords, field_struct::data, conf_struct::dimxname_eof, conf_struct::dimyname_eof, eof_info_struct::eof_coords, proj_struct::eof_coords, field_data_struct::eof_data, eof_info_struct::eof_filein_ls, field_data_struct::eof_info, eof_data_struct::eof_ls, eof_data_struct::eof_nomvar_ls, eof_info_struct::eof_project, conf_struct::eofname, extract_subdomain(), data_struct::field, info_field_struct::fillvalue, proj_struct::grid_mapping_name, eof_info_struct::info, field_struct::lat_eof_ls, conf_struct::latitude_max, conf_struct::latitude_min, conf_struct::latname_eof, field_struct::lon_eof_ls, conf_struct::longitude_max, conf_struct::longitude_min, conf_struct::lonname_eof, field_struct::n_ls, proj_struct::name, eof_info_struct::neof_ls, field_struct::nlat_eof_ls, field_struct::nlon_eof_ls, field_struct::proj, read_netcdf_dims_eof(), read_netcdf_var_1d(), read_netcdf_var_3d(), eof_data_struct::sing_ls, eof_data_struct::sing_nomvar_ls, and TRUE.

Referenced by wt_downscaling().

00066                                         {
00073   int istat; /* Diagnostic status */
00074   int i; /* Loop counter */
00075   int cat; /* Field category loop counter */
00076   double *buf = NULL; /* Temporary buffer for reading */
00077   double *lat = NULL; /* Temporary buffer for latitudes */
00078   double *lon = NULL; /* Temporary buffer for longitudes */
00079   int nlon; /* Longitude dimension */
00080   int nlat; /* Latitude dimension */
00081   int nlon_file; /* Longitude dimension for main large-scale fields in input file */
00082   int nlat_file; /* Latitude dimension for main large-scale fields in input file */
00083   int neof_file; /* EOF dimension for main large-scale fields in input file */
00084   proj_struct proj_eof; /* EOF spatial projection structure */
00085 
00086   proj_eof.eof_coords = (char *) NULL;
00087   proj_eof.name = (char *) NULL;
00088   proj_eof.grid_mapping_name = (char *) NULL;
00089 
00090   /* Loop over large-scale field categories (control and model run) */
00091   for (cat=0; cat<2; cat++) {
00092     /* Loop over large-scale fields */
00093     for (i=0; i<data->field[cat].n_ls; i++) {
00094 
00095       /* Verify that we need to project field onto EOF */
00096       if (data->field[cat].data[i].eof_info->eof_project == TRUE) {
00097       
00098         if (data->field[cat].lon_eof_ls == NULL) {
00099           /* Read dimensions for EOF */
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             /* In case of failure */
00108             (void) free(lon);
00109             (void) free(lat);
00110             return istat;
00111           }
00112         
00113           /* Transfer data into proper data structure */
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         /* Read EOF */
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           /* In case of failure */
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         /* Free memory if needed because of loop. Set pointers to NULL for realloc. */
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         /* Extraction */
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         /* Print missing value */
00174         printf("%s: EOF missing_value = %lf\n", __FILE__, (double) data->field[cat].data[i].eof_info->info->fillvalue);
00175       
00176         /* Read Singular Values */
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           /* In case of failure */
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       /* Free memory if needed */
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   /* Diagnostic status */
00221   return 0;
00222 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1