Commit a1b65cad authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

No commit message

No commit message
parent 7e5408d8
......@@ -233,6 +233,7 @@ src/Fldstat.c -text
src/Gengrid.c -text
src/Gradsdes.c -text
src/Gridcell.c -text
src/Gridstat.c -text
src/Harmonic.c -text
src/Hi.c -text
src/Histogram.c -text
......
/*
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2008 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:
Gridboxstat gridboxmin Gridbox minimum
Gridboxstat gridboxmax Gridbox maximum
Gridboxstat gridboxsum Gridbox sum
Gridboxstat gridboxmean Gridbox mean
Gridboxstat gridboxavg Gridbox average
Gridboxstat gridboxstd Gridbox standard deviation
Gridboxstat gridboxvar Gridbox variance
Gridboxstat gridboxpctl Gridbox percentiles
*/
#include "cdi.h"
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
#include "functs.h"
void *Gridboxstat(void *argument)
{
static char func[] = "Gridboxstat";
int operatorID;
int operfunc;
int streamID1, streamID2;
int vlistID1, vlistID2;
int gridID2, lastgrid = -1;
int wstatus = FALSE;
int code = 0, oldcode = 0;
int index, ngrids;
int recID, nrecs;
int tsID, varID, levelID;
int lim;
int needWeights = FALSE;
int nmiss;
double slon, slat;
double sglval;
FIELD field;
int taxisID1, taxisID2;
cdoInitialize(argument);
cdoOperatorAdd("gridboxmin", func_min, 0, NULL);
cdoOperatorAdd("gridboxmax", func_max, 0, NULL);
cdoOperatorAdd("gridboxsum", func_sum, 0, NULL);
cdoOperatorAdd("gridboxmean", func_mean, 0, NULL);
cdoOperatorAdd("gridboxavg", func_avg, 0, NULL);
cdoOperatorAdd("gridboxvar", func_var, 0, NULL);
cdoOperatorAdd("gridboxstd", func_std, 0, NULL);
operatorID = cdoOperatorID();
operfunc = cdoOperatorFunc(operatorID);
if ( operfunc == func_mean || operfunc == func_avg ||
operfunc == func_var || operfunc == func_std )
needWeights = TRUE;
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = vlistDuplicate(vlistID1);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
slon = 0;
slat = 0;
gridID2 = gridCreate(GRID_LONLAT, 1);
gridDefXsize(gridID2, 1);
gridDefYsize(gridID2, 1);
gridDefXvals(gridID2, &slon);
gridDefYvals(gridID2, &slat);
ngrids = vlistNgrids(vlistID1);
for ( index = 0; index < ngrids; index++ )
vlistChangeGridIndex(vlistID2, index, gridID2);
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
if ( streamID2 < 0 ) cdiError(streamID2, "Open failed on %s", cdoStreamName(1));
streamDefVlist(streamID2, vlistID2);
lim = vlistGridsizeMax(vlistID1);
field.ptr = (double *) malloc(lim*sizeof(double));
field.weight = NULL;
if ( needWeights )
field.weight = (double *) malloc(lim*sizeof(double));
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID);
for ( recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
streamReadRecord(streamID1, field.ptr, &field.nmiss);
field.grid = vlistInqVarGrid(vlistID1, varID);
field.size = gridInqSize(field.grid);
if ( needWeights && field.grid != lastgrid )
{
lastgrid = field.grid;
wstatus = gridWeights(field.grid, field.weight);
}
code = vlistInqVarCode(vlistID1, varID);
if ( wstatus != 0 && tsID == 0 && code != oldcode )
cdoWarning("Using constant grid cell area weights for code %d!", oldcode=code);
field.missval = vlistInqVarMissval(vlistID1, varID);
sglval = fldfun(field, operfunc);
if ( cdoVerbose )
if ( operfunc == func_min || operfunc == func_max )
{
if ( gridInqType(field.grid) == GRID_GAUSSIAN ||
gridInqType(field.grid) == GRID_LONLAT )
{
int i = 0, j, nlon, nlat;
nlon = gridInqXsize(field.grid);
nlat = gridInqYsize(field.grid);
for ( j = 0; j < nlat; ++j )
{
for ( i = 0; i < nlon; ++i )
{
if ( DBL_IS_EQUAL(field.ptr[j*nlon+i], sglval) ) break;
}
if ( i < nlon ) break;
}
if ( j < nlat )
{
int vdate, vtime, code;
int year, month, day, hour, minute;
double level;
double xval, yval;
xval = gridInqXval(field.grid, i);
yval = gridInqYval(field.grid, j);
vdate = taxisInqVdate(taxisID1);
vtime = taxisInqVtime(taxisID1);
decode_date(vdate, &year, &month, &day);
decode_time(vtime, &hour, &minute);
code = vlistInqVarCode(vlistID1, varID);
level = zaxisInqLevel(vlistInqVarZaxis(vlistID1, varID), levelID);
if ( tsID == 0 && recID == 0 )
{
if ( operfunc == func_min )
fprintf(stdout, " Date Time Code Level Lon Lat Minval\n");
else
fprintf(stdout, " Date Time Code Level Lon Lat Maxval\n");
}
fprintf(stdout, "%4.4d-%2.2d-%2.2d %2.2d:%2.2d %3d %7g %9.7g %9.7g %12.5g\n",
year, month, day, hour, minute,
code, level, xval, yval, sglval);
}
}
}
if ( DBL_IS_EQUAL(sglval, field.missval) )
nmiss = 1;
else
nmiss = 0;
streamDefRecord(streamID2, varID, levelID);
streamWriteRecord(streamID2, &sglval, nmiss);
}
tsID++;
}
streamClose(streamID2);
streamClose(streamID1);
if ( field.ptr ) free(field.ptr);
if ( field.weight ) free(field.weight);
cdoFinish();
return (0);
}
......@@ -31,6 +31,7 @@ cdo_SOURCES = Arith.c \
Fldstat.c \
Gengrid.c \
Gradsdes.c \
Gridboxstat.c \
Gridcell.c \
Harmonic.c \
Histogram.c \
......
......@@ -56,59 +56,59 @@ am_cdo_OBJECTS = Arith.$(OBJEXT) Arithc.$(OBJEXT) Arithdays.$(OBJEXT) \
Echam5ini.$(OBJEXT) Enlarge.$(OBJEXT) Enlargegrid.$(OBJEXT) \
Ensstat.$(OBJEXT) Exprf.$(OBJEXT) Filedes.$(OBJEXT) \
Fillmiss.$(OBJEXT) Fldrms.$(OBJEXT) Fldstat.$(OBJEXT) \
Gengrid.$(OBJEXT) Gradsdes.$(OBJEXT) Gridcell.$(OBJEXT) \
Harmonic.$(OBJEXT) Histogram.$(OBJEXT) Importamsr.$(OBJEXT) \
Importcmsaf.$(OBJEXT) Info.$(OBJEXT) Input.$(OBJEXT) \
Intgrid.$(OBJEXT) Intgridtraj.$(OBJEXT) Intlevel.$(OBJEXT) \
Inttime.$(OBJEXT) Intntime.$(OBJEXT) Intyear.$(OBJEXT) \
Invert.$(OBJEXT) Invertlev.$(OBJEXT) Log.$(OBJEXT) \
Maskbox.$(OBJEXT) Mastrfu.$(OBJEXT) Math.$(OBJEXT) \
Merge.$(OBJEXT) Mergegrid.$(OBJEXT) Mergetime.$(OBJEXT) \
Merstat.$(OBJEXT) Monarith.$(OBJEXT) Mrotuv.$(OBJEXT) \
Mrotuvb.$(OBJEXT) Ninfo.$(OBJEXT) Nmltest.$(OBJEXT) \
Output.$(OBJEXT) Outputgmt.$(OBJEXT) Pinfo.$(OBJEXT) \
Pressure.$(OBJEXT) Regres.$(OBJEXT) Remap.$(OBJEXT) \
Remapeta.$(OBJEXT) Replace.$(OBJEXT) Rotuv.$(OBJEXT) \
Runpctl.$(OBJEXT) Runstat.$(OBJEXT) Seascount.$(OBJEXT) \
Seaspctl.$(OBJEXT) Seasstat.$(OBJEXT) Selbox.$(OBJEXT) \
Select.$(OBJEXT) Seloperator.$(OBJEXT) Selrec.$(OBJEXT) \
Seltime.$(OBJEXT) Set.$(OBJEXT) Setbox.$(OBJEXT) \
Setgatt.$(OBJEXT) Setgrid.$(OBJEXT) Sethalo.$(OBJEXT) \
Setmiss.$(OBJEXT) Setrange.$(OBJEXT) Setrcaname.$(OBJEXT) \
Settime.$(OBJEXT) Setzaxis.$(OBJEXT) Showinfo.$(OBJEXT) \
Sinfo.$(OBJEXT) Smooth9.$(OBJEXT) Sort.$(OBJEXT) \
Specinfo.$(OBJEXT) Spectral.$(OBJEXT) Spectrum.$(OBJEXT) \
Split.$(OBJEXT) Splitrec.$(OBJEXT) Splitsel.$(OBJEXT) \
Splittime.$(OBJEXT) Splityear.$(OBJEXT) Subtrend.$(OBJEXT) \
Templates.$(OBJEXT) Test.$(OBJEXT) Tests.$(OBJEXT) \
Timcount.$(OBJEXT) Timpctl.$(OBJEXT) Timsort.$(OBJEXT) \
Timselpctl.$(OBJEXT) Timselstat.$(OBJEXT) Timstat.$(OBJEXT) \
Timstat2.$(OBJEXT) Timstat3.$(OBJEXT) Tinfo.$(OBJEXT) \
Trend.$(OBJEXT) Trms.$(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) \
grid.$(OBJEXT) gridnc.$(OBJEXT) gridh5.$(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) \
fourier.$(OBJEXT) specspace.$(OBJEXT) readline.$(OBJEXT) \
julian.$(OBJEXT) vinterp.$(OBJEXT) zaxis.$(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)
Gengrid.$(OBJEXT) Gradsdes.$(OBJEXT) Gridboxstat.$(OBJEXT) \
Gridcell.$(OBJEXT) Harmonic.$(OBJEXT) Histogram.$(OBJEXT) \
Importamsr.$(OBJEXT) Importcmsaf.$(OBJEXT) Info.$(OBJEXT) \
Input.$(OBJEXT) Intgrid.$(OBJEXT) Intgridtraj.$(OBJEXT) \
Intlevel.$(OBJEXT) Inttime.$(OBJEXT) Intntime.$(OBJEXT) \
Intyear.$(OBJEXT) Invert.$(OBJEXT) Invertlev.$(OBJEXT) \
Log.$(OBJEXT) Maskbox.$(OBJEXT) Mastrfu.$(OBJEXT) \
Math.$(OBJEXT) Merge.$(OBJEXT) Mergegrid.$(OBJEXT) \
Mergetime.$(OBJEXT) Merstat.$(OBJEXT) Monarith.$(OBJEXT) \
Mrotuv.$(OBJEXT) Mrotuvb.$(OBJEXT) Ninfo.$(OBJEXT) \
Nmltest.$(OBJEXT) Output.$(OBJEXT) Outputgmt.$(OBJEXT) \
Pinfo.$(OBJEXT) Pressure.$(OBJEXT) Regres.$(OBJEXT) \
Remap.$(OBJEXT) Remapeta.$(OBJEXT) Replace.$(OBJEXT) \
Rotuv.$(OBJEXT) Runpctl.$(OBJEXT) Runstat.$(OBJEXT) \
Seascount.$(OBJEXT) Seaspctl.$(OBJEXT) Seasstat.$(OBJEXT) \
Selbox.$(OBJEXT) Select.$(OBJEXT) Seloperator.$(OBJEXT) \
Selrec.$(OBJEXT) Seltime.$(OBJEXT) Set.$(OBJEXT) \
Setbox.$(OBJEXT) Setgatt.$(OBJEXT) Setgrid.$(OBJEXT) \
Sethalo.$(OBJEXT) Setmiss.$(OBJEXT) Setrange.$(OBJEXT) \
Setrcaname.$(OBJEXT) Settime.$(OBJEXT) Setzaxis.$(OBJEXT) \
Showinfo.$(OBJEXT) Sinfo.$(OBJEXT) Smooth9.$(OBJEXT) \
Sort.$(OBJEXT) Specinfo.$(OBJEXT) Spectral.$(OBJEXT) \
Spectrum.$(OBJEXT) Split.$(OBJEXT) Splitrec.$(OBJEXT) \
Splitsel.$(OBJEXT) Splittime.$(OBJEXT) Splityear.$(OBJEXT) \
Subtrend.$(OBJEXT) Templates.$(OBJEXT) Test.$(OBJEXT) \
Tests.$(OBJEXT) Timcount.$(OBJEXT) Timpctl.$(OBJEXT) \
Timsort.$(OBJEXT) Timselpctl.$(OBJEXT) Timselstat.$(OBJEXT) \
Timstat.$(OBJEXT) Timstat2.$(OBJEXT) Timstat3.$(OBJEXT) \
Tinfo.$(OBJEXT) Trend.$(OBJEXT) Trms.$(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) grid.$(OBJEXT) gridnc.$(OBJEXT) \
gridh5.$(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) fourier.$(OBJEXT) specspace.$(OBJEXT) \
readline.$(OBJEXT) julian.$(OBJEXT) vinterp.$(OBJEXT) \
zaxis.$(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)
am__DEPENDENCIES_1 =
cdo_DEPENDENCIES = $(am__DEPENDENCIES_1)
......@@ -254,6 +254,7 @@ cdo_SOURCES = Arith.c \
Fldstat.c \
Gengrid.c \
Gradsdes.c \
Gridboxstat.c \
Gridcell.c \
Harmonic.c \
Histogram.c \
......@@ -574,6 +575,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Fldstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Gengrid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Gradsdes.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Gridboxstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Gridcell.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Harmonic.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Hi.Po@am__quote@
......
......@@ -63,6 +63,7 @@ void *Fldrms(void *argument);
void *Fldstat(void *argument);
void *Gengrid(void *argument);
void *Gradsdes(void *argument);
void *Gridboxstat(void *argument);
void *Gridcell(void *argument);
void *Harmonic(void *argument);
void *Histogram(void *argument);
......@@ -261,6 +262,8 @@ void *Wct(void *argument);
#define FldstatOperators {"fldmin", "fldmax", "fldsum", "fldmean", "fldavg", "fldvar", "fldstd", "fldpctl"}
#define GengridOperators {"gengrid"}
#define GradsdesOperators {"gradsdes1", "gradsdes2", "dumpmap"}
#define GridboxstatOperators {"gridboxmin", "gridboxmax", "gridboxsum", "gridboxmean", "gridboxavg", \
"gridboxvar", "gridboxstd"}
#define GridcellOperators {"gridarea", "gridweights"}
#define HarmonicOperators {"harmonic"}
#define HistogramOperators {"histcount", "histsum", "histmean", "histfreq"}
......@@ -491,6 +494,7 @@ static MODULES Modules[] =
{ Fldstat, FldstatHelp, FldstatOperators, 1, 1 },
{ Gengrid, NULL, GengridOperators, 2, 1 },
{ Gradsdes, GradsdesHelp, GradsdesOperators, 1, 0 },
{ Gridboxstat, NULL, GridboxstatOperators, 1, 1 },
{ Gridcell, GridcellHelp, GridcellOperators, 1, 1 },
{ Harmonic, NULL, HarmonicOperators, 1, 1 },
{ Histogram, HistogramHelp, HistogramOperators, 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