Commit 8ac59aa8 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Perform redundant query only once.

parent ecd9f736
......@@ -133,13 +133,15 @@ void streamWriteVarF(int streamID, int varID, const float *data, int nmiss)
int (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype, const void *data, int nmiss)
= (int (*)(int, int, int, const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_).func;
if ( myCdiStreamWriteVar_(streamID, varID, MEMTYPE_FLOAT, (const void *) data, nmiss) )
{
// In case the file format does not support single precision writing,
// we fall back to double precision writing, converting the data on the fly.
size_t elementCount = (size_t) gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
elementCount *= (size_t) zaxisInqSize(vlistInqVarZaxis(streamInqVlist(streamID), varID));
// we fall back to double precision writing, converting the data
// on the fly.
int vlistID = streamInqVlist(streamID);
size_t elementCount = (size_t) gridInqSize(vlistInqVarGrid(vlistID, varID));
elementCount *= (size_t) zaxisInqSize(vlistInqVarZaxis(vlistID, varID));
double *conversionBuffer = (double *) Malloc(elementCount*sizeof(*conversionBuffer));
for ( size_t i = elementCount; i--; ) conversionBuffer[i] = (double) data[i];
myCdiStreamWriteVar_(streamID, varID, MEMTYPE_DOUBLE, (const void *) conversionBuffer, nmiss);
......
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