time_mean_variance_field_2d.c File Reference

Compute the time mean and variance of a 2D field. More...

#include <utils.h>
Include dependency graph for time_mean_variance_field_2d.c:

Go to the source code of this file.

Functions

void time_mean_variance_field_2d (double *bufmean, double *bufvar, double *buf, int ni, int nj, int nt)
 Compute the time mean and variance of a 2D field.

Detailed Description

Compute the time mean and variance of a 2D field.

Definition in file time_mean_variance_field_2d.c.


Function Documentation

void time_mean_variance_field_2d ( double *  bufmean,
double *  bufvar,
double *  buf,
int  ni,
int  nj,
int  nt 
)

Compute the time mean and variance of a 2D field.

Parameters:
[out] bufmean Time mean of 2D field
[out] bufvar Time variance of 2D field
[in] buf Input 3D buffer
[in] ni First dimension
[in] nj Second dimension
[in] nt Time dimension

Definition at line 58 of file time_mean_variance_field_2d.c.

Referenced by wt_downscaling(), and wt_learning().

00058                                                                                                   {
00059 
00069   int i; /* Loop counter */
00070   int j; /* Loop counter */
00071   int t; /* Loop counter */
00072 
00073   double sum; /* Temporary sum for buf */
00074   double diff; /* Temporary difference for variance calculation */
00075 
00076   /* First calculate mean over time of a 2D field */
00077   for (j=0; j<nj; j++)
00078     for (i=0; i<ni; i++) {
00079       sum = 0.0;
00080       for (t=0; t<nt; t++)
00081         sum += buf[i+j*ni+t*ni*nj];
00082       bufmean[i+j*ni] = sum / (double) nt;
00083     }
00084 
00085   /* Then calculate variance over time of a 2D field */
00086   for (j=0; j<nj; j++)
00087     for (i=0; i<ni; i++) {
00088       sum = 0.0;
00089       for (t=0; t<nt; t++) {
00090         diff = buf[i+j*ni+t*ni*nj] - bufmean[i+j*ni];
00091         sum += (diff * diff);
00092       bufvar[i+j*ni] = sqrtf(sum / (double) (nt-1));
00093       }
00094     }
00095 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1