Commit 2c4d5748 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added operator ymonrange.

parent a8e8b649
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
* Using CDI library version 1.9.0 * Using CDI library version 1.9.0
* Version 1.9.0 release * Version 1.9.0 release
2017-06-01 Uwe Schulzweida
* New operator ymonrange: Multi-year monthly range (ymonmax-ymonmin)
* New operator yseasrange: Multi-year seasonally range (yseasmax-yseasmin)
2017-05-30 Uwe Schulzweida 2017-05-30 Uwe Schulzweida
* New operator seasrange: seasonal range (seasmax-seasmin) * New operator seasrange: seasonal range (seasmax-seasmin)
......
...@@ -18,16 +18,16 @@ ...@@ -18,16 +18,16 @@
/* /*
This module contains the following operators: This module contains the following operators:
Seasstat seasrange Seasonal range Seasstat seasrange Seasonally range
Seasstat seasmin Seasonal minimum Seasstat seasmin Seasonally minimum
Seasstat seasmax Seasonal maximum Seasstat seasmax Seasonally maximum
Seasstat seassum Seasonal sum Seasstat seassum Seasonally sum
Seasstat seasmean Seasonal mean Seasstat seasmean Seasonally mean
Seasstat seasavg Seasonal average Seasstat seasavg Seasonally average
Seasstat seasvar Seasonal variance Seasstat seasvar Seasonally variance
Seasstat seasvar1 Seasonal variance [Normalize by (n-1)] Seasstat seasvar1 Seasonally variance [Normalize by (n-1)]
Seasstat seasstd Seasonal standard deviation Seasstat seasstd Seasonally standard deviation
Seasstat seasstd1 Seasonal standard deviation [Normalize by (n-1)] Seasstat seasstd1 Seasonally standard deviation [Normalize by (n-1)]
*/ */
......
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
Ymonarith ymonsub Subtract multi-year monthly time series Ymonarith ymonsub Subtract multi-year monthly time series
Ymonarith ymonmul Multiply multi-year monthly time series Ymonarith ymonmul Multiply multi-year monthly time series
Ymonarith ymondiv Divide multi-year monthly time series Ymonarith ymondiv Divide multi-year monthly time series
Ymonarith yseasadd Add multi-year seasonal time series Ymonarith ymonadd Add multi-year monthly time series
Ymonarith yseassub Subtract multi-year seasonal time series Ymonarith ymonsub Subtract multi-year monthly time series
Ymonarith yseasmul Multiply multi-year seasonal time series Ymonarith ymonmul Multiply multi-year monthly time series
Ymonarith yseasdiv Divide multi-year seasonal time series Ymonarith ymondiv Divide multi-year monthly time series
*/ */
#include <cdi.h> #include <cdi.h>
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
/* /*
This module contains the following operators: This module contains the following operators:
Ymonstat ymonrange Multi-year monthly range
Ymonstat ymonmin Multi-year monthly minimum Ymonstat ymonmin Multi-year monthly minimum
Ymonstat ymonmax Multi-year monthly maximum Ymonstat ymonmax Multi-year monthly maximum
Ymonstat ymonsum Multi-year monthly sum Ymonstat ymonsum Multi-year monthly sum
...@@ -65,7 +66,7 @@ void *Ymonstat(void *argument) ...@@ -65,7 +66,7 @@ void *Ymonstat(void *argument)
int year, month, day; int year, month, day;
int nrecs; int nrecs;
int levelID; int levelID;
int nsets[NMONTH]; int month_nsets[NMONTH];
int nmiss; int nmiss;
int vdates[NMONTH], vtimes[NMONTH]; int vdates[NMONTH], vtimes[NMONTH];
int mon[NMONTH]; int mon[NMONTH];
...@@ -75,30 +76,32 @@ void *Ymonstat(void *argument) ...@@ -75,30 +76,32 @@ void *Ymonstat(void *argument)
cdoInitialize(argument); cdoInitialize(argument);
cdoOperatorAdd("ymonmin", func_min, 0, NULL); cdoOperatorAdd("ymonrange", func_range, 0, NULL);
cdoOperatorAdd("ymonmax", func_max, 0, NULL); cdoOperatorAdd("ymonmin", func_min, 0, NULL);
cdoOperatorAdd("ymonsum", func_sum, 0, NULL); cdoOperatorAdd("ymonmax", func_max, 0, NULL);
cdoOperatorAdd("ymonmean", func_mean, 0, NULL); cdoOperatorAdd("ymonsum", func_sum, 0, NULL);
cdoOperatorAdd("ymonavg", func_avg, 0, NULL); cdoOperatorAdd("ymonmean", func_mean, 0, NULL);
cdoOperatorAdd("ymonvar", func_var, 0, NULL); cdoOperatorAdd("ymonavg", func_avg, 0, NULL);
cdoOperatorAdd("ymonvar1", func_var1, 0, NULL); cdoOperatorAdd("ymonvar", func_var, 0, NULL);
cdoOperatorAdd("ymonstd", func_std, 0, NULL); cdoOperatorAdd("ymonvar1", func_var1, 0, NULL);
cdoOperatorAdd("ymonstd1", func_std1, 0, NULL); cdoOperatorAdd("ymonstd", func_std, 0, NULL);
cdoOperatorAdd("ymonstd1", func_std1, 0, NULL);
int operatorID = cdoOperatorID(); int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID); int operfunc = cdoOperatorF1(operatorID);
bool lrange = operfunc == func_range;
bool lmean = operfunc == func_mean || operfunc == func_avg; bool lmean = operfunc == func_mean || operfunc == func_avg;
bool lstd = operfunc == func_std || operfunc == func_std1; bool lstd = operfunc == func_std || operfunc == func_std1;
bool lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1; bool lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
int divisor = operfunc == func_std1 || operfunc == func_var1; int divisor = operfunc == func_std1 || operfunc == func_var1;
for ( month = 0; month < NMONTH; month++ ) for ( month = 0; month < NMONTH; month++ )
{ {
vars1[month] = NULL; vars1[month] = NULL;
vars2[month] = NULL; vars2[month] = NULL;
samp1[month] = NULL; samp1[month] = NULL;
nsets[month] = 0; month_nsets[month] = 0;
} }
int streamID1 = streamOpenRead(cdoStreamName(0)); int streamID1 = streamOpenRead(cdoStreamName(0));
...@@ -145,7 +148,7 @@ void *Ymonstat(void *argument) ...@@ -145,7 +148,7 @@ void *Ymonstat(void *argument)
mon[nmon++] = month; mon[nmon++] = month;
vars1[month] = field_malloc(vlistID1, FIELD_PTR); vars1[month] = field_malloc(vlistID1, FIELD_PTR);
samp1[month] = field_malloc(vlistID1, FIELD_NONE); samp1[month] = field_malloc(vlistID1, FIELD_NONE);
if ( lvarstd ) if ( lvarstd || lrange )
vars2[month] = field_malloc(vlistID1, FIELD_PTR); vars2[month] = field_malloc(vlistID1, FIELD_PTR);
} }
...@@ -159,23 +162,31 @@ void *Ymonstat(void *argument) ...@@ -159,23 +162,31 @@ void *Ymonstat(void *argument)
recinfo[recID].levelID = levelID; recinfo[recID].levelID = levelID;
} }
field_type *psamp1 = &samp1[month][varID][levelID];
field_type *pvars1 = &vars1[month][varID][levelID]; field_type *pvars1 = &vars1[month][varID][levelID];
field_type *pvars2 = vars2[month] ? &vars2[month][varID][levelID] : NULL; field_type *pvars2 = vars2[month] ? &vars2[month][varID][levelID] : NULL;
int nsets = month_nsets[month];
int gridsize = pvars1->size; int gridsize = pvars1->size;
if ( nsets[month] == 0 ) if ( nsets == 0 )
{ {
streamReadRecord(streamID1, pvars1->ptr, &nmiss); streamReadRecord(streamID1, pvars1->ptr, &nmiss);
pvars1->nmiss = (size_t) nmiss; pvars1->nmiss = (size_t) nmiss;
if ( lrange )
if ( nmiss > 0 || samp1[month][varID][levelID].ptr ) {
pvars2->nmiss = pvars1->nmiss;
for ( int i = 0; i < gridsize; i++ )
pvars2->ptr[i] = pvars1->ptr[i];
}
if ( nmiss > 0 || psamp1->ptr )
{ {
if ( samp1[month][varID][levelID].ptr == NULL ) if ( psamp1->ptr == NULL )
samp1[month][varID][levelID].ptr = (double*) Malloc(gridsize*sizeof(double)); psamp1->ptr = (double*) Malloc(gridsize*sizeof(double));
for ( int i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
samp1[month][varID][levelID].ptr[i] = !DBL_IS_EQUAL(pvars1->ptr[i], pvars1->missval); psamp1->ptr[i] = !DBL_IS_EQUAL(pvars1->ptr[i], pvars1->missval);
} }
} }
else else
...@@ -185,18 +196,18 @@ void *Ymonstat(void *argument) ...@@ -185,18 +196,18 @@ void *Ymonstat(void *argument)
field.grid = pvars1->grid; field.grid = pvars1->grid;
field.missval = pvars1->missval; field.missval = pvars1->missval;
if ( field.nmiss > 0 || samp1[month][varID][levelID].ptr ) if ( field.nmiss > 0 || psamp1->ptr )
{ {
if ( samp1[month][varID][levelID].ptr == NULL ) if ( psamp1->ptr == NULL )
{ {
samp1[month][varID][levelID].ptr = (double*) Malloc(gridsize*sizeof(double)); psamp1->ptr = (double*) Malloc(gridsize*sizeof(double));
for ( int i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
samp1[month][varID][levelID].ptr[i] = nsets[month]; psamp1->ptr[i] = nsets;
} }
for ( int i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
if ( !DBL_IS_EQUAL(field.ptr[i], pvars1->missval) ) if ( !DBL_IS_EQUAL(field.ptr[i], pvars1->missval) )
samp1[month][varID][levelID].ptr[i]++; psamp1->ptr[i]++;
} }
if ( lvarstd ) if ( lvarstd )
...@@ -204,6 +215,11 @@ void *Ymonstat(void *argument) ...@@ -204,6 +215,11 @@ void *Ymonstat(void *argument)
farsumq(pvars2, field); farsumq(pvars2, field);
farsum(pvars1, field); farsum(pvars1, field);
} }
else if ( lrange )
{
farmin(pvars2, field);
farmax(pvars1, field);
}
else else
{ {
farfun(pvars1, field, operfunc); farfun(pvars1, field, operfunc);
...@@ -211,7 +227,7 @@ void *Ymonstat(void *argument) ...@@ -211,7 +227,7 @@ void *Ymonstat(void *argument)
} }
} }
if ( nsets[month] == 0 && lvarstd ) if ( month_nsets[month] == 0 && lvarstd )
for ( int recID = 0; recID < maxrecs; recID++ ) for ( int recID = 0; recID < maxrecs; recID++ )
{ {
int varID = recinfo[recID].varID; int varID = recinfo[recID].varID;
...@@ -224,14 +240,14 @@ void *Ymonstat(void *argument) ...@@ -224,14 +240,14 @@ void *Ymonstat(void *argument)
farmoq(pvars2, *pvars1); farmoq(pvars2, *pvars1);
} }
nsets[month]++; month_nsets[month]++;
tsID++; tsID++;
} }
if ( nmon == 12 ) if ( nmon == 12 )
{ {
int smon = 0; int smon = 0;
for ( month = 1; month <= 12; month++ ) if ( nsets[month] ) smon++; for ( month = 1; month <= 12; month++ ) if ( month_nsets[month] ) smon++;
if ( smon == 12 ) for ( month = 1; month <= 12; month++ ) mon[month-1] = month; if ( smon == 12 ) for ( month = 1; month <= 12; month++ ) mon[month-1] = month;
} }
...@@ -240,7 +256,7 @@ void *Ymonstat(void *argument) ...@@ -240,7 +256,7 @@ void *Ymonstat(void *argument)
nmon = 0; nmon = 0;
for ( month = 0; month < NMONTH; month++ ) for ( month = 0; month < NMONTH; month++ )
{ {
if ( nsets[month] == 0 ) if ( month_nsets[month] == 0 )
for ( i = month+1; i < NMONTH; i++ ) mon[i-1] = mon[i]; for ( i = month+1; i < NMONTH; i++ ) mon[i-1] = mon[i];
else else
nmon++; nmon++;
...@@ -257,43 +273,42 @@ void *Ymonstat(void *argument) ...@@ -257,43 +273,42 @@ void *Ymonstat(void *argument)
for ( int i = 0; i < nmon; i++ ) for ( int i = 0; i < nmon; i++ )
{ {
month = mon[i]; month = mon[i];
if ( nsets[month] == 0 ) cdoAbort("Internal problem, nsets[%d] not defined!", month); if ( month_nsets[month] == 0 ) cdoAbort("Internal problem, nsets[%d] not defined!", month);
if ( lmean )
for ( int recID = 0; recID < maxrecs; recID++ )
{
int varID = recinfo[recID].varID;
int levelID = recinfo[recID].levelID;
field_type *pvars1 = &vars1[month][varID][levelID];
if ( vlistInqVarTsteptype(vlistID1, varID) == TSTEP_CONSTANT ) continue;
if ( samp1[month][varID][levelID].ptr == NULL )
farcdiv(pvars1, (double)nsets[month]);
else
fardiv(pvars1, samp1[month][varID][levelID]);
}
else if ( lvarstd )
for ( int recID = 0; recID < maxrecs; recID++ )
{
int varID = recinfo[recID].varID;
int levelID = recinfo[recID].levelID;
field_type *pvars1 = &vars1[month][varID][levelID];
field_type *pvars2 = &vars2[month][varID][levelID];
if ( vlistInqVarTsteptype(vlistID1, varID) == TSTEP_CONSTANT ) continue; int nsets = month_nsets[month];
for ( int recID = 0; recID < maxrecs; recID++ )
{
int varID = recinfo[recID].varID;
int levelID = recinfo[recID].levelID;
field_type *psamp1 = &samp1[month][varID][levelID];
field_type *pvars1 = &vars1[month][varID][levelID];
field_type *pvars2 = vars2[month] ? &vars2[month][varID][levelID] : NULL;
if ( samp1[month][varID][levelID].ptr == NULL ) if ( vlistInqVarTsteptype(vlistID1, varID) == TSTEP_CONSTANT ) continue;
{
if ( lstd ) farcstd(pvars1, *pvars2, nsets[month], divisor); if ( lmean )
else farcvar(pvars1, *pvars2, nsets[month], divisor); {
} if ( psamp1->ptr ) fardiv(pvars1, *psamp1);
else else farcdiv(pvars1, (double)nsets);
{ }
if ( lstd ) farstd(pvars1, *pvars2, samp1[month][varID][levelID], divisor); else if ( lvarstd )
else farvar(pvars1, *pvars2, samp1[month][varID][levelID], divisor); {
} if ( psamp1->ptr )
} {
if ( lstd ) farstd(pvars1, *pvars2, *psamp1, divisor);
else farvar(pvars1, *pvars2, *psamp1, divisor);
}
else
{
if ( lstd ) farcstd(pvars1, *pvars2, nsets, divisor);
else farcvar(pvars1, *pvars2, nsets, divisor);
}
}
else if ( lrange )
{
farsub(pvars1, *pvars2);
}
}
taxisDefVdate(taxisID2, vdates[month]); taxisDefVdate(taxisID2, vdates[month]);
taxisDefVtime(taxisID2, vtimes[month]); taxisDefVtime(taxisID2, vtimes[month]);
......
...@@ -507,7 +507,7 @@ void *Samplegrid(void *argument); // "samplegrid", "subgrid" ...@@ -507,7 +507,7 @@ void *Samplegrid(void *argument); // "samplegrid", "subgrid"
#define YmonarithOperators {"ymonadd", "ymonsub", "ymonmul", "ymondiv"} #define YmonarithOperators {"ymonadd", "ymonsub", "ymonmul", "ymondiv"}
#define YseasarithOperators {"yseasadd", "yseassub", "yseasmul", "yseasdiv"} #define YseasarithOperators {"yseasadd", "yseassub", "yseasmul", "yseasdiv"}
#define YmonpctlOperators {"ymonpctl"} #define YmonpctlOperators {"ymonpctl"}
#define YmonstatOperators {"ymonmin", "ymonmax", "ymonsum", "ymonmean", "ymonavg", "ymonstd", "ymonstd1", "ymonvar", "ymonvar1"} #define YmonstatOperators {"ymonrange", "ymonmin", "ymonmax", "ymonsum", "ymonmean", "ymonavg", "ymonstd", "ymonstd1", "ymonvar", "ymonvar1"}
#define YseaspctlOperators {"yseaspctl"} #define YseaspctlOperators {"yseaspctl"}
#define YseasstatOperators {"yseasrange", "yseasmin", "yseasmax", "yseassum", "yseasmean", "yseasavg", "yseasstd", "yseasstd1", "yseasvar", "yseasvar1"} #define YseasstatOperators {"yseasrange", "yseasmin", "yseasmax", "yseassum", "yseasmean", "yseasavg", "yseasstd", "yseasstd1", "yseasvar", "yseasvar1"}
#define ZonstatOperators {"zonrange", "zonmin", "zonmax", "zonsum", "zonmean", "zonavg", "zonstd", "zonstd1", "zonvar", "zonvar1", "zonpctl"} #define ZonstatOperators {"zonrange", "zonmin", "zonmax", "zonsum", "zonmean", "zonavg", "zonstd", "zonstd1", "zonvar", "zonvar1", "zonpctl"}
......
...@@ -8,7 +8,7 @@ NETCDF_REF = netcdf_testfile01_sinfon_ref netcdf_testfile01_infon_ref netcdf_t ...@@ -8,7 +8,7 @@ NETCDF_REF = netcdf_testfile01_sinfon_ref netcdf_testfile01_infon_ref netcdf_t
COMP_REF = comp_eqc_ref comp_gec_ref comp_gtc_ref comp_lec_ref comp_ltc_ref comp_nec_ref comptest.srv COMP_REF = comp_eqc_ref comp_gec_ref comp_gtc_ref comp_lec_ref comp_ltc_ref comp_nec_ref comptest.srv
EOF_REF = eval_ref eof_ref pcoeff00000 EOF_REF = eval_ref eof_ref pcoeff00000
YDRUNSTAT_REF = ydrunmin_ref ydrunmax_ref ydrunsum_ref ydrunavg_ref ydrunmean_ref ydrunstd_ref ydrunstd1_ref ydrunvar_ref ydrunvar1_ref YDRUNSTAT_REF = ydrunmin_ref ydrunmax_ref ydrunsum_ref ydrunavg_ref ydrunmean_ref ydrunstd_ref ydrunstd1_ref ydrunvar_ref ydrunvar1_ref
YMONSTAT_REF = ymonmin_ref ymonmax_ref ymonsum_ref ymonavg_ref ymonmean_ref ymonstd_ref ymonstd1_ref ymonvar_ref ymonvar1_ref YMONSTAT_REF = ymonmin_ref ymonmax_ref ymonsum_ref ymonavg_ref ymonmean_ref ymonstd_ref ymonstd1_ref ymonvar_ref ymonvar1_ref ymonrange_ref
YSEASSTAT_REF = yseasmin_ref yseasmax_ref yseassum_ref yseasavg_ref yseasmean_ref yseasstd_ref yseasstd1_ref yseasvar_ref yseasvar1_ref yseasrange_ref YSEASSTAT_REF = yseasmin_ref yseasmax_ref yseassum_ref yseasavg_ref yseasmean_ref yseasstd_ref yseasstd1_ref yseasvar_ref yseasvar1_ref yseasrange_ref
SEASSTAT_REF = seasmin_ref seasmax_ref seassum_ref seasavg_ref seasmean_ref seasstd_ref seasstd1_ref seasvar_ref seasvar1_ref seasrange_ref SEASSTAT_REF = seasmin_ref seasmax_ref seassum_ref seasavg_ref seasmean_ref seasstd_ref seasstd1_ref seasvar_ref seasvar1_ref seasrange_ref
RUNSTAT_REF = runmin_ref runmax_ref runsum_ref runavg_ref runmean_ref runstd_ref runstd1_ref runvar_ref runvar1_ref runrange_ref RUNSTAT_REF = runmin_ref runmax_ref runsum_ref runavg_ref runmean_ref runstd_ref runstd1_ref runvar_ref runvar1_ref runrange_ref
......
...@@ -298,7 +298,7 @@ NETCDF_REF = netcdf_testfile01_sinfon_ref netcdf_testfile01_infon_ref netcdf_tes ...@@ -298,7 +298,7 @@ NETCDF_REF = netcdf_testfile01_sinfon_ref netcdf_testfile01_infon_ref netcdf_tes
COMP_REF = comp_eqc_ref comp_gec_ref comp_gtc_ref comp_lec_ref comp_ltc_ref comp_nec_ref comptest.srv COMP_REF = comp_eqc_ref comp_gec_ref comp_gtc_ref comp_lec_ref comp_ltc_ref comp_nec_ref comptest.srv
EOF_REF = eval_ref eof_ref pcoeff00000 EOF_REF = eval_ref eof_ref pcoeff00000
YDRUNSTAT_REF = ydrunmin_ref ydrunmax_ref ydrunsum_ref ydrunavg_ref ydrunmean_ref ydrunstd_ref ydrunstd1_ref ydrunvar_ref ydrunvar1_ref YDRUNSTAT_REF = ydrunmin_ref ydrunmax_ref ydrunsum_ref ydrunavg_ref ydrunmean_ref ydrunstd_ref ydrunstd1_ref ydrunvar_ref ydrunvar1_ref
YMONSTAT_REF = ymonmin_ref ymonmax_ref ymonsum_ref ymonavg_ref ymonmean_ref ymonstd_ref ymonstd1_ref ymonvar_ref ymonvar1_ref YMONSTAT_REF = ymonmin_ref ymonmax_ref ymonsum_ref ymonavg_ref ymonmean_ref ymonstd_ref ymonstd1_ref ymonvar_ref ymonvar1_ref ymonrange_ref
YSEASSTAT_REF = yseasmin_ref yseasmax_ref yseassum_ref yseasavg_ref yseasmean_ref yseasstd_ref yseasstd1_ref yseasvar_ref yseasvar1_ref yseasrange_ref YSEASSTAT_REF = yseasmin_ref yseasmax_ref yseassum_ref yseasavg_ref yseasmean_ref yseasstd_ref yseasstd1_ref yseasvar_ref yseasvar1_ref yseasrange_ref
SEASSTAT_REF = seasmin_ref seasmax_ref seassum_ref seasavg_ref seasmean_ref seasstd_ref seasstd1_ref seasvar_ref seasvar1_ref seasrange_ref SEASSTAT_REF = seasmin_ref seasmax_ref seassum_ref seasavg_ref seasmean_ref seasstd_ref seasstd1_ref seasvar_ref seasvar1_ref seasrange_ref
RUNSTAT_REF = runmin_ref runmax_ref runsum_ref runavg_ref runmean_ref runstd_ref runstd1_ref runvar_ref runvar1_ref runrange_ref RUNSTAT_REF = runmin_ref runmax_ref runsum_ref runavg_ref runmean_ref runstd_ref runstd1_ref runvar_ref runvar1_ref runrange_ref
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment