Commit 6cbd7793 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

New operator timcumsum: Cumulative sum over time.

parent 8ec5a435
2016-11-24 Uwe Schulzweida
* using CDI library version 1.8.0rc5
* Version 1.8.0rc5 release
2016-11-10 Uwe Schulzweida
* New operator timcumsum: Cumulative sum over time.
2016-11-04 Uwe Schulzweida
* using CDI library version 1.8.0rc4
......
......@@ -332,6 +332,7 @@ cdo_SOURCES += Adisit.c \
Test.c \
Tests.c \
Timcount.c \
Timcumsum.c \
Timpctl.c \
Timselpctl.c \
Timselstat.c \
......
......@@ -230,12 +230,12 @@ am_cdo_OBJECTS = cdo-cdo.$(OBJEXT) cdo-Adisit.$(OBJEXT) \
cdo-Splityear.$(OBJEXT) cdo-Subtrend.$(OBJEXT) \
cdo-Tee.$(OBJEXT) cdo-Templates.$(OBJEXT) cdo-Test.$(OBJEXT) \
cdo-Tests.$(OBJEXT) cdo-Timcount.$(OBJEXT) \
cdo-Timpctl.$(OBJEXT) cdo-Timselpctl.$(OBJEXT) \
cdo-Timselstat.$(OBJEXT) cdo-Timsort.$(OBJEXT) \
cdo-Timstat.$(OBJEXT) cdo-Timstat2.$(OBJEXT) \
cdo-Timstat3.$(OBJEXT) cdo-Tinfo.$(OBJEXT) \
cdo-Tocomplex.$(OBJEXT) cdo-Transpose.$(OBJEXT) \
cdo-Trend.$(OBJEXT) cdo-Trms.$(OBJEXT) \
cdo-Timcumsum.$(OBJEXT) cdo-Timpctl.$(OBJEXT) \
cdo-Timselpctl.$(OBJEXT) cdo-Timselstat.$(OBJEXT) \
cdo-Timsort.$(OBJEXT) cdo-Timstat.$(OBJEXT) \
cdo-Timstat2.$(OBJEXT) cdo-Timstat3.$(OBJEXT) \
cdo-Tinfo.$(OBJEXT) cdo-Tocomplex.$(OBJEXT) \
cdo-Transpose.$(OBJEXT) cdo-Trend.$(OBJEXT) cdo-Trms.$(OBJEXT) \
cdo-Tstepcount.$(OBJEXT) cdo-Vargen.$(OBJEXT) \
cdo-Varrms.$(OBJEXT) cdo-Vertintml.$(OBJEXT) \
cdo-Vertintap.$(OBJEXT) cdo-Vertstat.$(OBJEXT) \
......@@ -579,8 +579,8 @@ cdo_SOURCES = cdo.c Adisit.c Afterburner.c Arith.c Arithc.c \
Smooth.c Sort.c Sorttimestamp.c Specinfo.c Spectral.c \
Spectrum.c Split.c Splitrec.c Splitsel.c Splittime.c \
Splityear.c Subtrend.c Tee.c Templates.c Test.c Tests.c \
Timcount.c Timpctl.c Timselpctl.c Timselstat.c Timsort.c \
Timstat.c Timstat2.c Timstat3.c Tinfo.c Tocomplex.c \
Timcount.c Timcumsum.c Timpctl.c Timselpctl.c Timselstat.c \
Timsort.c Timstat.c Timstat2.c Timstat3.c Tinfo.c Tocomplex.c \
Transpose.c Trend.c Trms.c Tstepcount.c Vargen.c Varrms.c \
Vertintml.c Vertintap.c Vertstat.c Vertcum.c Vertwind.c \
Verifygrid.c Wct.c Wind.c Writegrid.c Writerandom.c XTimstat.c \
......@@ -948,6 +948,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Tests.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Timcount.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Timcumsum.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Timpctl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Timselpctl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Timselstat.Po@am__quote@
......@@ -3893,6 +3894,20 @@ cdo-Timcount.obj: Timcount.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-Timcount.obj `if test -f 'Timcount.c'; then $(CYGPATH_W) 'Timcount.c'; else $(CYGPATH_W) '$(srcdir)/Timcount.c'; fi`
cdo-Timcumsum.o: Timcumsum.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-Timcumsum.o -MD -MP -MF $(DEPDIR)/cdo-Timcumsum.Tpo -c -o cdo-Timcumsum.o `test -f 'Timcumsum.c' || echo '$(srcdir)/'`Timcumsum.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-Timcumsum.Tpo $(DEPDIR)/cdo-Timcumsum.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='Timcumsum.c' object='cdo-Timcumsum.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-Timcumsum.o `test -f 'Timcumsum.c' || echo '$(srcdir)/'`Timcumsum.c
cdo-Timcumsum.obj: Timcumsum.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-Timcumsum.obj -MD -MP -MF $(DEPDIR)/cdo-Timcumsum.Tpo -c -o cdo-Timcumsum.obj `if test -f 'Timcumsum.c'; then $(CYGPATH_W) 'Timcumsum.c'; else $(CYGPATH_W) '$(srcdir)/Timcumsum.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-Timcumsum.Tpo $(DEPDIR)/cdo-Timcumsum.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='Timcumsum.c' object='cdo-Timcumsum.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-Timcumsum.obj `if test -f 'Timcumsum.c'; then $(CYGPATH_W) 'Timcumsum.c'; else $(CYGPATH_W) '$(srcdir)/Timcumsum.c'; fi`
cdo-Timpctl.o: Timpctl.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-Timpctl.o -MD -MP -MF $(DEPDIR)/cdo-Timpctl.Tpo -c -o cdo-Timpctl.o `test -f 'Timpctl.c' || echo '$(srcdir)/'`Timpctl.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/cdo-Timpctl.Tpo $(DEPDIR)/cdo-Timpctl.Po
......
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2016 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/*
This module contains the following operators:
Timcumsum timcumsum Cumulative sum over time
*/
#include <cdi.h>
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
void *Timcumsum(void *argument)
{
int nrecs;
int varID, levelID;
int nmiss;
cdoInitialize(argument);
int streamID1 = streamOpenRead(cdoStreamName(0));
int vlistID1 = streamInqVlist(streamID1);
int vlistID2 = vlistDuplicate(vlistID1);
int taxisID1 = vlistInqTaxis(vlistID1);
int taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
int streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
streamDefVlist(streamID2, vlistID2);
int gridsize = vlistGridsizeMax(vlistID1);
if ( vlistNumber(vlistID1) != CDI_REAL ) gridsize *= 2;
field_t field;
field_init(&field);
field.ptr = (double*) Malloc(gridsize*sizeof(double));
field_t **vars1 = field_malloc(vlistID1, FIELD_PTR);
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID);
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
field_t *pvar1 = &vars1[varID][levelID];
gridsize = gridInqSize(pvar1->grid);
if ( tsID == 0 )
{
streamReadRecord(streamID1, pvar1->ptr, &nmiss);
// pvar1->nmiss = (size_t)nmiss;
if ( nmiss )
for ( int i = 0; i < gridsize; ++i )
if ( DBL_IS_EQUAL(pvar1->ptr[i], pvar1->missval) ) pvar1->ptr[i] = 0;
}
else
{
streamReadRecord(streamID1, field.ptr, &nmiss);
// field.nmiss = (size_t)nmiss;
field.size = gridsize;
field.grid = pvar1->grid;
field.missval = pvar1->missval;
if ( nmiss )
for ( int i = 0; i < gridsize; ++i )
if ( DBL_IS_EQUAL(field.ptr[i], pvar1->missval) ) field.ptr[i] = 0;
farfun(pvar1, field, func_sum);
}
streamDefRecord(streamID2, varID, levelID);
streamWriteRecord(streamID2, pvar1->ptr, (int)pvar1->nmiss);
}
tsID++;
}
field_free(vars1, vlistID1);
streamClose(streamID2);
streamClose(streamID1);
if ( field.ptr ) Free(field.ptr);
cdoFinish();
return 0;
}
......@@ -188,6 +188,7 @@ void *Testdata(void *argument);
void *Tests(void *argument);
void *Timsort(void *argument);
void *Timcount(void *argument);
void *Timcumsum(void *argument);
void *Timpctl(void *argument);
void *Timselpctl(void *argument);
void *Timselstat(void *argument);
......@@ -453,6 +454,7 @@ void *Maggraph(void *argument);
#define MoncountOperators {"moncount"}
#define DaycountOperators {"daycount"}
#define HourcountOperators {"hourcount"}
#define TimcumsumOperators {"timcumsum"}
#define TimpctlOperators {"timpctl"}
#define YearpctlOperators {"yearpctl"}
#define MonpctlOperators {"monpctl"}
......@@ -732,6 +734,7 @@ static modules_t Modules[] =
{ Timcount, NULL, MoncountOperators, 1, CDI_BOTH, 1, 1 },
{ Timcount, NULL, DaycountOperators, 1, CDI_BOTH, 1, 1 },
{ Timcount, NULL, HourcountOperators, 1, CDI_BOTH, 1, 1 },
{ Timcumsum, NULL, TimcumsumOperators, 1, CDI_BOTH, 1, 1 },
{ Timpctl, TimpctlHelp, TimpctlOperators, 1, CDI_REAL, 3, 1 },
{ Timpctl, YearpctlHelp, YearpctlOperators, 1, CDI_REAL, 3, 1 },
{ Timpctl, MonpctlHelp, MonpctlOperators, 1, CDI_REAL, 3, 1 },
......
Supports Markdown
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