Commit 13d6a27b authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Ydrunstat.cc: refactored

parent 3d02a9ce
......@@ -67,8 +67,6 @@ ydstatUpdate(YDAY_STATS &stats, int64_t vdate, int vtime, const FieldVector2D &v
{
bool lvarstd = vars2.size();
const auto nvars = vlistNvars(stats.vlist);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day %d out of range!", dayoy);
......@@ -81,6 +79,7 @@ ydstatUpdate(YDAY_STATS &stats, int64_t vdate, int vtime, const FieldVector2D &v
if (lvarstd) fieldsFromVlist(stats.vlist, stats.vars2[dayoy], FIELD_VEC);
}
const auto nvars = vlistNvars(stats.vlist);
for (int varID = 0; varID < nvars; varID++)
{
if (vlistInqVarTimetype(stats.vlist, varID) == TIME_CONSTANT) continue;
......@@ -120,48 +119,38 @@ ydstatUpdate(YDAY_STATS &stats, int64_t vdate, int vtime, const FieldVector2D &v
static void
ydstatFinalize(YDAY_STATS &stats, int operfunc)
{
int varID, levelID, nlevels;
const bool lmean = operfunc == func_mean || operfunc == func_avg;
const bool lstd = operfunc == func_std || operfunc == func_std1;
const bool lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
const int divisor = operfunc == func_std1 || operfunc == func_var1;
const auto nvars = vlistNvars(stats.vlist);
for (int dayoy = 0; dayoy < MaxDays; dayoy++)
if (stats.nsets[dayoy])
{
switch (operfunc)
const auto nvars = vlistNvars(stats.vlist);
for (int varID = 0; varID < nvars; varID++)
{
case func_avg:
case func_mean:
for (varID = 0; varID < nvars; varID++)
{
if (vlistInqVarTimetype(stats.vlist, varID) == TIME_CONSTANT) continue;
nlevels = zaxisInqSize(vlistInqVarZaxis(stats.vlist, varID));
for (levelID = 0; levelID < nlevels; levelID++)
vfarcdiv(stats.vars1[dayoy][varID][levelID], (double) stats.nsets[dayoy]);
}
break;
case func_std:
case func_std1:
for (varID = 0; varID < nvars; varID++)
{
if (vlistInqVarTimetype(stats.vlist, varID) == TIME_CONSTANT) continue;
nlevels = zaxisInqSize(vlistInqVarZaxis(stats.vlist, varID));
for (levelID = 0; levelID < nlevels; levelID++)
vfarcstd(stats.vars1[dayoy][varID][levelID], stats.vars2[dayoy][varID][levelID], stats.nsets[dayoy], divisor);
}
break;
if (vlistInqVarTimetype(stats.vlist, varID) == TIME_CONSTANT) continue;
case func_var:
case func_var1:
for (varID = 0; varID < nvars; varID++)
const auto nlevels = zaxisInqSize(vlistInqVarZaxis(stats.vlist, varID));
for (int levelID = 0; levelID < nlevels; levelID++)
{
if (vlistInqVarTimetype(stats.vlist, varID) == TIME_CONSTANT) continue;
nlevels = zaxisInqSize(vlistInqVarZaxis(stats.vlist, varID));
for (levelID = 0; levelID < nlevels; levelID++)
vfarcvar(stats.vars1[dayoy][varID][levelID], stats.vars2[dayoy][varID][levelID], stats.nsets[dayoy], divisor);
auto nsets = stats.nsets[dayoy];
auto &rvars1 = stats.vars1[dayoy][varID][levelID];
if (lmean)
{
vfarcdiv(rvars1, (double) nsets);
}
else if (lvarstd)
{
auto &rvars2 = stats.vars2[dayoy][varID][levelID];
if (lstd)
vfarcstd(rvars1, rvars2, nsets, divisor);
else
vfarcvar(rvars1, rvars2, nsets, divisor);
}
}
break;
}
}
}
......
Markdown is supported
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