Commit 1b6b46ab authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added operator complextorect

parent f28731dd
......@@ -231,6 +231,7 @@ src/Change.c -text
src/Change_e5slm.c -text
src/Comp.c -text
src/Compc.c -text
src/Complextorect.c -text
src/Cond.c -text
src/Cond2.c -text
src/Condc.c -text
......
/*
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.
*/
#include "cdi.h"
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
void *Complextorect(void *argument)
{
const char func[] = "Complextorect";
// int COMPLEXTORECT;
int operatorID;
int streamID1, streamID2, streamID3;
int tsID, tsID2, nrecs;
int recID, varID, levelID;
int vlistID1, vlistID2, vlistID3;
int taxisID1, taxisID2, taxisID3;
int i, gridsize;
int datatype;
int nmiss, nvars;
double *array1 = NULL, *array2 = NULL, *array3 = NULL;
cdoInitialize(argument);
// COMPLEXTORECT = cdoOperatorAdd("complextorect", 0, 0, NULL);
// operatorID = cdoOperatorID();
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = vlistDuplicate(vlistID1);
vlistID3 = vlistDuplicate(vlistID1);
nvars = vlistNvars(vlistID2);
for ( varID = 0; varID < nvars; ++varID )
{
datatype = vlistInqVarDatatype(vlistID2, varID);
if ( datatype == DATATYPE_CPX64 )
datatype = DATATYPE_FLT64;
else
datatype = DATATYPE_FLT32;
vlistDefVarDatatype(vlistID2, varID, datatype);
vlistDefVarDatatype(vlistID3, varID, datatype);
}
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
taxisID3 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
vlistDefTaxis(vlistID3, taxisID3);
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
if ( streamID2 < 0 ) cdiError(streamID2, "Open failed on %s", cdoStreamName(1));
streamDefVlist(streamID2, vlistID2);
streamID3 = streamOpenWrite(cdoStreamName(2), cdoFiletype());
if ( streamID3 < 0 ) cdiError(streamID2, "Open failed on %s", cdoStreamName(2));
streamDefVlist(streamID3, vlistID3);
gridsize = vlistGridsizeMax(vlistID1);
array1 = (double *) malloc(2*gridsize*sizeof(double));
array2 = (double *) malloc(gridsize*sizeof(double));
array3 = (double *) malloc(gridsize*sizeof(double));
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
taxisCopyTimestep(taxisID3, taxisID1);
streamDefTimestep(streamID2, tsID);
streamDefTimestep(streamID3, tsID);
for ( recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
streamDefRecord(streamID2, varID, levelID);
streamDefRecord(streamID3, varID, levelID);
gridsize = gridInqSize(vlistInqVarGrid(vlistID1, varID));
streamReadRecord(streamID1, array1, &nmiss);
for ( i = 0; i < gridsize; ++i )
{
array2[i] = array1[2*i];
array3[i] = array1[2*i+1];
}
streamWriteRecord(streamID2, array2, nmiss);
streamWriteRecord(streamID3, array3, nmiss);
}
tsID++;
}
streamClose(streamID3);
streamClose(streamID2);
streamClose(streamID1);
if ( array1 ) free(array1);
if ( array2 ) free(array2);
if ( array3 ) free(array3);
vlistDestroy(vlistID2);
vlistDestroy(vlistID3);
cdoFinish();
return (NULL);
}
......@@ -17,6 +17,7 @@ cdo_SOURCES = Arith.c \
Cond.c \
Cond2.c \
Condc.c \
Complextorect.c \
Copy.c \
Del29feb.c \
Detrend.c \
......
......@@ -51,14 +51,14 @@ am_cdo_OBJECTS = Arith.$(OBJEXT) Arithc.$(OBJEXT) Arithdays.$(OBJEXT) \
Arithlat.$(OBJEXT) Cat.$(OBJEXT) CDItest.$(OBJEXT) \
Change.$(OBJEXT) Change_e5slm.$(OBJEXT) Comp.$(OBJEXT) \
Compc.$(OBJEXT) Cond.$(OBJEXT) Cond2.$(OBJEXT) Condc.$(OBJEXT) \
Copy.$(OBJEXT) Del29feb.$(OBJEXT) Detrend.$(OBJEXT) \
Diff.$(OBJEXT) Echam5ini.$(OBJEXT) Enlarge.$(OBJEXT) \
Enlargegrid.$(OBJEXT) Ensstat.$(OBJEXT) Eofcoeff.$(OBJEXT) \
Exprf.$(OBJEXT) Filedes.$(OBJEXT) Fillmiss.$(OBJEXT) \
Filter.$(OBJEXT) Fldrms.$(OBJEXT) Fldstat.$(OBJEXT) \
Fourier.$(OBJEXT) Gengrid.$(OBJEXT) Gradsdes.$(OBJEXT) \
Gridboxstat.$(OBJEXT) Gridcell.$(OBJEXT) Harmonic.$(OBJEXT) \
Histogram.$(OBJEXT) Importamsr.$(OBJEXT) \
Complextorect.$(OBJEXT) Copy.$(OBJEXT) Del29feb.$(OBJEXT) \
Detrend.$(OBJEXT) Diff.$(OBJEXT) Echam5ini.$(OBJEXT) \
Enlarge.$(OBJEXT) Enlargegrid.$(OBJEXT) Ensstat.$(OBJEXT) \
Eofcoeff.$(OBJEXT) Exprf.$(OBJEXT) Filedes.$(OBJEXT) \
Fillmiss.$(OBJEXT) Filter.$(OBJEXT) Fldrms.$(OBJEXT) \
Fldstat.$(OBJEXT) Fourier.$(OBJEXT) Gengrid.$(OBJEXT) \
Gradsdes.$(OBJEXT) Gridboxstat.$(OBJEXT) Gridcell.$(OBJEXT) \
Harmonic.$(OBJEXT) Histogram.$(OBJEXT) Importamsr.$(OBJEXT) \
Importbinary.$(OBJEXT) Importcmsaf.$(OBJEXT) \
Importobs.$(OBJEXT) Info.$(OBJEXT) Input.$(OBJEXT) \
Intgrid.$(OBJEXT) Intgridtraj.$(OBJEXT) Intlevel.$(OBJEXT) \
......@@ -245,6 +245,7 @@ cdo_SOURCES = Arith.c \
Cond.c \
Cond2.c \
Condc.c \
Complextorect.c \
Copy.c \
Del29feb.c \
Detrend.c \
......@@ -583,6 +584,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Change_e5slm.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Comp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Compc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Complextorect.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Cond.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Cond2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Condc.Po@am__quote@
......
......@@ -2,7 +2,7 @@
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2009 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
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
......@@ -51,6 +51,7 @@ void *Compc(void *argument);
void *Cond(void *argument);
void *Cond2(void *argument);
void *Condc(void *argument);
void *Complextorect(void *argument);
void *Copy(void *argument);
void *Del29feb(void *argument);
void *Detrend(void *argument);
......@@ -244,6 +245,7 @@ void *Wct(void *argument);
#define CondOperators {"ifthen", "ifnotthen"}
#define Cond2Operators {"ifthenelse"}
#define CondcOperators {"ifthenc", "ifnotthenc"}
#define ComplextorectOperators {"complextorect"}
#define CopyOperators {"copy", "selall"}
#define Del29febOperators {"del29feb"}
#define DetrendOperators {"detrend"}
......@@ -473,6 +475,7 @@ static modules_t Modules[] =
{ Cond, CondHelp, CondOperators, CDI_REAL, 2, 1 },
{ Cond2, Cond2Help, Cond2Operators, CDI_REAL, 3, 1 },
{ Condc, CondcHelp, CondcOperators, CDI_REAL, 1, 1 },
{ Complextorect, NULL, ComplextorectOperators, CDI_COMP, 1, 2 },
{ Copy, CopyHelp, CopyOperators, CDI_REAL, -1, 1 },
{ Del29feb, NULL, Del29febOperators, CDI_REAL, 1, 1 },
{ Detrend, DetrendHelp, DetrendOperators, CDI_REAL, 1, 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