apply_regression.c

Go to the documentation of this file.
00001 /* ***************************************************** */
00002 /* Compute a field using regression coefficients         */
00003 /* and the field values.                                 */
00004 /* apply_regression.c                                    */
00005 /* ***************************************************** */
00006 /* Author: Christian Page, CERFACS, Toulouse, France.    */
00007 /* ***************************************************** */
00012 /* LICENSE BEGIN
00013 
00014 Copyright Cerfacs (Christian Page) (2015)
00015 
00016 christian.page@cerfacs.fr
00017 
00018 This software is a computer program whose purpose is to downscale climate
00019 scenarios using a statistical methodology based on weather regimes.
00020 
00021 This software is governed by the CeCILL license under French law and
00022 abiding by the rules of distribution of free software. You can use, 
00023 modify and/ or redistribute the software under the terms of the CeCILL
00024 license as circulated by CEA, CNRS and INRIA at the following URL
00025 "http://www.cecill.info". 
00026 
00027 As a counterpart to the access to the source code and rights to copy,
00028 modify and redistribute granted by the license, users are provided only
00029 with a limited warranty and the software's author, the holder of the
00030 economic rights, and the successive licensors have only limited
00031 liability. 
00032 
00033 In this respect, the user's attention is drawn to the risks associated
00034 with loading, using, modifying and/or developing or reproducing the
00035 software by the user in light of its specific status of free software,
00036 that may mean that it is complicated to manipulate, and that also
00037 therefore means that it is reserved for developers and experienced
00038 professionals having in-depth computer knowledge. Users are therefore
00039 encouraged to load and test the software's suitability as regards their
00040 requirements in conditions enabling the security of their systems and/or 
00041 data to be ensured and, more generally, to use and operate it in the 
00042 same conditions as regards security. 
00043 
00044 The fact that you are presently reading this means that you have had
00045 knowledge of the CeCILL license and that you accept its terms.
00046 
00047 LICENSE END */
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 #include <regress.h>
00056 
00058 void
00059 apply_regression(double *buf, double *reg, double *cst, double *dist, double *sup_dist, int npts, int ntime,
00060                  int nclust, int nreg) {
00073   int nt; /* Time loop counter */
00074   int pts; /* Points loop counter */
00075   int clust; /* Cluster loop counter */
00076 
00077   /* Loop over all regression points */
00078   for (pts=0; pts<npts; pts++) {
00079     /* Loop over all times */
00080     for (nt=0; nt<ntime; nt++) {
00081       /* Initialize value */
00082       buf[pts+nt*npts] = 0.0;
00083       /* Loop over all clusters and add each value after regression is applied */
00084       for (clust=0; clust<nclust; clust++) {
00085         buf[pts+nt*npts] += (dist[nt+clust*ntime] * reg[pts+clust*npts]);
00086 
00087         //        if (pts == 0 && nt == (ntime-5))
00088         //          printf("%d %lf %lf %lf\n",clust,buf[pts+nt*npts],(dist[nt+clust*ntime]),(reg[pts+clust*npts]));
00089       }
00090       /* Extra regression coefficient with a second supplemental vector */
00091       if (nclust == (nreg-1)) {
00092         buf[pts+nt*npts] += (sup_dist[nt] * reg[pts+(nreg-1)*npts]);
00093       }      
00094       
00095       /* Add regression constant */
00096       buf[pts+nt*npts] += cst[pts];
00097 
00098       //     if (pts == 0 && nt == (ntime-5))
00099       //       printf("%lf %lf\n",buf[pts+nt*npts],cst[pts]);
00100     }
00101   }
00102   //  nt = ntime-1;
00103   //  pts = 0;
00104   //  for (clust=0; clust<nclust; clust++)
00105   //    printf("REGRESS %d %lf %lf %lf %lf\n",clust,buf[pts+nt*npts],dist[nt+clust*ntime],reg[pts+clust*npts],cst[pts]);
00106 }

Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1