Commit 10f57aa4 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

New operator: selltype, setltype, chltype, showltype

parent 7c1f0c78
......@@ -195,6 +195,7 @@ src/Runstat.c -text
src/Seasstat.c -text
src/Selbox.c -text
src/Select.c -text
src/Seloperator.c -text
src/Selrec.c -text
src/Selstat.c -text
src/Seltime.c -text
......@@ -204,6 +205,7 @@ src/Setgatt.c -text
src/Setgrid.c -text
src/Sethalo.c -text
src/Setmiss.c -text
src/Setrcaname.c -text
src/Settime.c -text
src/Setzaxis.c -text
src/Showinfo.c -text
......
2006-08-?? Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using CDI library version 1.0.1
* New operator: setrcaname, seloperator for RCA GRIB datasets [Frida Brantvall]
* New operator: selltype, setltype, chltype, showltype [together with Frida Brantvall]
* New operator: setpartabv
* add new parameter table format
* fix problems on cygwin (report: Mark Hadfield)
* merge: move vlistDestroy after streamClose (report: Matthias Cuntz)
* gradsdes: fix bug for only one record without time (report: Angelika Heil)
* fix problems on cygwin [report: Mark Hadfield]
* merge: move vlistDestroy after streamClose [report: Matthias Cuntz]
* gradsdes: fix bug for only one record without time [report: Angelika Heil]
* namelist update
* New module: Setbox (Etienne Tourigny)
* history format changed to nco (Etienne Tourigny)
* New module: Setbox [Etienne Tourigny)
* history format changed to nco [Etienne Tourigny)
* process: set MAX_ARGS from 1024 to 8192
* Version 1.0.1 released
......
......@@ -23,6 +23,7 @@
Change chlevel Change level
Change chlevelc Change level of one code
Change chlevelv Change level of one variable
Change chltype Change GRIB level type
*/
......@@ -40,7 +41,7 @@
void *Change(void *argument)
{
static char func[] = "Change";
int CHCODE, CHVAR, CHLEVEL, CHLEVELC, CHLEVELV;
int CHCODE, CHVAR, CHLEVEL, CHLEVELC, CHLEVELV, CHLTYPE;
int operatorID;
int streamID1, streamID2 = CDI_UNDEFID;
int nrecs, nvars;
......@@ -56,8 +57,9 @@ void *Change(void *argument)
int nmiss;
int gridsize;
int nfound;
int nzaxis, zaxisID1, zaxisID2, k, nlevs, index;
int nzaxis, zaxisID1, zaxisID2, k, nlevs, index;
double chlevels[MAXARG];
int chltypes[MAXARG];
double *levels = NULL;
double *array = NULL;
......@@ -68,6 +70,7 @@ void *Change(void *argument)
CHLEVEL = cdoOperatorAdd("chlevel", 0, 0, "pairs of old and new level");
CHLEVELC = cdoOperatorAdd("chlevelc", 0, 0, "code number, old and new level");
CHLEVELV = cdoOperatorAdd("chlevelv", 0, 0, "variable name, old and new level");
CHLTYPE = cdoOperatorAdd("chltype", 0, 0, "pairs of old and new type");
operatorID = cdoOperatorID();
......@@ -109,6 +112,12 @@ void *Change(void *argument)
chlevels[0] = atof(operatorArgv()[1]);
chlevels[1] = atof(operatorArgv()[2]);
}
else if ( operatorID == CHLTYPE )
{
if ( nch%2 ) cdoAbort("Odd number of input arguments!");
for ( i = 0; i < nch; i++ )
chltypes[i] = atoi(operatorArgv()[i]);
}
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
......@@ -216,6 +225,35 @@ void *Change(void *argument)
free(levels);
}
else if ( operatorID == CHLTYPE )
{
int zaxistype, zaxistype1, zaxistype2, ltype1, ltype2;
nzaxis = vlistNzaxis(vlistID2);
for ( index = 0; index < nzaxis; index++ )
{
zaxisID1 = vlistZaxis(vlistID2, index);
zaxisID2 = zaxisDuplicate(zaxisID1);
zaxistype = zaxisInqType(zaxisID2);
for ( i = 0; i < nch; i += 2 )
{
ltype1 = chltypes[i];
ltype2 = chltypes[i+1];
zaxistype1 = ltype2ztype(ltype1);
zaxistype2 = ltype2ztype(ltype2);
if ( zaxistype1 != -1 && zaxistype2 != -1 )
if ( zaxistype1 == zaxistype )
{
zaxisChangeType(zaxisID2, zaxistype2);
vlistChangeZaxis(vlistID2, index, zaxisID2);
}
}
}
}
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
if ( streamID2 < 0 ) cdiError(streamID2, "Open failed on %s", cdoStreamName(1));
......
......@@ -52,6 +52,7 @@ cdo_SOURCES = Arith.c \
Seasstat.c \
Selbox.c \
Select.c \
Seloperator.c \
Selrec.c \
Selstat.c \
Seltime.c \
......@@ -61,6 +62,7 @@ cdo_SOURCES = Arith.c \
Setgrid.c \
Sethalo.c \
Setmiss.c \
Setrcaname.c \
Settime.c \
Setzaxis.c \
Showinfo.c \
......
......@@ -132,6 +132,7 @@ cdo_SOURCES = Arith.c \
Seasstat.c \
Selbox.c \
Select.c \
Seloperator.c \
Selrec.c \
Selstat.c \
Seltime.c \
......@@ -141,6 +142,7 @@ cdo_SOURCES = Arith.c \
Setgrid.c \
Sethalo.c \
Setmiss.c \
Setrcaname.c \
Settime.c \
Setzaxis.c \
Showinfo.c \
......@@ -265,33 +267,34 @@ am_cdo_OBJECTS = Arith.$(OBJEXT) Arithc.$(OBJEXT) Arithdays.$(OBJEXT) \
Outputgmt.$(OBJEXT) Pinfo.$(OBJEXT) Remap.$(OBJEXT) \
Replace.$(OBJEXT) Rotuv.$(OBJEXT) Runstat.$(OBJEXT) \
Seasstat.$(OBJEXT) Selbox.$(OBJEXT) Select.$(OBJEXT) \
Selrec.$(OBJEXT) Selstat.$(OBJEXT) Seltime.$(OBJEXT) \
Set.$(OBJEXT) Setbox.$(OBJEXT) Setgatt.$(OBJEXT) \
Setgrid.$(OBJEXT) Sethalo.$(OBJEXT) Setmiss.$(OBJEXT) \
Settime.$(OBJEXT) Setzaxis.$(OBJEXT) Showinfo.$(OBJEXT) \
Sinfo.$(OBJEXT) Sort.$(OBJEXT) Specinfo.$(OBJEXT) \
Spectral.$(OBJEXT) Split.$(OBJEXT) Splitrec.$(OBJEXT) \
Splittime.$(OBJEXT) Splityear.$(OBJEXT) Subtrend.$(OBJEXT) \
Templates.$(OBJEXT) Test.$(OBJEXT) Timsort.$(OBJEXT) \
Timstat.$(OBJEXT) Trend.$(OBJEXT) Trms.$(OBJEXT) \
Vardup.$(OBJEXT) Vargen.$(OBJEXT) Varrms.$(OBJEXT) \
Vertint.$(OBJEXT) Vertstat.$(OBJEXT) Wind.$(OBJEXT) \
Writegrid.$(OBJEXT) Writerandom.$(OBJEXT) Ydaystat.$(OBJEXT) \
Ymonarith.$(OBJEXT) Ymonstat.$(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) \
grid.$(OBJEXT) history.$(OBJEXT) institution.$(OBJEXT) \
interpol.$(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) fourier.$(OBJEXT) \
specspace.$(OBJEXT) readline.$(OBJEXT) julian.$(OBJEXT) \
vinterp.$(OBJEXT) zaxis.$(OBJEXT) pthread_debug.$(OBJEXT) \
color.$(OBJEXT) list.$(OBJEXT)
Seloperator.$(OBJEXT) Selrec.$(OBJEXT) Selstat.$(OBJEXT) \
Seltime.$(OBJEXT) Set.$(OBJEXT) Setbox.$(OBJEXT) \
Setgatt.$(OBJEXT) Setgrid.$(OBJEXT) Sethalo.$(OBJEXT) \
Setmiss.$(OBJEXT) Setrcaname.$(OBJEXT) Settime.$(OBJEXT) \
Setzaxis.$(OBJEXT) Showinfo.$(OBJEXT) Sinfo.$(OBJEXT) \
Sort.$(OBJEXT) Specinfo.$(OBJEXT) Spectral.$(OBJEXT) \
Split.$(OBJEXT) Splitrec.$(OBJEXT) Splittime.$(OBJEXT) \
Splityear.$(OBJEXT) Subtrend.$(OBJEXT) Templates.$(OBJEXT) \
Test.$(OBJEXT) Timsort.$(OBJEXT) Timstat.$(OBJEXT) \
Trend.$(OBJEXT) Trms.$(OBJEXT) Vardup.$(OBJEXT) \
Vargen.$(OBJEXT) Varrms.$(OBJEXT) Vertint.$(OBJEXT) \
Vertstat.$(OBJEXT) Wind.$(OBJEXT) Writegrid.$(OBJEXT) \
Writerandom.$(OBJEXT) Ydaystat.$(OBJEXT) Ymonarith.$(OBJEXT) \
Ymonstat.$(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) grid.$(OBJEXT) \
history.$(OBJEXT) institution.$(OBJEXT) interpol.$(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) fourier.$(OBJEXT) specspace.$(OBJEXT) \
readline.$(OBJEXT) julian.$(OBJEXT) vinterp.$(OBJEXT) \
zaxis.$(OBJEXT) pthread_debug.$(OBJEXT) color.$(OBJEXT) \
list.$(OBJEXT)
cdo_OBJECTS = $(am_cdo_OBJECTS)
cdo_DEPENDENCIES =
cdo_LDFLAGS =
......@@ -327,11 +330,12 @@ am__depfiles_maybe = depfiles
@AMDEP_TRUE@ ./$(DEPDIR)/Replace.Po ./$(DEPDIR)/Rotuv.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Runstat.Po ./$(DEPDIR)/Seasstat.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Selbox.Po ./$(DEPDIR)/Select.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Selrec.Po ./$(DEPDIR)/Selstat.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Seltime.Po ./$(DEPDIR)/Set.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Setbox.Po ./$(DEPDIR)/Setgatt.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Setgrid.Po ./$(DEPDIR)/Sethalo.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Setmiss.Po ./$(DEPDIR)/Settime.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Seloperator.Po ./$(DEPDIR)/Selrec.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Selstat.Po ./$(DEPDIR)/Seltime.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Set.Po ./$(DEPDIR)/Setbox.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Setgatt.Po ./$(DEPDIR)/Setgrid.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Sethalo.Po ./$(DEPDIR)/Setmiss.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Setrcaname.Po ./$(DEPDIR)/Settime.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Setzaxis.Po ./$(DEPDIR)/Showinfo.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Sinfo.Po ./$(DEPDIR)/Sort.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Specinfo.Po ./$(DEPDIR)/Spectral.Po \
......@@ -487,6 +491,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Seasstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Selbox.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Select.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Seloperator.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Selrec.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Selstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Seltime.Po@am__quote@
......@@ -496,6 +501,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Setgrid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Sethalo.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Setmiss.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Setrcaname.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Settime.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Setzaxis.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Showinfo.Po@am__quote@
......
......@@ -28,6 +28,7 @@
Select selzaxis Select zaxis
Select selzaxisname Select zaxis by name
Select seltabnum Select parameter table number
Select selltype Select level type
*/
......@@ -47,7 +48,7 @@
void *Select(void *argument)
{
const char func[] = "Select";
int SELCODE, SELVAR, SELLEVEL, SELGRID, SELGRIDNAME, SELZAXIS, SELZAXISNAME;
int SELCODE, SELVAR, SELLEVEL, SELGRID, SELGRIDNAME, SELZAXIS, SELZAXISNAME, SELLTYPE;
int SELTABNUM, DELCODE, DELVAR;
int operatorID;
int streamID1, streamID2;
......@@ -72,6 +73,7 @@ void *Select(void *argument)
int nmiss;
double *array = NULL;
int taxisID1, taxisID2;
int zaxistype, ltype;
LIST *ilist = listNew(INT_LIST);
LIST *flist = listNew(FLT_LIST);
......@@ -87,6 +89,7 @@ void *Select(void *argument)
SELTABNUM = cdoOperatorAdd("seltabnum", 0, 0, "table number");
DELCODE = cdoOperatorAdd("delcode", 0, 0, "codes");
DELVAR = cdoOperatorAdd("delvar", 0, 0, "vars");
SELLTYPE = cdoOperatorAdd("selltype", 0, 0, "GRIB level types");
if ( UNCHANGED_RECORD ) lcopy = TRUE;
......@@ -239,6 +242,18 @@ void *Select(void *argument)
selfound[isel] = TRUE;
}
}
else if ( operatorID == SELLTYPE )
{
zaxistype = zaxisInqType(zaxisID);
ltype = ztype2ltype(zaxistype);
if ( intarr[isel] == ltype )
{
vlistDefFlag(vlistID1, varID, levID, TRUE);
selfound[isel] = TRUE;
}
}
}
}
}
......@@ -279,6 +294,10 @@ void *Select(void *argument)
{
cdoWarning("Table number %d not found!", intarr[isel]);
}
else if ( operatorID == SELLTYPE )
{
cdoWarning("GRIB level type %d not found!", intarr[isel]);
}
}
}
......
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2006 Uwe Schulzweida, schulzweida@dkrz.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 <string.h>
#include "cdi.h"
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
void *Seloperator(void *argument)
{
int streamID1, streamID2 = CDI_UNDEFID;
int nrecs;
int tsID, recID, varID, levelID;
int vlistID1, vlistID2;
int taxisID1, taxisID2;
int scode, sltype;
double slevel = 0, level;
int nvars, nlevs, code, zaxisID, selfound = FALSE;
int levID, ltype = 0;
int varID2, levelID2;
int sellevel, selcode, selltype, zaxistype;
cdoInitialize(argument);
operatorInputArg("code, ltype, level");
scode = atoi(operatorArgv()[0]);
sltype = atoi(operatorArgv()[1]);
if ( operatorArgc() == 3 )
slevel = atof(operatorArgv()[2]);
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
nvars = vlistNvars(vlistID1);
for ( varID = 0; varID < nvars; varID++ )
{
code = vlistInqVarCode(vlistID1, varID);
zaxisID = vlistInqVarZaxis(vlistID1, varID);
nlevs = zaxisInqSize(zaxisID);
zaxistype = zaxisInqType(zaxisID);
ltype = ztype2ltype(zaxistype);
for ( levID = 0; levID < nlevs; levID++ )
{
level = zaxisInqLevel(zaxisID, levID);
if ( operatorArgc() == 3 )
sellevel = DBL_IS_EQUAL(level, slevel);
else
sellevel = TRUE;
if ( scode == -1 || scode == code )
selcode = TRUE;
else
selcode = FALSE;
if ( sltype == -1 || sltype == ltype )
selltype = TRUE;
else
selltype = FALSE;
if ( selcode && selltype && sellevel )
{
vlistDefFlag(vlistID1, varID, levID, TRUE);
selfound = TRUE;
}
}
}
if ( selfound == FALSE )
cdoWarning("Code %d, ltype %d, level %g not found!", scode, sltype, slevel);
vlistID2 = vlistCreate();
vlistCopyFlag(vlistID2, vlistID1);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
if ( streamID2 < 0 ) cdiError(streamID2, "Open failed on %s", cdoStreamName(1));
streamDefVlist(streamID2, vlistID2);
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID);
for ( recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
if ( vlistInqFlag(vlistID1, varID, levelID) == TRUE )
{
varID2 = vlistFindVar(vlistID2, varID);
levelID2 = vlistFindLevel(vlistID2, varID, levelID);
streamDefRecord(streamID2, varID2, levelID2);
streamCopyRecord(streamID2, streamID1);
}
}
tsID++;
}
streamClose(streamID1);
streamClose(streamID2);
cdoFinish();
return (0);
}
......@@ -22,6 +22,7 @@
Set setcode Set code
Set setvar Set variable name
Set setlevel Set level
Set setltype Set GRIB level type
*/
......@@ -37,7 +38,7 @@
void *Set(void *argument)
{
static char func[] = "Set";
int SETPARTAB, SETPARTABV, SETCODE, SETVAR, SETLEVEL;
int SETPARTAB, SETPARTABV, SETCODE, SETVAR, SETLEVEL, SETLTYPE;
int operatorID;
int streamID1, streamID2 = CDI_UNDEFID;
int nrecs, nvars, newval = -1;
......@@ -49,6 +50,7 @@ void *Set(void *argument)
int index, zaxisID1, zaxisID2, nzaxis, nlevs;
int tableID = -1;
int tableformat = 0;
int zaxistype;
char *newname = NULL, *partab = NULL;
double newlevel = 0;
double *levels = NULL;
......@@ -61,11 +63,12 @@ void *Set(void *argument)
SETCODE = cdoOperatorAdd("setcode", 0, 0, "code");
SETVAR = cdoOperatorAdd("setvar", 0, 0, "variable name");
SETLEVEL = cdoOperatorAdd("setlevel", 0, 0, "level");
SETLTYPE = cdoOperatorAdd("setltype", 0, 0, "GRIB level type");
operatorID = cdoOperatorID();
operatorInputArg(cdoOperatorEnter(operatorID));
if ( operatorID == SETCODE )
if ( operatorID == SETCODE || operatorID == SETLTYPE )
{
newval = atoi(operatorArgv()[0]);
}
......@@ -274,6 +277,23 @@ void *Set(void *argument)
free(levels);
}
}
else if ( operatorID == SETLTYPE )
{
nzaxis = vlistNzaxis(vlistID2);
for ( index = 0; index < nzaxis; index++ )
{
zaxisID1 = vlistZaxis(vlistID2, index);
zaxisID2 = zaxisDuplicate(zaxisID1);
zaxistype = ltype2ztype(newval);
if ( zaxistype != -1 )
{
zaxisChangeType(zaxisID2, zaxistype);
vlistChangeZaxis(vlistID2, index, zaxisID2);
}
}
}
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
if ( streamID2 < 0 ) cdiError(streamID2, "Open failed on %s", cdoStreamName(1));
......
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2006 Uwe Schulzweida, schulzweida@dkrz.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 <string.h>
#include "cdi.h"
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
#define MAX_LINE_LEN 4096
void *Setrcaname(void *argument)
{
int streamID1, streamID2 = CDI_UNDEFID;
int nrecs;
int tsID, recID, varID, levelID;
int vlistID1, vlistID2;
int taxisID1, taxisID2;
char **rcsnames;
FILE *fp;
char line[MAX_LINE_LEN];
char sname[256], sdescription[256], sunits[256];
int scode, sltype, slevel;
int nvars;
int zaxisID, ltype, code, zaxistype, nlev;
int level;
cdoInitialize(argument);
operatorInputArg("file name with RCA names");
rcsnames = operatorArgv();
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = vlistDuplicate(vlistID1);
nvars = vlistNvars(vlistID2);
fp = fopen(rcsnames[0], "r");
if ( fp != NULL )
{
while ( readline(fp, line, MAX_LINE_LEN) )
{
fscanf(fp, "%d\t%d\t%d\t%s\t%s\t%s", &scode, &sltype, &slevel, sname, sdescription, sunits);
/*
printf("%s\n", line);
printf("%d:%d:%d:%s:%s:%s\n", scode, sltype, slevel, sname, sdescription, sunits);
*/
for ( varID = 0; varID < nvars; varID++ )
{
code = vlistInqVarCode(vlistID2, varID);
zaxisID = vlistInqVarZaxis(vlistID2, varID);
nlev = zaxisInqSize(zaxisID);
zaxistype = zaxisInqType(zaxisID);
ltype = ztype2ltype(zaxistype);
if ( code == scode )
{
if ( ltype == 105 )
{
if ( nlev != 1 )
{
cdoWarning("Number of levels must be 1 for level type 105!");
cdoWarning("Maybe environment variable SPLIT_LYTPE_105 is not set.");
continue;
}
level = (int) zaxisInqLevel(zaxisID, 0);
if ( sltype == 105 && slevel == level )
{
vlistDefVarName(vlistID2, varID, sname);
vlistDefVarLongname(vlistID2, varID, sdescription);
vlistDefVarUnits(vlistID2, varID, sunits);
break;
}
}
else if ( sltype != 105 )
{
vlistDefVarName(vlistID2, varID, sname);
vlistDefVarLongname(vlistID2, varID, sdescription);
vlistDefVarUnits(vlistID2, varID, sunits);
break;
}
}
}
}
fclose(fp);
}
else
{
perror(rcsnames[0]);
}
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
if ( streamID2 < 0 ) cdiError(streamID2, "Open failed on %s", cdoStreamName(1));
streamDefVlist(streamID2, vlistID2);
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID);
for ( recID = 0;