normalize_pc.c File Reference

Normalize a 2D variable by the norm of the first column of the first dimension and recompute the new norm. More...

#include <pceof.h>
Include dependency graph for normalize_pc.c:

Go to the source code of this file.

Functions

void normalize_pc (double *norm_all, double *first_variance, double *buf_renorm, double *bufin, int neof, int ntime)
 Normalize a 2D variable by the norm of the first column of the first dimension and recompute the new norm.

Detailed Description

Normalize a 2D variable by the norm of the first column of the first dimension and recompute the new norm.

Definition in file normalize_pc.c.


Function Documentation

void normalize_pc ( double *  norm_all,
double *  first_variance,
double *  buf_renorm,
double *  bufin,
int  neof,
int  ntime 
)

Normalize a 2D variable by the norm of the first column of the first dimension and recompute the new norm.

Parameters:
[out] norm_all New norm vector
[in,out] first_variance Variance of the first column of the first dimension. Only calculate if not set to -9999.9999
[out] buf_renorm 2D field normalized
[in] bufin Input 2D field
[in] neof EOF dimension
[in] ntime Time dimension

Definition at line 60 of file normalize_pc.c.

Referenced by main(), and wt_downscaling().

00060                                                                                                                {
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 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1