change_date_origin.c

Go to the documentation of this file.
00001 /* ***************************************************** */
00002 /* Change date origin of time expressed in udunits.      */
00003 /* change_date_origin.c                                  */
00004 /* ***************************************************** */
00005 /* Author: Christian Page, CERFACS, Toulouse, France.    */
00006 /* ***************************************************** */
00011 /* LICENSE BEGIN
00012 
00013 Copyright Cerfacs (Christian Page) (2015)
00014 
00015 christian.page@cerfacs.fr
00016 
00017 This software is a computer program whose purpose is to downscale climate
00018 scenarios using a statistical methodology based on weather regimes.
00019 
00020 This software is governed by the CeCILL license under French law and
00021 abiding by the rules of distribution of free software. You can use, 
00022 modify and/ or redistribute the software under the terms of the CeCILL
00023 license as circulated by CEA, CNRS and INRIA at the following URL
00024 "http://www.cecill.info". 
00025 
00026 As a counterpart to the access to the source code and rights to copy,
00027 modify and redistribute granted by the license, users are provided only
00028 with a limited warranty and the software's author, the holder of the
00029 economic rights, and the successive licensors have only limited
00030 liability. 
00031 
00032 In this respect, the user's attention is drawn to the risks associated
00033 with loading, using, modifying and/or developing or reproducing the
00034 software by the user in light of its specific status of free software,
00035 that may mean that it is complicated to manipulate, and that also
00036 therefore means that it is reserved for developers and experienced
00037 professionals having in-depth computer knowledge. Users are therefore
00038 encouraged to load and test the software's suitability as regards their
00039 requirements in conditions enabling the security of their systems and/or 
00040 data to be ensured and, more generally, to use and operate it in the 
00041 same conditions as regards security. 
00042 
00043 The fact that you are presently reading this means that you have had
00044 knowledge of the CeCILL license and that you accept its terms.
00045 
00046 LICENSE END */
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 #include <utils.h>
00055 
00057 void
00058 change_date_origin(double *timeout, char *tunits_out, double *timein, char *tunits_in, int ntime) {
00059 
00068   int t; /* Time loop counter */
00069   int istat; /* Diagnostic status */
00070 
00071   utUnit dataunit_in; /* Input data time units (udunits) */
00072   utUnit dataunit_out; /* Output data time units (udunits) */
00073 
00074   int *year = NULL; /* Year vector */
00075   int *month = NULL; /* Month vector */
00076   int *day = NULL; /* Day vector */
00077   int *hour = NULL; /* Hour vector */
00078   int *minutes = NULL; /* Minutes vector */
00079   float *seconds = NULL; /* Seconds vector */
00080 
00081   /* Initialize udunits */
00082   if (utIsInit() != TRUE)
00083     istat = utInit("");
00084 
00085   /* Generate time units (udunits) */
00086   istat = utScan(tunits_in,  &dataunit_in);
00087   istat = utScan(tunits_out, &dataunit_out);
00088 
00089   /* Allocate memory */
00090   year = (int *) malloc(ntime * sizeof(int));
00091   if (year == NULL) alloc_error(__FILE__, __LINE__);
00092   month = (int *) malloc(ntime * sizeof(int));
00093   if (month == NULL) alloc_error(__FILE__, __LINE__);
00094   day = (int *) malloc(ntime * sizeof(int));
00095   if (day == NULL) alloc_error(__FILE__, __LINE__);
00096   hour = (int *) malloc(ntime * sizeof(int));
00097   if (hour == NULL) alloc_error(__FILE__, __LINE__);
00098   minutes = (int *) malloc(ntime * sizeof(int));
00099   if (minutes == NULL) alloc_error(__FILE__, __LINE__);
00100   seconds = (float *) malloc(ntime * sizeof(float));
00101   if (seconds == NULL) alloc_error(__FILE__, __LINE__);
00102 
00103   /* Parse all times and convert time info */
00104   for (t=0; t<ntime; t++) {
00105     istat = utCalendar(timein[t], &dataunit_in, &(year[t]), &(month[t]), &(day[t]), &(hour[t]), &(minutes[t]), &(seconds[t]));
00106     istat = utInvCalendar(year[t], month[t], day[t], hour[t], minutes[t], seconds[t], &dataunit_out, &(timeout[t]));
00107   }
00108 
00109   /* Free memory */
00110   (void) free(year);
00111   (void) free(month);
00112   (void) free(day);
00113   (void) free(hour);
00114   (void) free(minutes);
00115   (void) free(seconds);
00116 
00117   /* Terminate udunits */
00118   (void) utTerm();
00119 }

Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1