Fix most float conversion warnings

Fixes ~200 out of ~240 `-Wfloat-conversion` warnings on gcc 13.2
This commit is contained in:
Peter Hill 2023-10-26 16:01:24 +01:00
parent cb61d34185
commit 763e54f8a1
No known key found for this signature in database
GPG Key ID: 0C6B9742E72848EE
36 changed files with 136 additions and 135 deletions

View File

@ -45,7 +45,7 @@ main()
/* Create a bunch of phoney data so we have something to write in
the example file. */
for (fp=(float *)temp, i=0; i<LAT_LEN*LON_LEN; i++)
*fp++ = 10. + i/10.;
*fp++ = 10.f + (float)i/10.f;
/* Now create the file in both formats with the same code. */
for (i=0; i<2; i++)

View File

@ -40,10 +40,10 @@
#define DEGREES_NORTH "degrees_north"
/* These are used to construct some example data. */
#define SAMPLE_PRESSURE 900
#define SAMPLE_TEMP 9.0
#define START_LAT 25.0
#define START_LON -125.0
#define SAMPLE_PRESSURE 900.0f
#define SAMPLE_TEMP 9.0f
#define START_LAT 25.0f
#define START_LON -125.0f
/* For the units attributes. */
#define UNITS "units"
@ -87,16 +87,16 @@ main()
* would have some real data to write, for example, model
* output. */
for (lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5.*lat;
lats[lat] = START_LAT + 5.f*(float)lat;
for (lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5.*lon;
lons[lon] = START_LON + 5.f*(float)lon;
for (lvl = 0; lvl < NLVL; lvl++)
for (lat = 0; lat < NLAT; lat++)
for (lon = 0; lon < NLON; lon++)
{
pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + i;
temp_out[lvl][lat][lon] = SAMPLE_TEMP + i++;
pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + (float)i;
temp_out[lvl][lat][lon] = SAMPLE_TEMP + (float)i++;
}
/* Create the file. */

View File

@ -35,10 +35,10 @@
#define DEGREES_NORTH "degrees_north"
/* These are used to construct some example data. */
#define SAMPLE_PRESSURE 900
#define SAMPLE_TEMP 9.0
#define START_LAT 25.0
#define START_LON -125.0
#define SAMPLE_PRESSURE 900.0f
#define SAMPLE_TEMP 9.0f
#define START_LAT 25.0f
#define START_LON -125.0f
/* Handle errors by printing an error message and exiting with a
* non-zero status. */
@ -78,15 +78,15 @@ main()
* would have some real data to write, for example, model
* output. */
for (lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5.*lat;
lats[lat] = START_LAT + 5.f*(float)lat;
for (lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5.*lon;
lons[lon] = START_LON + 5.f*(float)lon;
for (lat = 0; lat < NLAT; lat++)
for (lon = 0; lon < NLON; lon++)
{
pres_out[lat][lon] = SAMPLE_PRESSURE + (lon * NLAT + lat);
temp_out[lat][lon] = SAMPLE_TEMP + .25 * (lon * NLAT + lat);
pres_out[lat][lon] = SAMPLE_PRESSURE + (float)(lon * NLAT + lat);
temp_out[lat][lon] = SAMPLE_TEMP + .25f * (float)(lon * NLAT + lat);
}
/* Create the file. */

View File

@ -75,7 +75,7 @@ main()
if (!(cvc_out[i].data[j].p = calloc(sizeof(struct s1), cvc_out[i].data[j].len))) ERR;
for (k = 0; k < cvc_out[i].data[j].len; k++)
{
((struct s1 *)cvc_out[i].data[j].p)[k].x = 42.42;
((struct s1 *)cvc_out[i].data[j].p)[k].x = 42.42f;
((struct s1 *)cvc_out[i].data[j].p)[k].y = 2.0;
}
}

View File

@ -75,7 +75,7 @@ main()
if (!(vc_out[i].p = calloc(sizeof(struct s1), vc_out[i].len))) ERR;
for (k = 0; k < vc_out[i].len; k++)
{
((struct s1 *)vc_out[i].p)[k].x = 42.42;
((struct s1 *)vc_out[i].p)[k].x = 42.42f;
((struct s1 *)vc_out[i].p)[k].y = 2.0;
}
}

View File

@ -301,10 +301,10 @@ main()
/* Initialize data. */
for (i = 0; i < DIM6_LEN; i++)
{
obsdata[i].day = 15 * i + 1;
obsdata[i].elev = 2 * i + 1;
obsdata[i].day = 15 * (char)i + 1;
obsdata[i].elev = 2 * (short)i + 1;
obsdata[i].count = 2 * i + 1;
obsdata[i].relhum = 2.0 * i + 1;
obsdata[i].relhum = 2.0f * (float)i + 1;
obsdata[i].time = 2.0 * i + 1;
}
@ -453,8 +453,8 @@ main()
hr_data_out[i].svc_rec.i1 = 95;
hr_data_out[i].svc_rec.i2 = 90;
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].min_temp = -9.99;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .1;
}
@ -558,8 +558,8 @@ main()
hr_data_out[i].svc_rec.i1 = 95;
hr_data_out[i].svc_rec.i2 = 90;
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].min_temp = -9.99;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .1;
}
@ -666,8 +666,8 @@ main()
hr_data_out[i].svc_rec.i1 = 95;
hr_data_out[i].svc_rec.i2 = 90;
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].min_temp = -9.99;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .1;
}
@ -757,7 +757,7 @@ main()
for (i = 0; i < DIM1_LEN; i++)
{
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].max_temp = 99.99f;
}
/* Open file and get root group. */
@ -842,7 +842,7 @@ main()
for (i = 0; i < DIM2_LEN; i++)
{
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].max_temp = 99.99f;
}
/* Open file and get root group. */
@ -921,7 +921,7 @@ main()
{
for (j = 0; j < STR_LEN + 1; j++)
data_out[i].x[j] = 4;
data_out[i].y = 99.99;
data_out[i].y = 99.99f;
}
/* Set latest_format in access propertly list and

View File

@ -76,7 +76,7 @@ main()
* dimension varies most slowly. */
for (lat = 0; lat < LAT_LEN; lat++)
for (lon = 0; lon < LON_LEN; lon++)
float_data_out[lat][lon] = -666.666;
float_data_out[lat][lon] = -666.666f;
/* Create file and group. */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,

