Commit 5950a375 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge branch 'develop' of git.mpimet.mpg.de:cdo into develop

parents 4d71f728 eae192be
......@@ -82,6 +82,8 @@ INTEGER Comma separated list of years.
INTEGER Comma separated list of timesteps. Negative values selects timesteps from the end (NetCDF only).
@Item = timestep_of_year
INTEGER Comma separated list of timesteps of year.
@Item = timestepmask
STRING Read timesteps from a mask file.
@EndParameter
......
......@@ -12,6 +12,7 @@ libcdo_la_SOURCES = \
cdo_task.c \
cdo_task.h \
cdo_history.c \
cdo_read.c \
cdi_uuid.h \
cmortable_parser.c \
after_sptrans.c \
......
......@@ -105,29 +105,30 @@ am__dirstamp = $(am__leading_dot)dirstamp
am_libcdo_la_OBJECTS = libcdo_la-array.lo libcdo_la-cdo_pthread.lo \
libcdo_la-cdo_vlist.lo libcdo_la-cdo_getopt.lo \
libcdo_la-cdo_task.lo libcdo_la-cdo_history.lo \
libcdo_la-cmortable_parser.lo libcdo_la-after_sptrans.lo \
libcdo_la-after_fctrans.lo libcdo_la-after_dvtrans.lo \
libcdo_la-after_vertint.lo libcdo_la-after_namelist.lo \
libcdo_la-afterburnerlib.lo libcdo_la-constants.lo \
libcdo_la-color.lo libcdo_la-commandline.lo \
libcdo_la-convert_units.lo libcdo_la-datetime.lo \
libcdo_la-ecacore.lo libcdo_la-ecautil.lo \
libcdo_la-exception.lo libcdo_la-expr.lo libcdo_la-expr_fun.lo \
libcdo_la-expr_lex.lo libcdo_la-expr_yacc.lo \
libcdo_la-features.lo libcdo_la-field.lo libcdo_la-field2.lo \
libcdo_la-fieldc.lo libcdo_la-fieldmem.lo \
libcdo_la-fieldmer.lo libcdo_la-fieldzon.lo \
libcdo_la-gradsdeslib.lo libcdo_la-grid.lo \
libcdo_la-grid_area.lo libcdo_la-grid_define.lo \
libcdo_la-grid_gme.lo libcdo_la-grid_lcc.lo \
libcdo_la-grid_rot.lo libcdo_la-grid_from_name.lo \
libcdo_la-grid_read.lo libcdo_la-grid_read_pingo.lo \
libcdo_la-grid_print.lo libcdo_la-gridreference.lo \
libcdo_la-griddes.lo libcdo_la-griddes_h5.lo \
libcdo_la-griddes_nc.lo libcdo_la-hetaeta.lo \
libcdo_la-institution.lo libcdo_la-interpol.lo \
libcdo_la-job.lo libcdo_la-juldate.lo libcdo_la-grid_search.lo \
libcdo_la-listarray.lo libcdo_la-list.lo libcdo_la-listbuf.lo \
libcdo_la-cdo_read.lo libcdo_la-cmortable_parser.lo \
libcdo_la-after_sptrans.lo libcdo_la-after_fctrans.lo \
libcdo_la-after_dvtrans.lo libcdo_la-after_vertint.lo \
libcdo_la-after_namelist.lo libcdo_la-afterburnerlib.lo \
libcdo_la-constants.lo libcdo_la-color.lo \
libcdo_la-commandline.lo libcdo_la-convert_units.lo \
libcdo_la-datetime.lo libcdo_la-ecacore.lo \
libcdo_la-ecautil.lo libcdo_la-exception.lo libcdo_la-expr.lo \
libcdo_la-expr_fun.lo libcdo_la-expr_lex.lo \
libcdo_la-expr_yacc.lo libcdo_la-features.lo \
libcdo_la-field.lo libcdo_la-field2.lo libcdo_la-fieldc.lo \
libcdo_la-fieldmem.lo libcdo_la-fieldmer.lo \
libcdo_la-fieldzon.lo libcdo_la-gradsdeslib.lo \
libcdo_la-grid.lo libcdo_la-grid_area.lo \
libcdo_la-grid_define.lo libcdo_la-grid_gme.lo \
libcdo_la-grid_lcc.lo libcdo_la-grid_rot.lo \
libcdo_la-grid_from_name.lo libcdo_la-grid_read.lo \
libcdo_la-grid_read_pingo.lo libcdo_la-grid_print.lo \
libcdo_la-gridreference.lo libcdo_la-griddes.lo \
libcdo_la-griddes_h5.lo libcdo_la-griddes_nc.lo \
libcdo_la-hetaeta.lo libcdo_la-institution.lo \
libcdo_la-interpol.lo libcdo_la-job.lo libcdo_la-juldate.lo \
libcdo_la-grid_search.lo libcdo_la-listarray.lo \
libcdo_la-list.lo libcdo_la-listbuf.lo \
libcdo_la-merge_sort2.lo libcdo_la-modules.lo \
libcdo_la-namelist.lo libcdo_la-namelist_parser.lo \
libcdo_la-normal.lo libcdo_la-nth_element.lo \
......@@ -510,26 +511,27 @@ top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libcdo.la
libcdo_la_SOURCES = array.h array.c cdo_int.h compare.h cdo_pthread.c \
cdo_vlist.c cdo_getopt.c cdo_getopt.h cdo_task.c cdo_task.h \
cdo_history.c cdi_uuid.h cmortable_parser.c after_sptrans.c \
after_fctrans.c after_dvtrans.c after_vertint.c \
after_vertint.h after_namelist.c afterburnerlib.c \
afterburner.h vct_l191.h calendar.h constants.h constants.c \
color.c color.h commandline.c const.h convert_units.c \
convert_units.h counter.h datetime.c datetime.h dmemory.h \
ecacore.c ecacore.h ecautil.c ecautil.h error.h etopo.h temp.h \
mask.h exception.c expr.c expr.h expr_fun.c expr_fun.h \
expr_lex.c expr_yacc.c expr_yacc.h features.c field.c field.h \
field2.c fieldc.c fieldmem.c fieldmer.c fieldzon.c functs.h \
gradsdeslib.c gradsdeslib.h grid.c grid.h grid_area.c \
grid_define.c grid_gme.c grid_lcc.c grid_rot.c \
grid_from_name.c grid_read.c grid_read_pingo.c grid_print.c \
gridreference.c griddes.c griddes.h griddes_h5.c griddes_nc.c \
hetaeta.c hetaeta.h institution.c interpol.c interpol.h job.c \
juldate.c grid_search.c grid_search.h listarray.c listarray.h \
list.c list.h listbuf.c listbuf.h merge_sort2.c merge_sort2.h \
modules.c modules.h namelist.c namelist.h namelist_parser.c \
normal.c nth_element.c nth_element.h operator_help.h par_io.c \
par_io.h parse_literal.c percentiles_hist.c percentiles_hist.h \
cdo_history.c cdo_read.c cdi_uuid.h cmortable_parser.c \
after_sptrans.c after_fctrans.c after_dvtrans.c \
after_vertint.c after_vertint.h after_namelist.c \
afterburnerlib.c afterburner.h vct_l191.h calendar.h \
constants.h constants.c color.c color.h commandline.c const.h \
convert_units.c convert_units.h counter.h datetime.c \
datetime.h dmemory.h ecacore.c ecacore.h ecautil.c ecautil.h \
error.h etopo.h temp.h mask.h exception.c expr.c expr.h \
expr_fun.c expr_fun.h expr_lex.c expr_yacc.c expr_yacc.h \
features.c field.c field.h field2.c fieldc.c fieldmem.c \
fieldmer.c fieldzon.c functs.h gradsdeslib.c gradsdeslib.h \
grid.c grid.h grid_area.c grid_define.c grid_gme.c grid_lcc.c \
grid_rot.c grid_from_name.c grid_read.c grid_read_pingo.c \
grid_print.c gridreference.c griddes.c griddes.h griddes_h5.c \
griddes_nc.c hetaeta.c hetaeta.h institution.c interpol.c \
interpol.h job.c juldate.c grid_search.c grid_search.h \
listarray.c listarray.h list.c list.h listbuf.c listbuf.h \
merge_sort2.c merge_sort2.h modules.c modules.h namelist.c \
namelist.h namelist_parser.c normal.c nth_element.c \
nth_element.h operator_help.h par_io.c par_io.h \
parse_literal.c percentiles_hist.c percentiles_hist.h \
percentiles.c percentiles.h pipe.c pipe.h pmlist.c pmlist.h \
sellist.c sellist.h pragma_omp_atomic_update.h printinfo.h \
process.c process.h pstream.c pstream.h pstream_write.h \
......@@ -1020,6 +1022,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-cdo_getopt.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-cdo_history.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-cdo_pthread.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-cdo_read.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-cdo_task.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-cdo_vlist.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-cmortable_parser.Plo@am__quote@
......@@ -1186,6 +1189,13 @@ libcdo_la-cdo_history.lo: cdo_history.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libcdo_la-cdo_history.lo `test -f 'cdo_history.c' || echo '$(srcdir)/'`cdo_history.c
 
