read_learning_rea_eof.c

Go to the documentation of this file.
00001 /* ***************************************************** */
00002 /* read_learning_rea_eof Read reanalysis data EOFs for   */
00003 /* learning period.                                      */
00004 /* read_learning_rea_eof.c                               */
00005 /* ***************************************************** */
00006 /* Author: Christian Page, CERFACS, Toulouse, France.    */
00007 /* ***************************************************** */
00008 /* Date of creation: dec 2008                            */
00009 /* Last date of modification: dec 2008                   */
00010 /* ***************************************************** */
00011 /* Original version: 1.0                                 */
00012 /* Current revision:                                     */
00013 /* ***************************************************** */
00014 /* Revisions                                             */
00015 /* ***************************************************** */
00020 /* LICENSE BEGIN
00021 
00022 Copyright Cerfacs (Christian Page) (2015)
00023 
00024 christian.page@cerfacs.fr
00025 
00026 This software is a computer program whose purpose is to downscale climate
00027 scenarios using a statistical methodology based on weather regimes.
00028 
00029 This software is governed by the CeCILL license under French law and
00030 abiding by the rules of distribution of free software. You can use, 
00031 modify and/ or redistribute the software under the terms of the CeCILL
00032 license as circulated by CEA, CNRS and INRIA at the following URL
00033 "http://www.cecill.info". 
00034 
00035 As a counterpart to the access to the source code and rights to copy,
00036 modify and redistribute granted by the license, users are provided only
00037 with a limited warranty and the software's author, the holder of the
00038 economic rights, and the successive licensors have only limited
00039 liability. 
00040 
00041 In this respect, the user's attention is drawn to the risks associated
00042 with loading, using, modifying and/or developing or reproducing the
00043 software by the user in light of its specific status of free software,
00044 that may mean that it is complicated to manipulate, and that also
00045 therefore means that it is reserved for developers and experienced
00046 professionals having in-depth computer knowledge. Users are therefore
00047 encouraged to load and test the software's suitability as regards their
00048 requirements in conditions enabling the security of their systems and/or 
00049 data to be ensured and, more generally, to use and operate it in the 
00050 same conditions as regards security. 
00051 
00052 The fact that you are presently reading this means that you have had
00053 knowledge of the CeCILL license and that you accept its terms.
00054 
00055 LICENSE END */
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 #include <dsclim.h>
00064 
00066 int
00067 read_learning_rea_eof(data_struct *data) {
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 }

Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1