Commit 2c309907 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

removed unnecessary casts in iterator_grib.c, fixed some warings in cdi.c

parent ca2ffaf8
......@@ -57,7 +57,7 @@ static
void version(void)
{
int filetypes[] = {FILETYPE_SRV, FILETYPE_EXT, FILETYPE_IEG, FILETYPE_GRB, FILETYPE_GRB2, FILETYPE_NC, FILETYPE_NC2, FILETYPE_NC4, FILETYPE_NC4C};
char *typenames[] = { "srv", "ext", "ieg", "grb", "grb2", "nc", "nc2", "nc4", "nc4c"};
const char *typenames[] = { "srv", "ext", "ieg", "grb", "grb2", "nc", "nc2", "nc4", "nc4c"};
fprintf(stderr, "CDI version 1.8\n");
#if defined (COMPILER)
......
......@@ -10,7 +10,7 @@
#include <stdio.h>
#include <sys/types.h>
/*
#if defined(__cplusplus)
#ifdef __cplusplus
extern "C" {
#endif
*/
......@@ -1177,7 +1177,6 @@ int vlistInqVarSubtype(int vlistID, int varID);
void gribapiLibraryVersion(int *major_version, int *minor_version, int *revision_version);
/*
#if defined (__cplusplus)
}
......
......@@ -126,7 +126,7 @@ CdiGribIterator *cdiGribIterator_makeClone(CdiIterator *super)
//Error handling.
deleteGribHandle:
if(result->gribHandle) grib_handle_delete((grib_handle *)result->gribHandle);
if(result->gribHandle) grib_handle_delete(result->gribHandle);
freeBuffer:
free(result->gribBuffer);
freeResult:
......@@ -139,8 +139,8 @@ char *cdiGribIterator_serialize(CdiIterator *super)
{
CdiGribIterator *me = (CdiGribIterator*)super;
const char* path = (char *)cdiInputFile_getPath(me->file);
char* escapedPath = (char *)cdiEscapeSpaces(path);
const char* path = cdiInputFile_getPath(me->file);
char* escapedPath = cdiEscapeSpaces(path);
char* result = (char *)malloc(strlen(escapedPath) + 3 * sizeof(int) * CHAR_BIT/8);
sprintf(result, "%s %zu", escapedPath, me->fileOffset);
free(escapedPath);
......@@ -321,7 +321,7 @@ static void hexdump(void *data, size_t size)
static int readMessage(CdiGribIterator *me)
{
//Destroy the old grib_handle.
if(me->gribHandle) grib_handle_delete((grib_handle *)me->gribHandle), me->gribHandle = NULL;
if(me->gribHandle) grib_handle_delete(me->gribHandle), me->gribHandle = NULL;
me->fileOffset += (off_t)me->curRecordSize;
//Find the next record and determine its size.
......@@ -357,11 +357,11 @@ int cdiGribIterator_nextField(CdiIterator *super)
if(result) return result;
//Get the metadata that's published as variables in the base class.
super->datatype = gribGetDatatype((grib_handle *)me->gribHandle);
super->timesteptype = gribapiGetTsteptype((grib_handle *)me->gribHandle);
cdiDecodeParam(gribapiGetParam((grib_handle *)me->gribHandle), &super->param.number, &super->param.category, &super->param.discipline);
super->datatype = gribGetDatatype(me->gribHandle);
super->timesteptype = gribapiGetTsteptype(me->gribHandle);
cdiDecodeParam(gribapiGetParam(me->gribHandle), &super->param.number, &super->param.category, &super->param.discipline);
grid_t grid;
gribapiGetGrid((grib_handle *)me->gribHandle, &grid);
gribapiGetGrid(me->gribHandle, &grid);
super->gridId = gridGenerate(&grid);
return CDI_NOERR;
......@@ -370,7 +370,7 @@ int cdiGribIterator_nextField(CdiIterator *super)
char *cdiGribIterator_inqTime(CdiIterator *super, bool getEndTime)
{
CdiGribIterator *me = (CdiGribIterator*)super;
return gribMakeTimeString((grib_handle *)me->gribHandle, getEndTime);
return gribMakeTimeString(me->gribHandle, getEndTime);
}
int cdiGribIterator_levelType(CdiIterator *super, int levelSelector, char **outName, char **outLongName, char **outStdName, char **outUnit)
......@@ -379,15 +379,15 @@ int cdiGribIterator_levelType(CdiIterator *super, int levelSelector, char **outN
//First determine the zaxis type corresponding to the given level.
int zaxisType = ZAXIS_GENERIC;
if(gribEditionNumber((grib_handle *)me->gribHandle) <= 1)
if(gribEditionNumber(me->gribHandle) <= 1)
{
int levelType = (int)gribGetLongDefault((grib_handle *)me->gribHandle, "indicatorOfTypeOfLevel", 255);
int levelType = gribGetLongDefault(me->gribHandle, "indicatorOfTypeOfLevel", 255);
if(levelSelector && !isGrib1DualLevel(levelType)) levelType = 255;
zaxisType = grib1ltypeToZaxisType(levelType);
}
else
{
int levelType = (int)gribGetLongDefault((grib_handle *)me->gribHandle, levelSelector ? "typeOfSecondFixedSurface" : "typeOfFirstFixedSurface", 255);
int levelType = gribGetLongDefault(me->gribHandle, levelSelector ? "typeOfSecondFixedSurface" : "typeOfFirstFixedSurface", 255);
zaxisType = grib2ltypeToZaxisType(levelType);
}
......@@ -443,8 +443,8 @@ static int readLevel2(grib_handle *gribHandle, const char *levelTypeKey, const c
int status;
//XXX: I'm not 100% sure about how the coordinate pairs are stored in the file.
// I'm assuming an array of pairs due to the example code in grib_api-1.12.3/examples/F90/set_pv.f90, but that may be wrong.
if((status = (int)grib_get_double_element(gribHandle, "pv", (int)value*2 , outValue1))) return status;
if((status = (int)grib_get_double_element(gribHandle, "pv", (int)value*2 + 1, outValue2))) return status;
if((status = grib_get_double_element(gribHandle, "pv", (int)value*2 , outValue1))) return status;
if((status = grib_get_double_element(gribHandle, "pv", (int)value*2 + 1, outValue2))) return status;
break;
}
......@@ -467,33 +467,33 @@ int cdiGribIterator_level(CdiIterator *super, int levelSelector, double *outValu
if(!outValue2) outValue2 = &trash;
*outValue1 = *outValue2 = 0;
if(gribEditionNumber((grib_handle *)me->gribHandle) > 1)
if(gribEditionNumber(me->gribHandle) > 1)
{
if(levelSelector)
{
return readLevel2((grib_handle *)me->gribHandle, "typeOfFirstFixedSurface", "scaleFactorOfFirstFixedSurface", "scaledValueOfFirstFixedSurface", outValue1, outValue2);
return readLevel2(me->gribHandle, "typeOfFirstFixedSurface", "scaleFactorOfFirstFixedSurface", "scaledValueOfFirstFixedSurface", outValue1, outValue2);
}
else
{
return readLevel2((grib_handle *)me->gribHandle, "typeOfSecondFixedSurface", "scaleFactorOfSecondFixedSurface", "scaledValueOfSecondFixedSurface", outValue1, outValue2);
return readLevel2(me->gribHandle, "typeOfSecondFixedSurface", "scaleFactorOfSecondFixedSurface", "scaledValueOfSecondFixedSurface", outValue1, outValue2);
}
}
else
{
long levelType = (uint8_t)gribGetLongDefault((grib_handle *)me->gribHandle, "indicatorOfTypeOfLevel", -1); //1 byte
long levelType = (uint8_t)gribGetLongDefault(me->gribHandle, "indicatorOfTypeOfLevel", -1); //1 byte
if(levelType == 255)
{}
else if(isGrib1DualLevel((int)levelType))
{
*outValue1 = (double)gribGetLongDefault((grib_handle *)me->gribHandle, (levelSelector ? "bottomLevel" : "topLevel"), 0);
*outValue1 = (double)gribGetLongDefault(me->gribHandle, (levelSelector ? "bottomLevel" : "topLevel"), 0);
}
else if(levelType == 100)
{
*outValue1 = 100 * (double)gribGetLongDefault((grib_handle *)me->gribHandle, "level", 0); //2 bytes
*outValue1 = 100 * (double)gribGetLongDefault(me->gribHandle, "level", 0); //2 bytes
}
else
{
*outValue1 = (double)gribGetLongDefault((grib_handle *)me->gribHandle, "level", 0); //2 bytes
*outValue1 = (double)gribGetLongDefault(me->gribHandle, "level", 0); //2 bytes
}
}
return CDI_NOERR;
......@@ -506,19 +506,19 @@ int cdiGribIterator_zaxisUuid(CdiIterator *super, int *outVgridNumber, int *outL
if(outVgridNumber)
{
long temp;
if(grib_get_long((grib_handle *)me->gribHandle, "numberOfVGridUsed", &temp)) return CDI_EINVAL;
if(grib_get_long(me->gribHandle, "numberOfVGridUsed", &temp)) return CDI_EINVAL;
*outVgridNumber = (int)temp;
}
if(outLevelCount)
{
long temp;
if(grib_get_long((grib_handle *)me->gribHandle, "nlev", &temp)) return CDI_EINVAL;
if(grib_get_long(me->gribHandle, "nlev", &temp)) return CDI_EINVAL;
*outLevelCount = (int)temp;
}
if(outUuid)
{
size_t size = CDI_UUID_SIZE;
if(grib_get_bytes((grib_handle *)me->gribHandle, "uuidOfVGrid", outUuid, &size)) return CDI_EINVAL;
if(grib_get_bytes(me->gribHandle, "uuidOfVGrid", outUuid, &size)) return CDI_EINVAL;
if(size != CDI_UUID_SIZE) return CDI_EUFSTRUCT;
}
......@@ -528,18 +528,18 @@ int cdiGribIterator_zaxisUuid(CdiIterator *super, int *outVgridNumber, int *outL
char *cdiGribIterator_copyVariableName(CdiIterator *super)
{
CdiGribIterator *me = (CdiGribIterator*)super;
return gribCopyString((grib_handle *)me->gribHandle, "shortName");
return gribCopyString(me->gribHandle, "shortName");
}
void cdiGribIterator_readField(CdiIterator *super, double *buffer, size_t *nmiss)
{
CdiGribIterator *me = (CdiGribIterator*)super;
gribGetDoubleArray((grib_handle *)me->gribHandle, "values", buffer);
long gridType = gribGetLong((grib_handle *)me->gribHandle, "gridDefinitionTemplateNumber");
gribGetDoubleArray(me->gribHandle, "values", buffer);
long gridType = gribGetLong(me->gribHandle, "gridDefinitionTemplateNumber");
if(nmiss)
{
*nmiss = (gridType >= 50 && gridType <= 53) ? (size_t)0 : (size_t)gribGetLong((grib_handle *)me->gribHandle, "numberOfMissing"); //The condition excludes harmonic data.
*nmiss = (gridType >= 50 && gridType <= 53) ? (size_t)0 : (size_t)gribGetLong(me->gribHandle, "numberOfMissing"); //The condition excludes harmonic data.
}
}
......@@ -547,7 +547,7 @@ void cdiGribIterator_readFieldF(CdiIterator *super, float *buffer, size_t *nmiss
{
CdiGribIterator *me = (CdiGribIterator*)super;
size_t valueCount = gribGetArraySize((grib_handle *)me->gribHandle, "values");
size_t valueCount = gribGetArraySize(me->gribHandle, "values");
double* temp = (double *)malloc(valueCount*sizeof(*temp));
cdiGribIterator_readField(super, temp, nmiss);
for(size_t i = valueCount; i--; ) buffer[i] = (float)temp[i];
......@@ -597,7 +597,7 @@ void cdiGribIterator_delete(CdiGribIterator *me)
int cdiGribIterator_inqEdition(CdiGribIterator *me)
{
#ifdef HAVE_LIBGRIB_API
return (int)gribEditionNumber((grib_handle *)me->gribHandle);
return (int)gribEditionNumber(me->gribHandle);
#else
(void)me;
xabort("CDI was compiled without GribAPI support, so you can't possibly have a valid CdiGribIterator* to call this function with");
......@@ -621,7 +621,7 @@ int cdiGribIterator_inqEdition(CdiGribIterator *me)
int cdiGribIterator_getLong(CdiGribIterator *me, const char *key, long *result)
{
#ifdef HAVE_LIBGRIB_API
return grib_get_long((grib_handle *)me->gribHandle, key, result);
return grib_get_long(me->gribHandle, key, result);
#else
(void)me;
(void)key;
......@@ -647,7 +647,7 @@ int cdiGribIterator_getLong(CdiGribIterator *me, const char *key, long *result)
int cdiGribIterator_getLength(CdiGribIterator *me, const char *key, size_t *result)
{
#ifdef HAVE_GRIB_GET_LENGTH
return grib_get_length((grib_handle *)me->gribHandle, key, result);
return grib_get_length(me->gribHandle, key, result);
#elif defined(HAVE_LIBGRIB_API)
(void)me;
(void)key;
......@@ -679,7 +679,7 @@ int cdiGribIterator_getLength(CdiGribIterator *me, const char *key, size_t *resu
int cdiGribIterator_getString(CdiGribIterator *me, const char *key, char *result, size_t *length)
{
#ifdef HAVE_LIBGRIB_API
return grib_get_string((grib_handle *)me->gribHandle, key, result, length);
return grib_get_string(me->gribHandle, key, result, length);
#else
(void)me;
(void)key;
......@@ -707,7 +707,7 @@ int cdiGribIterator_getString(CdiGribIterator *me, const char *key, char *result
long cdiGribIterator_inqLongValue(CdiGribIterator *me, const char *key)
{
#ifdef HAVE_LIBGRIB_API
return gribGetLong((grib_handle *)me->gribHandle, key);
return gribGetLong(me->gribHandle, key);
#else
(void)me;
(void)key;
......@@ -734,7 +734,7 @@ long cdiGribIterator_inqLongValue(CdiGribIterator *me, const char *key)
long cdiGribIterator_inqLongDefaultValue(CdiGribIterator *me, const char *key, long defaultValue)
{
#ifdef HAVE_LIBGRIB_API
return gribGetLongDefault((grib_handle *)me->gribHandle, key, defaultValue);
return gribGetLongDefault(me->gribHandle, key, defaultValue);
#else
(void)me;
(void)key;
......@@ -762,7 +762,7 @@ long cdiGribIterator_inqLongDefaultValue(CdiGribIterator *me, const char *key, l
char *cdiGribIterator_inqStringValue(CdiGribIterator *me, const char *key)
{
#ifdef HAVE_LIBGRIB_API
return gribCopyString((grib_handle *)me->gribHandle, key);
return gribCopyString(me->gribHandle, key);
#else
(void)me;
(void)key;
......@@ -787,7 +787,7 @@ char *cdiGribIterator_inqStringValue(CdiGribIterator *me, const char *key)
int cdiGribIterator_getDouble(CdiGribIterator *me, const char *key, double *result)
{
#ifdef HAVE_LIBGRIB_API
return grib_get_double((grib_handle *)me->gribHandle, key, result);
return grib_get_double(me->gribHandle, key, result);
#else
(void)me;
(void)key;
......@@ -813,7 +813,7 @@ int cdiGribIterator_getDouble(CdiGribIterator *me, const char *key, double *resu
int cdiGribIterator_getSize(CdiGribIterator *me, const char *key, size_t *result)
{
#ifdef HAVE_LIBGRIB_API
return grib_get_size((grib_handle *)me->gribHandle, key, result);
return grib_get_size(me->gribHandle, key, result);
#else
(void)me;
(void)key;
......@@ -839,7 +839,7 @@ int cdiGribIterator_getSize(CdiGribIterator *me, const char *key, size_t *result
int cdiGribIterator_getLongArray(CdiGribIterator *me, const char *key, long *result, size_t *size)
{
#ifdef HAVE_LIBGRIB_API
return grib_get_long_array((grib_handle *)me->gribHandle, key, result, size);
return grib_get_long_array(me->gribHandle, key, result, size);
#else
(void)me;
(void)key;
......@@ -866,7 +866,7 @@ int cdiGribIterator_getLongArray(CdiGribIterator *me, const char *key, long *res
int cdiGribIterator_getDoubleArray(CdiGribIterator *me, const char *key, double *result, size_t *size)
{
#ifdef HAVE_LIBGRIB_API
return grib_get_double_array((grib_handle *)me->gribHandle, key, result, size);
return grib_get_double_array(me->gribHandle, key, result, size);
#else
(void)me;
(void)key;
......@@ -894,7 +894,7 @@ int cdiGribIterator_getDoubleArray(CdiGribIterator *me, const char *key, double
double cdiGribIterator_inqDoubleValue(CdiGribIterator *me, const char *key)
{
#ifdef HAVE_LIBGRIB_API
return gribGetDouble((grib_handle *)me->gribHandle, key);
return gribGetDouble(me->gribHandle, key);
#else
(void)me;
(void)key;
......@@ -921,7 +921,7 @@ double cdiGribIterator_inqDoubleValue(CdiGribIterator *me, const char *key)
double cdiGribIterator_inqDoubleDefaultValue(CdiGribIterator *me, const char *key, double defaultValue)
{
#ifdef HAVE_LIBGRIB_API
return gribGetDoubleDefault((grib_handle *)me->gribHandle, key, defaultValue);
return gribGetDoubleDefault(me->gribHandle, key, defaultValue);
#else
(void)me;
(void)key;
......
......@@ -429,7 +429,7 @@ void cdfGetAttDouble(int fileID, int ncvarid, char *attname, int attlen, double
}
static
void cdfGetAttText(int fileID, int ncvarid, char *attname, int attlen, char *atttext)
void cdfGetAttText(int fileID, int ncvarid,const char *attname, int attlen, char *atttext)
{
nc_type atttype;
size_t nc_attlen;
......
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