Commit 52fa38cb authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Fix implicit conversions.

parent 9235f599
...@@ -26,9 +26,9 @@ void gribapiLibraryVersion(int* major_version, int* minor_version, int* revision ...@@ -26,9 +26,9 @@ void gribapiLibraryVersion(int* major_version, int* minor_version, int* revision
{ {
#if defined (HAVE_LIBGRIB_API) #if defined (HAVE_LIBGRIB_API)
long version = grib_get_api_version(); long version = grib_get_api_version();
(*major_version) = version/10000; (*major_version) = (int)(version/10000);
(*minor_version) = (version-(*major_version)*10000)/100; (*minor_version) = (int)((version-(*major_version)*10000)/100);
(*revision_version) = (version-(*major_version)*10000-(*minor_version)*100); (*revision_version) = (int)(version-(*major_version)*10000-(*minor_version)*100);
#else #else
(*major_version) = 0; (*major_version) = 0;
(*minor_version) = 0; (*minor_version) = 0;
......
...@@ -331,7 +331,7 @@ static ...@@ -331,7 +331,7 @@ static
int calcLevel(int level_sf, long factor, long level) int calcLevel(int level_sf, long factor, long level)
{ {
double result = 0; double result = 0;
if(level != GRIB_MISSING_LONG) result = level*grib2ScaleFactor(factor); if(level != GRIB_MISSING_LONG) result = (double)level*grib2ScaleFactor(factor);
if(level_sf) result *= level_sf; if(level_sf) result *= level_sf;
return (int)result; return (int)result;
} }
...@@ -488,19 +488,19 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, ...@@ -488,19 +488,19 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
case ZAXIS_HYBRID: case ZAXIS_HYBRID:
case ZAXIS_HYBRID_HALF: case ZAXIS_HYBRID_HALF:
{ {
int vctsize; size_t vctsize;
size_t dummy; size_t dummy;
double *vctptr; double *vctptr;
GRIB_CHECK(grib_get_long(gh, "NV", &lpar), 0); GRIB_CHECK(grib_get_long(gh, "NV", &lpar), 0);
/* FIXME: assert(lpar >= INT_MIN && lpar <= INT_MAX) */ /* FIXME: assert(lpar >= 0) */
vctsize = (int)lpar; vctsize = (size_t)lpar;
if ( vctsize > 0 ) if ( vctsize > 0 )
{ {
vctptr = (double *) malloc(vctsize*sizeof(double)); vctptr = (double *) malloc(vctsize*sizeof(double));
dummy = (size_t)vctsize; dummy = vctsize;
GRIB_CHECK(grib_get_double_array(gh, "pv", vctptr, &dummy), 0); GRIB_CHECK(grib_get_double_array(gh, "pv", vctptr, &dummy), 0);
varDefVCT((size_t)vctsize, vctptr); varDefVCT(vctsize, vctptr);
free(vctptr); free(vctptr);
} }
break; break;
...@@ -716,7 +716,7 @@ static void ensureBufferSize(size_t requiredSize, size_t* curSize, unsigned char ...@@ -716,7 +716,7 @@ static void ensureBufferSize(size_t requiredSize, size_t* curSize, unsigned char
} }
static static
grib_handle* gribapiGetDiskRepresentation(long recsize, size_t* buffersize, unsigned char** gribbuffer, int* outDatatype, int* outCompressionType, long* outUnzipsize) grib_handle* gribapiGetDiskRepresentation(size_t recsize, size_t* buffersize, unsigned char** gribbuffer, int* outDatatype, int* outCompressionType, long* outUnzipsize)
{ {
int lieee = FALSE; int lieee = FALSE;
...@@ -736,10 +736,10 @@ grib_handle* gribapiGetDiskRepresentation(long recsize, size_t* buffersize, unsi ...@@ -736,10 +736,10 @@ grib_handle* gribapiGetDiskRepresentation(long recsize, size_t* buffersize, unsi
} }
else else
{ {
if( gribGetZip(recsize, *gribbuffer, outUnzipsize) > 0 ) if( gribGetZip((long)recsize, *gribbuffer, outUnzipsize) > 0 )
{ {
*outCompressionType = COMPRESS_SZIP; *outCompressionType = COMPRESS_SZIP;
ensureBufferSize(*outUnzipsize + 100, buffersize, gribbuffer); ensureBufferSize((size_t)*outUnzipsize + 100, buffersize, gribbuffer);
} }
else else
{ {
...@@ -964,10 +964,10 @@ int gribapiScanTimestep1(stream_t * streamptr) ...@@ -964,10 +964,10 @@ int gribapiScanTimestep1(stream_t * streamptr)
{ {
streamptr->tsteps[0].recordSize = nrecords; streamptr->tsteps[0].recordSize = nrecords;
streamptr->tsteps[0].records = streamptr->tsteps[0].records =
(record_t *) realloc(streamptr->tsteps[0].records, nrecords*sizeof(record_t)); (record_t *)xrealloc(streamptr->tsteps[0].records, (size_t)nrecords*sizeof(record_t));
} }
streamptr->tsteps[0].recIDs = (int *) malloc(nrecords*sizeof(int)); streamptr->tsteps[0].recIDs = (int *)xmalloc((size_t)nrecords*sizeof(int));
streamptr->tsteps[0].nrecs = nrecords; streamptr->tsteps[0].nrecs = nrecords;
for ( int recID = 0; recID < nrecords; recID++ ) for ( int recID = 0; recID < nrecords; recID++ )
streamptr->tsteps[0].recIDs[recID] = recID; streamptr->tsteps[0].recIDs[recID] = recID;
...@@ -1039,7 +1039,7 @@ int gribapiScanTimestep2(stream_t * streamptr) ...@@ -1039,7 +1039,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
cdi_create_records(streamptr, tsID); cdi_create_records(streamptr, tsID);
int nrecords = streamptr->tsteps[tsID].nallrecs; int nrecords = streamptr->tsteps[tsID].nallrecs;
streamptr->tsteps[1].recIDs = (int *) malloc(nrecords*sizeof(int)); streamptr->tsteps[1].recIDs = (int *) malloc((size_t)nrecords*sizeof(int));
streamptr->tsteps[1].nrecs = 0; streamptr->tsteps[1].nrecs = 0;
for ( recID = 0; recID < nrecords; recID++ ) for ( recID = 0; recID < nrecords; recID++ )
streamptr->tsteps[1].recIDs[recID] = -1; streamptr->tsteps[1].recIDs[recID] = -1;
...@@ -1070,7 +1070,8 @@ int gribapiScanTimestep2(stream_t * streamptr) ...@@ -1070,7 +1070,8 @@ int gribapiScanTimestep2(stream_t * streamptr)
if ( rstatus ) break; if ( rstatus ) break;
long unzipsize; long unzipsize;
if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 ) ensureBufferSize(unzipsize + 100, &buffersize, &gribbuffer); if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 )
ensureBufferSize((size_t)unzipsize + 100, &buffersize, &gribbuffer);
nrecs_scanned++; nrecs_scanned++;
gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize); gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize);
...@@ -1259,7 +1260,7 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1259,7 +1260,7 @@ int gribapiScanTimestep(stream_t * streamptr)
nrecs = streamptr->tsteps[1].nrecs; nrecs = streamptr->tsteps[1].nrecs;
streamptr->tsteps[tsID].nrecs = nrecs; streamptr->tsteps[tsID].nrecs = nrecs;
streamptr->tsteps[tsID].recIDs = (int *) malloc(nrecs*sizeof(int)); streamptr->tsteps[tsID].recIDs = (int *) malloc((size_t)nrecs*sizeof(int));
for ( recID = 0; recID < nrecs; recID++ ) for ( recID = 0; recID < nrecs; recID++ )
streamptr->tsteps[tsID].recIDs[recID] = streamptr->tsteps[1].recIDs[recID]; streamptr->tsteps[tsID].recIDs[recID] = streamptr->tsteps[1].recIDs[recID];
...@@ -1298,7 +1299,8 @@ int gribapiScanTimestep(stream_t * streamptr) ...@@ -1298,7 +1299,8 @@ int gribapiScanTimestep(stream_t * streamptr)
} }
long unzipsize; long unzipsize;
if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 ) ensureBufferSize(unzipsize + 100, &buffersize, &gribbuffer); if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 )
ensureBufferSize((size_t)unzipsize + 100, &buffersize, &gribbuffer);
nrecs_scanned++; nrecs_scanned++;
gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize); gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize);
...@@ -1949,8 +1951,8 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -1949,8 +1951,8 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
nlon = 0; nlon = 0;
rowlon = (int *) malloc(nlat*sizeof(int)); rowlon = (int *)xmalloc((size_t)nlat*sizeof(int));
pl = (long *) malloc(nlat*sizeof(long)); pl = (long *)xmalloc((size_t)nlat*sizeof(long));
gridInqRowlon(gridID, rowlon); gridInqRowlon(gridID, rowlon);
for ( i = 0; i < nlat; ++i ) pl[i] = rowlon[i]; for ( i = 0; i < nlat; ++i ) pl[i] = rowlon[i];
...@@ -2100,8 +2102,10 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2100,8 +2102,10 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
GRIB_CHECK(my_grib_set_long(gh, "Nx", xsize), 0); GRIB_CHECK(my_grib_set_long(gh, "Nx", xsize), 0);
GRIB_CHECK(my_grib_set_long(gh, "Ny", ysize), 0); GRIB_CHECK(my_grib_set_long(gh, "Ny", ysize), 0);
GRIB_CHECK(my_grib_set_double(gh, "DxInMetres", lround(xincm)), 0); /* FIXME: lround should probably be round here */
GRIB_CHECK(my_grib_set_double(gh, "DyInMetres", lround(yincm)), 0); GRIB_CHECK(my_grib_set_double(gh, "DxInMetres", (double)lround(xincm)), 0);
/* FIXME: lround should probably be round here */
GRIB_CHECK(my_grib_set_double(gh, "DyInMetres", (double)lround(yincm)), 0);
GRIB_CHECK(my_grib_set_double(gh, "longitudeOfFirstGridPointInDegrees", originLon), 0); GRIB_CHECK(my_grib_set_double(gh, "longitudeOfFirstGridPointInDegrees", originLon), 0);
GRIB_CHECK(my_grib_set_double(gh, "latitudeOfFirstGridPointInDegrees", originLat), 0); GRIB_CHECK(my_grib_set_double(gh, "latitudeOfFirstGridPointInDegrees", originLat), 0);
GRIB_CHECK(my_grib_set_double(gh, "LoVInDegrees", lonParY), 0); GRIB_CHECK(my_grib_set_double(gh, "LoVInDegrees", lonParY), 0);
...@@ -2607,7 +2611,7 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI ...@@ -2607,7 +2611,7 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
if ( ! gc->init ) gribapiDefInstitut(gh, vlistID, varID); if ( ! gc->init ) gribapiDefInstitut(gh, vlistID, varID);
if ( ! gc->init ) gribapiDefModel(gh, vlistID, varID); if ( ! gc->init ) gribapiDefModel(gh, vlistID, varID);
if ( ! gc->init ) gribapiDefParam(editionNumber, gh, param, name, stdname); if ( ! gc->init ) gribapiDefParam((int)editionNumber, gh, param, name, stdname);
if ( editionNumber == 2 && (datatype == DATATYPE_FLT32 || datatype == DATATYPE_FLT64) ) lieee = TRUE; if ( editionNumber == 2 && (datatype == DATATYPE_FLT32 || datatype == DATATYPE_FLT64) ) lieee = TRUE;
......
...@@ -920,7 +920,8 @@ ptaxisDefLongname(taxis_t *taxisptr, const char *longname) ...@@ -920,7 +920,8 @@ ptaxisDefLongname(taxis_t *taxisptr, const char *longname)
} }
void cdiDecodeTimevalue(int timeunit, double timevalue, int *days, int *secs) static void
cdiDecodeTimevalue(int timeunit, double timevalue, int *days, int *secs)
{ {
static int lwarn = TRUE; static int lwarn = TRUE;
...@@ -942,7 +943,7 @@ void cdiDecodeTimevalue(int timeunit, double timevalue, int *days, int *secs) ...@@ -942,7 +943,7 @@ void cdiDecodeTimevalue(int timeunit, double timevalue, int *days, int *secs)
{ {
*days = (int) (timevalue/86400); *days = (int) (timevalue/86400);
double seconds = timevalue - *days*86400.; double seconds = timevalue - *days*86400.;
*secs = lround(seconds); *secs = (int)lround(seconds);
if ( *secs < 0 ) { *days -= 1; *secs += 86400; }; if ( *secs < 0 ) { *days -= 1; *secs += 86400; };
/* /*
{ {
...@@ -956,7 +957,7 @@ void cdiDecodeTimevalue(int timeunit, double timevalue, int *days, int *secs) ...@@ -956,7 +957,7 @@ void cdiDecodeTimevalue(int timeunit, double timevalue, int *days, int *secs)
{ {
*days = (int) timevalue; *days = (int) timevalue;
double seconds = (timevalue - *days)*86400; double seconds = (timevalue - *days)*86400;
*secs = lround(seconds); *secs = (int)lround(seconds);
if ( *secs < 0 ) { *days -= 1; *secs += 86400; }; if ( *secs < 0 ) { *days -= 1; *secs += 86400; };
/* /*
{ {
......
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