View File

@ -199,7 +199,7 @@ main()
hid_t did, fapl_id, fcpl_id, gcpl_id, attid;
hsize_t num_obj;
hid_t fileid, grpid, spaceid;
float val = 3.1495;
float val = 3.1495f;
#if H5_VERSION_GE(1,12,0)
H5O_info2_t obj_info;
#else

View File

@ -995,7 +995,7 @@ nc4_hdf5_get_chunk_cache(int ncid, size_t *sizep, size_t *nelemsp,
if (H5Pget_cache(plistid, NULL, nelemsp, sizep, &dpreemption) < 0)
return NC_EHDFERR;
if (preemptionp)
*preemptionp = dpreemption;
*preemptionp = (float)dpreemption;
return NC_NOERR;
}

View File

@ -1481,7 +1481,7 @@ nc4_get_var_meta(NC_VAR_INFO_T *var)
if ((H5Pget_chunk_cache(access_pid, &(var->chunkcache.nelems),
&(var->chunkcache.size), &rdcc_w0)) < 0)
BAIL(NC_EHDFERR);
var->chunkcache.preemption = rdcc_w0;
var->chunkcache.preemption = (float)rdcc_w0;
/* Get the dataset creation properties. */
if ((propid = H5Dget_create_plist(hdf5_var->hdf_datasetid)) < 0)

View File

