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

Merge branch 'develop' of git.mpimet.mpg.de:libcdi into develop

parents 37085fd4 230236fa
......@@ -2401,7 +2401,7 @@ bool cdf_read_coordinates(struct cdfLazyGrid *restrict lazyGrid, ncvar_t *ncvar,
}
static
bool cdf_set_unstructured_par(ncvar_t *ncvar, grid_t *grid, int xdimid, int ydimid, int number_of_grid_used, unsigned char *uuidOfHGrid)
bool cdf_set_unstructured_par(ncvar_t *ncvar, grid_t *grid, int *xdimid, int *ydimid, int number_of_grid_used, unsigned char *uuidOfHGrid)
{
int ndims = ncvar->ndims;
int *dimtype = ncvar->dimtype;
......@@ -2416,20 +2416,20 @@ bool cdf_set_unstructured_par(ncvar_t *ncvar, grid_t *grid, int xdimid, int ydim
else if ( dimtype[i] == Z_AXIS ) zdimid = ncvar->dimids[i];
}
if ( xdimid != UNDEFID && ydimid != UNDEFID && zdimid == UNDEFID )
if ( *xdimid != UNDEFID && *ydimid != UNDEFID && zdimid == UNDEFID )
{
if ( grid->x.size > grid->y.size && grid->y.size < 1000 )
{
dimtype[ydimidx] = Z_AXIS;
ydimid = UNDEFID;
*ydimid = UNDEFID;
grid->size = grid->x.size;
grid->y.size = 0;
}
else if ( grid->y.size > grid->x.size && grid->x.size < 1000 )
{
dimtype[xdimidx] = Z_AXIS;
xdimid = ydimid;
ydimid = UNDEFID;
*xdimid = *ydimid;
*ydimid = UNDEFID;
grid->size = grid->y.size;
grid->x.size = grid->y.size;
grid->y.size = 0;
......@@ -2479,10 +2479,10 @@ void cdf_set_grid_to_similar_vars(ncvar_t *ncvar1, ncvar_t *ncvar2, int gridtype
int xdimidx = UNDEFID, ydimidx = UNDEFID;
int ndims2 = ncvar2->ndims;
int *dimtype2 = ncvar2->dimtype;
int *dimids2 = ncvar2->dimids;
for ( int i = 0; i < ndims2; i++ )
{
int *dimtype2 = ncvar2->dimtype;
int *dimids2 = ncvar2->dimids;
if ( dimtype2[i] == X_AXIS ) { xdimid2 = dimids2[i]; xdimidx = i; }
else if ( dimtype2[i] == Y_AXIS ) { ydimid2 = dimids2[i]; ydimidx = i; }
else if ( dimtype2[i] == Z_AXIS ) { zdimid2 = dimids2[i]; }
......@@ -2504,12 +2504,11 @@ void cdf_set_grid_to_similar_vars(ncvar_t *ncvar1, ncvar_t *ncvar2, int gridtype
}
}
if ( xdimid == xdimid2 &&
(ydimid == ydimid2 || (xdimid == ydimid && ydimid2 == UNDEFID)) )
if ( xdimid == xdimid2 && (ydimid == ydimid2 || (xdimid == ydimid && ydimid2 == UNDEFID)) )
{
bool same_grid = ncvar1->xvarid == ncvar2->xvarid
&& ncvar1->yvarid == ncvar2->yvarid
&& ncvar1->position == ncvar2->position;
&& ncvar1->yvarid == ncvar2->yvarid
&& ncvar1->position == ncvar2->position;
/*
if ( xvarid != -1 && ncvar2->xvarid != UNDEFID &&
xvarid != ncvar2->xvarid ) same_grid = false;
......@@ -2595,11 +2594,13 @@ void cdf_define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
timedimid, xvarid, yvarid, xsize, ysize, &vdimid) )
continue;
if ( number_of_grid_used != UNDEFID && (grid->type == UNDEFID || grid->type == GRID_GENERIC) )
if ( number_of_grid_used != UNDEFID &&
(grid->type == UNDEFID || grid->type == GRID_GENERIC) &&
xdimid != UNDEFID && xsize > 9999 )
grid->type = GRID_UNSTRUCTURED;
if ( grid->type == GRID_UNSTRUCTURED )
if ( cdf_set_unstructured_par(ncvar, grid, xdimid, ydimid, number_of_grid_used, uuidOfHGrid) )
if ( cdf_set_unstructured_par(ncvar, grid, &xdimid, &ydimid, number_of_grid_used, uuidOfHGrid) )
continue;
if ( lproj && lgrid )
......
......@@ -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