Skip to content
Snippets Groups Projects
Commit fe7594f6 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel: Committed by Sergey Kosukhin
Browse files

Use pointer to existing array instead of array copy.

parent 0b645c75
No related branches found
No related tags found
2 merge requests!34Version 2.2.0,!13Consolidation with CDI-PIO (develop)
......@@ -1220,14 +1220,18 @@ cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int *ncvaridp, int zaxisI
int nvdimID = CDI_UNDEFID;
double *buffer = (double *) malloc(4 * dimlen * sizeof(double));
double *levels = buffer;
double *lbounds = buffer + 2 * dimlen;
double *ubounds = buffer + 3 * dimlen;
double *restrict levels;
if (zaxisInqLevels(zaxisID, NULL))
zaxisInqLevels(zaxisID, levels);
bool hasLevels = zaxisInqLevels(zaxisID, NULL) != 0;
if (hasLevels)
levels = (double *) zaxisInqLevelsPtr(zaxisID);
else
for (size_t i = 0; i < dimlen; ++i) levels[i] = i + 1;
{
levels = (double *) Malloc(sizeof(*levels) * dimlen);
for (size_t i = 0; i < dimlen; ++i) levels[i] = (double) (i + 1);
}
if (zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL))
{
......@@ -1281,6 +1285,7 @@ cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int *ncvaridp, int zaxisI
streamptr->ncmode = 2;
cdf_put_var_double(fileID, ncvarid, levels);
if (!hasLevels) Free(levels);
if (p0varid != CDI_UNDEFID) cdf_put_var_double(fileID, p0varid, &p0value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment