Remove seasonal cycle for a time serie. More...
#include <clim.h>
Go to the source code of this file.
Functions | |
void | remove_seasonal_cycle (double *bufout, double *clim, double *bufin, tstruct *buftime, double missing_val, int filter_width, char *type, int clim_provided, int ni, int nj, int ntime) |
Remove seasonal cycle using a time filter. |
Remove seasonal cycle for a time serie.
Definition in file remove_seasonal_cycle.c.
void remove_seasonal_cycle | ( | double * | bufout, | |
double * | clim, | |||
double * | bufin, | |||
tstruct * | buftime, | |||
double | missing_val, | |||
int | filter_width, | |||
char * | type, | |||
int | clim_provided, | |||
int | ni, | |||
int | nj, | |||
int | ntime | |||
) |
Remove seasonal cycle using a time filter.
[out] | bufout | Output data 3D matrix with seasonal cycle removed. |
[in,out] | clim | Climatology vector (on 366 days). Can be already provided as input or not (clim_provided parameter). |
[in] | bufin | Input 3D matrix. |
[in] | buftime | Time vector for input vector data. |
[in] | type | Type of filter. Possible values: hanning. |
[in] | missing_val | Missing value. |
[in] | filter_width | Width of filter. |
[in] | clim_provided | Set to 1 if clim is already calculated and provided as input. |
[in] | ni | Horizontal dimension of buffer input vector. |
[in] | nj | Horizontal dimension of buffer input vector. |
[in] | ntime | Dimension of buffer input vector. |
Output filtered climatology value
Definition at line 58 of file remove_seasonal_cycle.c.
References alloc_error(), clim_daily_tserie_climyear(), dayofclimyear(), filter(), tstruct::month, and TRUE.
Referenced by main(), and remove_clim().
00059 { 00074 double *tmpbuf = NULL; /* Temporary vector. */ 00075 int i; /* Loop counter for ni. */ 00076 int j; /* Loop counter for nj. */ 00077 int t; /* Loop counter. */ 00078 int ndays_m = 31; /* Maximum number of days in a month. */ 00079 int month; /* Climatological month. */ 00080 int day; /* Climatological day. */ 00081 int dayofclimy; /* Day of year in a 366-day climatological year */ 00082 00083 /* Allocate temporay buffer memory. */ 00084 tmpbuf = (double *) calloc(ni*nj*ntime, sizeof(double)); 00085 if (tmpbuf == NULL) alloc_error(__FILE__, __LINE__); 00086 00087 (void) fprintf(stdout, "%s: Removing seasonal cycle for a time serie.\n", __FILE__); 00088 00089 if (clim_provided != TRUE) { 00090 /* Climatology field was not provided */ 00091 00092 /* Compute daily climatologies for climatological year */ 00093 (void) clim_daily_tserie_climyear(bufout, bufin, buftime, missing_val, ni, nj, ntime); 00094 (void) fprintf(stdout, "%s: Using a %s filter for climatology (wrap edges).\n", __FILE__, type); 00095 /* Filter climatologies using a filter (wrap edges) */ 00096 (void) filter(tmpbuf, bufout, type, filter_width, ni, nj, ntime); 00097 00098 /* Remove climatology from time serie */ 00099 for (t=0; t<ntime; t++) 00100 for (j=0; j<nj; j++) 00101 for (i=0; i<ni; i++) 00102 bufout[i+j*ni+t*ni*nj] = bufin[i+j*ni+t*ni*nj] - tmpbuf[i+j*ni+t*ni*nj]; 00103 00105 for (month=0; month<12; month++) 00106 for (day=0; day<ndays_m; day++) 00107 /* Loop over all the times */ 00108 for (t=0; t<ntime; t++) { 00109 if (buftime[t].day == (day+1) && buftime[t].month == (month+1)) { 00110 dayofclimy = dayofclimyear(day+1, month+1); 00111 for (j=0; j<nj; j++) 00112 for (i=0; i<ni; i++) 00113 clim[i+j*ni+(dayofclimy-1)*ni*nj] = tmpbuf[i+j*ni+t*ni*nj]; 00114 /* Exit loop: matched month and day */ 00115 t = ntime; 00116 } 00117 } 00118 } 00119 else { 00120 /* Climatology field was provided */ 00121 /* Loop over all the times */ 00122 for (t=0; t<ntime; t++) { 00123 dayofclimy = dayofclimyear(buftime[t].day, buftime[t].month); 00124 for (j=0; j<nj; j++) 00125 for (i=0; i<ni; i++) 00126 bufout[i+j*ni+t*ni*nj] = bufin[i+j*ni+t*ni*nj] - clim[i+j*ni+(dayofclimy-1)*ni*nj]; 00127 } 00128 } 00129 00130 /* Free memory */ 00131 (void) free(tmpbuf); 00132 }