Compute daily climatology for climatological year. More...
#include <clim.h>
Go to the source code of this file.
Functions | |
void | clim_daily_tserie_climyear (double *bufout, double *bufin, tstruct *buftime, double missing_val, int ni, int nj, int nt) |
Compute daily climatology for climatological months of a daily time serie. |
Compute daily climatology for climatological year.
Definition in file clim_daily_tserie_climyear.c.
void clim_daily_tserie_climyear | ( | double * | bufout, | |
double * | bufin, | |||
tstruct * | buftime, | |||
double | missing_val, | |||
int | ni, | |||
int | nj, | |||
int | nt | |||
) |
Compute daily climatology for climatological months of a daily time serie.
[out] | bufout | Output 3D matrix of daily climatology for a year. |
[in] | bufin | Input 3D matrix. |
[in] | buftime | Time vector for input vector data. |
[in] | missing_val | Missing value. |
[in] | ni | Horizontal dimension of buffer input vector. |
[in] | nj | Horizontal dimension of buffer input vector. |
[in] | nt | Temporal dimension of buffer input vector. |
Definition at line 58 of file clim_daily_tserie_climyear.c.
References alloc_error().
Referenced by remove_seasonal_cycle().
00058 { 00069 int *index = NULL; /* Index to flag matching a specific day and month in a time serie covering several years. */ 00070 double *sum; /* Sum over all matching days. */ 00071 int *ndays = NULL; /* Number of days matching days. */ 00072 int month; /* Climatological month. */ 00073 00074 int t; /* Loop counter for time. */ 00075 int i; /* Loop counter for ni. */ 00076 int j; /* Loop counter for nj. */ 00077 int day; /* Loop counter for days. */ 00078 00079 (void) fprintf(stdout, "%s: Computing climatological months of a daily time serie.\n", __FILE__); 00080 00081 /* Allocate memory */ 00082 index = (int *) calloc(nt, sizeof(int)); 00083 if (index == NULL) alloc_error(__FILE__, __LINE__); 00084 sum = (double *) malloc(ni*nj * sizeof(double)); 00085 if (sum == NULL) alloc_error(__FILE__, __LINE__); 00086 ndays = (int *) malloc(ni*nj * sizeof(int)); 00087 if (ndays == NULL) alloc_error(__FILE__, __LINE__); 00088 00089 /* Loop over the 12 months of the year to generate daily climatological months */ 00090 for (month=1; month<=12; month++) { 00091 00092 /* Loop over each day of the month */ 00093 for (day=1; day<=31; day++) { 00094 00095 for (j=0; j<nj; j++) 00096 for (i=0; i<ni; i++) { 00097 sum[i+j*ni] = 0.0; 00098 ndays[i+j*ni] = 0; /* Initialize the number of days */ 00099 } 00100 00101 /* Loop over all the times */ 00102 for (t=0; t<nt; t++) { 00103 /* Initialize */ 00104 index[t] = 0; 00105 if (buftime[t].day == day && buftime[t].month == month) { 00106 /* The climatological day and month match */ 00107 index[t] = 1; /* Flag it */ 00108 for (j=0; j<nj; j++) 00109 for (i=0; i<ni; i++) 00110 if (bufin[i+j*ni+t*ni*nj] != missing_val) { 00111 /* Ignore missing values */ 00112 sum[i+j*ni] += bufin[i+j*ni+t*ni*nj]; /* Sum all the values for this matching day/month */ 00113 ndays[i+j*ni]++; 00114 } 00115 } 00116 } 00117 for (t=0; t<nt; t++) 00118 /* Compute the mean over all the matching days and apply mean for all these flagged days */ 00119 /* Assign mean value for all flagged days used in computing this mean */ 00120 if (index[t] == 1) { 00121 for (j=0; j<nj; j++) 00122 for (i=0; i<ni; i++) 00123 if (ndays[i+j*ni] > 0) { 00124 bufout[i+j*ni+t*ni*nj] = sum[i+j*ni] / (double) ndays[i+j*ni]; 00125 } 00126 else { 00127 bufout[i+j*ni+t*ni*nj] = missing_val; 00128 } 00129 } 00130 } 00131 } 00132 00133 /* Free memory */ 00134 (void) free(index); 00135 (void) free(sum); 00136 (void) free(ndays); 00137 }