Commit 0cd6ec59 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Changed while statement for cdoStreamInqTimestep().

parent eb8f3173
Pipeline #5699 passed with stages
in 15 minutes and 2 seconds
......@@ -144,7 +144,7 @@ static void calculateOuterPeriod(Field &field, int MaxMonths, int recentYear, in
if (cdoAssertFilesOnly() == false)
cdoAbort("infile1 cannot be a pipe");
const auto maxrecs = vlistNrecs(vlistID1);
CdiStreamID cdiStream = streamOpenRead(cdoGetStreamName(0));
auto cdiStream = streamOpenRead(cdoGetStreamName(0));
const auto cdiVlistID = streamInqVlist(cdiStream);
const auto cdiTaxisID = vlistInqTaxis(cdiVlistID);
......@@ -152,14 +152,17 @@ static void calculateOuterPeriod(Field &field, int MaxMonths, int recentYear, in
int tempdpy = 0;
for ( int i = 0; i<MaxMonths; i++)
tempdpm[i] = 0;
int year, month, day, tsID = 0, nrecs = 0, varID, levelID;
int year, month, day, tsID = 0, varID, levelID;
bool lHasStarted = false;
if (Options::cdoVerbose) cdoPrint("Start to process variables");
while ( ( nrecs = streamInqTimestep(cdiStream, tsID++) ) )
while (true)
{
int64_t vdate = taxisInqVdate(cdiTaxisID);
const auto nrecs = streamInqTimestep(cdiStream, tsID++);
if (nrecs == 0) break;
auto vdate = taxisInqVdate(cdiTaxisID);
cdiDecodeDate(vdate, &year, &month, &day);
if ( !lHasStarted && year != recentYear )
continue;
......@@ -180,14 +183,13 @@ static void calculateOuterPeriod(Field &field, int MaxMonths, int recentYear, in
fieldFill(cei[loopmonth][0][0], 0.);
}
}
if ( year == endOfCalc && func2 == func_avg )
break;
if (year == endOfCalc && func2 == func_avg) break;
tempdpy++;
int dayoy = (month >= 1 && month <= 12) ? (month - 1) * 31 + day : 0;
tempdpm[month-1]++;
if ( func2 == func_sum )
dayoy = 1;
if ( func2 == func_sum ) dayoy = 1;
for (int recID = 0; recID < nrecs; recID++)
{
streamInqRecord(cdiStream, &varID, &levelID);
......@@ -217,7 +219,7 @@ static void calculateOuterPeriod(Field &field, int MaxMonths, int recentYear, in
fieldFill(cei[0][0][0], 0.);
if ( frequency == 8 )
for ( int loopmonth = 1; loopmonth < MaxMonths; loopmonth++)
for (int loopmonth = 1; loopmonth < MaxMonths; loopmonth++)
{
tempdpm[loopmonth] = 0;
fieldFill(cei[loopmonth][0][0], 0.);
......@@ -232,7 +234,6 @@ etccdi_op(ETCCDI_REQUEST *request)
constexpr int MaxDays = 373;
constexpr int MaxMonths = 12;
int varID;
int nrecs;
int levelID;
size_t nmiss;
int year, month, day, dayoy;
......@@ -336,8 +337,11 @@ etccdi_op(ETCCDI_REQUEST *request)
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID2, tsID);
if (nrecs == 0) break;
if (nrecs != cdoStreamInqTimestep(streamID3, tsID))
cdoAbort("Number of records at time step %d of %s and %s differ!", tsID + 1, cdoGetStreamName(1),
cdoGetStreamName(2));
......@@ -415,8 +419,11 @@ etccdi_op(ETCCDI_REQUEST *request)
tsID = 0;
bool lOnlyRefPeriod = true;
int firstYear = 0, lastYear = 0;
while ( (nrecs = cdoStreamInqTimestep(streamID1, tsID++) ) )
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID++);
if (nrecs == 0) break;
vdate = taxisInqVdate(taxisID1);
vtime = taxisInqVtime(taxisID1);
......@@ -435,7 +442,7 @@ etccdi_op(ETCCDI_REQUEST *request)
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day %d out of range!", dayoy);
if (wdaysSrc[dayoy] || request->func2 == func_sum )
{
/* Variable independent ? */
/* Variable independent ? */
wdaysRead[dayoy+(year-request->startboot)*(MaxDays-1)] = dayoy+(year-request->startboot)*(MaxDays-1);
dpy[year-request->startboot]++;
dpm[(year-request->startboot)*MaxMonths+(int)((dayoy-1)/31.)]++;
......
......@@ -35,7 +35,6 @@ void *
Ydayarith(void *process)
{
constexpr int MaxDays = 373;
int nrecs;
int varID, levelID;
cdoInitialize(process);
......@@ -78,8 +77,11 @@ Ydayarith(void *process)
FieldVector2D vars2[MaxDays];
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID2, tsID);
if (nrecs == 0) break;
const auto vdate = taxisInqVdate(taxisID2);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
......@@ -99,8 +101,11 @@ Ydayarith(void *process)
}
tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto vdate = taxisInqVdate(taxisID1);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
......
......@@ -35,7 +35,6 @@ void *
Ydaypctl(void *process)
{
constexpr int MaxDays = 373;
int nrecs;
size_t nmiss;
int64_t vdates1[MaxDays] = { 0 }, vdates2[MaxDays] = { 0 };
int vtimes1[MaxDays] = { 0 };
......@@ -87,8 +86,11 @@ Ydaypctl(void *process)
field.resize(gridsizemax);
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID2, tsID);
if (nrecs == 0) break;
if (nrecs != cdoStreamInqTimestep(streamID3, tsID))
cdoAbort("Number of records at time step %d of %s and %s differ!", tsID + 1, cdoGetStreamName(1), cdoGetStreamName(2));
......@@ -138,8 +140,11 @@ Ydaypctl(void *process)
}
tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto vdate = taxisInqVdate(taxisID1);
const auto vtime = taxisInqVtime(taxisID1);
......
......@@ -91,7 +91,6 @@ void *
Ydaystat(void *process)
{
constexpr int MaxDays = 373;
int nrecs;
int dayoy_nsets[MaxDays] = { 0 };
int64_t vdates[MaxDays] = { 0 };
int vtimes[MaxDays] = { 0 };
......@@ -139,8 +138,11 @@ Ydaystat(void *process)
int tsID = 0;
int otsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto vdate = taxisInqVdate(taxisID1);
const auto vtime = taxisInqVtime(taxisID1);
......
......@@ -38,7 +38,6 @@ void *
Ydrunpctl(void *process)
{
constexpr int MaxDays = 373;
int nrecs;
int its;
size_t nmiss;
int64_t vdates1[MaxDays] = { 0 }, vdates2[MaxDays] = { 0 };
......@@ -117,8 +116,11 @@ Ydrunpctl(void *process)
int tsID = 0;
int startYear = 0, endYear = 0, mon = 0, day = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID2, tsID);
if (nrecs == 0) break;
if (nrecs != cdoStreamInqTimestep(streamID3, tsID))
cdoAbort("Number of records at time step %d of %s and %s differ!", tsID + 1, cdoGetStreamName(1), cdoGetStreamName(2));
......@@ -170,7 +172,7 @@ Ydrunpctl(void *process)
for (tsID = 0; tsID < ndates; tsID++)
{
nrecs = cdoStreamInqTimestep(streamID1, tsID);
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) cdoAbort("File has less then %d timesteps!", ndates);
datetime[tsID].date = taxisInqVdate(taxisID1);
......@@ -226,7 +228,7 @@ Ydrunpctl(void *process)
vars1[inp] = vars1[inp + 1];
}
nrecs = cdoStreamInqTimestep(streamID1, tsID);
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
datetime[ndates - 1].date = taxisInqVdate(taxisID1);
......@@ -254,10 +256,10 @@ Ydrunpctl(void *process)
int missTimes = 0;
for ( missTimes = 0; missTimes < ndates-1; missTimes++ )
{
int year;
nrecs = streamInqTimestep(cdiStream, missTimes);
const auto nrecs = streamInqTimestep(cdiStream, missTimes);
if (nrecs == 0) break;
int year;
cdiDecodeDate(taxisInqVdate(cdiTaxisID), &year, &mon, &day);
datetime[ndates - 1].date = cdiEncodeDate(endYear+1, mon, day);
datetime[ndates - 1].time = taxisInqVtime(cdiTaxisID);
......
......@@ -56,7 +56,6 @@ addOperators(void)
void *
Yeararith(void *process)
{
int nrecs;
int varID, levelID;
cdoInitialize(process);
......@@ -101,15 +100,20 @@ Yeararith(void *process)
int year2last = 0;
int tsID2 = 0;
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto year = getYear(taxisInqVdate(taxisID1));
if (year > year0)
{
bool lfound = false;
int nrecs2;
while ((nrecs2 = cdoStreamInqTimestep(streamID2, tsID2)))
while (true)
{
const auto nrecs2 = cdoStreamInqTimestep(streamID2, tsID2);
if (nrecs2 == 0) break;
tsID2++;
const auto year2 = getYear(taxisInqVdate(taxisID2));
if (year == year2)
......
......@@ -38,7 +38,6 @@ Yearmonstat(void *process)
TimeStat timestat_date = TimeStat::MEAN;
int64_t vdate0 = 0;
int vtime0 = 0;
int nrecs;
int year0 = 0, month0 = 0;
int year, month, day;
......@@ -93,10 +92,14 @@ Yearmonstat(void *process)
int otsID = 0;
while (true)
{
int nrecs = 0;
long nsets = 0;
double dsets = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
double dsets = 0.0;
while (true)
{
nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
dtlist.taxisInqTimestep(taxisID1, nsets);
const auto vdate = dtlist.getVdate(nsets);
const auto vtime = dtlist.getVtime(nsets);
......@@ -113,7 +116,7 @@ Yearmonstat(void *process)
cdoAbort("Month does not change!");
}
const int dpm = days_per_month(calendar, year, month);
const auto dpm = days_per_month(calendar, year, month);
for (int recID = 0; recID < nrecs; recID++)
{
......
......@@ -48,7 +48,6 @@ getHourOfYearIndex(int64_t vdate, int vtime)
void *
Yhourarith(void *process)
{
int nrecs;
int varID, levelID;
cdoInitialize(process);
......@@ -91,8 +90,11 @@ Yhourarith(void *process)
FieldVector2D vars2[MaxHours];
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID2, tsID);
if (nrecs == 0) break;
const auto houroy = getHourOfYearIndex(taxisInqVdate(taxisID2), taxisInqVtime(taxisID2));
if (vars2[houroy].size() > 0) cdoAbort("Hour of year index %d already allocated!", houroy);
......@@ -110,8 +112,11 @@ Yhourarith(void *process)
}
tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto houroy = getHourOfYearIndex(taxisInqVdate(taxisID1), taxisInqVtime(taxisID1));
if (vars2[houroy].size() == 0) cdoAbort("Hour of year index %d not found!", houroy);
......
......@@ -81,7 +81,6 @@ void *
Yhourstat(void *process)
{
TimeStat timestat_date = TimeStat::LAST;
int nrecs;
cdoInitialize(process);
......@@ -137,8 +136,11 @@ Yhourstat(void *process)
int tsID = 0;
int otsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto vdate = taxisInqVdate(taxisID1);
const auto vtime = taxisInqVtime(taxisID1);
......@@ -240,7 +242,7 @@ Yhourstat(void *process)
for (int hourot = 0; hourot < MaxHours; ++hourot)
if (hourot_nsets[hourot])
{
const int nsets = hourot_nsets[hourot];
const auto nsets = hourot_nsets[hourot];
for (int recID = 0; recID < maxrecs; recID++)
{
if (recList[recID].lconst) continue;
......
......@@ -92,7 +92,6 @@ addOperators(void)
void *
Ymonarith(void *process)
{
int nrecs;
int varID, levelID;
const char *seas_names[4];
......@@ -136,9 +135,12 @@ Ymonarith(void *process)
FieldVector2D vars2[MaxMonths];
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
while (true)
{
int mon = getMonthIndex(taxisInqVdate(taxisID2));
const auto nrecs = cdoStreamInqTimestep(streamID2, tsID);
if (nrecs == 0) break;
auto mon = getMonthIndex(taxisInqVdate(taxisID2));
if (opertype == SEASONAL) mon = monthToSeason(mon + 1);
if (vars2[mon].size()) alreadyAllocated(opertype == SEASONAL, mon, seas_names);
......@@ -156,8 +158,11 @@ Ymonarith(void *process)
}
tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
auto mon = getMonthIndex(taxisInqVdate(taxisID1));
if (opertype == SEASONAL) mon = monthToSeason(mon + 1);
if (vars2[mon].size() == 0) notFound(opertype == SEASONAL, mon, seas_names);
......
......@@ -36,7 +36,6 @@ Ymonpctl(void *process)
{
constexpr int MaxMonths = 17;
size_t nmiss;
int nrecs;
int64_t vdates1[MaxMonths] = { 0 }, vdates2[MaxMonths] = { 0 };
int vtimes1[MaxMonths] = { 0 };
long nsets[MaxMonths] = { 0 };
......@@ -87,8 +86,11 @@ Ymonpctl(void *process)
field.resize(gridsizemax);
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID2, tsID);
if (nrecs == 0) break;
if (nrecs != cdoStreamInqTimestep(streamID3, tsID))
cdoAbort("Number of records at time step %d of %s and %s differ!", tsID + 1, cdoGetStreamName(1), cdoGetStreamName(2));
......@@ -138,8 +140,11 @@ Ymonpctl(void *process)
}
tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto vdate = taxisInqVdate(taxisID1);
const auto vtime = taxisInqVtime(taxisID1);
......
......@@ -36,7 +36,6 @@ void *
Yseaspctl(void *process)
{
constexpr int MaxSeasons = 4;
int nrecs;
size_t nmiss;
long nsets[MaxSeasons] = { 0 };
CdoDateTime datetime1[MaxSeasons], datetime2[MaxSeasons];
......@@ -87,8 +86,11 @@ Yseaspctl(void *process)
field.resize(gridsizemax);
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID2, tsID);
if (nrecs == 0) break;
if (nrecs != cdoStreamInqTimestep(streamID3, tsID))
cdoAbort("Number of records at time step %d of %s and %s differ!", tsID + 1, cdoGetStreamName(1), cdoGetStreamName(2));
......@@ -137,8 +139,11 @@ Yseaspctl(void *process)
}
tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto vdate = taxisInqVdate(taxisID1);
const auto vtime = taxisInqVtime(taxisID1);
......
......@@ -58,7 +58,6 @@ void *
Yseasstat(void *process)
{
constexpr int MaxSeasons = 4;
int nrecs;
int seas_nsets[MaxSeasons] = { 0 };
CdoDateTime datetime[MaxSeasons];
FieldVector2D vars1[MaxSeasons], vars2[MaxSeasons], samp1[MaxSeasons];
......@@ -102,8 +101,11 @@ Yseasstat(void *process)
int tsID = 0;
int otsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto vdate = taxisInqVdate(taxisID1);
const auto vtime = taxisInqVtime(taxisID1);
......
......@@ -66,7 +66,6 @@ Zonstat(void *process)
int gridID1 = -1, gridID2 = -1;
int zongridID = -1;
int index;
int nrecs;
int varID, levelID;
cdoInitialize(process);
......@@ -76,7 +75,7 @@ Zonstat(void *process)
const auto operatorID = cdoOperatorID();
const auto operfunc = cdoOperatorF1(operatorID);
double pn = 0;
double pn = 0.0;
if (operfunc == func_pctl)
{
operatorInputArg("percentile number");
......@@ -165,8 +164,11 @@ Zonstat(void *process)
field2.grid = gridID2;
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
taxisCopyTimestep(taxisID2, taxisID1);
cdoDefTimestep(streamID2, tsID);
......
......@@ -56,10 +56,12 @@ cdo_read_timestepmask(const char *maskfile, std::vector<bool> &imask)
n = nts;
imask.resize(nts);
int nrecs;
int tsID = 0;
while ((nrecs = streamInqTimestep(streamID, tsID)))
while (true)
{
auto nrecs = streamInqTimestep(streamID, tsID);
if (nrecs == 0) break;
if (nrecs != 1) cdoAbort("Internal error; unexprected number of records!");
int varID, levelID;
......
......@@ -45,11 +45,9 @@ eca1(const ECA_REQUEST_1 *request)
char indate1[DATE_LEN + 1], indate2[DATE_LEN + 1];
int64_t ivdate = 0, ovdate = 0, indate21 = 0;
int ivtime = 0, ovtime = 0;
int nrecs;
int levelID;
int itsID;
int otsID;
long nsets;
const auto cmplen = DATE_LEN - cdoOperatorF2(operatorID);
......@@ -148,9 +146,13 @@ eca1(const ECA_REQUEST_1 *request)
otsID = 0;
while (true)
{
nsets = 0;
while ((nrecs = cdoStreamInqTimestep(istreamID, itsID)) > 0)
int nrecs = 0;
long nsets = 0;
while (true)
{
nrecs = cdoStreamInqTimestep(istreamID, itsID);
if (nrecs == 0) break;
ivdate = taxisInqVdate(itaxisID);
ivtime = taxisInqVtime(itaxisID);
......@@ -368,11 +370,9 @@ eca2(const ECA_REQUEST_2 *request)
char indate1[DATE_LEN + 1], indate2[DATE_LEN + 1];
int64_t ivdate = 0, ovdate = 0, indate21 = 0;
int ivtime = 0, ovtime = 0;
int nrecs;
int varID, levelID;
int itsID;
int otsID;
long nsets;
const auto cmplen = DATE_LEN - cdoOperatorF2(operatorID);
......@@ -478,8 +478,11 @@ eca2(const ECA_REQUEST_2 *request)
}
}
itsID = 0;
while ((nrecs = cdoStreamInqTimestep(istreamID2, itsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(istreamID2, itsID);
if (nrecs == 0) break;
ivdate = taxisInqVdate(vlistInqTaxis(ivlistID2));
const auto dayoy = decodeDayOfYear(ivdate);
......@@ -505,9 +508,13 @@ eca2(const ECA_REQUEST_2 *request)
otsID = 0;
while (true)
{
nsets = 0;
while ((nrecs = cdoStreamInqTimestep(istreamID1, itsID)) > 0)
int nrecs = 0;
long nsets = 0;
while (true)
{
nrecs = cdoStreamInqTimestep(istreamID1, itsID);
if (nrecs == 0) break;
ivdate = taxisInqVdate(itaxisID1);
ivtime = taxisInqVtime(itaxisID1);
......@@ -733,11 +740,9 @@ eca3(const ECA_REQUEST_3 *request)
int ivtime1 = 0, ivtime2 = 0;
int64_t ovdate = 0;
int ovtime = 0;
int nrecs;
int varID, levelID;
int itsID;
int otsID;
long nsets;