@ -2391,7 +2391,7 @@ nc_set_var_chunk_cache_ints(int ncid, int varid, int size, int nelems,
real_nelems = nelems;
if (preemption >= 0)
real_preemption = preemption / 100.;
real_preemption = (float)(preemption / 100.);
return NC4_HDF5_set_var_chunk_cache(ncid, varid, real_size, real_nelems,
real_preemption);

View File

@ -126,7 +126,7 @@ printf("*** testing diskless file with scalar vars...");
int ndims_in, nvars_in, natts_in, unlimdimid_in;
char name_in[NC_MAX_NAME + 1];
nc_type type_in;
float float_data = 3.14, float_data_in;
float float_data = 3.14f, float_data_in;
int int_data = 42, int_data_in;
short short_data = 2, short_data_in;
@ -176,7 +176,7 @@ printf("*** testing diskless file with scalar vars...");
if(!usenetcdf4 && persist) {
int ncid, varid0, varid1, varid2;
float float_data = 3.14, float_data_in;
float float_data = 3.14f, float_data_in;
int int_data = 42, int_data_in;
short short_data = 2, short_data_in;
@ -221,7 +221,7 @@ printf("*** testing diskless file with scalar vars...");
size_t start[1] = {0};
size_t count[1] = {DIM1_LEN};
int i;
float float_data = 42.22, float_data_in;
float float_data = 42.22f, float_data_in;
/* This is some really important data that I want to save. */
for (i = 0; i < DIM1_LEN; i++)
@ -301,7 +301,7 @@ printf("*** testing diskless file with scalar vars...");
int ndims_in, nvars_in, natts_in, unlimdimid_in;
char name_in[NC_MAX_NAME + 1];
nc_type type_in;
float float_data = 3.14, float_data_in;
float float_data = 3.14f, float_data_in;
int int_data = 42, int_data_in;
short short_data = 2, short_data_in;

View File

@ -88,8 +88,8 @@ inRange_float(const double value, const nc_type xtype)
case NC_UBYTE: min = 0; max = X_UCHAR_MAX; break;
case NC_USHORT: min = 0; max = X_USHORT_MAX; break;
case NC_UINT: min = 0; max = X_UINT_MAX; break;
case NC_INT64: min = X_INT64_MIN; max = X_INT64_MAX; break;
case NC_UINT64: min = 0; max = X_UINT64_MAX; break;
case NC_INT64: min = X_INT64_MIN; max = (double)X_INT64_MAX; break;
case NC_UINT64: min = 0; max = (double)X_UINT64_MAX; break;
default: assert(0);
}
if(!( value >= min && value <= max)) {

View File

@ -28,11 +28,11 @@ main(int argc, char **argv)
/* Create phony data. */
for (i = 0; i < DIM_LEN; i++)
{
if (!(data[i].temp_vl.p = malloc(sizeof(float) * (i + 1))))
if (!(data[i].temp_vl.p = malloc(sizeof(float) * (size_t)(i + 1))))
return NC_ENOMEM;
for (j = 0; j < i + 1; j++)
((float *)(data[i].temp_vl.p))[j] = 23.5 - j;
data[i].temp_vl.len = i + 1;
((float *)(data[i].temp_vl.p))[j] = 23.5f - (float)j;
data[i].temp_vl.len = (size_t)i + 1;
}
printf("\n*** Testing netcdf-4 CDM compliance: sea soundings.\n");

View File

@ -1215,7 +1215,7 @@ create_file()
check_err(stat,__LINE__,__FILE__);
}
{ /* Gf */
static const float Gf_att[5] = {-3.4028231e+38, 3.4028231e+38, -9.96921e+36, 9.96921e+36, 531} ;
static const float Gf_att[5] = {-3.4028231e+38f, 3.4028231e+38f, -9.96921e+36f, 9.96921e+36f, 531} ;
stat = nc_put_att_float(ncid, NC_GLOBAL, "Gf", NC_FLOAT, 5, Gf_att);
check_err(stat,__LINE__,__FILE__);
}
@ -1247,7 +1247,7 @@ create_file()
check_err(stat,__LINE__,__FILE__);
}
{ /* f */
static const float i_f_att[4] = {-3.4028231e+38, 3.4028231e+38, -9.96921e+36, 9.96921e+36} ;
static const float i_f_att[4] = {-3.4028231e+38f, 3.4028231e+38f, -9.96921e+36f, 9.96921e+36f} ;
stat = nc_put_att_float(ncid, i_id, "f", NC_FLOAT, 4, i_f_att);
check_err(stat,__LINE__,__FILE__);
}
@ -1330,7 +1330,7 @@ create_file()
}
{
float fr_data[2] = {-3.4028231e+38, 3.4028231e+38} ;
float fr_data[2] = {-3.4028231e+38f, 3.4028231e+38f} ;
size_t fr_startset[1] = {0} ;
size_t fr_countset[1] = {2} ;
stat = nc_put_vara(ncid, fr_id, fr_startset, fr_countset, fr_data);
@ -1378,7 +1378,7 @@ create_file()
}
{
float f1_data[1] = {-3.4028231e+38} ;
float f1_data[1] = {-3.4028231e+38f} ;
size_t f1_startset[1] = {0} ;
size_t f1_countset[1] = {1} ;
stat = nc_put_vara(ncid, f1_id, f1_startset, f1_countset, f1_data);
@ -1426,7 +1426,7 @@ create_file()
}
{
float f2_data[2] = {-3.4028231e+38, 3.4028231e+38} ;
float f2_data[2] = {-3.4028231e+38f, 3.4028231e+38f} ;
size_t f2_startset[1] = {0} ;
size_t f2_countset[1] = {2} ;
stat = nc_put_vara(ncid, f2_id, f2_startset, f2_countset, f2_data);
@ -1474,7 +1474,7 @@ create_file()
}
{
float f3_data[3] = {-3.4028231e+38, 3.4028231e+38, -9.96921e+36} ;
float f3_data[3] = {-3.4028231e+38f, 3.4028231e+38f, -9.96921e+36f} ;
size_t f3_startset[1] = {0} ;
size_t f3_countset[1] = {3} ;
stat = nc_put_vara(ncid, f3_id, f3_startset, f3_countset, f3_data);
@ -1522,7 +1522,7 @@ create_file()
}
{
float f4_data[4] = {-3.4028231e+38, 3.4028231e+38, -9.96921e+36, 9.96921e+36} ;
float f4_data[4] = {-3.4028231e+38f, 3.4028231e+38f, -9.96921e+36f, 9.96921e+36f} ;
size_t f4_startset[1] = {0} ;
size_t f4_countset[1] = {4} ;
stat = nc_put_vara(ncid, f4_id, f4_startset, f4_countset, f4_data);

View File

@ -50,7 +50,7 @@ calculate_waste(int ndims, size_t *dimlen, size_t *chunksize, float *waste)
#endif
/* Percent of the chunked file that is wasted space. */
*waste = ((float)(chunked - unchunked) / (float)chunked) * 100.0;
*waste = ((float)(chunked - unchunked) / (float)chunked) * 100.0f;
#ifdef PRINT_CHUNK_WASTE_REPORT
printf("\ndimlen\tchunksize\tnum_chunks\n");

View File

@ -546,8 +546,8 @@ main(int argc, char **argv)
hr_data_out[i].starfleet_id = i;
hr_data_out[i].svc_rec = data[i];
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].min_temp = -9.99;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .030303;
}
@ -659,10 +659,10 @@ main(int argc, char **argv)
/* Initialize data. */
for (i = 0; i < DIM6_LEN; i++)
{
obsdata[i].day = 15 * i + 1;
obsdata[i].elev = 2 * i + 1;
obsdata[i].day = 15 * (char)i + 1;
obsdata[i].elev = 2 * (short)i + 1;
obsdata[i].count = 2 * i + 1;
obsdata[i].relhum = 2.0 * i + 1;
obsdata[i].relhum = 2.0f * (float)i + 1;
obsdata[i].time = 2.0 * i + 1;
}
missing_val.day = 99;
@ -863,7 +863,7 @@ main(int argc, char **argv)
for (i = 0; i < DIM1_LEN; i++)
{
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].max_temp = 99.99f;
}
/* Create a file with a nested compound type attribute and variable. */
@ -927,7 +927,7 @@ main(int argc, char **argv)
/* Create some phony data. */
for (i = 0; i < DIM1_LEN; i++)
{
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].max_temp = 99.99f;
for (j = 0; j < ARRAY_LEN; j++)
hr_data_out[i].name[j] = j;
}

