Commit 03ac5f68 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Sortierung nach levels fuer Pressure-ZAxis (patch from Thomas Jahns)

parent 9d1f9bf9
......@@ -2,6 +2,7 @@
# include "config.h"
#endif
#include <stdbool.h>
#include <string.h>
#include <math.h>
......@@ -538,34 +539,36 @@ void cdi_generate_vars(stream_t *streamptr)
if ( nlevels > 1 )
{
int linc = FALSE, ldec = FALSE, lsort = FALSE;
/* check increasing of levels */
for ( levelID = 1; levelID < nlevels; levelID++ )
if ( dlevels[levelID] < dlevels[levelID-1] ) break;
if ( levelID == nlevels ) linc = TRUE;
/* check decreasing of levels */
bool linc = false, ldec = false, lsort = false;
for ( levelID = 1; levelID < nlevels; levelID++ )
if ( dlevels[levelID] > dlevels[levelID-1] ) break;
if ( levelID == nlevels ) ldec = TRUE;
if ( linc == FALSE )
{
if ( ldec == FALSE && zaxistype == ZAXIS_PRESSURE )
{
qsort(vartable[varid].levelTable, nlevels, sizeof(leveltable_t), cmpLevelTableInv);
lsort = TRUE;
}
else if ( ldec == FALSE ||
zaxistype == ZAXIS_HYBRID ||
zaxistype == ZAXIS_DEPTH_BELOW_LAND )
{
qsort(vartable[varid].levelTable, nlevels, sizeof(leveltable_t), cmpLevelTable);
lsort = TRUE;
}
}
{
/* check increasing of levels */
linc &= (dlevels[levelID] > dlevels[levelID-1]);
/* check decreasing of levels */
ldec &= (dlevels[levelID] < dlevels[levelID-1]);
}
/*
* always sort pressure z-axis to ensure
* vartable[varid].levelTable[levelID1].level1 < vartable[varid].levelTable[levelID2].level1 <=> levelID1 > levelID2
* unless already sorted in decreasing order
*/
if ( !ldec && zaxistype == ZAXIS_PRESSURE )
{
qsort(vartable[varid].levelTable, (size_t)nlevels, sizeof(leveltable_t), cmpLevelTableInv);
lsort = true;
}
/*
* always sort hybrid and depth-below-land z-axis to ensure
* vartable[varid].levelTable[levelID1].level1 < vartable[varid].levelTable[levelID2].level1 <=> levelID1 < levelID2
* unless already sorted in increasing order
*/
else if ( (!linc && !ldec) ||
zaxistype == ZAXIS_HYBRID ||
zaxistype == ZAXIS_DEPTH_BELOW_LAND )
{
qsort(vartable[varid].levelTable, (size_t)nlevels, sizeof(leveltable_t), cmpLevelTable);
lsort = true;
}
if ( lsort )
{
......@@ -587,7 +590,7 @@ void cdi_generate_vars(stream_t *streamptr)
dlevels2 = (double *) malloc(nlevels*sizeof(double));
for ( levelID = 0; levelID < nlevels; levelID++ )
dlevels2[levelID] = level_sf*vartable[varid].levelTable[levelID].level2;
}
}
char *unitptr = cdiUnitNamePtr(vartable[varid].level_unit);
zaxisID = varDefZaxis(vlistID, zaxistype, nlevels, dlevels, lbounds, dlevels1, dlevels2,
......
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