Commit 3b6b1408 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

replaced NINT() by round()/lround()

parent 2b3fc6cb
......@@ -89,14 +89,6 @@ char *strdup(const char *s);
#endif
#ifndef INT
# define INT(x) ((int)(x))
#endif
#ifndef NINT
# define NINT(x) ((x) < 0 ? (int)((x)-.5) : (int)((x)+.5))
#endif
#define FALSE 0
#define TRUE 1
......
......@@ -2484,8 +2484,6 @@ void decode_double_array_unrolled(const unsigned char * restrict igrib, long jle
#undef _ENABLE_AVX
#undef _ENABLE_SSE4_1
#define NINT(x) ((x) < 0 ? (int)((x)-.5) : (int)((x)+.5))
void confp3(double pval, int *kexp, int *kmant, int kbits, int kround)
{
......@@ -2637,14 +2635,14 @@ void confp3(double pval, int *kexp, int *kmant, int kbits, int kround)
if ( isign == 0 )
*kmant = (int) rpowref;
else
*kmant = NINT(rpowref + 0.5);
*kmant = lround(rpowref + 0.5);
}
else
{
/* Closest number in GRIB format to the original number */
/* (equal to, greater than or less than original number). */
*kmant = NINT(rpowref);
*kmant = lround(rpowref);
}
/* Check that mantissa value does not exceed 24 bits. */
......@@ -2694,14 +2692,14 @@ void confp3(double pval, int *kexp, int *kmant, int kbits, int kround)
if ( isign == 0 )
*kmant = (int) rpowref;
else
*kmant = NINT(rpowref + 0.5);
*kmant = lround(rpowref + 0.5);
}
else
{
/* Closest number in GRIB format to the original number */
/* (equal to, greater or less than original number). */
*kmant = NINT(rpowref);
*kmant = lround(rpowref);
}
/* Repeat calculation (with modified exponent) if still have */
......
......@@ -3436,7 +3436,7 @@ int cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtyp
pdata_sp = mdata_sp;
}
for ( i = 0; i < nvals; i++ ) mdata_sp[i] = NINT(mdata_sp[i]);
for ( i = 0; i < nvals; i++ ) mdata_sp[i] = roundf(mdata_sp[i]);
if ( dtype == DATATYPE_UINT8 )
{
......@@ -3458,7 +3458,7 @@ int cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtyp
pdata_dp = mdata_dp;
}
for ( i = 0; i < nvals; i++ ) mdata_dp[i] = NINT(mdata_dp[i]);
for ( i = 0; i < nvals; i++ ) mdata_dp[i] = round(mdata_dp[i]);
if ( dtype == DATATYPE_UINT8 )
{
......
......@@ -1753,19 +1753,19 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
ISEC2_NumLon = nlon;
ISEC2_NumLat = nlat;
ISEC2_FirstLat = NINT(yfirst*1000);
ISEC2_LastLat = NINT(ylast*1000);
ISEC2_FirstLat = lround(yfirst*1000);
ISEC2_LastLat = lround(ylast*1000);
if ( gridtype == GRID_GAUSSIAN_REDUCED )
{
ISEC2_FirstLon = 0;
ISEC2_LastLon = NINT(1000*(360.-360./(nlat*2)));
ISEC2_LonIncr = NINT(1000*360./(nlat*2));
ISEC2_LastLon = lround(1000*(360.-360./(nlat*2)));
ISEC2_LonIncr = lround(1000*360./(nlat*2));
}
else
{
ISEC2_FirstLon = NINT(xfirst*1000);
ISEC2_LastLon = NINT(xlast*1000);
ISEC2_LonIncr = NINT(xinc*1000);
ISEC2_FirstLon = lround(xfirst*1000);
ISEC2_LastLon = lround(xlast*1000);
ISEC2_LonIncr = lround(xinc*1000);
}
// if ( fabs(xinc*1000 - ISEC2_LonIncr) > FLT_EPSILON ) ISEC2_LonIncr = 0;
......@@ -1778,7 +1778,7 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
}
else
{
ISEC2_LatIncr = NINT(yinc*1000);
ISEC2_LatIncr = lround(yinc*1000);
// if ( fabs(yinc*1000 - ISEC2_LatIncr) > FLT_EPSILON ) ISEC2_LatIncr = 0;
if ( ISEC2_LatIncr < 0 ) ISEC2_LatIncr = -ISEC2_LatIncr;
......@@ -1797,8 +1797,8 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
if ( gridIsRotated(gridID) )
{
ISEC2_LatSP = - NINT(gridInqYpole(gridID) * 1000);
ISEC2_LonSP = NINT((gridInqXpole(gridID) + 180) * 1000);
ISEC2_LatSP = - lround(gridInqYpole(gridID) * 1000);
ISEC2_LonSP = lround((gridInqXpole(gridID) + 180) * 1000);
}
/* East -> West */
......@@ -1824,13 +1824,13 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
ISEC2_GridType = GRIB1_GTYPE_LCC;
ISEC2_NumLon = xsize;
ISEC2_NumLat = ysize;
ISEC2_FirstLon = NINT(originLon * 1000);
ISEC2_FirstLat = NINT(originLat * 1000);
ISEC2_Lambert_Lov = NINT(lonParY * 1000);
ISEC2_Lambert_LatS1 = NINT(lat1 * 1000);
ISEC2_Lambert_LatS2 = NINT(lat2 * 1000);
ISEC2_Lambert_dx = NINT(xincm);
ISEC2_Lambert_dy = NINT(yincm);
ISEC2_FirstLon = lround(originLon * 1000);
ISEC2_FirstLat = lround(originLat * 1000);
ISEC2_Lambert_Lov = lround(lonParY * 1000);
ISEC2_Lambert_LatS1 = lround(lat1 * 1000);
ISEC2_Lambert_LatS2 = lround(lat2 * 1000);
ISEC2_Lambert_dx = lround(xincm);
ISEC2_Lambert_dy = lround(yincm);
ISEC2_Lambert_LatSP = 0;
ISEC2_Lambert_LatSP = 0;
ISEC2_Lambert_ProjFlag = projflag;
......
......@@ -21,8 +21,6 @@
# include "grib_api.h"
#endif
#define NINT(x) ((x) < 0 ? (int)((x)-.5) : (int)((x)+.5))
extern int cdiInventoryMode;
typedef struct {
......@@ -2532,13 +2530,13 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int ljpeg, i
ISEC2_GridType = GRIB2_GTYPE_LCC;
ISEC2_NumLon = xsize;
ISEC2_NumLat = ysize;
ISEC2_FirstLon = NINT(originLon * 1000);
ISEC2_FirstLat = NINT(originLat * 1000);
ISEC2_Lambert_Lov = NINT(lonParY * 1000);
ISEC2_Lambert_LatS1 = NINT(lat1 * 1000);
ISEC2_Lambert_LatS2 = NINT(lat2 * 1000);
ISEC2_Lambert_dx = NINT(xincm);
ISEC2_Lambert_dy = NINT(yincm);
ISEC2_FirstLon = lround(originLon * 1000);
ISEC2_FirstLat = lround(originLat * 1000);
ISEC2_Lambert_Lov = lround(lonParY * 1000);
ISEC2_Lambert_LatS1 = lround(lat1 * 1000);
ISEC2_Lambert_LatS2 = lround(lat2 * 1000);
ISEC2_Lambert_dx = lround(xincm);
ISEC2_Lambert_dy = lround(yincm);
ISEC2_Lambert_LatSP = 0;
ISEC2_Lambert_LatSP = 0;
ISEC2_Lambert_ProjFlag = projflag;
......
......@@ -304,11 +304,11 @@ void iegDefGrid(int *gdb, int gridID)
IEG_G_NumLon(gdb) = nlon;
IEG_G_NumLat(gdb) = nlat;
IEG_G_FirstLat(gdb) = NINT(yfirst*1000);
IEG_G_LastLat(gdb) = NINT(ylast*1000);
IEG_G_FirstLon(gdb) = NINT(xfirst*1000);
IEG_G_LastLon(gdb) = NINT(xlast*1000);
IEG_G_LonIncr(gdb) = NINT(xinc*1000);
IEG_G_FirstLat(gdb) = lround(yfirst*1000);
IEG_G_LastLat(gdb) = lround(ylast*1000);
IEG_G_FirstLon(gdb) = lround(xfirst*1000);
IEG_G_LastLon(gdb) = lround(xlast*1000);
IEG_G_LonIncr(gdb) = lround(xinc*1000);
if ( fabs(xinc*1000 - IEG_G_LonIncr(gdb)) > FLT_EPSILON )
IEG_G_LonIncr(gdb) = 0;
......@@ -316,17 +316,17 @@ void iegDefGrid(int *gdb, int gridID)
IEG_G_LatIncr(gdb) = nlat/2;
else
{
IEG_G_LatIncr(gdb) = NINT(yinc*1000);
IEG_G_LatIncr(gdb) = lround(yinc*1000);
if ( fabs(yinc*1000 - IEG_G_LatIncr(gdb)) > FLT_EPSILON )
IEG_G_LatIncr(gdb) = 0;
if ( IEG_G_LatIncr(gdb) < 0 ) IEG_G_LatIncr(gdb) = -IEG_G_LatIncr(gdb);
}
if ( IEG_G_NumLon(gdb) > 1 && IEG_G_NumLat(gdb) == 1 )
if ( IEG_G_NumLon(gdb) > 1 && IEG_G_NumLat(gdb) == 1 )
if ( IEG_G_LonIncr(gdb) != 0 && IEG_G_LatIncr(gdb) == 0 ) IEG_G_LatIncr(gdb) = IEG_G_LonIncr(gdb);
if ( IEG_G_NumLon(gdb) == 1 && IEG_G_NumLat(gdb) > 1 )
if ( IEG_G_NumLon(gdb) == 1 && IEG_G_NumLat(gdb) > 1 )
if ( IEG_G_LonIncr(gdb) == 0 && IEG_G_LatIncr(gdb) != 0 ) IEG_G_LonIncr(gdb) = IEG_G_LatIncr(gdb);
if ( IEG_G_LatIncr(gdb) == 0 || IEG_G_LonIncr(gdb) == 0 )
......@@ -336,8 +336,8 @@ void iegDefGrid(int *gdb, int gridID)
if ( gridIsRotated(gridID) )
{
IEG_G_LatSP(gdb) = - NINT(gridInqYpole(gridID) * 1000);
IEG_G_LonSP(gdb) = NINT((gridInqXpole(gridID) + 180) * 1000);
IEG_G_LatSP(gdb) = - lround(gridInqYpole(gridID) * 1000);
IEG_G_LonSP(gdb) = lround((gridInqXpole(gridID) + 180) * 1000);
IEG_G_Size(gdb) = 42;
}
else
......
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