Commit 7b2d5597 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Timstat2: cleanup.

parent 8bd5ebed
......@@ -51,10 +51,10 @@ correlation(size_t gridsize, double missval1, double missval2, size_t *nofvals,
double *work3, double *work4)
{
size_t nmiss = 0;
double cor;
for (size_t i = 0; i < gridsize; ++i)
{
double cor;
const auto nvals = nofvals[i];
if (nvals > 0)
{
......@@ -67,10 +67,7 @@ correlation(size_t gridsize, double missval1, double missval2, size_t *nofvals,
const auto temp6 = MULMN(temp4, temp5);
cor = DIVMN(temp1, SQRTMN(temp6));
if (cor < -1)
cor = -1;
else if (cor > 1)
cor = 1;
cor = std::min(std::max(cor, -1.0), 1.0);
if (DBL_IS_EQUAL(cor, missval1)) nmiss++;
}
......@@ -107,10 +104,10 @@ static size_t
covariance(size_t gridsize, double missval1, double missval2, size_t *nofvals, double *work0, double *work1, double *work2)
{
size_t nmiss = 0;
double covar;
for (size_t i = 0; i < gridsize; ++i)
{
double covar;
const auto nvals = nofvals[i];
if (nvals > 0)
{
......@@ -227,16 +224,18 @@ Timstat2(void *process)
cdoReadRecord(streamID1, &array1[0], &nmiss);
cdoReadRecord(streamID2, &array2[0], &nmiss);
auto &rwork = work[varID][levelID];
auto &rnofvals = nofvals[varID][levelID];
if (operfunc == func_cor)
{
correlationInit(gridsize, &array1[0], &array2[0], missval1, missval2, &nofvals[varID][levelID][0],
&work[varID][levelID][0][0], &work[varID][levelID][1][0], &work[varID][levelID][2][0],
&work[varID][levelID][3][0], &work[varID][levelID][4][0]);
correlationInit(gridsize, array1.data(), array2.data(), missval1, missval2, rnofvals.data(),
rwork[0].data(), rwork[1].data(), rwork[2].data(), rwork[3].data(), rwork[4].data());
}
else if (operfunc == func_covar)
{
covarianceInit(gridsize, &array1[0], &array2[0], missval1, missval2, &nofvals[varID][levelID][0],
&work[varID][levelID][0][0], &work[varID][levelID][1][0], &work[varID][levelID][2][0]);
covarianceInit(gridsize, array1.data(), array2.data(), missval1, missval2, rnofvals.data(),
rwork[0].data(), rwork[1].data(), rwork[2].data());
}
}
......@@ -257,20 +256,22 @@ Timstat2(void *process)
const auto missval1 = varList1[varID].missval;
const auto missval2 = varList2[varID].missval;
auto &rwork = work[varID][levelID];
auto &rnofvals = nofvals[varID][levelID];
if (operfunc == func_cor)
{
nmiss = correlation(gridsize, missval1, missval2, &nofvals[varID][levelID][0], &work[varID][levelID][0][0],
&work[varID][levelID][1][0], &work[varID][levelID][2][0], &work[varID][levelID][3][0],
&work[varID][levelID][4][0]);
nmiss = correlation(gridsize, missval1, missval2, rnofvals.data(), rwork[0].data(),
rwork[1].data(), rwork[2].data(), rwork[3].data(), rwork[4].data());
}
else if (operfunc == func_covar)
{
nmiss = covariance(gridsize, missval1, missval2, &nofvals[varID][levelID][0], &work[varID][levelID][0][0],
&work[varID][levelID][1][0], &work[varID][levelID][2][0]);
nmiss = covariance(gridsize, missval1, missval2, rnofvals.data(), rwork[0].data(),
rwork[1].data(), rwork[2].data());
}
cdoDefRecord(streamID3, varID, levelID);
cdoWriteRecord(streamID3, &work[varID][levelID][0][0], nmiss);
cdoWriteRecord(streamID3, rwork[0].data(), nmiss);
}
cdoStreamClose(streamID3);
......
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