00001 /* ***************************************************** */ 00002 /* Normalize a 2D variable by the norm of the first */ 00003 /* column of the first dimension and recompute the new */ 00004 /* norm. */ 00005 /* normalize_pc.c */ 00006 /* ***************************************************** */ 00007 /* Author: Christian Page, CERFACS, Toulouse, France. */ 00008 /* ***************************************************** */ 00013 /* LICENSE BEGIN 00014 00015 Copyright Cerfacs (Christian Page) (2015) 00016 00017 christian.page@cerfacs.fr 00018 00019 This software is a computer program whose purpose is to downscale climate 00020 scenarios using a statistical methodology based on weather regimes. 00021 00022 This software is governed by the CeCILL license under French law and 00023 abiding by the rules of distribution of free software. You can use, 00024 modify and/ or redistribute the software under the terms of the CeCILL 00025 license as circulated by CEA, CNRS and INRIA at the following URL 00026 "http://www.cecill.info". 00027 00028 As a counterpart to the access to the source code and rights to copy, 00029 modify and redistribute granted by the license, users are provided only 00030 with a limited warranty and the software's author, the holder of the 00031 economic rights, and the successive licensors have only limited 00032 liability. 00033 00034 In this respect, the user's attention is drawn to the risks associated 00035 with loading, using, modifying and/or developing or reproducing the 00036 software by the user in light of its specific status of free software, 00037 that may mean that it is complicated to manipulate, and that also 00038 therefore means that it is reserved for developers and experienced 00039 professionals having in-depth computer knowledge. Users are therefore 00040 encouraged to load and test the software's suitability as regards their 00041 requirements in conditions enabling the security of their systems and/or 00042 data to be ensured and, more generally, to use and operate it in the 00043 same conditions as regards security. 00044 00045 The fact that you are presently reading this means that you have had 00046 knowledge of the CeCILL license and that you accept its terms. 00047 00048 LICENSE END */ 00049 00050 00051 00052 00053 00054 00055 00056 #include <pceof.h> 00057 00059 void 00060 normalize_pc(double *norm_all, double *first_variance, double *buf_renorm, double *bufin, int neof, int ntime) { 00061 00071 int eof; /* EOF loop counter */ 00072 int nt; /* Time loop counter */ 00073 00074 /* Check if we need to calculate the variance of the first column of the first dimension */ 00075 if (*first_variance == -9999.9999) { 00076 eof = 0; 00077 *first_variance = gsl_stats_variance(&(bufin[eof*ntime]), 1, ntime); 00078 printf("first variance set=%lf %lf!\n",*first_variance,sqrt(*first_variance)); 00079 } 00080 else 00081 printf("first variance=%lf %lf!\n",*first_variance,sqrt(*first_variance)); 00082 00083 /* Loop over all EOFs */ 00084 for (eof=0; eof<neof; eof++) { 00085 00086 // for (nt=0; nt<ntime; nt++) { 00087 // printf("norm_1 %d %d %lf\n",eof,nt,bufin[eof+nt*neof]); 00088 // } 00089 00090 /* Loop over time */ 00091 for (nt=0; nt<ntime; nt++) 00092 /* Normalize with the first variance */ 00093 buf_renorm[nt+eof*ntime] = bufin[nt+eof*ntime] / sqrt(*first_variance); 00094 00095 /* for (nt=(ntime-5); nt<ntime; nt++) 00096 printf("bufin %d eof %d %lf\n",nt,eof,bufin[nt+eof*ntime]); 00097 00098 printf("before renorm %d %d %lf %lf ",eof,ntime,bufin[ntime-5+eof*ntime], sqrt(gsl_stats_variance(&(bufin[eof*ntime]), 1, ntime))); 00099 printf("renorm %lf\n",buf_renorm[ntime-5+eof*ntime]);*/ 00100 00101 /* Recompute the norm for each EOF */ 00102 norm_all[eof] = gsl_stats_variance(&(buf_renorm[eof*ntime]), 1, ntime); 00103 00104 printf("%s: Norm %d %lf\n",__FILE__,eof,sqrt(norm_all[eof])); 00105 00106 } 00107 }