libcdo_la-cdo_read.lo: cdo_read.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libcdo_la-cdo_read.lo -MD -MP -MF $(DEPDIR)/libcdo_la-cdo_read.Tpo -c -o libcdo_la-cdo_read.lo `test -f 'cdo_read.c' || echo '$(srcdir)/'`cdo_read.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcdo_la-cdo_read.Tpo $(DEPDIR)/libcdo_la-cdo_read.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cdo_read.c' object='libcdo_la-cdo_read.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libcdo_la-cdo_read.lo `test -f 'cdo_read.c' || echo '$(srcdir)/'`cdo_read.c
libcdo_la-cmortable_parser.lo: cmortable_parser.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libcdo_la-cmortable_parser.lo -MD -MP -MF $(DEPDIR)/libcdo_la-cmortable_parser.Tpo -c -o libcdo_la-cmortable_parser.lo `test -f 'cmortable_parser.c' || echo '$(srcdir)/'`cmortable_parser.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcdo_la-cmortable_parser.Tpo $(DEPDIR)/libcdo_la-cmortable_parser.Plo
......
......@@ -29,6 +29,8 @@
double datestr_to_double(const char *datestr, int opt);
bool *cdo_read_timestepmask(const char *maskfile, int *n);
static
void write_const_vars(int streamID2, int vlistID2, int nvars, double **vardata2)
{
......@@ -54,7 +56,39 @@ void write_const_vars(int streamID2, int vlistID2, int nvars, double **vardata2)
vardata2[varID2c] = NULL;
}
}
}
}
static
void eval_timestepmask(const char *maskfile, list_t *kvlist)
{
int n = 0;
bool *imask = cdo_read_timestepmask(maskfile, &n);
int nvals = 0;
for ( int i = 0; i < n; ++i ) if ( imask[i] ) nvals++;
if ( nvals == 0 ) cdoPrint("timestepmask has no values!");
else
{
char **values = (char**) Malloc(nvals*sizeof(char*));
int j = 0;
for ( int i = 0; i < n; ++i )
{
if ( imask[i] )
{
size_t length = (size_t)log10(j+1)+2;
values[j] = (char*) Malloc(length*sizeof(char));
sprintf(values[j++], "%d", i+1);
}
}
kvlist_append(kvlist, "timestep", (const char **)values, nvals);
for ( int i = 0; i < nvals; ++i ) Free(values[i]);
Free(values);
}
Free(imask);
}
void *Select(void *argument)
......@@ -100,6 +134,13 @@ void *Select(void *argument)
if ( kvlist_parse_cmdline(kvlist, nsel, argnames) != 0 ) cdoAbort("Parse error!");
if ( cdoVerbose ) kvlist_print(kvlist);
keyValues_t *kv = kvlist_search(kvlist, "timestepmask");
if ( kv && kv->nvalues > 0 )
{
if ( kvlist_search(kvlist, "timestep") ) cdoAbort("Parameter timestep and timestepmask can't be combined!");
eval_timestepmask(kv->values[0], kvlist);
}
sellist_t *sellist = sellist_create(kvlist);
SELLIST_ADD_INT(timestep_of_year, "Timestep of year");
......@@ -124,11 +165,15 @@ void *Select(void *argument)
SELLIST_ADD_WORD(enddate, "End date");
SELLIST_ADD_WORD(season, "Season");
SELLIST_ADD_WORD(date, "Date");
SELLIST_ADD_WORD(timestepmask, "Timestep mask");
if ( cdoVerbose ) sellist_print(sellist);
sellist_verify(sellist);
if ( SELLIST_NVAL(timestepmask) > 1 ) cdoAbort("Key timestepmask has too many values!");
UNUSED(timestepmask);
int streamCnt = cdoStreamCnt();
int nfiles = streamCnt - 1;
......
......@@ -66,13 +66,12 @@ int get_tunits(const char *unit, int *incperiod, int *incunit, int *tunit)
static
void shifttime(int calendar, int tunit, int ijulinc, int *pdate, int *ptime)
{
int year, month, day;
int vdate = *pdate;
int vtime = *ptime;
juldate_t juldate;
if ( tunit == TUNIT_MONTH || tunit == TUNIT_YEAR )
{
int year, month, day;
cdiDecodeDate(vdate, &year, &month, &day);
month += ijulinc;
......@@ -86,6 +85,7 @@ void shifttime(int calendar, int tunit, int ijulinc, int *pdate, int *ptime)
}
else
{
juldate_t juldate;
juldate = juldate_encode(calendar, vdate, vtime);
juldate = juldate_add_seconds(ijulinc, juldate);
juldate_decode(calendar, juldate, &vdate, &vtime);
......
#include <cdi.h>
#include "cdo_int.h"
bool *cdo_read_timestepmask(const char *maskfile, int *n)
{
*n = 0;
int streamID = streamOpenRead(maskfile);
if ( streamID == CDI_UNDEFID ) cdoAbort("Open failed on %s!", maskfile);
int vlistID = streamInqVlist(streamID);
int nvars = vlistNvars(vlistID);
if ( nvars > 1 ) cdoAbort("timestepmask %s contains more than one variable!", maskfile);
int gridsize = gridInqSize(vlistInqVarGrid(vlistID, 0));
if ( gridsize > 1 ) cdoAbort("timestepmask %s has more than one gridpoint!", maskfile);
int nlev = zaxisInqSize(vlistInqVarZaxis(vlistID, 0));
if ( nlev > 1 ) cdoAbort("timestepmask %s has more than one level!", maskfile);
int nts = vlistNtsteps(vlistID);
if ( nts == -1 )
{
nts = 0;
while ( streamInqTimestep(streamID, nts) ) nts++;
if ( cdoVerbose ) cdoPrint("%s: counted %i timeSteps in %s", __func__, nts, maskfile);
streamClose(streamID);
streamID = streamOpenRead(maskfile);
}
else
if ( cdoVerbose ) cdoPrint("%s: found %i timeSteps in %s", __func__, nts, maskfile);
*n = nts;
bool *imask = (bool*) Malloc(nts*sizeof(bool));
int nrecs;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID, tsID)) )
{
if ( nrecs != 1 ) cdoAbort("Internal error; unexprected number of records!");
int varID, levelID;
int nmiss;
double value;
streamInqRecord(streamID, &varID, &levelID);
streamReadRecord(streamID, &value, &nmiss);
imask[tsID] = !(nmiss || IS_EQUAL(value, 0));
tsID++;
}
streamClose(streamID);
return imask;
}
......@@ -333,6 +333,17 @@ void sellist_def_val(sellist_t *sellist, int idx, int vindex, void *val)
}
}
static
void sellist_print_val(int type, cvalues_t *cvalues, int i)
{
switch (type)
{
case SELLIST_INT: printf(" %d", ((int*)cvalues)[i]); break;
case SELLIST_FLT: printf(" %g", ((double*)cvalues)[i]); break;
case SELLIST_WORD: printf(" %s", ((char**)cvalues)[i]); break;
}
}
void sellist_print(sellist_t *sellist)
{
......@@ -345,15 +356,10 @@ void sellist_print(sellist_t *sellist)
selentry_t *e = &(sellist->entry[idx]);
printf("%3d %-16s %4d %4d ", idx+1, e->key, e->type, e->nvalues);
int nvalues = e->nvalues;
if ( nvalues > 12 ) nvalues = 12;
for ( int i = 0; i < nvalues; ++i )
switch (e->type)
{
case SELLIST_INT: printf(" %d", ((int*)e->cvalues)[i]); break;
case SELLIST_FLT: printf(" %g", ((double*)e->cvalues)[i]); break;
case SELLIST_WORD: printf(" %s", ((char**)e->cvalues)[i]); break;
}
if ( nvalues > 12 ) nvalues = 11;
for ( int i = 0; i < nvalues; ++i ) sellist_print_val(e->type, e->cvalues, i);
if ( nvalues < e->nvalues ) printf(" ...");
sellist_print_val(e->type, e->cvalues, e->nvalues-1);
printf("\n");
}
}
......
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