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

Add module Setbox

parent 041eb8a1
......@@ -199,6 +199,7 @@ src/Selrec.c -text
src/Selstat.c -text
src/Seltime.c -text
src/Set.c -text
src/Setbox.c -text
src/Setgatt.c -text
src/Setgrid.c -text
src/Sethalo.c -text
......
......@@ -34,7 +34,7 @@
void *Filedes(void *argument)
{
int GRIDDES, ZAXISDES, VCT, VARDES, TAXISDES, FILEDES, VLIST;
int GRIDDES, ZAXISDES, VCT, VARDES, TAXISDES, FILEDES, VLIST, PARTAB;
int operatorID;
int streamID = 0;
int zaxisID;
......@@ -51,6 +51,7 @@ void *Filedes(void *argument)
VARDES = cdoOperatorAdd("vardes", 0, 0, NULL);
FILEDES = cdoOperatorAdd("filedes", 0, 0, NULL);
VLIST = cdoOperatorAdd("vlist", 0, 0, NULL);
PARTAB = cdoOperatorAdd("partab", 0, 0, NULL);
operatorID = cdoOperatorID();
......
......@@ -56,6 +56,7 @@ cdo_SOURCES = Arith.c \
Selstat.c \
Seltime.c \
Set.c \
Setbox.c \
Setgatt.c \
Setgrid.c \
Sethalo.c \
......
......@@ -136,6 +136,7 @@ cdo_SOURCES = Arith.c \
Selstat.c \
Seltime.c \
Set.c \
Setbox.c \
Setgatt.c \
Setgrid.c \
Sethalo.c \
......@@ -265,32 +266,32 @@ am_cdo_OBJECTS = Arith.$(OBJEXT) Arithc.$(OBJEXT) Arithdays.$(OBJEXT) \
Replace.$(OBJEXT) Rotuv.$(OBJEXT) Runstat.$(OBJEXT) \
Seasstat.$(OBJEXT) Selbox.$(OBJEXT) Select.$(OBJEXT) \
Selrec.$(OBJEXT) Selstat.$(OBJEXT) Seltime.$(OBJEXT) \
Set.$(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)
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)
cdo_OBJECTS = $(am_cdo_OBJECTS)
cdo_DEPENDENCIES =
cdo_LDFLAGS =
......@@ -328,39 +329,39 @@ am__depfiles_maybe = depfiles
@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)/Setgatt.Po ./$(DEPDIR)/Setgrid.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Sethalo.Po ./$(DEPDIR)/Setmiss.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Settime.Po ./$(DEPDIR)/Setzaxis.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Showinfo.Po ./$(DEPDIR)/Sinfo.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Sort.Po ./$(DEPDIR)/Specinfo.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Spectral.Po ./$(DEPDIR)/Split.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Splitrec.Po ./$(DEPDIR)/Splittime.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Splityear.Po ./$(DEPDIR)/Subtrend.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Templates.Po ./$(DEPDIR)/Test.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Timsort.Po ./$(DEPDIR)/Timstat.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Trend.Po ./$(DEPDIR)/Trms.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Vardup.Po ./$(DEPDIR)/Vargen.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Varrms.Po ./$(DEPDIR)/Vertint.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Vertstat.Po ./$(DEPDIR)/Wind.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Writegrid.Po ./$(DEPDIR)/Writerandom.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Ydaystat.Po ./$(DEPDIR)/Ymonarith.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Ymonstat.Po ./$(DEPDIR)/Yseasstat.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Zonstat.Po ./$(DEPDIR)/cdilib.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cdo.Po ./$(DEPDIR)/cdo_pthread.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cdo_vlist.Po ./$(DEPDIR)/color.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/commandline.Po ./$(DEPDIR)/exception.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/expr.Po ./$(DEPDIR)/expr_lex.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/expr_yacc.Po ./$(DEPDIR)/field.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/field2.Po ./$(DEPDIR)/fieldc.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/fieldmer.Po ./$(DEPDIR)/fieldzon.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/fourier.Po ./$(DEPDIR)/grid.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/history.Po ./$(DEPDIR)/institution.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/interpol.Po ./$(DEPDIR)/julian.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/legendre.Po ./$(DEPDIR)/list.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/modules.Po ./$(DEPDIR)/namelist.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/normal.Po ./$(DEPDIR)/pipe.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/process.Po ./$(DEPDIR)/pstream.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/pthread_debug.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)/Setzaxis.Po ./$(DEPDIR)/Showinfo.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Sinfo.Po ./$(DEPDIR)/Sort.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Specinfo.Po ./$(DEPDIR)/Spectral.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Split.Po ./$(DEPDIR)/Splitrec.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Splittime.Po ./$(DEPDIR)/Splityear.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Subtrend.Po ./$(DEPDIR)/Templates.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Test.Po ./$(DEPDIR)/Timsort.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Timstat.Po ./$(DEPDIR)/Trend.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Trms.Po ./$(DEPDIR)/Vardup.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Vargen.Po ./$(DEPDIR)/Varrms.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Vertint.Po ./$(DEPDIR)/Vertstat.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Wind.Po ./$(DEPDIR)/Writegrid.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Writerandom.Po ./$(DEPDIR)/Ydaystat.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Ymonarith.Po ./$(DEPDIR)/Ymonstat.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/Yseasstat.Po ./$(DEPDIR)/Zonstat.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cdilib.Po ./$(DEPDIR)/cdo.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/cdo_pthread.Po ./$(DEPDIR)/cdo_vlist.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/color.Po ./$(DEPDIR)/commandline.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/exception.Po ./$(DEPDIR)/expr.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/expr_lex.Po ./$(DEPDIR)/expr_yacc.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/field.Po ./$(DEPDIR)/field2.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/fieldc.Po ./$(DEPDIR)/fieldmer.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/fieldzon.Po ./$(DEPDIR)/fourier.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/grid.Po ./$(DEPDIR)/history.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/institution.Po ./$(DEPDIR)/interpol.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/julian.Po ./$(DEPDIR)/legendre.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/list.Po ./$(DEPDIR)/modules.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/namelist.Po ./$(DEPDIR)/normal.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/pipe.Po ./$(DEPDIR)/process.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/pstream.Po ./$(DEPDIR)/pthread_debug.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/readline.Po ./$(DEPDIR)/realtime.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/remaplib.Po ./$(DEPDIR)/specspace.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/table.Po ./$(DEPDIR)/timer.Po \
......@@ -490,6 +491,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Selstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Seltime.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Set.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Setbox.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Setgatt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Setgrid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Sethalo.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-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.
*/
/*
This module contains the following operators:
Setbox setclonlatbox Set lon/lat box to constant
*/
#include <string.h>
#include <stdlib.h>
#include "cdi.h"
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
static void genlonlatbox(int gridID1, int *lat1, int *lat2, int *lon11, int *lon12, int *lon21, int *lon22, double *constant)
{
static char func[] = "genlonlatbox";
int nlon1, nlat1;
double *xvals1, *yvals1;
double xlon1, xlon2, xlat1, xlat2;
operatorCheckArgc(5);
*constant=atof(operatorArgv()[0]);
xlon1 = atof(operatorArgv()[1]);
xlon2 = atof(operatorArgv()[2]);
xlat1 = atof(operatorArgv()[3]);
xlat2 = atof(operatorArgv()[4]);
nlon1 = gridInqXsize(gridID1);
nlat1 = gridInqYsize(gridID1);
xvals1 = (double *) malloc(nlon1*sizeof(double));
yvals1 = (double *) malloc(nlat1*sizeof(double));
gridInqXvals(gridID1, xvals1);
gridInqYvals(gridID1, yvals1);
xlon2 -= 360 * floor ((xlon2 - xlon1) / 360);
if ( DBL_IS_EQUAL(xlon1, xlon2) ) xlon2 += 360;
xlon2 -= 360 * floor ((xlon1 - xvals1[0]) / 360);
xlon1 -= 360 * floor ((xlon1 - xvals1[0]) / 360);
for ( *lon21 = 0; *lon21 < nlon1 && xvals1[*lon21] < xlon1; (*lon21)++ );
for ( *lon22 = *lon21; *lon22 < nlon1 && xvals1[*lon22] < xlon2; (*lon22)++ );
(*lon22)--;
xlon1 -= 360;
xlon2 -= 360;
for ( *lon11 = 0; xvals1[*lon11] < xlon1; (*lon11)++ );
for ( *lon12 = *lon11; *lon12 < nlon1 && xvals1[*lon12] < xlon2; (*lon12)++ );
(*lon12)--;
if ( *lon12 - *lon11 + 1 + *lon22 - *lon21 + 1 <= 0 )
cdoAbort("Longitudinal dimension is too small!");
if ( yvals1[0] > yvals1[nlat1 - 1] )
{
if ( xlat1 > xlat2 )
{
for ( *lat1 = 0; *lat1 < nlat1 && yvals1[*lat1] > xlat1; (*lat1)++ );
for ( *lat2 = nlat1 - 1; *lat2 && yvals1[*lat2] < xlat2; (*lat2)-- );
}
else
{
for ( *lat1 = 0; *lat1 < nlat1 && yvals1[*lat1] > xlat2; (*lat1)++ );
for ( *lat2 = nlat1 - 1; *lat2 && yvals1[*lat2] < xlat1; (*lat2)-- );
}
}
else
{
if ( xlat1 < xlat2 )
{
for ( *lat1 = 0; *lat1 < nlat1 && yvals1[*lat1] < xlat1; (*lat1)++ );
for ( *lat2 = nlat1 - 1; *lat2 && yvals1[*lat2] > xlat2; (*lat2)-- );
}
else
{
for ( *lat1 = 0; *lat1 < nlat1 && yvals1[*lat1] < xlat2; (*lat1)++ );
for ( *lat2 = nlat1 - 1; *lat2 && yvals1[*lat2] > xlat1; (*lat2)-- );
}
}
if ( *lat2 - *lat1 + 1 <= 0 )
cdoAbort("Latitudinal dimension is too small!");
free(xvals1);
free(yvals1);
}
static void genindexbox(int gridID1, int *lat1, int *lat2, int *lon11, int *lon12, int *lon21, int *lon22)
{
int nlon1, nlat1;
int temp;
operatorCheckArgc(4);
*lon11 = atoi(operatorArgv()[0]);
*lon12 = atoi(operatorArgv()[1]);
*lat1 = atoi(operatorArgv()[2]);
*lat2 = atoi(operatorArgv()[3]);
if ( *lat1 > *lat2 )
{
temp = *lat1;
*lat1 = *lat2;
*lat2 = temp;
}
nlon1 = gridInqXsize(gridID1);
nlat1 = gridInqYsize(gridID1);
if ( *lat1 < 1 )
{
cdoWarning("first latitude index out of range. Set to 1.");
*lat1 = 1;
}
if ( *lat2 > nlat1 )
{
cdoWarning("last latitude index out of range. Set to %d.", nlat1);
*lat2 = nlat1;
}
if ( *lon11 < 1 )
{
cdoWarning("first longitude index out of range. Set to 1.");
*lon11 = 1;
}
if ( *lon12 > nlon1+1 )
{
cdoWarning("last longitude index out of range. Set to %d.", nlon1);
*lon12 = nlon1;
}
(*lon11)--;
(*lon12)--;
(*lat1)--;
(*lat2)--;
if ( *lon11 > *lon12 )
{
*lon21 = *lon11;
*lon22 = nlon1 - 1;
*lon11 = 0;
}
else
{
if ( *lon12 > nlon1-1 )
{
*lon21 = *lon11;
*lon22 = nlon1 - 1;
*lon11 = 0;
*lon12 = 0;
}
else
{
*lon21 = 0;
*lon22 = -1;
}
}
}
static void setcbox(double constant, double *array, int gridID,
int lat1, int lat2, int lon11, int lon12, int lon21, int lon22)
{
int nlon, nlat;
int ilat, ilon;
nlon = gridInqXsize(gridID);
nlat = gridInqYsize(gridID);
for ( ilat = 0; ilat < nlat; ilat++ )
for ( ilon = 0; ilon < nlon; ilon++ )
if ( (lat1 <= ilat && ilat <= lat2 &&
((lon11 <= ilon && ilon <= lon12) || (lon21 <= ilon && ilon <= lon22))) ) {
array[nlon*ilat + ilon] = constant;
}
}
void *Setbox(void *argument)
{
static char func[] = "Setcbox";
int SETCLONLATBOX;
int operatorID;
int streamID1, streamID2;
int nrecs, nvars;
int tsID, recID, varID, levelID;
int gridsize;
int vlistID1, vlistID2;
int gridID = -1;
int index, ngrids, gridtype;
int nmiss;
int *vars;
int i;
int lat1, lat2, lon11, lon12, lon21, lon22;
double missval;
double constant;
double *array;
int taxisID1, taxisID2;
cdoInitialize(argument);
SETCLONLATBOX = cdoOperatorAdd("setclonlatbox", 0, 0, "constant, western and eastern longitude and southern and northern latitude");
operatorID = cdoOperatorID();
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
ngrids = vlistNgrids(vlistID1);
for ( index = 0; index < ngrids; index++ )
{
gridID = vlistGrid(vlistID1, index);
gridtype = gridInqType(gridID);
if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN ) break;
}
if ( gridInqType(gridID) == GRID_GAUSSIAN_REDUCED )
cdoAbort("Gaussian reduced grid found. Use option -R to convert it to a regular grid!");
if ( index == ngrids ) cdoAbort("No regular grid found!");
if ( ngrids > 1 ) cdoAbort("Too much different grids!");
operatorInputArg(cdoOperatorEnter(operatorID));
genlonlatbox(gridID, &lat1, &lat2, &lon11, &lon12, &lon21, &lon22, &constant);
vlistID2 = vlistDuplicate(vlistID1);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
nvars = vlistNvars(vlistID1);
vars = (int *) malloc(nvars*sizeof(int));
for ( varID = 0; varID < nvars; varID++ )
{
if ( gridID == vlistInqVarGrid(vlistID1, varID) )
vars[varID] = TRUE;
else
vars[varID] = FALSE;
}
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
if ( streamID2 < 0 ) cdiError(streamID2, "Open failed on %s", cdoStreamName(1));
streamDefVlist(streamID2, vlistID2);
gridsize = gridInqSize(gridID);
array = (double *) malloc(gridsize*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);
if ( vars[varID] )
{
streamReadRecord(streamID1, array, &nmiss);
missval = vlistInqVarMissval(vlistID1, varID);
setcbox(constant, array, gridID, lat1, lat2, lon11, lon12, lon21, lon22);
nmiss = 0;
for ( i = 0; i < gridsize; i++ )
if ( DBL_IS_EQUAL(array[i], missval) ) nmiss++;
streamDefRecord(streamID2, varID, levelID);
streamWriteRecord(streamID2, array, nmiss);
}
}
tsID++;
}
streamClose(streamID2);
streamClose(streamID1);
if ( vars ) free(vars);
if ( array ) free(array);
cdoFinish();
return (0);
}
......@@ -90,6 +90,7 @@ void *Selrec(void *argument);
void *Selstat(void *argument);
void *Seltime(void *argument);
void *Set(void *argument);
void *Setbox(void *argument);
void *Setgatt(void *argument);
void *Setgrid(void *argument);
void *Sethalo(void *argument);
......@@ -187,6 +188,7 @@ void *Zonstat(void *argument);
#define SelrecOperators {"selrec"}
#define SeltimeOperators {"seltimestep", "selyear", "selseas", "selmon", "selday", "selhour", "seldate", "seltime"}
#define SetOperators {"setpartab", "setcode", "setvar", "setlevel"}
#define SetboxOperators {"setclonlatbox", "setcindexbox"}
#define SetgattOperators {"setgatt", "setgatts"}
#define SetgridOperators {"setgrid", "setgridtype", "setgridarea"}
#define SethaloOperators {"sethalo"}
......@@ -293,6 +295,7 @@ static MODULES Modules[] =
{ Selstat, SelstatHelp, SelstatOperators, 1, 1 },
{ Seltime, SeltimeHelp, SeltimeOperators, 1, 1 },
{ Set, SetHelp, SetOperators, 1, 1 },
{ Setbox, NULL, SetboxOperators, 1, 1 },
{ Setgatt, SetgattHelp, SetgattOperators, 1, 1 },
{ Setgrid, SetgridHelp, SetgridOperators, 1, 1 },
{ Sethalo, NULL, SethaloOperators, 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