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

Added operator ymonrange.

parent a8e8b649
......@@ -3,6 +3,11 @@
* Using CDI library version 1.9.0
* 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
* New operator seasrange: seasonal range (seasmax-seasmin)
......
......@@ -18,16 +18,16 @@
/*
This module contains the following operators:
Seasstat seasrange Seasonal range
Seasstat seasmin Seasonal minimum
Seasstat seasmax Seasonal maximum
Seasstat seassum Seasonal sum
Seasstat seasmean Seasonal mean
Seasstat seasavg Seasonal average
Seasstat seasvar Seasonal variance
Seasstat seasvar1 Seasonal variance [Normalize by (n-1)]
Seasstat seasstd Seasonal standard deviation
Seasstat seasstd1 Seasonal standard deviation [Normalize by (n-1)]
Seasstat seasrange Seasonally range
Seasstat seasmin Seasonally minimum
Seasstat seasmax Seasonally maximum
Seasstat seassum Seasonally sum
Seasstat seasmean Seasonally mean
Seasstat seasavg Seasonally average
Seasstat seasvar Seasonally variance
Seasstat seasvar1 Seasonally variance [Normalize by (n-1)]
Seasstat seasstd Seasonally standard deviation
Seasstat seasstd1 Seasonally standard deviation [Normalize by (n-1)]
*/
......
......@@ -22,10 +22,10 @@
Ymonarith ymonsub Subtract multi-year monthly time series
Ymonarith ymonmul Multiply multi-year monthly time series
Ymonarith ymondiv Divide multi-year monthly time series
Ymonarith yseasadd Add multi-year seasonal time series
Ymonarith yseassub Subtract multi-year seasonal time series
Ymonarith yseasmul Multiply multi-year seasonal time series
Ymonarith yseasdiv Divide multi-year seasonal time series
Ymonarith ymonadd Add multi-year monthly time series
Ymonarith ymonsub Subtract multi-year monthly time series
Ymonarith ymonmul Multiply multi-year monthly time series
Ymonarith ymondiv Divide multi-year monthly time series
*/
#include <cdi.h>
......
......@@ -18,6 +18,7 @@
/*
This module contains the following operators:
Ymonstat ymonrange Multi-year monthly range
Ymonstat ymonmin Multi-year monthly minimum
Ymonstat ymonmax Multi-year monthly maximum
Ymonstat ymonsum Multi-year monthly sum
......@@ -65,7 +66,7 @@ void *Ymonstat(void *argument)
int year, month, day;
int nrecs;
int levelID;
int nsets[NMONTH];
int month_nsets[NMONTH];
int nmiss;
int vdates[NMONTH], vtimes[NMONTH];
int mon[NMONTH];
......@@ -75,6 +76,7 @@ void *Ymonstat(void *argument)
cdoInitialize(argument);
cdoOperatorAdd("ymonrange", func_range, 0, NULL);
cdoOperatorAdd("ymonmin", func_min, 0, NULL);
cdoOperatorAdd("ymonmax", func_max, 0, NULL);
cdoOperatorAdd("ymonsum", func_sum, 0, NULL);
......@@ -88,6 +90,7 @@ void *Ymonstat(void *argument)
int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID);
bool lrange = operfunc == func_range;
bool lmean = operfunc == func_mean || operfunc == func_avg;
bool lstd = operfunc == func_std || operfunc == func_std1;
bool lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
......@@ -98,7 +101,7 @@ void *Ymonstat(void *argument)
vars1[month] = NULL;
vars2[month] = NULL;
samp1[month] = NULL;
nsets[month] = 0;
month_nsets[month] = 0;
}
int streamID1 = streamOpenRead(cdoStreamName(0));
......@@ -145,7 +148,7 @@ void *Ymonstat(void *argument)
mon[nmon++] = month;
vars1[month] = field_malloc(vlistID1, FIELD_PTR);
samp1[month] = field_malloc(vlistID1, FIELD_NONE);
if ( lvarstd )
if ( lvarstd || lrange )
vars2[month] = field_malloc(vlistID1, FIELD_PTR);
}
......@@ -159,23 +162,31 @@ void *Ymonstat(void *argument)
recinfo[recID].levelID = 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;
int nsets = month_nsets[month];
int gridsize = pvars1->size;
if ( nsets[month] == 0 )
if ( nsets == 0 )
{
streamReadRecord(streamID1, pvars1->ptr, &nmiss);
pvars1->nmiss = (size_t) nmiss;
if ( lrange )
{
pvars2->nmiss = pvars1->nmiss;
for ( int i = 0; i < gridsize; i++ )
pvars2->ptr[i] = pvars1->ptr[i];
}
if ( nmiss > 0 || samp1[month][varID][levelID].ptr )
if ( nmiss > 0 || psamp1->ptr )
{
if ( samp1[month][varID][levelID].ptr == NULL )
samp1[month][varID][levelID].ptr = (double*) Malloc(gridsize*sizeof(double));
if ( psamp1->ptr == NULL )
psamp1->ptr = (double*) Malloc(gridsize*sizeof(double));
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
......@@ -185,18 +196,18 @@ void *Ymonstat(void *argument)
field.grid = pvars1->grid;
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++ )
samp1[month][varID][levelID].ptr[i] = nsets[month];
psamp1->ptr[i] = nsets;
}
for ( int i = 0; i < gridsize; i++ )
if ( !DBL_IS_EQUAL(field.ptr[i], pvars1->missval) )
samp1[month][varID][levelID].ptr[i]++;
psamp1->ptr[i]++;
}
if ( lvarstd )
......@@ -204,6 +215,11 @@ void *Ymonstat(void *argument)
farsumq(pvars2, field);
farsum(pvars1, field);
}
else if ( lrange )
{
farmin(pvars2, field);
farmax(pvars1, field);
}
else
{
farfun(pvars1, field, operfunc);
......@@ -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++ )
{
int varID = recinfo[recID].varID;
......@@ -224,14 +240,14 @@ void *Ymonstat(void *argument)
farmoq(pvars2, *pvars1);
}
nsets[month]++;
month_nsets[month]++;
tsID++;
}
if ( nmon == 12 )
{
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;
}
......@@ -240,7 +256,7 @@ void *Ymonstat(void *argument)
nmon = 0;
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];
else
nmon++;
......@@ -257,41 +273,40 @@ void *Ymonstat(void *argument)
for ( int i = 0; i < nmon; 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 )
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 ( 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]);
if ( lmean )
{
if ( psamp1->ptr ) fardiv(pvars1, *psamp1);
else farcdiv(pvars1, (double)nsets);
}
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;
if ( samp1[month][varID][levelID].ptr == NULL )
if ( psamp1->ptr )
{
if ( lstd ) farcstd(pvars1, *pvars2, nsets[month], divisor);
else farcvar(pvars1, *pvars2, nsets[month], divisor);
if ( lstd ) farstd(pvars1, *pvars2, *psamp1, divisor);
else farvar(pvars1, *pvars2, *psamp1, divisor);
}
else
{
if ( lstd ) farstd(pvars1, *pvars2, samp1[month][varID][levelID], divisor);
else farvar(pvars1, *pvars2, samp1[month][varID][levelID], divisor);
if ( lstd ) farcstd(pvars1, *pvars2, nsets, divisor);
else farcvar(pvars1, *pvars2, nsets, divisor);
}
}
else if ( lrange )
{
farsub(pvars1, *pvars2);
}
}
......
......@@ -507,7 +507,7 @@ void *Samplegrid(void *argument); // "samplegrid", "subgrid"
#define YmonarithOperators {"ymonadd", "ymonsub", "ymonmul", "ymondiv"}
#define YseasarithOperators {"yseasadd", "yseassub", "yseasmul", "yseasdiv"}
#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 YseasstatOperators {"yseasrange", "yseasmin", "yseasmax", "yseassum", "yseasmean", "yseasavg", "yseasstd", "yseasstd1", "yseasvar", "yseasvar1"}
#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
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
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
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
......
......@@ -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
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
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
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
......
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