Compute the spatial mean of a field. More...
#include <utils.h>
Go to the source code of this file.
Functions | |
void | mean_field_spatial (double *buf_mean, double *buf, short int *mask, int ni, int nj, int ntime) |
Compute the spatial mean of a field. |
Compute the spatial mean of a field.
Definition in file mean_field_spatial.c.
void mean_field_spatial | ( | double * | buf_mean, | |
double * | buf, | |||
short int * | mask, | |||
int | ni, | |||
int | nj, | |||
int | ntime | |||
) |
Compute the spatial mean of a field.
[out] | buf_mean | Vector (over time) of spatially averaged data |
[in] | buf | Input 3D buffer |
[in] | mask | Input 2D mask |
[in] | ni | First dimension |
[in] | nj | Second dimension |
[in] | ntime | Time dimension |
Definition at line 58 of file mean_field_spatial.c.
Referenced by main(), wt_downscaling(), and wt_learning().
00058 { 00059 00069 double sum; /* Sum used to calculate the mean */ 00070 00071 int t; /* Time loop counter */ 00072 int i; /* Loop counter */ 00073 int j; /* Loop counter */ 00074 int pts = 0; /* Points counter */ 00075 00076 /* Loop over all time and average spatially, optionally using a mask */ 00077 if (mask == NULL) 00078 for (t=0; t<ntime; t++) { 00079 sum = 0.0; 00080 for (j=0; j<nj; j++) 00081 for (i=0; i<ni; i++) 00082 sum += buf[i+j*ni+t*ni*nj]; 00083 buf_mean[t] = sum / (double) (ni*nj); 00084 } 00085 else { 00086 for (t=0; t<ntime; t++) { 00087 sum = 0.0; 00088 pts = 0; 00089 for (j=0; j<nj; j++) 00090 for (i=0; i<ni; i++) 00091 if (mask[i+j*ni] == 1) { 00092 sum += buf[i+j*ni+t*ni*nj]; 00093 pts++; 00094 } 00095 buf_mean[t] = sum / (double) pts; 00096 } 00097 } 00098 }