Read reanalysis data EOFs for learning period. Currently only NetCDF is implemented. More...
#include <dsclim.h>
Go to the source code of this file.
Functions | |
int | read_learning_rea_eof (data_struct *data) |
Read reanalysis data EOFs for learning period. |
Read reanalysis data EOFs for learning period. Currently only NetCDF is implemented.
Definition in file read_learning_rea_eof.c.
int read_learning_rea_eof | ( | data_struct * | data | ) |
Read reanalysis data EOFs for learning period.
Currently only NetCDF is implemented.
[in] | data | MASTER data structure. |
Definition at line 67 of file read_learning_rea_eof.c.
References alloc_error(), data_struct::conf, learning_eof_struct::eof, conf_struct::eofname, learning_eof_struct::filename_eof, get_time_info(), data_struct::learning, learning_eof_struct::nomvar_eof, learning_eof_struct::nomvar_sing, learning_struct::nomvar_time, learning_eof_struct::ntime, learning_struct::rea, learning_struct::rea_neof, learning_struct::rea_timename, read_netcdf_var_1d(), read_netcdf_var_2d(), learning_eof_struct::sing, learning_eof_struct::time_s, and TRUE.
Referenced by wt_learning().
00067 { 00074 int istat; /* Diagnostic status */ 00075 int neof; /* EOF dimension for main large-scale fields in input file */ 00076 int ntime; /* Time dimension for main large-scale fields in input file */ 00077 double *time; 00078 char *cal_type = NULL; /* Calendar type (udunits) */ 00079 char *time_units = NULL; /* Time units (udunits) */ 00080 double *buf = NULL; 00081 int t; 00082 int eof; 00083 00084 /* Read EOF principal components */ 00085 istat = read_netcdf_var_2d(&buf, (info_field_struct *) NULL, (proj_struct *) NULL, 00086 data->learning->rea->filename_eof, data->learning->rea->nomvar_eof, 00087 data->conf->eofname, data->learning->rea_timename, &neof, &ntime, TRUE); 00088 if (istat != 0) { 00089 /* In case of failure */ 00090 return istat; 00091 } 00092 if (data->learning->rea_neof != neof) { 00093 (void) fprintf(stderr, "%s: ERROR: Number of EOFs (%d) for reanalysis %s field from EOF file (%s) is not equal to number of EOFs specified in XML configuration file for reanalysis fields (%d)!\n", __FILE__, neof, 00094 data->learning->rea->nomvar_eof, data->learning->rea->filename_eof, data->learning->rea_neof); 00095 return -1; 00096 } 00097 /* Re-order array with time as fastest varying dimension */ 00098 data->learning->rea->eof = malloc(neof*ntime * sizeof(double)); 00099 if (data->learning->rea->eof == NULL) alloc_error(__FILE__, __LINE__); 00100 for (eof=0; eof<neof; eof++) 00101 for (t=0; t<ntime; t++) 00102 data->learning->rea->eof[t+eof*ntime] = buf[eof+t*neof]; 00103 (void) free(buf); 00104 00105 /* Get time information */ 00106 istat = get_time_info(data->learning->rea->time_s, &time, &time_units, &cal_type, 00107 &ntime, data->learning->rea->filename_eof, data->learning->nomvar_time, TRUE); 00108 (void) free(cal_type); 00109 (void) free(time_units); 00110 (void) free(time); 00111 if (istat != 0) { 00112 /* In case of failure */ 00113 (void) free(data->learning->rea->time_s); 00114 return istat; 00115 } 00116 00117 data->learning->rea->ntime = ntime; 00118 00119 /* Read Singular Values */ 00120 istat = read_netcdf_var_1d(&(data->learning->rea->sing), (info_field_struct *) NULL, 00121 data->learning->rea->filename_eof, data->learning->rea->nomvar_sing, 00122 data->conf->eofname, &neof, TRUE); 00123 if (istat != 0) { 00124 /* In case of failure */ 00125 (void) free(data->learning->rea->time_s); 00126 return istat; 00127 } 00128 if (data->learning->rea_neof != neof) { 00129 (void) fprintf(stderr, "%s: ERROR: Number of EOFs (%d) for reanalysis %s field from EOF file (%s) is not equal to number of EOFs specified in XML configuration file for reanalysis fields (%d)!\n", __FILE__, neof, 00130 data->learning->rea->nomvar_sing, data->learning->rea->filename_eof, data->learning->rea_neof); 00131 (void) free(data->learning->rea->time_s); 00132 return -1; 00133 } 00134 00135 /* Diagnostic status */ 00136 return 0; 00137 }