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

zaxisCompare: check levels pointer (bug fix).

parent 8742878d
......@@ -2,9 +2,6 @@
# include "config.h"
#endif
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include "cdi.h"
#include "cdi_int.h"
......@@ -74,7 +71,7 @@ typedef struct
int comptype; // compression type
int complevel; // compression level
short timave;
short lmissval;
bool lmissval;
double missval;
char *name;
char *stdname;
......@@ -98,9 +95,8 @@ static vartable_t *vartable;
static unsigned varTablesize = 0;
static unsigned nvars = 0;
static void
paramInitEntry(unsigned varID, int param)
static
void paramInitEntry(unsigned varID, int param)
{
vartable[varID].param = param;
vartable[varID].prec = 0;
......@@ -124,7 +120,7 @@ paramInitEntry(unsigned varID, int param)
vartable[varID].productDefinitionTemplate = UNDEFID;
vartable[varID].comptype = CDI_COMPRESS_NONE;
vartable[varID].complevel = 1;
vartable[varID].lmissval = 0;
vartable[varID].lmissval = false;
vartable[varID].missval = 0;
vartable[varID].name = NULL;
vartable[varID].stdname = NULL;
......@@ -143,7 +139,7 @@ varGetEntry(int param, int zaxistype, int ltype1, int tsteptype, const char *nam
{
/* testing for "param" implicitly checks if we are beyond the
* current vartable size: */
if (vartable[varID].param == param)
if ( vartable[varID].param == param )
{
int no_of_tiles = -1;
if ( tiles ) no_of_tiles = tiles->numberOfTiles;
......@@ -309,7 +305,7 @@ static int levelNewEntry(unsigned varID, int level1, int level2, int tileID)
/*
If the table overflows, double its size.
*/
if( levelID == levelTableSize )
if ( levelID == levelTableSize )
{
levelTable = (leveltable_t *) Realloc(levelTable,
(size_t)(levelTableSize *= 2)
......@@ -374,7 +370,7 @@ paramNewEntry(int param)
{
vartable = (vartable_t *) Realloc(vartable, (size_t)(varTablesize *= 2)
* sizeof (vartable_t));
for( unsigned i = varID; i < varTablesize; i++ )
for ( unsigned i = varID; i < varTablesize; i++ )
{
vartable[i].param = UNDEF_PARAM;
vartable[i].opt_grib_kvpair = NULL;
......@@ -422,6 +418,7 @@ int varInsertTileSubtype(vartable_t *vptr, const var_tile_t *tiles)
subtypeDestroyPtr(subtype_ptr);
return vptr->tiles->nentries - 1;
}
return CDI_UNDEFID;
}
......@@ -478,11 +475,12 @@ void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds,
int this_tile = varInsertTileSubtype(&vartable[varID], tiles);
int tileID = tileGetEntry(varID, this_tile);
if ( tile_index ) (*tile_index) = this_tile;
if (tileID == CDI_UNDEFID) {
tileID = tileNewEntry((int)varID);
vartable[varID].recordTable[tileID].subtypeIndex = this_tile;
vartable[varID].nsubtypes++;
}
if ( tileID == CDI_UNDEFID )
{
tileID = tileNewEntry((int)varID);
vartable[varID].recordTable[tileID].subtypeIndex = this_tile;
vartable[varID].nsubtypes++;
}
/* append current level to level table info */
int levelID = levelNewEntry(varID, level1, level2, tileID);
......@@ -864,21 +862,16 @@ void varDefZAxisReference(int nhlev, int nvgrid, unsigned char uuid[CDI_UUID_SIZ
bool zaxisCompare(int zaxisID, int zaxistype, int nlevels, bool lbounds, const double *levels, const char *longname, const char *units, int ltype1)
{
bool differ = true;
bool zlbounds = false;
bool ltype_is_equal = false;
if ( ltype1 == zaxisInqLtype(zaxisID) ) ltype_is_equal = true;
bool ltype_is_equal = (ltype1 == zaxisInqLtype(zaxisID));
if ( ltype_is_equal && (zaxistype == zaxisInqType(zaxisID) || zaxistype == ZAXIS_GENERIC) )
{
if ( zaxisInqLbounds(zaxisID, NULL) > 0 ) zlbounds = true;
bool zlbounds = (zaxisInqLbounds(zaxisID, NULL) > 0);
if ( nlevels == zaxisInqSize(zaxisID) && zlbounds == lbounds )
{
char zlongname[CDI_MAX_NAME];
char zunits[CDI_MAX_NAME];
const double *dlevels = zaxisInqLevelsPtr(zaxisID);
if ( dlevels )
if ( dlevels && levels )
{
int levelID;
for ( levelID = 0; levelID < nlevels; levelID++ )
......@@ -886,23 +879,24 @@ bool zaxisCompare(int zaxisID, int zaxistype, int nlevels, bool lbounds, const d
if ( fabs(dlevels[levelID] - levels[levelID]) > 1.e-9 )
break;
}
if ( levelID == nlevels ) differ = false;
}
if ( ! differ )
{
zaxisInqLongname(zaxisID, zlongname);
zaxisInqUnits(zaxisID, zunits);
if ( longname && zlongname[0] )
{
if ( strcmp(longname, zlongname) != 0 ) differ = true;
}
if ( units && zunits[0] )
{
if ( strcmp(units, zunits) != 0 ) differ = true;
}
}
if ( longname )
{
char zlongname[CDI_MAX_NAME];
zaxisInqLongname(zaxisID, zlongname);
if ( zlongname[0] && strcmp(longname, zlongname) != 0 ) differ = true;
}
if ( units )
{
char zunits[CDI_MAX_NAME];
zaxisInqUnits(zaxisID, zunits);
if ( zunits[0] && strcmp(units, zunits) != 0 ) differ = true;
}
}
}
}
......@@ -957,7 +951,7 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, const double *levels, b
{
zaxisID = vlistptr->zaxisIDs[index];
if ( zaxisCompare(zaxisID, zaxistype, nlevels, lbounds, levels, longname, units, ltype1) == false )
if ( !zaxisCompare(zaxisID, zaxistype, nlevels, lbounds, levels, longname, units, ltype1) )
{
zaxisdefined = true;
break;
......@@ -1021,7 +1015,7 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, const double *levels, b
void varDefMissval(int varID, double missval)
{
vartable[varID].lmissval = 1;
vartable[varID].lmissval = true;
vartable[varID].missval = missval;
}
......
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