Commit a9d61320 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

ensavg: use fldavg().

parent c0aa8bdb
......@@ -195,24 +195,13 @@ void *Ensstat(void *argument)
for ( int recID = 0; recID < nrecs0; recID++ )
{
int varID = 0, levelID;
/*
#if defined(_OPENMP)
#pragma omp parallel for default(none) shared(ef, nfiles) lastprivate(varID, levelID)
#endif
for ( int fileID = 0; fileID < nfiles; fileID++ )
{
int nmiss;
streamInqRecord(ef[fileID].streamID, &varID, &levelID);
streamReadRecord(ef[fileID].streamID, ef[fileID].array, &nmiss);
ef[fileID].missval = vlistInqVarMissval(ef[fileID].vlistID, varID);
}
*/
for ( int fileID = 0; fileID < nfiles; fileID++ )
{
streamInqRecord(ef[fileID].streamID, &varID, &levelID);
ef[fileID].missval = vlistInqVarMissval(ef[fileID].vlistID, varID);
}
#pragma omp parallel for default(none) shared(ef, nfiles)
//#pragma omp parallel for default(none) shared(ef, nfiles)
for ( int fileID = 0; fileID < nfiles; fileID++ )
{
streamReadRecord(ef[fileID].streamID, ef[fileID].array, &ef[fileID].nmiss);
......
......@@ -341,32 +341,26 @@ double fldavg(field_type field)
const double missval1 = field.missval;
const double missval2 = field.missval;
const double *restrict array = field.ptr;
const double *restrict w = field.weight;
double rsum = 0, rsumw = 0;
double ravg = 0;
assert(array!=NULL);
assert(w!=NULL);
if ( nmiss )
{
for ( size_t i = 0; i < len; i++ )
if ( !DBL_IS_EQUAL(w[i], missval1) )
{
rsum = ADDMN(rsum, MULMN(w[i], array[i]));
rsumw = ADDMN(rsumw, w[i]);
}
for ( size_t i = 0; i < len; ++i )
{
rsum = ADDMN(rsum, array[i]);
rsumw += 1;
}
ravg = DIVMN(rsum, rsumw);
}
else
{
for ( size_t i = 0; i < len; i++ )
{
rsum += w[i] * array[i];
rsumw += w[i];
}
int fpeRaised = array_mean_val(len, array, &ravg);
}
double ravg = DIVMN(rsum, rsumw);
return ravg;
}
......
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