Commit 148480cf authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

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

parents 499a0f60 34fee212
......@@ -42,7 +42,7 @@ bool CDI_netcdf_lazy_grid_load = false;
char *cdiPartabPath = NULL;
int cdiPartabIntern = 1;
double CDO_default_missval = -9.E33;
double CDI_default_missval = -9.E33;
double CDI_grid_missval = -9999.;
static const char Filetypes[][9] = {
......@@ -114,7 +114,7 @@ cdiPrintDefaults(void)
"default modelID : %d\n"
"default tableID : %d\n"
"default missval : %g\n", cdiDefaultInstID,
cdiDefaultModelID, cdiDefaultTableID, CDO_default_missval);
cdiDefaultModelID, cdiDefaultTableID, CDI_default_missval);
}
void cdiPrintVersion(void)
......@@ -361,7 +361,7 @@ void cdiInitialize(void)
if ( value >= 0 ) CDI_netcdf_hdr_pad = (size_t) value;
envstr = getenv("CDI_MISSVAL");
if ( envstr ) CDO_default_missval = atof(envstr);
if ( envstr ) CDI_default_missval = atof(envstr);
/*
envstr = getenv("NC_MISSING_VALUE");
if ( envstr ) cdiNcMissingValue = atoi(envstr);
......@@ -491,7 +491,7 @@ void cdiDefMissval(double missval)
{
cdiInitialize();
CDO_default_missval = missval;
CDI_default_missval = missval;
}
......@@ -499,7 +499,7 @@ double cdiInqMissval(void)
{
cdiInitialize();
return CDO_default_missval;
return CDI_default_missval;
}
......@@ -507,7 +507,7 @@ double cdiInqGridMissval(void)
{
cdiInitialize();
return CDO_default_missval;
return CDI_default_missval;
}
/*
......
......@@ -325,7 +325,7 @@ extern int cdiDebugExt;
extern int CDI_Debug; /* If set to 1, debuggig (default 0) */
extern int CDI_Recopt;
extern int cdiGribApiDebug;
extern double CDO_default_missval;
extern double CDI_default_missval;
extern double CDI_grid_missval;
extern int cdiDefaultInstID;
extern int cdiDefaultModelID;
......
......@@ -577,7 +577,7 @@ void cdiGribIterator_readField(CdiIterator *super, double *buffer, size_t *nmiss
{
CdiGribIterator *me = (CdiGribIterator*)(void *)super;
GRIB_CHECK(my_grib_set_double(me->gribHandle, "missingValue", CDO_default_missval), 0);
GRIB_CHECK(my_grib_set_double(me->gribHandle, "missingValue", CDI_default_missval), 0);
gribGetDoubleArray(me->gribHandle, "values", buffer);
long gridType = gribGetLong(me->gribHandle, "gridDefinitionTemplateNumber");
if(nmiss)
......
......@@ -1833,7 +1833,7 @@ streamPack(void * streamptr, void * packBuffer, int packBufferSize,
uint32_t d = cdiCheckSum(CDI_DATATYPE_INT, streamNint, intBuffer);
serializePack(&d, 1, CDI_DATATYPE_UINT32, packBuffer, packBufferSize, packBufferPos, context);
serializePack(&CDO_default_missval, 1, CDI_DATATYPE_FLT64, packBuffer, packBufferSize, packBufferPos, context);
serializePack(&CDI_default_missval, 1, CDI_DATATYPE_FLT64, packBuffer, packBufferSize, packBufferPos, context);
serializePack(streamP->filename, intBuffer[2], CDI_DATATYPE_TXT, packBuffer, packBufferSize, packBufferPos, context);
d = cdiCheckSum(CDI_DATATYPE_TXT, intBuffer[2], streamP->filename);
serializePack(&d, 1, CDI_DATATYPE_UINT32, packBuffer, packBufferSize, packBufferPos, context);
......@@ -1854,7 +1854,7 @@ streamUnpack(char * unpackBuffer, int unpackBufferSize,
xassert(cdiCheckSum(CDI_DATATYPE_INT, streamNint, intBuffer) == d);
serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
&CDO_default_missval, 1, CDI_DATATYPE_FLT64, context);
&CDI_default_missval, 1, CDI_DATATYPE_FLT64, context);
serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
&filename, intBuffer[2], CDI_DATATYPE_TXT, context);
serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
......
......@@ -459,40 +459,43 @@ void gribapiGetKeys(grib_handle *gh, int varID)
}
long section2Length;
grib_get_long(gh, "section2Length", &section2Length);
if ( section2Length > 0 )
int status = grib_get_long(gh, "section2Length", &section2Length);
if (status == 0 && section2Length > 0)
{
long grib2LocalSectionNumber;
long mpimType, mpimClass, mpimUser;
grib_get_long(gh, "grib2LocalSectionNumber", &grib2LocalSectionNumber);
size_t section2PaddingLength = 0;
int status = grib_get_size(gh, "section2Padding", &section2PaddingLength);
if ( status == 0 && section2PaddingLength > 0 )
status = grib_get_long(gh, "grib2LocalSectionNumber", &grib2LocalSectionNumber);
if (status == 0)
{
varDefKeyInt(varID, CDI_KEY_GRIB2LOCALSECTIONNUMBER, (int) grib2LocalSectionNumber);
varDefKeyInt(varID, CDI_KEY_SECTION2PADDINGLENGTH, (int) section2PaddingLength);
unsigned char *section2Padding = (unsigned char*) Malloc(section2PaddingLength);
grib_get_bytes(gh, "section2Padding", section2Padding, &section2PaddingLength);
varDefKeyBytes(varID, CDI_KEY_SECTION2PADDING, section2Padding, (int)section2PaddingLength);
Free(section2Padding);
size_t section2PaddingLength = 0;
status = grib_get_size(gh, "section2Padding", &section2PaddingLength);
if (status == 0 && section2PaddingLength > 0)
{
varDefKeyInt(varID, CDI_KEY_GRIB2LOCALSECTIONNUMBER, (int) grib2LocalSectionNumber);
varDefKeyInt(varID, CDI_KEY_SECTION2PADDINGLENGTH, (int) section2PaddingLength);
unsigned char *section2Padding = (unsigned char*) Malloc(section2PaddingLength);
grib_get_bytes(gh, "section2Padding", section2Padding, &section2PaddingLength);
varDefKeyBytes(varID, CDI_KEY_SECTION2PADDING, section2Padding, (int)section2PaddingLength);
Free(section2Padding);
}
else if ( grib_get_long(gh, "mpimType", &mpimType) == 0 &&
grib_get_long(gh, "mpimClass", &mpimClass) == 0 &&
grib_get_long(gh, "mpimUser", &mpimUser) == 0)
{
varDefKeyInt(varID, CDI_KEY_MPIMTYPE, mpimType);
varDefKeyInt(varID, CDI_KEY_MPIMCLASS, mpimClass);
varDefKeyInt(varID, CDI_KEY_MPIMUSER, mpimUser);
size_t revNumLen = 20;
unsigned char revNumber[revNumLen];
if ( grib_get_bytes(gh, "revNumber", revNumber, &revNumLen) == 0 )
varDefKeyBytes(varID, CDI_KEY_REVNUMBER, revNumber, (int)revNumLen);
long revStatus;
grib_get_long(gh, "revStatus", &revStatus);
varDefKeyInt(varID, CDI_KEY_REVSTATUS, revStatus);
}
}
else if ( grib_get_long(gh, "mpimType", &mpimType) == 0 &&
grib_get_long(gh, "mpimClass", &mpimClass) == 0 &&
grib_get_long(gh, "mpimUser", &mpimUser) == 0)
{
varDefKeyInt(varID, CDI_KEY_MPIMTYPE, mpimType);
varDefKeyInt(varID, CDI_KEY_MPIMCLASS, mpimClass);
varDefKeyInt(varID, CDI_KEY_MPIMUSER, mpimUser);
size_t revNumLen = 20;
unsigned char revNumber[revNumLen];
if ( grib_get_bytes(gh, "revNumber", revNumber, &revNumLen) == 0 )
varDefKeyBytes(varID, CDI_KEY_REVNUMBER, revNumber, (int)revNumLen);
long revStatus;
grib_get_long(gh, "revStatus", &revStatus);
varDefKeyInt(varID, CDI_KEY_REVSTATUS, revStatus);
}
}
}
......@@ -604,17 +607,8 @@ void gribapiAddRecord(stream_t *streamptr, int param, grib_handle *gh,
record->gridsize = gribapiGetGridsize(gh);
record->tiles = tiles ? *tiles : dummy_tiles;
//FIXME: This may leave the variable name unterminated (which is the behavior that I found in the code).
// I don't know precisely how this field is used, so I did not change this behavior to avoid regressions,
// but I think that it would be better to at least add a line
//
// record->varname[sizeof(record->varname) - 1] = 0;`
//
// after the `strncpy()` call.
//
// I would consider using strdup() (that requires POSIX-2008 compliance, though), or a similar homebrew approach.
// I. e. kick the fixed size array and allocate enough space, whatever that may be.
strncpy(record->varname, varname, sizeof(record->varname));
strncpy(record->varname, varname, sizeof(record->varname)-1);
record->varname[sizeof(record->varname) - 1] = 0;
grid_t *grid = (grid_t *)Malloc(sizeof(*grid));
gribapiGetGrid(gh, grid);
......@@ -955,7 +949,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
gh = gribapiGetDiskRepresentation(recsize, &buffersize, &gribbuffer, &datatype, &comptype, &unzipsize);
nrecs_scanned++;
GRIB_CHECK(my_grib_set_double(gh, "missingValue", CDO_default_missval), 0);
GRIB_CHECK(my_grib_set_double(gh, "missingValue", CDI_default_missval), 0);
int param = gribapiGetParam(gh);
int leveltype1 = -1, leveltype2 = -1, lbounds, level_sf, level_unit;
......@@ -1168,7 +1162,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
nrecs_scanned++;
gh = grib_handle_new_from_message(NULL, gribbuffer, recsize);
GRIB_CHECK(my_grib_set_double(gh, "missingValue", CDO_default_missval), 0);
GRIB_CHECK(my_grib_set_double(gh, "missingValue", CDI_default_missval), 0);
int param = gribapiGetParam(gh);
int level1 = 0, level2 = 0, leveltype1, leveltype2, lbounds, level_sf, level_unit;
......@@ -1398,7 +1392,7 @@ int gribapiScanTimestep(stream_t * streamptr)
nrecs_scanned++;
gh = grib_handle_new_from_message(NULL, gribbuffer, recsize);
GRIB_CHECK(my_grib_set_double(gh, "missingValue", CDO_default_missval), 0);
GRIB_CHECK(my_grib_set_double(gh, "missingValue", CDI_default_missval), 0);
int param = gribapiGetParam(gh);
int level1 = 0, level2 = 0, leveltype1, leveltype2 = -1, lbounds, level_sf, level_unit;
......
......@@ -52,8 +52,7 @@ int recordNewEntry(stream_t *streamptr, int tsID)
}
else
{
while ( recordID < recordSize
&& records[recordID].used != CDI_UNDEFID )
while ( recordID < recordSize && records[recordID].used != CDI_UNDEFID )
++recordID;
}
/*
......@@ -67,8 +66,7 @@ int recordNewEntry(stream_t *streamptr, int tsID)
recordSize = INT_MAX;
else
Error("Cannot handle this many records!\n");
records = (record_t *) Realloc(records,
recordSize * sizeof (record_t));
records = (record_t *) Realloc(records, recordSize * sizeof (record_t));
for ( size_t i = recordID; i < recordSize; i++ )
records[i].used = CDI_UNDEFID;
......
......@@ -535,83 +535,61 @@ int cmpLevelTableInv(const void* s1, const void* s2)
}
struct paraminfo
{
int varid, param, ltype;
};
static
int cmp_param(const void* s1, const void* s2)
void varCopyKeys(int vlistID, int varID)
{
const struct paraminfo *x = (const struct paraminfo*) s1;
const struct paraminfo *y = (const struct paraminfo*) s2;
int cmp = (( x->param > y->param ) - ( x->param < y->param )) * 2
+ ( x->ltype > y->ltype ) - ( x->ltype < y->ltype );
return cmp;
cdi_keys_t *keysp = &(vartable[varID].keys);
cdiCopyVarKeys(keysp, vlistID, varID);
}
struct varinfo
struct cdi_generate_varinfo
{
int varid;
const char *name;
};
/*
static
int cmp_varname(const void *s1, const void *s2)
{
const struct varinfo *x = (const struct varinfo *)s1,
*y = (const struct varinfo *)s2;
return strcmp(x->name, y->name);
}
*/
static
int cmp_varname(const void *s1, const void *s2)
int cdi_generate_cmp_varname(const void *s1, const void *s2)
{
const vartable_t *x = (const vartable_t *)s1,
*y = (const vartable_t *)s2;
const struct cdi_generate_varinfo *x = (const struct cdi_generate_varinfo *)s1,
*y = (const struct cdi_generate_varinfo *)s2;
return strcmp(x->name, y->name);
}
void varCopyKeys(int vlistID, int varID)
{
cdi_keys_t *keysp = &(vartable[varID].keys);
cdiCopyVarKeys(keysp, vlistID, varID);
}
void cdi_generate_vars(stream_t *streamptr)
{
int vlistID = streamptr->vlistID;
int *varids = (int *) Malloc(varTableUsed*sizeof(int));
for ( size_t varID = 0; varID < varTableUsed; varID++ ) varids[varID] = (int)varID;
/*
if ( streamptr->sortparam )
if ( streamptr->sortname )
{
struct paraminfo *varInfo = (struct paraminfo *) Malloc((size_t)varTableUsed * sizeof(struct paraminfo));
size_t varID;
for ( varID = 0; varID < varTableUsed; varID++ )
if (!vartable[varID].name) break;
for ( unsigned varID = 0; varID < varTableUsed; varID++ )
{
varInfo[varID].varid = varids[varID];
varInfo[varID].param = vartable[varID].param;
varInfo[varID].ltype = vartable[varID].ltype1;
}
qsort(varInfo, (size_t)varTableUsed, sizeof(struct paraminfo), cmp_param);
for ( unsigned varID = 0; varID < varTableUsed; varID++ )
{
varids[varID] = varInfo[varID].varid;
}
Free(varInfo);
}
if ( varID == varTableUsed )
{
struct cdi_generate_varinfo *varInfo
= (struct cdi_generate_varinfo *) Malloc((size_t)varTableUsed * sizeof(struct cdi_generate_varinfo));
if ( streamptr->sortname )
{
qsort(vartable, (size_t)varTableUsed, sizeof(vartable_t), cmp_varname);
for ( size_t varID = 0; varID < varTableUsed; varID++ )
{
varInfo[varID].varid = varids[varID];
varInfo[varID].name = vartable[varids[varID]].name;
}
qsort(varInfo, varTableUsed, sizeof(varInfo[0]), cdi_generate_cmp_varname);
for ( size_t varID = 0; varID < varTableUsed; varID++ )
{
varids[varID] = varInfo[varID].varid;
}
Free(varInfo);
}
}
*/
for ( size_t index = 0; index < varTableUsed; index++ )
{
int varid = varids[index];
......@@ -830,10 +808,8 @@ void cdi_generate_vars(stream_t *streamptr)
unsigned nsub = vartable[varid].nsubtypes >= 0 ? (unsigned)vartable[varid].nsubtypes : 0U;
for ( size_t isub = 0; isub < nsub; isub++ )
{
sleveltable_t *restrict streamRecordTable
= streamptr->vars[index].recordTable + isub;
leveltable_t *restrict vartableLevelTable
= vartable[varid].recordTable[isub].levelTable;
sleveltable_t *restrict streamRecordTable = streamptr->vars[index].recordTable + isub;
leveltable_t *restrict vartableLevelTable = vartable[varid].recordTable[isub].levelTable;
for ( unsigned levelID = 0; levelID < nlevels; levelID++ )
{
streamRecordTable->recordID[levelID] = vartableLevelTable[levelID].recID;
......
......@@ -36,7 +36,7 @@ void vlistvarInitEntry(int vlistID, int varID)
vlistptr->vars[varID].modelID = CDI_UNDEFID;
vlistptr->vars[varID].tableID = CDI_UNDEFID;
vlistptr->vars[varID].missvalused = false;
vlistptr->vars[varID].missval = CDO_default_missval;
vlistptr->vars[varID].missval = CDI_default_missval;
vlistptr->vars[varID].addoffset = 0.0;
vlistptr->vars[varID].scalefactor = 1.0;
vlistptr->vars[varID].name = NULL;
......
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