Read observation 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_obs_eof (data_struct *data) |
Read observation data EOFs for learning period. |
Read observation data EOFs for learning period. Currently only NetCDF is implemented.
Definition in file read_learning_obs_eof.c.
int read_learning_obs_eof | ( | data_struct * | data | ) |
Read observation data EOFs for learning period.
Currently only NetCDF is implemented.
[in] | data | MASTER data structure. |
Definition at line 67 of file read_learning_obs_eof.c.
References alloc_error(), time_vect_struct::day, learning_eof_struct::eof, learning_eof_struct::filename_eof, get_time_info(), time_vect_struct::hour, data_struct::learning, time_vect_struct::minutes, time_vect_struct::month, learning_eof_struct::nomvar_eof, learning_eof_struct::nomvar_sing, learning_struct::nomvar_time, learning_eof_struct::ntime, learning_struct::ntime, learning_struct::obs, learning_struct::obs_eofname, learning_struct::obs_neof, learning_struct::obs_timename, read_netcdf_var_1d(), read_netcdf_var_2d(), time_vect_struct::seconds, learning_eof_struct::sing, learning_struct::time_s, learning_eof_struct::time_s, TRUE, and time_vect_struct::year.
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 = NULL; 00078 char *cal_type = NULL; /* Calendar type (udunits) */ 00079 char *time_units = NULL; /* Time units (udunits) */ 00080 double *buf = NULL; 00081 int i; 00082 int t; 00083 int eof; 00084 00085 if (data->learning->obs_neof != 0) { 00086 /* Only read variable if considering observation EOFs */ 00087 00088 /* Read EOF */ 00089 istat = read_netcdf_var_2d(&buf, (info_field_struct *) NULL, (proj_struct *) NULL, 00090 data->learning->obs->filename_eof, data->learning->obs->nomvar_eof, 00091 data->learning->obs_eofname, data->learning->obs_timename, &neof, &ntime, TRUE); 00092 if (istat != 0) { 00093 /* In case of failure */ 00094 (void) free(buf); 00095 return istat; 00096 } 00097 if (data->learning->obs_neof != neof) { 00098 (void) fprintf(stderr, "%s: ERROR: Number of EOFs (%d) for observation %s field from EOF file (%s) is not equal to number of EOFs specified in XML configuration file for observation fields (%d)!\n", __FILE__, neof, 00099 data->learning->obs->nomvar_eof, data->learning->obs->filename_eof, data->learning->obs_neof); 00100 (void) free(buf); 00101 return -1; 00102 } 00103 /* Re-order array with time as fastest varying dimension */ 00104 data->learning->obs->eof = malloc(neof*ntime * sizeof(double)); 00105 if (data->learning->obs->eof == NULL) alloc_error(__FILE__, __LINE__); 00106 for (eof=0; eof<neof; eof++) 00107 for (t=0; t<ntime; t++) 00108 data->learning->obs->eof[t+eof*ntime] = buf[eof+t*neof]; 00109 (void) free(buf); 00110 00111 /* Read Singular Values */ 00112 istat = read_netcdf_var_1d(&(data->learning->obs->sing), (info_field_struct *) NULL, 00113 data->learning->obs->filename_eof, data->learning->obs->nomvar_sing, 00114 data->learning->obs_eofname, &neof, TRUE); 00115 if (istat != 0) { 00116 /* In case of failure */ 00117 return istat; 00118 } 00119 if (data->learning->obs_neof != neof) { 00120 (void) fprintf(stderr, "%s: ERROR: Number of EOFs (%d) for observation %s field from EOF file (%s) is not equal to number of EOFs specified in XML configuration file for observation fields (%d)!\n", __FILE__, neof, 00121 data->learning->obs->nomvar_sing, data->learning->obs->filename_eof, data->learning->obs_neof); 00122 return -1; 00123 } 00124 } 00125 00126 /* Get time information */ 00127 istat = get_time_info(data->learning->obs->time_s, &time, &time_units, &cal_type, 00128 &ntime, data->learning->obs->filename_eof, data->learning->nomvar_time, TRUE); 00129 (void) free(cal_type); 00130 (void) free(time_units); 00131 (void) free(time); 00132 if (istat < 0) { 00133 (void) free(data->learning->obs->time_s); 00134 return -1; 00135 } 00136 00137 data->learning->ntime = ntime; 00138 data->learning->obs->ntime = ntime; 00139 00140 /* Copy into main time structure */ 00141 data->learning->time_s->year = (int *) malloc(ntime * sizeof(int)); 00142 if (data->learning->time_s->year == NULL) alloc_error(__FILE__, __LINE__); 00143 data->learning->time_s->month = (int *) malloc(ntime * sizeof(int)); 00144 if (data->learning->time_s->month == NULL) alloc_error(__FILE__, __LINE__); 00145 data->learning->time_s->day = (int *) malloc(ntime * sizeof(int)); 00146 if (data->learning->time_s->day == NULL) alloc_error(__FILE__, __LINE__); 00147 data->learning->time_s->hour = (int *) malloc(ntime * sizeof(int)); 00148 if (data->learning->time_s->hour == NULL) alloc_error(__FILE__, __LINE__); 00149 data->learning->time_s->minutes = (int *) malloc(ntime * sizeof(int)); 00150 if (data->learning->time_s->minutes == NULL) alloc_error(__FILE__, __LINE__); 00151 data->learning->time_s->seconds = (double *) malloc(ntime * sizeof(double)); 00152 if (data->learning->time_s->seconds == NULL) alloc_error(__FILE__, __LINE__); 00153 00154 for (i=0; i<ntime; i++) { 00155 data->learning->time_s->year[i] = data->learning->obs->time_s->year[i]; 00156 data->learning->time_s->month[i] = data->learning->obs->time_s->month[i]; 00157 data->learning->time_s->day[i] = data->learning->obs->time_s->day[i]; 00158 data->learning->time_s->hour[i] = data->learning->obs->time_s->hour[i]; 00159 data->learning->time_s->minutes[i] = data->learning->obs->time_s->minutes[i]; 00160 data->learning->time_s->seconds[i] = data->learning->obs->time_s->seconds[i]; 00161 } 00162 00163 /* Diagnostic status */ 00164 return 0; 00165 }