View File

@ -49,7 +49,7 @@ main(int argc, char **argv)
/* Create some phony data. */
for (i = 0; i < DIM1_LEN; i++)
{
data_out[i].y = 99.99;
data_out[i].y = 99.99f;
for (j = 0; j < ARRAY_LEN; j++)
data_out[i].x[j] = j;
}

View File

@ -136,7 +136,7 @@ main(int argc, char **argv)
for (i = 0; i < ATT_LEN; i++)
{
a1_att[i].s1.x = 13.3;
a1_att[i].s1.x = 13.3f;
a1_att[i].s1.y = 13.3;
}
/* Create a file with two groups, define a type in each group,

View File

@ -215,7 +215,7 @@ main(int argc, char **argv)
if (uint64_in != ivalue) ERR;
if (nc_get_var_float(ncid, varid, &float_in)) ERR;
if(fabs( (float_in-X_INT_MAX) - ((float)ivalue - X_INT_MAX)) > 1) ERR;
if(fabs( (float_in-(float)X_INT_MAX) - ((float)ivalue - (float)X_INT_MAX)) > 1) ERR;
if (nc_get_var_double(ncid, varid, &double_in)) ERR;
if (double_in != (double)ivalue) ERR;

View File

@ -38,8 +38,8 @@ main(int argc, char **argv)
#define LAT_NAME "lat"
#define LON_NAME "lon"
#define NVARS 2
#define START_LAT 25.0
#define START_LON -125.0
#define START_LAT 25.0f
#define START_LON -125.0f
{
int ncid, lon_dimid, lat_dimid;
int lat_varid, lon_varid;
@ -52,9 +52,9 @@ main(int argc, char **argv)
/* Initialize coord data. */
for (lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5. * lat;
lats[lat] = START_LAT + 5.f * (float)lat;
for (lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5. * lon;
lons[lon] = START_LON + 5.f * (float)lon;
/* Create file with two dimensions. */
if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR;
@ -103,7 +103,7 @@ main(int argc, char **argv)
#define DIM0_NAME "d0"
#define CACHE_SIZE 1000000
#define CACHE_NELEMS 1009
#define CACHE_PREEMPTION .90
#define CACHE_PREEMPTION .90f
int ncid, dimid, varid;
char name_in[NC_MAX_NAME + 1];
@ -413,12 +413,12 @@ main(int argc, char **argv)
check_err(stat,__LINE__,__FILE__);
}
{ /* missing_value */
static const float pr_missing_value_att[1] = {1e+20} ;
static const float pr_missing_value_att[1] = {1e+20f} ;
stat = nc_put_att_float(root_grp, pr_id, "missing_value", NC_FLOAT, 1, pr_missing_value_att);
check_err(stat,__LINE__,__FILE__);
}
{ /* _FillValue */
static const float pr_FillValue_att[1] = {1e+20} ;
static const float pr_FillValue_att[1] = {1e+20f} ;
stat = nc_put_att_float(root_grp, pr_id, "_FillValue", NC_FLOAT, 1, pr_FillValue_att);
check_err(stat,__LINE__,__FILE__);
}

View File

@ -849,9 +849,9 @@ main(int argc, char **argv)
/* Lats and lons suitable for some South American data. */
for (lat[0] = 40.0, i = 1; i < LAT_LEN; i++)
lat[i] = lat[i - 1] + .5;
lat[i] = (float)lat[i - 1] + .5f;
for (lon[0] = 20.0, i = 1; i < LON_LEN; i++)
lon[i] = lon[i - 1] + 1.5;
lon[i] = (float)lon[i - 1] + 1.5f;
/* Some phoney 2D pressure data. */
for (i = 0; i < LAT_LEN; i++)
@ -1002,9 +1002,9 @@ main(int argc, char **argv)
/* Some phony 1D lats and lons. */
for (i = 0; i < LAT_LEN; i++)
lat[i] = i * 5.;
lat[i] = (float)i * 5.f;
for (i = 0; i < LON_LEN; i++)
lon[i] = i * 5.;
lon[i] = (float)i * 5.f;
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

View File

@ -209,7 +209,7 @@ main(int argc, char **argv)
int dimids_var[2], var_type;
size_t dim_len;
char dim_name[NC_MAX_NAME+1], var_name[NC_MAX_NAME+1];
float float_in, float_out = 99.99;
float float_in, float_out = 99.99f;
int int_in, int_out = -9999;
/* Create a file, this time with attributes. */

View File

@ -42,7 +42,7 @@ main()
int dimids[NDIMS];
for (i = 0; i < (X_LEN * Y_LEN * Z_LEN); i++)
mydata[i] = i;
mydata[i] = (float)i;
/* create the file in NetCDF-4 format */
if ((retval = nc_create(FILE_NAME, NC_NETCDF4, &ncid)))

View File

@ -277,7 +277,7 @@ main(int argc, char **argv)
{
int ncid, varid1, varid2;
int quantize_mode_in, nsd_in;
float float_data[DIM_LEN_1] = {1.1111111};
float float_data[DIM_LEN_1] = {1.1111111f};
double double_data[DIM_LEN_1] = {1.111111111111};
printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]);
@ -394,7 +394,7 @@ main(int argc, char **argv)
{
int ncid, dimid, varid1, varid2;
int quantize_mode_in, nsd_in;
float float_data[DIM_LEN_1] = {1.1111111};
float float_data[DIM_LEN_1] = {1.1111111f};
double double_data[DIM_LEN_1] = {1.111111111111};
printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]);
@ -485,7 +485,7 @@ main(int argc, char **argv)
{
int ncid, dimid, varid1, varid2;
int quantize_mode_in, nsd_in;
float float_data[DIM_LEN_5] = {1.11111111, 1.0, 9.99999999, 12345.67, .1234567};
float float_data[DIM_LEN_5] = {1.11111111f, 1.0f, 9.99999999f, 12345.67f, .1234567f};
double double_data[DIM_LEN_5] = {1.1111111, 1.0, 9.999999999, 1234567890.12345, 123456789012345.0};
int x;
@ -616,7 +616,7 @@ main(int argc, char **argv)
{
int ncid, dimid, varid1, varid2;
int quantize_mode_in, nsd_in;
float float_data[DIM_LEN_1] = {1.1111111};
float float_data[DIM_LEN_1] = {1.1111111f};
double double_data[DIM_LEN_1] = {1.111111111111};
printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]);
@ -733,7 +733,7 @@ main(int argc, char **argv)
{
int ncid, dimid, varid1, varid2;
int quantize_mode_in, nsd_in;
float float_data[DIM_LEN_5] = {1.11111111, 1.0, 9.99999999, 12345.67, .1234567};
float float_data[DIM_LEN_5] = {1.11111111f, 1.0, 9.99999999f, 12345.67f, .1234567f};
double double_data[DIM_LEN_5] = {1.1111111, 1.0, 9.999999999, 1234567890.12345, 123456789012345.0};
int x;
@ -862,7 +862,7 @@ main(int argc, char **argv)
{
int ncid, dimid, varid1, varid2;
int quantize_mode_in, nsd_in;
float float_data[DIM_LEN_5] = {1.11111111, NC_FILL_FLOAT, 9.99999999, 12345.67, NC_FILL_FLOAT};
float float_data[DIM_LEN_5] = {1.11111111f, NC_FILL_FLOAT, 9.99999999f, 12345.67f, NC_FILL_FLOAT};
double double_data[DIM_LEN_5] = {1.1111111, NC_FILL_DOUBLE, 9.999999999, 1234567890.12345, NC_FILL_DOUBLE};
int x;
@ -987,13 +987,13 @@ main(int argc, char **argv)
SUMMARIZE_ERR;
printf("\t**** testing more quantization values with custom fill values...\n");
{
#define CUSTOM_FILL_FLOAT 99.99999
#define CUSTOM_FILL_FLOAT 99.99999f
#define CUSTOM_FILL_DOUBLE -99999.99999
for (q = 0; q < NUM_QUANTIZE_MODES; q++)
{
int ncid, dimid, varid1, varid2;
int quantize_mode_in, nsd_in;
float float_data[DIM_LEN_5] = {1.11111111, CUSTOM_FILL_FLOAT, 9.99999999, 12345.67, CUSTOM_FILL_FLOAT};
float float_data[DIM_LEN_5] = {1.11111111f, CUSTOM_FILL_FLOAT, 9.99999999f, 12345.67f, CUSTOM_FILL_FLOAT};
double double_data[DIM_LEN_5] = {1.1111111, CUSTOM_FILL_DOUBLE, 9.999999999, 1234567890.12345, CUSTOM_FILL_DOUBLE};
float custom_fill_float = CUSTOM_FILL_FLOAT;
double custom_fill_double = CUSTOM_FILL_DOUBLE;
@ -1311,8 +1311,8 @@ main(int argc, char **argv)
ERR;
for (i = 0; i < DIM_LEN_SIMPLE; i++)
{
float_data[i] = 1.5 * i;
double_data[i] = 1.5 * i;
float_data[i] = 1.5f * (float)i;
double_data[i] = 1.5 * (double)i;
}
/* Create the file. */

View File

@ -51,7 +51,7 @@ main(int argc, char **argv)
for (time = 0; time < NUM_TIMESTEPS; time++)
for (lat = 0; lat < LAT_LEN; lat++)
for (lon = 0; lon < LON_LEN; lon++)
data_out[time][lat][lon] = 25.5 + lat + lon + time;
data_out[time][lat][lon] = 25.5f + (float)(lat + lon + time);
/* Create a file with a 3D surface temp variable. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

View File

@ -56,10 +56,10 @@
#define NVARS_EX 4
/* These are used to construct some example data. */
#define SAMPLE_PRESSURE 900
#define SAMPLE_TEMP 9.0
#define START_LAT 25.0
#define START_LON -125.0
#define SAMPLE_PRESSURE 900.f
#define SAMPLE_TEMP 9.0f
#define START_LAT 25.0f
#define START_LON -125.0f
/* For the units attributes. */
#define UNITS "units"
@ -97,16 +97,16 @@ create_4D_example(char *file_name, int cmode)
* would have some real data to write, for example, model
* output. */
for (lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5.*lat;
lats[lat] = START_LAT + 5.f*(float)lat;
for (lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5.*lon;
lons[lon] = START_LON + 5.f*(float)lon;
for (lvl = 0; lvl < NLVL; lvl++)
for (lat = 0; lat < NLAT; lat++)
for (lon = 0; lon < NLON; lon++)
{
pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + i;
temp_out[lvl][lat][lon] = SAMPLE_TEMP + i++;
pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + (float)i;
temp_out[lvl][lat][lon] = SAMPLE_TEMP + (float)i++;
}
/* Create the file. */
@ -307,7 +307,7 @@ main(int argc, char **argv)
unsigned short ushort_out[DIM1_LEN][DIM2_LEN] = {{110, 128, 255},{110, 128, 255}};
short short_in[DIM1_LEN][DIM2_LEN], short_out[DIM1_LEN][DIM2_LEN] = {{-110, -128, 255},{-110, -128, 255}};
int int_in[DIM1_LEN][DIM2_LEN], int_out[DIM1_LEN][DIM2_LEN] = {{0, 128, 255},{0, 128, 255}};
float float_in[DIM1_LEN][DIM2_LEN], float_out[DIM1_LEN][DIM2_LEN] = {{-.1, 9999.99, 100.001},{-.1, 9999.99, 100.001}};
float float_in[DIM1_LEN][DIM2_LEN], float_out[DIM1_LEN][DIM2_LEN] = {{-.1f, 9999.99f, 100.001f},{-.1f, 9999.99f, 100.001f}};
double double_in[DIM1_LEN][DIM2_LEN], double_out[DIM1_LEN][DIM2_LEN] = {{0.02, .1128, 1090.1},{0.02, .1128, 1090.1}};
unsigned int uint_in[DIM1_LEN][DIM2_LEN], uint_out[DIM1_LEN][DIM2_LEN] = {{0, 128, 255},{0, 128, 255}};
long long int64_in[DIM1_LEN][DIM2_LEN], int64_out[DIM1_LEN][DIM2_LEN] = {{-111, 777, 100},{-111, 777, 100}};

View File

@ -312,7 +312,7 @@ main(int argc, char **argv)
return NC_ENOMEM;
for (j = 0; j < vlen_of_comp_out[i].len; j++)
{
((struct s1 *)vlen_of_comp_out[i].p)[j].x = 42.42;
((struct s1 *)vlen_of_comp_out[i].p)[j].x = 42.42f;
((struct s1 *)vlen_of_comp_out[i].p)[j].y = 2.0;
}
}
@ -322,7 +322,7 @@ main(int argc, char **argv)
for (i = 0; i < DIM2_LEN; i++)
for (j = 0; j < NUM_S1; j++)
{
comp_array_of_comp_out[i].data[j].x = 42.42;
comp_array_of_comp_out[i].data[j].x = 42.42f;
comp_array_of_comp_out[i].data[j].y = 2.0;
}
@ -336,7 +336,7 @@ main(int argc, char **argv)
return NC_ENOMEM;
for (k = 0; k < comp_array_of_vlen_of_comp_out[i].data[j].len; k++)
{
((struct s1 *)comp_array_of_vlen_of_comp_out[i].data[j].p)[k].x = 42.42;
((struct s1 *)comp_array_of_vlen_of_comp_out[i].data[j].p)[k].x = 42.42f;
((struct s1 *)comp_array_of_vlen_of_comp_out[i].data[j].p)[k].y = 2.0;
}
}

View File

@ -317,7 +317,7 @@ static float int162float32_data[DIMSIZE]={0.000,256.000,512.000,768.000,1024.000
static int int32_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
static float int32tofloat32_data[DIMSIZE]={0.000,2048.000,4096.000,6144.000,8192.000,10240.000,12288.000,14336.000,16384.000,18432.000,20480.000,22528.000,24576.000,26624.000,28672.000,30720.000,32768.000,34816.000,36864.000,38912.000,40960.000,43008.000,45056.000,47104.000,49152.000};
static long int32toilong_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
static float float32_data[DIMSIZE]={0.000,0.010,0.020,0.030,0.040,0.050,0.060,0.070,0.080,0.090,0.100,0.110,0.120,0.130,0.140,0.149,0.159,0.169,0.179,0.189,0.199,0.208,0.218,0.228,0.238};
static float float32_data[DIMSIZE]={0.000f,0.010f,0.020f,0.030f,0.040f,0.050f,0.060f,0.070f,0.080f,0.090f,0.100f,0.110f,0.120f,0.130f,0.140f,0.149f,0.159f,0.169f,0.179f,0.189f,0.199f,0.208f,0.218f,0.228f,0.238f};
static double float64_data[DIMSIZE]={1.000,1.000,1.000,1.000,0.999,0.999,0.998,0.998,0.997,0.996,0.995,0.994,0.993,0.992,0.990,0.989,0.987,0.986,0.984,0.982,0.980,0.978,0.976,0.974,0.971};
#ifndef USE_NETCDF4

View File

@ -316,7 +316,7 @@ static float int162float32_data[DIMSIZE]={0.000,256.000,512.000,768.000,1024.000
static int int32_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
static float int32tofloat32_data[DIMSIZE]={0.000,2048.000,4096.000,6144.000,8192.000,10240.000,12288.000,14336.000,16384.000,18432.000,20480.000,22528.000,24576.000,26624.000,28672.000,30720.000,32768.000,34816.000,36864.000,38912.000,40960.000,43008.000,45056.000,47104.000,49152.000};
static long int32toilong_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
static float float32_data[DIMSIZE]={0.000,0.010,0.020,0.030,0.040,0.050,0.060,0.070,0.080,0.090,0.100,0.110,0.120,0.130,0.140,0.149,0.159,0.169,0.179,0.189,0.199,0.208,0.218,0.228,0.238};
static float float32_data[DIMSIZE]={0.000f,0.010f,0.020f,0.030f,0.040f,0.050f,0.060f,0.070f,0.080f,0.090f,0.100f,0.110f,0.120f,0.130f,0.140f,0.149f,0.159f,0.169f,0.179f,0.189f,0.199f,0.208f,0.218f,0.228f,0.238f};
static double float64_data[DIMSIZE]={1.000,1.000,1.000,1.000,0.999,0.999,0.998,0.998,0.997,0.996,0.995,0.994,0.993,0.992,0.990,0.989,0.987,0.986,0.984,0.982,0.980,0.978,0.976,0.974,0.971};
#ifndef USE_NETCDF4

View File

@ -33,33 +33,33 @@ TODO: Note that this test uses thredds server
#define VAR "SST"
static float expected_stride1[12] = {
29.430857,
29.403780,
29.325428,
29.578333,
29.660833,
29.378437,
29.151943,
29.109715,
29.114864,
29.550285,
29.542500,
29.500286
29.430857f,
29.403780f,
29.325428f,
29.578333f,
29.660833f,
29.378437f,
29.151943f,
29.109715f,
29.114864f,
29.550285f,
29.542500f,
29.500286f
};
static float expected_stride2[6] = {
29.430857,
29.325428,
29.660833,
29.151943,
29.114864,
29.542500
29.430857f,
29.325428f,
29.660833f,
29.151943f,
29.114864f,
29.542500f
};
static float expected_stride3[3] = {
29.430857,
29.378437,
29.542500
29.430857f,
29.378437f,
29.542500f
};
void

View File

@ -7,6 +7,7 @@
*********************************************************************/
#include "config.h" /* for USE_NETCDF4 macro */
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_GETOPT_H
@ -2310,7 +2311,7 @@ main(int argc, char**argv)
double dval = double_with_suffix(optarg); /* "K" for kilobytes. "M" for megabytes, ... */
if(dval < 0)
error("Suffix used for '-m' option value must be K, M, G, T, or P");
option_copy_buffer_size = dval;
option_copy_buffer_size = (size_t)dval;
break;
}
case 'h': /* non-default size of chunk cache */
@ -2318,7 +2319,7 @@ main(int argc, char**argv)
double dval = double_with_suffix(optarg); /* "K" for kilobytes. "M" for megabytes, ... */
if(dval < 0)
error("Suffix used for '-h' option value must be K, M, G, T, or P");
option_chunk_cache_size = dval;
option_chunk_cache_size = (size_t)dval;
break;
}
case 'e': /* number of elements chunk cache can hold */
@ -2326,7 +2327,7 @@ main(int argc, char**argv)
double dval = double_with_suffix(optarg); /* "K" for kilobytes. "M" for megabytes, ... */
if(dval < 0 )
error("Suffix used for '-e' option value must be K, M, G, T, or P");
option_chunk_cache_nelems = (long)dval;
option_chunk_cache_nelems = (size_t)dval;
break;
}
case 'r':

View File

@ -699,7 +699,7 @@ pr_att_valsx(
case NC_BYTE:
case NC_SHORT:
case NC_INT:
ii = vals[iel];
ii = (int)vals[iel];
res = snprintf(gps, PRIM_LEN, "%d", ii);
assert(res < PRIM_LEN);
(void) strlcat(attvals, gps, attvalslen);
@ -708,28 +708,28 @@ pr_att_valsx(
case NC_UBYTE:
case NC_USHORT:
case NC_UINT:
ui = vals[iel];
ui = (unsigned int)vals[iel];
res = snprintf(gps, PRIM_LEN, "%u", ui);
assert(res < PRIM_LEN);
(void) strlcat(attvals, gps, attvalslen);
(void) strlcat(attvals, iel < len-1 ? " " : "", attvalslen);
break;
case NC_INT64:
i64 = vals[iel];
i64 = (int64_t)vals[iel];
res = snprintf(gps, PRIM_LEN, "%lld", i64);
assert(res < PRIM_LEN);
(void) strlcat(attvals, gps, attvalslen);
(void) strlcat(attvals, iel < len-1 ? " " : "", attvalslen);
break;
case NC_UINT64:
ui64 = vals[iel];
ui64 = (uint64_t)vals[iel];
res = snprintf(gps, PRIM_LEN, "%llu", ui64);
assert(res < PRIM_LEN);
(void) strlcat(attvals, gps, attvalslen);
(void) strlcat(attvals, iel < len-1 ? " " : "", attvalslen);
break;
case NC_FLOAT:
ff = vals[iel];
ff = (float)vals[iel];
res = snprintf(gps, PRIM_LEN, float_attx_fmt, ff);
assert(res < PRIM_LEN);
tztrim(gps); /* trim trailing 0's after '.' */
@ -847,7 +847,7 @@ pr_att(
case NC_VLEN:
/* because size returned for vlen is base type size, but we
* need space to read array of vlen structs into ... */
data = emalloc((att.len + 1) * sizeof(nc_vlen_t));
data = emalloc((att.len + 1) * sizeof(nc_vlen_t));
break;
case NC_OPAQUE:
data = emalloc((att.len + 1) * type_size);

View File

@ -226,8 +226,8 @@ main(int argc, char **argv)
#define ATT_NAME_CMP "my_favorite_wind_speeds"
#define COMPOUND_NAME "wind_vector"
#define NUM_FAVS 3
#define U_VALUE 13.3
#define V_VALUE 12.2
#define U_VALUE 13.3f
#define V_VALUE 12.2f
{
int ncid;

View File

@ -91,7 +91,7 @@ main(int argc, char **argv)
array[i] = (float *) malloc(ncolumns * sizeof(float));
if(array[i] == NULL) ERR;
for (j = 0; j < ncolumns; j++) {
array[i][j] = 10.0 * (i + 1) + j;
array[i][j] = 10.0f * (float)(i + 1) + (float)j;
}
}
array[4][0] = missing_value; /* overwrite last row with missing for equality test */

View File

@ -52,7 +52,7 @@ calculate_waste(int ndims, size_t *dimlen, size_t *chunksize, float *waste)
#endif
/* Percent of the chunked file that is wasted space. */
*waste = ((float)(chunked - unchunked) / (float)chunked) * 100.0;
*waste = ((float)(chunked - unchunked) / (float)chunked) * 100.0f;
#ifdef PRINT_CHUNK_WASTE_REPORT
printf("\ndimlen\tchunksize\tnum_chunks\n");