Commit 072842e8 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added operator cdiread

parent c32888ed
......@@ -285,6 +285,7 @@ src/Arith.c -text
src/Arithc.c -text
src/Arithdays.c -text
src/Arithlat.c -text
src/CDIread.c -text
src/CDItest.c -text
src/CDIwrite.c -text
src/Cat.c -text
......
......@@ -31,6 +31,7 @@ bandpass -bandpass \
beta -beta \
boxavg -boxavg \
cat -cat \
cdiread -cdiread \
cdiwrite -cdiwrite \
change_e5lsm -change_e5lsm \
change_e5mask -change_e5mask \
......
......@@ -31,6 +31,7 @@ bandpass \
beta \
boxavg \
cat \
cdiread \
cdiwrite \
change_e5lsm \
change_e5mask \
......
......@@ -31,6 +31,7 @@ bandpass -bandpass \
beta -beta \
boxavg -boxavg \
cat -cat \
cdiread -cdiread \
cdiwrite -cdiwrite \
change_e5lsm -change_e5lsm \
change_e5mask -change_e5mask \
......
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2012 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"
static
const char *filetypestr(int filetype)
{
switch ( filetype )
{
case FILETYPE_GRB: return ("GRIB"); break;
case FILETYPE_GRB2: return ("GRIB2"); break;
case FILETYPE_NC: return ("netCDF"); break;
case FILETYPE_NC2: return ("netCDF2"); break;
case FILETYPE_NC4: return ("netCDF4"); break;
case FILETYPE_NC4C: return ("netCDF4 classic"); break;
case FILETYPE_SRV: return ("SERVICE"); break;
case FILETYPE_EXT: return ("EXTRA"); break;
case FILETYPE_IEG: return ("IEG"); break;
default: return ("");
}
}
static
const char *datatypestr(int datatype)
{
static char str[20];
str[0] = 0;
sprintf(str, "%d bit packed", datatype);
if ( datatype == DATATYPE_PACK ) return ("P0");
else if ( datatype > 0 && datatype <= 32 ) return (str);
else if ( datatype == DATATYPE_CPX32 ) return ("C32");
else if ( datatype == DATATYPE_CPX64 ) return ("C64");
else if ( datatype == DATATYPE_FLT32 ) return ("32 bit floats");
else if ( datatype == DATATYPE_FLT64 ) return ("64 bit floats");
else if ( datatype == DATATYPE_INT8 ) return ("I8");
else if ( datatype == DATATYPE_INT16 ) return ("I16");
else if ( datatype == DATATYPE_INT32 ) return ("I32");
else if ( datatype == DATATYPE_UINT8 ) return ("U8");
else if ( datatype == DATATYPE_UINT16 ) return ("U16");
else if ( datatype == DATATYPE_UINT32 ) return ("U32");
else return ("");
}
static
off_t filesize(const char *filename)
{
FILE *fp;
off_t pos = 0;
fp = fopen(filename, "r");
if ( fp == NULL )
{
fprintf(stderr, "Open failed on %s\n", filename);
}
else
{
fseek(fp, 0L, SEEK_END);
pos = ftello(fp);
}
return pos;
}
static
void print_stat(const char *sinfo, int memtype, int datatype, int filetype, off_t nvalues, double data_size, double file_size, double tw)
{
nvalues /= 1000000;
data_size /= 1024.*1024.*1024.;
if ( memtype == MEMTYPE_FLOAT )
cdoPrint("%s Read %.1f GB of 32 bit floats from %s %s, %.1f MVal/s", sinfo, data_size, datatypestr(datatype), filetypestr(filetype), nvalues/tw);
else
cdoPrint("%s Read %.1f GB of 64 bit floats from %s %s, %.1f MVal/s", sinfo, data_size, datatypestr(datatype), filetypestr(filetype), nvalues/tw);
file_size /= 1024.*1024.*1024.;
cdoPrint("%s Read %.1f GB in %.1f seconds, total %.1f MB/s", sinfo, file_size, tw, 1024*file_size/tw);
}
void *CDIread(void *argument)
{
int memtype = MEMTYPE_DOUBLE;
int streamID;
int tsID, varID, levelID;
int gridsize, i, nmiss;
int recID, nrecs;
int vlistID;
int filetype = -1, datatype = -1;
int irun, nruns = 1;
char sinfo[64];
char *envstr;
off_t nvalues = 0;
double file_size = 0, data_size = 0;
double tw, tw0, t0, twsum = 0;
float *farray = NULL;
double *darray = NULL;
extern int timer_read;
sinfo[0] = 0;
cdoInitialize(argument);
envstr = getenv("MEMTYPE");
if ( envstr )
{
if ( strcmp(envstr, "float") == 0 ) memtype = MEMTYPE_FLOAT;
else if ( strcmp(envstr, "double") == 0 ) memtype = MEMTYPE_DOUBLE;
}
if ( cdoVerbose ) cdoPrint("parameter: <nruns>");
if ( operatorArgc() > 1 ) cdoAbort("Too many arguments!");
if ( operatorArgc() == 1 ) nruns = atol(operatorArgv()[0]);
if ( nruns < 0 ) nruns = 0;
if ( nruns > 99 ) nruns = 99;
if ( cdoVerbose )
{
cdoPrint("nruns : %d", nruns);
}
// vlistDefNtsteps(vlistID, 1);
for ( irun = 0; irun < nruns; ++irun )
{
tw0 = timer_val(timer_read);
data_size = 0;
nvalues = 0;
streamID = streamOpenRead(cdoStreamName(0));
vlistID = streamInqVlist(streamID);
filetype = streamInqFiletype(streamID);
datatype = vlistInqVarDatatype(vlistID, 0);
gridsize = vlistGridsizeMax(vlistID);
if ( darray == NULL ) darray = (double *) malloc(gridsize*sizeof(double));
if ( farray == NULL && memtype == MEMTYPE_FLOAT ) farray = (float *) malloc(gridsize*sizeof(float));
t0 = timer_val(timer_read);
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID, tsID)) )
{
for ( recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID, &varID, &levelID);
gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
nvalues += gridsize;
if ( memtype == MEMTYPE_FLOAT )
{
cdoAbort("streamReadRecordF not implemented!");
// streamReadRecordF(streamID, farray, &nmiss);
for ( i = 0; i < gridsize; ++i ) darray[i] = farray[i];
data_size += gridsize*4;
}
else
{
streamReadRecord(streamID, darray, &nmiss);
data_size += gridsize*8;
}
}
if ( cdoVerbose )
{
tw = timer_val(timer_read) - t0;
t0 = timer_val(timer_read);
cdoPrint("Timestep %d: %.2f seconds", tsID+1, tw);
}
tsID++;
}
streamClose(streamID);
tw = timer_val(timer_read) - tw0;
twsum += tw;
file_size = (double) filesize(cdoStreamName(0));
if ( nruns > 1 ) sprintf(sinfo, "(run %d)", irun+1);
print_stat(sinfo, memtype, datatype, filetype, nvalues, data_size, file_size, tw);
}
if ( nruns > 1 )
print_stat("(mean)", memtype, datatype, filetype, nvalues, data_size, file_size, twsum/nruns);
if ( darray ) free(darray);
if ( farray ) free(farray);
cdoFinish();
return (0);
}
......@@ -8,6 +8,7 @@ cdo_SOURCES += Arith.c \
Arithdays.c \
Arithlat.c \
CDItest.c \
CDIread.c \
CDIwrite.c \
Cat.c \
Change.c \
......
......@@ -58,9 +58,10 @@ PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS)
am_cdo_OBJECTS = cdo-cdo.$(OBJEXT) cdo-Arith.$(OBJEXT) \
cdo-Arithc.$(OBJEXT) cdo-Arithdays.$(OBJEXT) \
cdo-Arithlat.$(OBJEXT) cdo-CDItest.$(OBJEXT) \
cdo-CDIwrite.$(OBJEXT) cdo-Cat.$(OBJEXT) cdo-Change.$(OBJEXT) \
cdo-Change_e5slm.$(OBJEXT) cdo-Cloudlayer.$(OBJEXT) \
cdo-Command.$(OBJEXT) cdo-Comp.$(OBJEXT) cdo-Compc.$(OBJEXT) \
cdo-CDIread.$(OBJEXT) cdo-CDIwrite.$(OBJEXT) cdo-Cat.$(OBJEXT) \
cdo-Change.$(OBJEXT) cdo-Change_e5slm.$(OBJEXT) \
cdo-Cloudlayer.$(OBJEXT) cdo-Command.$(OBJEXT) \
cdo-Comp.$(OBJEXT) cdo-Compc.$(OBJEXT) \
cdo-Complextorect.$(OBJEXT) cdo-Cond.$(OBJEXT) \
cdo-Cond2.$(OBJEXT) cdo-Condc.$(OBJEXT) \
cdo-Consecstat.$(OBJEXT) cdo-Copy.$(OBJEXT) \
......@@ -352,31 +353,31 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
#
cdo_SOURCES = cdo.c Arith.c Arithc.c Arithdays.c Arithlat.c CDItest.c \
CDIwrite.c Cat.c Change.c Change_e5slm.c Cloudlayer.c \
Command.c Comp.c Compc.c Complextorect.c Cond.c Cond2.c \
Condc.c Consecstat.c Copy.c Deltime.c Derivepar.c Detrend.c \
Diff.c Duplicate.c EOFs.c Eof3d.c EcaIndices.c Echam5ini.c \
Enlarge.c Enlargegrid.c Ensstat.c Ensstat3.c Ensval.c \
Eofcoeff.c Eofcoeff3d.c Exprf.c FC.c Filedes.c Fillmiss.c \
Filter.c Fldrms.c Fldstat.c Fldstat2.c Fourier.c Gather.c \
Gengrid.c Gradsdes.c Gridboxstat.c Gridcell.c Harmonic.c Hi.c \
Histogram.c Importamsr.c Importbinary.c Importcmsaf.c \
Importobs.c Info.c Input.c Intgrid.c Intgridtraj.c Intlevel.c \
Intlevel3d.c Intntime.c Inttime.c Intyear.c Invert.c \
Invertlev.c Isosurface.c Log.c Magplot.c Magvector.c \
Maggraph.c Maskbox.c Mastrfu.c Math.c Merge.c Mergegrid.c \
Mergetime.c Merstat.c Monarith.c Mrotuv.c Mrotuvb.c Ninfo.c \
Nmltest.c Output.c Outputgmt.c Pinfo.c Pressure.c Regres.c \
Remap.c Remapeta.c Replace.c Replacevalues.c Rhopot.c Rotuv.c \
Runpctl.c Runstat.c Scatter.c Seascount.c Seaspctl.c \
Seasstat.c Selbox.c Select.c Seloperator.c Selrec.c Seltime.c \
Selvar.c Set.c Setbox.c Setgatt.c Setgrid.c Sethalo.c \
Setmiss.c Setrcaname.c Settime.c Setzaxis.c Showinfo.c Sinfo.c \
Smooth9.c Sort.c Sorttimestamp.c Specinfo.c Spectral.c \
Spectrum.c Split.c Splitrec.c Splitsel.c Splittime.c \
Splityear.c SSOpar.c Subtrend.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 \
CDIread.c CDIwrite.c Cat.c Change.c Change_e5slm.c \
Cloudlayer.c Command.c Comp.c Compc.c Complextorect.c Cond.c \
Cond2.c Condc.c Consecstat.c Copy.c Deltime.c Derivepar.c \
Detrend.c Diff.c Duplicate.c EOFs.c Eof3d.c EcaIndices.c \
Echam5ini.c Enlarge.c Enlargegrid.c Ensstat.c Ensstat3.c \
Ensval.c Eofcoeff.c Eofcoeff3d.c Exprf.c FC.c Filedes.c \
Fillmiss.c Filter.c Fldrms.c Fldstat.c Fldstat2.c Fourier.c \
Gather.c Gengrid.c Gradsdes.c Gridboxstat.c Gridcell.c \
Harmonic.c Hi.c Histogram.c Importamsr.c Importbinary.c \
Importcmsaf.c Importobs.c Info.c Input.c Intgrid.c \
Intgridtraj.c Intlevel.c Intlevel3d.c Intntime.c Inttime.c \
Intyear.c Invert.c Invertlev.c Isosurface.c Log.c Magplot.c \
Magvector.c Maggraph.c Maskbox.c Mastrfu.c Math.c Merge.c \
Mergegrid.c Mergetime.c Merstat.c Monarith.c Mrotuv.c \
Mrotuvb.c Ninfo.c Nmltest.c Output.c Outputgmt.c Pinfo.c \
Pressure.c Regres.c Remap.c Remapeta.c Replace.c \
Replacevalues.c Rhopot.c Rotuv.c Runpctl.c Runstat.c Scatter.c \
Seascount.c Seaspctl.c Seasstat.c Selbox.c Select.c \
Seloperator.c Selrec.c Seltime.c Selvar.c Set.c Setbox.c \
Setgatt.c Setgrid.c Sethalo.c Setmiss.c Setrcaname.c Settime.c \
Setzaxis.c Showinfo.c Sinfo.c Smooth9.c Sort.c Sorttimestamp.c \
Specinfo.c Spectral.c Spectrum.c Split.c Splitrec.c Splitsel.c \
Splittime.c Splityear.c SSOpar.c Subtrend.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 \
Transpose.c Trend.c Trms.c Tstepcount.c Vardup.c Vargen.c \
Varrms.c Vertint.c Vertstat.c Vertwind.c Wct.c Wind.c \
Writegrid.c Writerandom.c Ydayarith.c Ydaypctl.c Ydaystat.c \
......@@ -536,6 +537,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Arithc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Arithdays.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Arithlat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-CDIread.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-CDItest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-CDIwrite.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdo-Cat.Po@am__quote@
......@@ -871,6 +873,20 @@ cdo-CDItest.obj: CDItest.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-CDItest.obj `if test -f 'CDItest.c'; then $(CYGPATH_W) 'CDItest.c'; else $(CYGPATH_W) '$(srcdir)/CDItest.c'; fi`
cdo-CDIread.o: CDIread.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-CDIread.o -MD -MP -MF $(DEPDIR)/cdo-CDIread.Tpo -c -o cdo-CDIread.o `test -f 'CDIread.c' || echo '$(srcdir)/'`CDIread.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/cdo-CDIread.Tpo $(DEPDIR)/cdo-CDIread.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='CDIread.c' object='cdo-CDIread.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-CDIread.o `test -f 'CDIread.c' || echo '$(srcdir)/'`CDIread.c
cdo-CDIread.obj: CDIread.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-CDIread.obj -MD -MP -MF $(DEPDIR)/cdo-CDIread.Tpo -c -o cdo-CDIread.obj `if test -f 'CDIread.c'; then $(CYGPATH_W) 'CDIread.c'; else $(CYGPATH_W) '$(srcdir)/CDIread.c'; fi`
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/cdo-CDIread.Tpo $(DEPDIR)/cdo-CDIread.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='CDIread.c' object='cdo-CDIread.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cdo-CDIread.obj `if test -f 'CDIread.c'; then $(CYGPATH_W) 'CDIread.c'; else $(CYGPATH_W) '$(srcdir)/CDIread.c'; fi`
cdo-CDIwrite.o: CDIwrite.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(cdo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cdo-CDIwrite.o -MD -MP -MF $(DEPDIR)/cdo-CDIwrite.Tpo -c -o cdo-CDIwrite.o `test -f 'CDIwrite.c' || echo '$(srcdir)/'`CDIwrite.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/cdo-CDIwrite.Tpo $(DEPDIR)/cdo-CDIwrite.Po
......
......@@ -44,6 +44,7 @@ void *Arithdays(void *argument);
void *Arithlat(void *argument);
void *Cat(void *argument);
void *CDItest(void *argument);
void *CDIread(void *argument);
void *CDIwrite(void *argument);
void *Change(void *argument);
void *Change_e5slm(void *argument);
......@@ -261,6 +262,7 @@ void *Wct(void *argument);
#define ArithlatOperators {"mulcoslat", "divcoslat"}
#define CatOperators {"cat"}
#define CDItestOperators {"ncopy"}
#define CDIreadOperators {"cdiread"}
#define CDIwriteOperators {"cdiwrite"}
#define ChangeOperators {"chcode", "chtabnum", "chparam", "chname", "chlevel", "chlevelc", "chlevelv", "chltype"}
#define Change_e5slmOperators {"change_e5slm", "change_e5lsm", "change_e5mask"}
......@@ -517,6 +519,7 @@ static modules_t Modules[] =
{ Arithlat, NULL, ArithlatOperators, CDI_REAL, 1, 1 },
{ Cat, CopyHelp, CatOperators, CDI_REAL, -1, 1 },
{ CDItest, NULL, CDItestOperators, CDI_REAL, 1, 1 },
{ CDIread, NULL, CDIreadOperators, CDI_REAL, 1, 0 },
{ CDIwrite, NULL, CDIwriteOperators, CDI_REAL, 0, 1 },
{ Change, ChangeHelp, ChangeOperators, CDI_REAL, 1, 1 },
{ Change_e5slm, NULL, Change_e5slmOperators, 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