Commit e8a341ba authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Fix implicit conversions.

parent 80ba8063
......@@ -16,7 +16,7 @@
#define FAIL_ON_GRIB_ERROR(function, gribHandle, key, ...) do\
{\
int errorCode = function(gribHandle, key, __VA_ARGS__);\
int errorCode = (int)function(gribHandle, key, __VA_ARGS__); \
if(errorCode)\
{\
fprintf(stderr, "%s:%d: Error in function `%s`: `%s` returned error code %d for key \"%s\"", __FILE__, __LINE__, __func__, #function, errorCode, key);\
......@@ -211,13 +211,13 @@ static int addSecondsToDate(struct tm* me, long long amount)
//It is irrelevant here whether days are zero or one based, the correction would have be undone again so that it is effectless.
long long seconds = ((me->tm_mday*24ll + me->tm_hour)*60 + me->tm_min)*60 + me->tm_sec; //The portion of the date that uses fixed increments.
seconds += amount;
me->tm_mday = seconds/24/60/60;
seconds -= me->tm_mday*24*60*60;
me->tm_hour = seconds/60/60;
seconds -= me->tm_hour*60*60;
me->tm_min = seconds/60;
seconds -= me->tm_min*60;
me->tm_sec = seconds;
me->tm_mday = (int)(seconds / 24 / 60 / 60);
seconds -= (long long)me->tm_mday * 24 * 60 * 60;
me->tm_hour = (int)(seconds / 60 / 60);
seconds -= (long long)me->tm_hour * 60 * 60;
me->tm_min = (int)(seconds / 60);
seconds -= (long long)(me->tm_min * 60);
me->tm_sec = (int)seconds;
return normalizeDays(me);
}
......@@ -225,9 +225,9 @@ static void addMonthsToDate(struct tm* me, long long amount)
{
long long months = me->tm_year*12ll + me->tm_mon;
months += amount;
me->tm_year = months/12;
months -= me->tm_year*12;
me->tm_mon = months;
me->tm_year = (int)(months/12);
months -= (long long)me->tm_year*12;
me->tm_mon = (int)months;
}
//unit is a value according to code table 4.4 of the GRIB2 specification, returns non-zero on error
......@@ -289,19 +289,19 @@ char* gribMakeTimeString(grib_handle* gh, bool getEndTime)
{
//Get the parts of the reference date.
struct tm date = {
.tm_mon = gribGetLong(gh, "month") - 1, //months are zero based in struct tm and one based in GRIB
.tm_mday = gribGetLong(gh, "day"),
.tm_hour = gribGetLong(gh, "hour"),
.tm_min = gribGetLong(gh, "minute")
.tm_mon = (int)gribGetLong(gh, "month") - 1, //months are zero based in struct tm and one based in GRIB
.tm_mday = (int)gribGetLong(gh, "day"),
.tm_hour = (int)gribGetLong(gh, "hour"),
.tm_min = (int)gribGetLong(gh, "minute")
};
if(gribEditionNumber(gh) == 1)
{
date.tm_year = gribGetLong(gh, "yearOfCentury"); //years are -1900 based both in struct tm and GRIB1
date.tm_year = (int)gribGetLong(gh, "yearOfCentury"); //years are -1900 based both in struct tm and GRIB1
}
else
{
date.tm_year = gribGetLong(gh, "year") - 1900; //years are -1900 based in struct tm and zero based in GRIB2
date.tm_sec = gribGetLong(gh, "second");
date.tm_year = (int)gribGetLong(gh, "year") - 1900; //years are -1900 based in struct tm and zero based in GRIB2
date.tm_sec = (int)gribGetLong(gh, "second");
//Determine whether we have a forecast time and a time range.
bool haveForecastTime, haveTimeRange;
......@@ -612,14 +612,14 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
long lpar;
FAIL_ON_GRIB_ERROR(grib_get_long, gh, "Nx", &lpar);
nlon = lpar;
nlon = (int)lpar;
FAIL_ON_GRIB_ERROR(grib_get_long, gh, "Ny", &lpar);
nlat = lpar;
nlat = (int)lpar;
if ( numberOfPoints != nlon*nlat )
Error("numberOfPoints (%d) and gridSize (%d) differ!", (int)numberOfPoints, nlon*nlat);
grid->size = numberOfPoints;
grid->size = (int)numberOfPoints;
grid->xsize = nlon;
grid->ysize = nlat;
......
......@@ -199,7 +199,7 @@ static const unsigned char* positionOfGribMarker(const unsigned char* data, size
{
for(const unsigned char* currentPosition = data, *end = data + size; currentPosition < end; currentPosition++)
{
currentPosition = memchr(currentPosition, 'G', size - (currentPosition - data) - 3); //-3 to ensure that we don't overrun the buffer during the strncmp() call.
currentPosition = memchr(currentPosition, 'G', size - (size_t)(currentPosition - data) - 3); //-3 to ensure that we don't overrun the buffer during the strncmp() call.
if(!currentPosition) return NULL;
if(!strncmp((const char*)currentPosition, "GRIB", 4)) return currentPosition;
}
......@@ -218,19 +218,19 @@ static ssize_t scanToGribMarker(CdiGribIterator* me)
scanSize = me->bufferSize;
if(scannedBytes + scanSize > kMaxScanSize) scanSize = kMaxScanSize - scannedBytes;
assert(scanSize <= me->bufferSize);
int status = cdiInputFile_read(me->file, me->fileOffset + scannedBytes, scanSize, &scanSize, me->gribBuffer);
int status = cdiInputFile_read(me->file, me->fileOffset + (off_t)scannedBytes, scanSize, &scanSize, me->gribBuffer);
if(status != CDI_NOERR && status != CDI_EEOF) return status;
const unsigned char* startPosition = positionOfGribMarker(me->gribBuffer, scanSize);
if(startPosition)
{
return me->fileOffset + scannedBytes + (startPosition - me->gribBuffer);
return (ssize_t)(me->fileOffset + (off_t)scannedBytes + (off_t)(startPosition - me->gribBuffer));
}
//Get the offset for the next iteration if there is a next iteration.
scanSize -= 3; //so that we won't miss a 'GRIB' sequence that happens to be cut off
scannedBytes += scanSize;
scannedBytes &= ~0xf; //make 16 bytes aligned
scannedBytes &= ~(size_t)0xf; //make 16 bytes aligned
}
return -1;
}
......@@ -305,7 +305,7 @@ static int readMessage(CdiGribIterator* me)
{
//Destroy the old grib_handle.
if(me->gribHandle) grib_handle_delete(me->gribHandle), me->gribHandle = NULL;
me->fileOffset += me->curRecordSize;
me->fileOffset += (off_t)me->curRecordSize;
//Find the next record and determine its size.
ssize_t gribFileOffset = scanToGribMarker(me);
......@@ -364,13 +364,13 @@ int cdiGribIterator_levelType(CdiIterator* super, int levelSelector, char** outN
int zaxisType = ZAXIS_GENERIC;
if(gribEditionNumber(me->gribHandle) <= 1)
{
int levelType = gribGetLongDefault(me->gribHandle, "indicatorOfTypeOfLevel", 255);
int levelType = (int)gribGetLongDefault(me->gribHandle, "indicatorOfTypeOfLevel", 255);
if(levelSelector && !isGrib1DualLevel(levelType)) levelType = 255;
zaxisType = grib1ltypeToZaxisType(levelType);
}
else
{
int levelType = gribGetLongDefault(me->gribHandle, levelSelector ? "typeOfSecondFixedSurface" : "typeOfFirstFixedSurface", 255);
int levelType = (int)gribGetLongDefault(me->gribHandle, levelSelector ? "typeOfSecondFixedSurface" : "typeOfFirstFixedSurface", 255);
zaxisType = grib2ltypeToZaxisType(levelType);
}
......@@ -394,13 +394,13 @@ static double logicalLevelValue2(long gribType, long storedValue, long power)
case GRIB2_LTYPE_LANDDEPTH:
case GRIB2_LTYPE_ISOBARIC:
case GRIB2_LTYPE_SIGMA:
return storedValue*(1000/factor); //The evaluation order allows the factors of ten to cancel out before rounding.
return (double)storedValue * (1000.0/factor); //The evaluation order allows the factors of ten to cancel out before rounding.
case 255:
return 0;
default:
return storedValue/factor;
return (double)storedValue/factor;
}
}
......@@ -426,8 +426,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 = grib_get_double_element(gribHandle, "pv", value*2 , outValue1))) return status;
if((status = grib_get_double_element(gribHandle, "pv", value*2 + 1, outValue2))) return status;
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;
break;
}
......@@ -466,17 +466,17 @@ int cdiGribIterator_level(CdiIterator* super, int levelSelector, double* outValu
long levelType = (uint8_t)gribGetLongDefault(me->gribHandle, "indicatorOfTypeOfLevel", -1); //1 byte
if(levelType == 255)
{}
else if(isGrib1DualLevel(levelType))
else if(isGrib1DualLevel((int)levelType))
{
*outValue1 = gribGetLongDefault(me->gribHandle, (levelSelector ? "bottomLevel" : "topLevel"), 0);
*outValue1 = (double)gribGetLongDefault(me->gribHandle, (levelSelector ? "bottomLevel" : "topLevel"), 0);
}
else if(levelType == 100)
{
*outValue1 = 100*gribGetLongDefault(me->gribHandle, "level", 0); //2 bytes
*outValue1 = 100 * (double)gribGetLongDefault(me->gribHandle, "level", 0); //2 bytes
}
else
{
*outValue1 = gribGetLongDefault(me->gribHandle, "level", 0); //2 bytes
*outValue1 = (double)gribGetLongDefault(me->gribHandle, "level", 0); //2 bytes
}
}
return CDI_NOERR;
......@@ -522,7 +522,7 @@ void cdiGribIterator_readField(CdiIterator* super, double* buffer, size_t* nmiss
long gridType = gribGetLong(me->gribHandle, "gridDefinitionTemplateNumber");
if(nmiss)
{
*nmiss = (gridType >= 50 && gridType <= 53) ? 0 : (int)gribGetLong(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.
}
}
......@@ -533,7 +533,7 @@ void cdiGribIterator_readFieldF(CdiIterator* super, float* buffer, size_t* nmiss
size_t valueCount = gribGetArraySize(me->gribHandle, "values");
double* temp = malloc(valueCount*sizeof(*temp));
cdiGribIterator_readField(super, temp, nmiss);
for(size_t i = valueCount; i--; ) buffer[i] = temp[i];
for(size_t i = valueCount; i--; ) buffer[i] = (float)temp[i];
free(temp);
}
......@@ -573,7 +573,7 @@ void cdiGribIterator_delete(CdiGribIterator* me)
*/
int cdiGribIterator_inqEdition(CdiGribIterator* me)
{
return gribEditionNumber(me->gribHandle);
return (int)gribEditionNumber(me->gribHandle);
}
/**
......
Supports Markdown
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