Commit 09b5fcaf authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added module Ydayarith

parent df3a14b8
......@@ -415,6 +415,7 @@ src/Wct.c -text
src/Wind.c -text
src/Writegrid.c -text
src/Writerandom.c -text
src/Ydayarith.c -text
src/Ydaypctl.c -text
src/Ydaystat.c -text
src/Ydrunpctl.c -text
......
......@@ -145,6 +145,7 @@ cdo_SOURCES = Arith.c \
Writegrid.c \
Writerandom.c \
Yhourstat.c \
Ydayarith.c \
Ydaypctl.c \
Ydaystat.c \
Ydrunpctl.c \
......
......@@ -112,30 +112,30 @@ am_cdo_OBJECTS = Arith.$(OBJEXT) Arithc.$(OBJEXT) Arithdays.$(OBJEXT) \
Vardup.$(OBJEXT) Vargen.$(OBJEXT) Varrms.$(OBJEXT) \
Vertint.$(OBJEXT) Vertstat.$(OBJEXT) Vertwind.$(OBJEXT) \
Wind.$(OBJEXT) Writegrid.$(OBJEXT) Writerandom.$(OBJEXT) \
Yhourstat.$(OBJEXT) Ydaypctl.$(OBJEXT) Ydaystat.$(OBJEXT) \
Ydrunpctl.$(OBJEXT) Ydrunstat.$(OBJEXT) Ymonarith.$(OBJEXT) \
Ymonpctl.$(OBJEXT) Ymonstat.$(OBJEXT) Yseaspctl.$(OBJEXT) \
Yseasstat.$(OBJEXT) Zonstat.$(OBJEXT) cdilib.$(OBJEXT) \
commandline.$(OBJEXT) exception.$(OBJEXT) expr_yacc.$(OBJEXT) \
expr_lex.$(OBJEXT) expr.$(OBJEXT) cdo.$(OBJEXT) \
cdo_pthread.$(OBJEXT) cdo_vlist.$(OBJEXT) field.$(OBJEXT) \
fieldc.$(OBJEXT) field2.$(OBJEXT) fieldmer.$(OBJEXT) \
fieldzon.$(OBJEXT) fieldmem.$(OBJEXT) gradsdeslib.$(OBJEXT) \
grid.$(OBJEXT) grid_gme.$(OBJEXT) grid_lcc.$(OBJEXT) \
grid_rot.$(OBJEXT) griddes.$(OBJEXT) griddes_nc.$(OBJEXT) \
griddes_h5.$(OBJEXT) hetaeta.$(OBJEXT) history.$(OBJEXT) \
institution.$(OBJEXT) interpol.$(OBJEXT) job.$(OBJEXT) \
modules.$(OBJEXT) namelist.$(OBJEXT) normal.$(OBJEXT) \
pipe.$(OBJEXT) process.$(OBJEXT) remaplib.$(OBJEXT) \
timer.$(OBJEXT) realtime.$(OBJEXT) pstream.$(OBJEXT) \
table.$(OBJEXT) userlog.$(OBJEXT) util.$(OBJEXT) \
legendre.$(OBJEXT) fouriertrans.$(OBJEXT) specspace.$(OBJEXT) \
readline.$(OBJEXT) juldate.$(OBJEXT) vinterp.$(OBJEXT) \
zaxis.$(OBJEXT) par_io.$(OBJEXT) pthread_debug.$(OBJEXT) \
color.$(OBJEXT) list.$(OBJEXT) percentiles.$(OBJEXT) \
nth_element.$(OBJEXT) ecacore.$(OBJEXT) ecautil.$(OBJEXT) \
EcaIndices.$(OBJEXT) Hi.$(OBJEXT) Wct.$(OBJEXT) \
statistic.$(OBJEXT)
Yhourstat.$(OBJEXT) Ydayarith.$(OBJEXT) Ydaypctl.$(OBJEXT) \
Ydaystat.$(OBJEXT) Ydrunpctl.$(OBJEXT) Ydrunstat.$(OBJEXT) \
Ymonarith.$(OBJEXT) Ymonpctl.$(OBJEXT) Ymonstat.$(OBJEXT) \
Yseaspctl.$(OBJEXT) Yseasstat.$(OBJEXT) Zonstat.$(OBJEXT) \
cdilib.$(OBJEXT) commandline.$(OBJEXT) exception.$(OBJEXT) \
expr_yacc.$(OBJEXT) expr_lex.$(OBJEXT) expr.$(OBJEXT) \
cdo.$(OBJEXT) cdo_pthread.$(OBJEXT) cdo_vlist.$(OBJEXT) \
field.$(OBJEXT) fieldc.$(OBJEXT) field2.$(OBJEXT) \
fieldmer.$(OBJEXT) fieldzon.$(OBJEXT) fieldmem.$(OBJEXT) \
gradsdeslib.$(OBJEXT) grid.$(OBJEXT) grid_gme.$(OBJEXT) \
grid_lcc.$(OBJEXT) grid_rot.$(OBJEXT) griddes.$(OBJEXT) \
griddes_nc.$(OBJEXT) griddes_h5.$(OBJEXT) hetaeta.$(OBJEXT) \
history.$(OBJEXT) institution.$(OBJEXT) interpol.$(OBJEXT) \
job.$(OBJEXT) modules.$(OBJEXT) namelist.$(OBJEXT) \
normal.$(OBJEXT) pipe.$(OBJEXT) process.$(OBJEXT) \
remaplib.$(OBJEXT) timer.$(OBJEXT) realtime.$(OBJEXT) \
pstream.$(OBJEXT) table.$(OBJEXT) userlog.$(OBJEXT) \
util.$(OBJEXT) legendre.$(OBJEXT) fouriertrans.$(OBJEXT) \
specspace.$(OBJEXT) readline.$(OBJEXT) juldate.$(OBJEXT) \
vinterp.$(OBJEXT) zaxis.$(OBJEXT) par_io.$(OBJEXT) \
pthread_debug.$(OBJEXT) color.$(OBJEXT) list.$(OBJEXT) \
percentiles.$(OBJEXT) nth_element.$(OBJEXT) ecacore.$(OBJEXT) \
ecautil.$(OBJEXT) EcaIndices.$(OBJEXT) Hi.$(OBJEXT) \
Wct.$(OBJEXT) statistic.$(OBJEXT)
cdo_OBJECTS = $(am_cdo_OBJECTS)
cdo_DEPENDENCIES =
am_cdotest_OBJECTS = cdilib.$(OBJEXT) cdotest.$(OBJEXT)
......@@ -422,6 +422,7 @@ cdo_SOURCES = Arith.c \
Writegrid.c \
Writerandom.c \
Yhourstat.c \
Ydayarith.c \
Ydaypctl.c \
Ydaystat.c \
Ydrunpctl.c \
......@@ -793,6 +794,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Wind.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Writegrid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Writerandom.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Ydayarith.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Ydaypctl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Ydaystat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Ydrunpctl.Po@am__quote@
......
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2010 Uwe Schulzweida, Uwe.Schulzweida@zmaw.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:
Ydayarith ydayadd Add multi-year daily time series
Ydayarith ydaysub Subtract multi-year daily time series
Ydayarith ydaymul Multiply multi-year daily time series
Ydayarith ydaydiv Divide multi-year daily time series
*/
#include "cdi.h"
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
#define MAX_DAY 1232
void *Ydayarith(void *argument)
{
static char func[] = "Ydayarith";
int operatorID;
int operfunc;
int streamID1, streamID2, streamID3;
int gridsize;
int nrecs, nvars, nlev, recID;
int tsID;
int varID, levelID;
int offset;
int vlistID1, vlistID2, vlistID3;
int taxisID1, taxisID2, taxisID3;
int vdate, vtime, year, mon, day;
field_t field1, field2;
int **varnmiss2[MAX_DAY];
double **vardata2[MAX_DAY];
cdoInitialize(argument);
cdoOperatorAdd("ydayadd", func_add, 0, NULL);
cdoOperatorAdd("ydaysub", func_sub, 0, NULL);
cdoOperatorAdd("ydaymul", func_mul, 0, NULL);
cdoOperatorAdd("ydaydiv", func_div, 0, NULL);
operatorID = cdoOperatorID();
operfunc = cdoOperatorFunc(operatorID);
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
streamID2 = streamOpenRead(cdoStreamName(1));
if ( streamID2 < 0 ) cdiError(streamID2, "Open failed on %s", cdoStreamName(1));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = streamInqVlist(streamID2);
vlistID3 = vlistDuplicate(vlistID1);
vlistCompare(vlistID1, vlistID2, CMP_SFT);
gridsize = vlistGridsizeMax(vlistID1);
field1.ptr = (double *) malloc(gridsize*sizeof(double));
field2.ptr = (double *) malloc(gridsize*sizeof(double));
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = vlistInqTaxis(vlistID2);
taxisID3 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID3, taxisID3);
streamID3 = streamOpenWrite(cdoStreamName(2), cdoFiletype());
if ( streamID3 < 0 ) cdiError(streamID3, "Open failed on %s", cdoStreamName(2));
streamDefVlist(streamID3, vlistID3);
nvars = vlistNvars(vlistID2);
for ( day = 0; day < MAX_DAY ; day++ ) vardata2[day] = NULL;
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID2, tsID)) )
{
vdate = taxisInqVdate(taxisID2);
cdiDecodeDate(vdate, &year, &mon, &day);
day += mon*100;
if ( day < 0 || day >= MAX_DAY ) cdoAbort("Day %d out of range!", day);
if ( vardata2[day] != NULL ) cdoAbort("Day %d already allocatd!", day);
vardata2[day] = (double **) malloc(nvars*sizeof(double *));
varnmiss2[day] = (int **) malloc(nvars*sizeof(int *));
for ( varID = 0; varID < nvars; varID++ )
{
gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
nlev = zaxisInqSize(vlistInqVarZaxis(vlistID2, varID));
vardata2[day][varID] = (double *) malloc(nlev*gridsize*sizeof(double));
varnmiss2[day][varID] = (int *) malloc(nlev*sizeof(int));
}
for ( recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID2, &varID, &levelID);
gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
offset = gridsize*levelID;
streamReadRecord(streamID2, vardata2[day][varID]+offset, &field2.nmiss);
varnmiss2[day][varID][levelID] = field2.nmiss;
}
tsID++;
}
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
vdate = taxisInqVdate(taxisID1);
vtime = taxisInqVtime(taxisID1);
cdiDecodeDate(vdate, &year, &mon, &day);
day += mon*100;
if ( day < 0 || day >= MAX_DAY ) cdoAbort("Day %d out of range!", day);
taxisDefVdate(taxisID3, vdate);
taxisDefVtime(taxisID3, vtime);
streamDefTimestep(streamID3, tsID);
for ( recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
streamReadRecord(streamID1, field1.ptr, &field1.nmiss);
gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
offset = gridsize*levelID;
if ( vardata2[day] == NULL ) cdoAbort("Day %d not found!", day);
memcpy(field2.ptr, vardata2[day][varID]+offset, gridsize*sizeof(double));
field2.nmiss = varnmiss2[day][varID][levelID];
field1.grid = vlistInqVarGrid(vlistID1, varID);
field1.missval = vlistInqVarMissval(vlistID1, varID);
field2.grid = vlistInqVarGrid(vlistID2, varID);
field2.missval = vlistInqVarMissval(vlistID2, varID);
farfun(&field1, field2, operfunc);
streamDefRecord(streamID3, varID, levelID);
streamWriteRecord(streamID3, field1.ptr, field1.nmiss);
}
tsID++;
}
streamClose(streamID3);
streamClose(streamID2);
streamClose(streamID1);
for ( day = 0; day < MAX_DAY ; day++ )
if ( vardata2[day] )
{
for ( varID = 0; varID < nvars; varID++ )
{
free(vardata2[day][varID]);
free(varnmiss2[day][varID]);
}
free(vardata2[day]);
free(varnmiss2[day]);
}
if ( field1.ptr ) free(field1.ptr);
if ( field2.ptr ) free(field2.ptr);
cdoFinish();
return (0);
}
......@@ -45,7 +45,7 @@ void *Ymonarith(void *argument)
int offset;
int vlistID1, vlistID2, vlistID3;
int taxisID1, taxisID2, taxisID3;
int vdate, vtime, mon;
int vdate, vtime, year, mon, day;
field_t field1, field2;
int **varnmiss2[MAX_MON];
double **vardata2[MAX_MON];
......@@ -95,7 +95,7 @@ void *Ymonarith(void *argument)
{
vdate = taxisInqVdate(taxisID2);
mon = (vdate - (vdate/10000)*10000) / 100;
cdiDecodeDate(vdate, &year, &mon, &day);
if ( mon < 0 || mon >= MAX_MON ) cdoAbort("Month %d out of range!", mon);
if ( vardata2[mon] != NULL ) cdoAbort("Month %d already allocatd!", mon);
......@@ -132,7 +132,7 @@ void *Ymonarith(void *argument)
vdate = taxisInqVdate(taxisID1);
vtime = taxisInqVtime(taxisID1);
mon = (vdate - (vdate/10000)*10000) / 100;
cdiDecodeDate(vdate, &year, &mon, &day);
if ( mon < 0 || mon >= MAX_MON ) cdoAbort("Month %d out of range!", mon);
taxisDefVdate(taxisID3, vdate);
......@@ -147,6 +147,7 @@ void *Ymonarith(void *argument)
gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
offset = gridsize*levelID;
if ( vardata2[mon] == NULL ) cdoAbort("Month %d not found!", mon);
memcpy(field2.ptr, vardata2[mon][varID]+offset, gridsize*sizeof(double));
field2.nmiss = varnmiss2[mon][varID][levelID];
......
......@@ -182,6 +182,7 @@ void *Wind(void *argument);
void *Writegrid(void *argument);
void *Writerandom(void *argument);
void *Yhourstat(void *argument);
void *Ydayarith(void *argument);
void *Ydaypctl(void *argument);
void *Ydaystat(void *argument);
void *Ydrunpctl(void *argument);
......@@ -411,6 +412,7 @@ void *Wct(void *argument);
#define WritegridOperators {"writegrid"}
#define WriterandomOperators {"writerandom"}
#define YhourstatOperators {"yhourmin", "yhourmax", "yhoursum", "yhourmean", "yhouravg", "yhourvar", "yhourstd"}
#define YdayarithOperators {"ydayadd", "ydaysub", "ydaymul", "ydaydiv"}
#define YdaypctlOperators {"ydaypctl"}
#define YdaystatOperators {"ydaymin", "ydaymax", "ydaysum", "ydaymean", "ydayavg", "ydayvar", "ydaystd"}
#define YdrunpctlOperators {"ydrunpctl"}
......@@ -635,6 +637,7 @@ static modules_t Modules[] =
{ Writegrid, NULL, WritegridOperators, CDI_REAL, 1, 1 }, /* no cdi output */
{ Writerandom, NULL, WriterandomOperators, CDI_REAL, 1, 1 },
{ Yhourstat, YhourstatHelp, YhourstatOperators, CDI_REAL, 1, 1 },
{ Ydayarith, NULL, YdayarithOperators, CDI_REAL, 2, 1 },
{ Ydaypctl, YdaypctlHelp, YdaypctlOperators, CDI_REAL, 3, 1 },
{ Ydaystat, YdaystatHelp, YdaystatOperators, CDI_REAL, 1, 1 },
{ Ydrunpctl, YdrunpctlHelp, YdrunpctlOperators, 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