Commit 1fadaa09 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function cdo_read_timestepmask().

parent cf19267d
#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;
}
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