merge_seasons.c

Go to the documentation of this file.
00001 /* ***************************************************** */
00002 /* Merge seasonal analog date data.                      */
00003 /* merge_seasons.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 <dsclim.h>
00055 
00057 int
00058 merge_seasons(analog_day_struct analog_days_merged, analog_day_struct analog_days, int *merged_itimes, int ntimes_merged, int ntimes) {
00067   int t; /* Time loop counter */
00068   int i; /* Loop counter */
00069   int curindex; /* Current index in the merged times vector */
00070   int index_all; /* Current index in the whole time vector */
00071 
00072   /* Process each downscaled day for a specific season subperiod */
00073   for (t=0; t<ntimes; t++) {
00074     /* Index of season-specific time into ntime_ls whole time vector */
00075     index_all = analog_days.tindex_s_all[t];
00076     /* Retrieve index in merge time vector from index of whole time vector ntime_ls */
00077     curindex = merged_itimes[index_all];
00078     /* Retrieve values */
00079     analog_days_merged.tindex_all[curindex] = analog_days.tindex_all[t];
00080     analog_days_merged.time[curindex] = analog_days.time[t];
00081     analog_days_merged.year[curindex] = analog_days.year[t];
00082     analog_days_merged.month[curindex] = analog_days.month[t];
00083     analog_days_merged.day[curindex] = analog_days.day[t];
00084 
00085     analog_days_merged.tindex_s_all[curindex] = analog_days.tindex_s_all[t];
00086     analog_days_merged.year_s[curindex] = analog_days.year_s[t];
00087     analog_days_merged.month_s[curindex] = analog_days.month_s[t];
00088     analog_days_merged.day_s[curindex] = analog_days.day_s[t];
00089     //    printf("IDM %d %d %d\n",t,curindex,index_all);
00090     analog_days_merged.ndayschoice[curindex] = analog_days.ndayschoice[t];
00091     //    printf("%d %d\n",analog_days_merged.ndayschoice[curindex],analog_days.ndayschoice[t]);
00092     if (analog_days_merged.analog_dayschoice[curindex] == NULL) {
00093       analog_days_merged.analog_dayschoice[curindex] =
00094         (tstruct *) malloc(analog_days_merged.ndayschoice[curindex] * sizeof(tstruct));
00095     //    printf("%d %d\n",analog_days_merged.ndayschoice[curindex],analog_days.ndayschoice[t]);
00096       if (analog_days_merged.analog_dayschoice[curindex] == NULL) alloc_error(__FILE__, __LINE__);
00097     }
00098     //    printf("%d %d\n",analog_days_merged.ndayschoice[curindex],analog_days.ndayschoice[t]);
00099     if (analog_days_merged.metric_norm[curindex] == NULL) {
00100       analog_days_merged.metric_norm[curindex] = (float *) malloc(analog_days_merged.ndayschoice[curindex] * sizeof(float));
00101     //    printf("%d %d\n",analog_days_merged.ndayschoice[curindex],analog_days.ndayschoice[t]);
00102       if (analog_days_merged.metric_norm[curindex] == NULL) alloc_error(__FILE__, __LINE__);
00103     }
00104     //    printf("%d %d\n",analog_days_merged.ndayschoice[curindex],analog_days.ndayschoice[t]);
00105     for (i=0; i<analog_days_merged.ndayschoice[curindex]; i++) {
00106       analog_days_merged.metric_norm[curindex][i] = analog_days.metric_norm[t][i];
00107       analog_days_merged.analog_dayschoice[curindex][i].year = analog_days.analog_dayschoice[t][i].year;
00108       analog_days_merged.analog_dayschoice[curindex][i].month = analog_days.analog_dayschoice[t][i].month;
00109       analog_days_merged.analog_dayschoice[curindex][i].day = analog_days.analog_dayschoice[t][i].day;
00110       analog_days_merged.analog_dayschoice[curindex][i].hour = analog_days.analog_dayschoice[t][i].hour;
00111       analog_days_merged.analog_dayschoice[curindex][i].min = analog_days.analog_dayschoice[t][i].min;
00112       analog_days_merged.analog_dayschoice[curindex][i].sec = analog_days.analog_dayschoice[t][i].sec;
00113     }      
00114 
00115   }
00116 
00117   /* Success status */
00118   return 0;
00119 }

Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1