From 763e54f8a11b07bd247221fedac9bdb7492f4fa3 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 26 Oct 2023 16:01:24 +0100 Subject: [PATCH] Fix most float conversion warnings Fixes ~200 out of ~240 `-Wfloat-conversion` warnings on gcc 13.2 --- examples/C/format.c | 2 +- examples/C/pres_temp_4D_wr.c | 16 ++++++------- examples/C/sfc_pres_temp_wr.c | 16 ++++++------- h5_test/tst_h_atts3.c | 2 +- h5_test/tst_h_atts4.c | 2 +- h5_test/tst_h_compounds.c | 24 ++++++++++---------- h5_test/tst_h_vars.c | 2 +- h5_test/tst_h_vars2.c | 2 +- libhdf5/hdf5internal.c | 2 +- libhdf5/hdf5open.c | 2 +- libhdf5/hdf5var.c | 2 +- nc_test/tst_diskless.c | 8 +++---- nc_test/util.c | 4 ++-- nc_test4/cdm_sea_soundings.c | 6 ++--- nc_test4/tst_atts3.c | 14 ++++++------ nc_test4/tst_chunks2.c | 2 +- nc_test4/tst_compounds.c | 14 ++++++------ nc_test4/tst_compounds2.c | 2 +- nc_test4/tst_compounds3.c | 2 +- nc_test4/tst_converts2.c | 2 +- nc_test4/tst_coords.c | 14 ++++++------ nc_test4/tst_dims.c | 8 +++---- nc_test4/tst_files.c | 2 +- nc_test4/tst_put_vars.c | 2 +- nc_test4/tst_quantize.c | 20 ++++++++--------- nc_test4/tst_unlim_vars.c | 2 +- nc_test4/tst_vars.c | 18 +++++++-------- nc_test4/tst_xplatform2.c | 6 ++--- ncdap_test/t_dap3a.c | 2 +- ncdap_test/test_cvt.c | 2 +- ncdap_test/test_varm3.c | 42 +++++++++++++++++------------------ ncdump/nccopy.c | 7 +++--- ncdump/ncdump.c | 12 +++++----- ncdump/tst_create_files.c | 4 ++-- ncdump/tst_vlen_data.c | 2 +- nczarr_test/test_zchunks2.c | 2 +- 36 files changed, 136 insertions(+), 135 deletions(-) diff --git a/examples/C/format.c b/examples/C/format.c index 291aad65b6..40413dbe3f 100644 --- a/examples/C/format.c +++ b/examples/C/format.c @@ -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; ichunkcache.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) diff --git a/libhdf5/hdf5var.c b/libhdf5/hdf5var.c index 0a1273250b..6d37fe9099 100644 --- a/libhdf5/hdf5var.c +++ b/libhdf5/hdf5var.c @@ -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); diff --git a/nc_test/tst_diskless.c b/nc_test/tst_diskless.c index 13ae21b354..54f41f8770 100644 --- a/nc_test/tst_diskless.c +++ b/nc_test/tst_diskless.c @@ -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; diff --git a/nc_test/util.c b/nc_test/util.c index 4399763754..7bb16e44f3 100644 --- a/nc_test/util.c +++ b/nc_test/util.c @@ -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)) { diff --git a/nc_test4/cdm_sea_soundings.c b/nc_test4/cdm_sea_soundings.c index f7da504ce9..b2e2f681cd 100644 --- a/nc_test4/cdm_sea_soundings.c +++ b/nc_test4/cdm_sea_soundings.c @@ -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"); diff --git a/nc_test4/tst_atts3.c b/nc_test4/tst_atts3.c index 0c0bd621b2..84726014d4 100644 --- a/nc_test4/tst_atts3.c +++ b/nc_test4/tst_atts3.c @@ -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); diff --git a/nc_test4/tst_chunks2.c b/nc_test4/tst_chunks2.c index f166a500eb..0499d6f392 100644 --- a/nc_test4/tst_chunks2.c +++ b/nc_test4/tst_chunks2.c @@ -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"); diff --git a/nc_test4/tst_compounds.c b/nc_test4/tst_compounds.c index f91c210021..731ed8bc4f 100644 --- a/nc_test4/tst_compounds.c +++ b/nc_test4/tst_compounds.c @@ -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; } diff --git a/nc_test4/tst_compounds2.c b/nc_test4/tst_compounds2.c index 7b1af1de96..8a9fadb4db 100644 --- a/nc_test4/tst_compounds2.c +++ b/nc_test4/tst_compounds2.c @@ -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; } diff --git a/nc_test4/tst_compounds3.c b/nc_test4/tst_compounds3.c index c09cb0b448..d388658bbb 100644 --- a/nc_test4/tst_compounds3.c +++ b/nc_test4/tst_compounds3.c @@ -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, diff --git a/nc_test4/tst_converts2.c b/nc_test4/tst_converts2.c index 0f3bd92258..da6006a163 100644 --- a/nc_test4/tst_converts2.c +++ b/nc_test4/tst_converts2.c @@ -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; diff --git a/nc_test4/tst_coords.c b/nc_test4/tst_coords.c index 000b8a632b..f7133a57f9 100644 --- a/nc_test4/tst_coords.c +++ b/nc_test4/tst_coords.c @@ -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__); } diff --git a/nc_test4/tst_dims.c b/nc_test4/tst_dims.c index d821e20f73..f64ba66d59 100644 --- a/nc_test4/tst_dims.c +++ b/nc_test4/tst_dims.c @@ -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; diff --git a/nc_test4/tst_files.c b/nc_test4/tst_files.c index e0f7ddf302..f2ad31bedd 100644 --- a/nc_test4/tst_files.c +++ b/nc_test4/tst_files.c @@ -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. */ diff --git a/nc_test4/tst_put_vars.c b/nc_test4/tst_put_vars.c index 62f59ff80e..1ce011c2a3 100644 --- a/nc_test4/tst_put_vars.c +++ b/nc_test4/tst_put_vars.c @@ -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))) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 47c8ce2eef..eb43c30437 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -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. */ diff --git a/nc_test4/tst_unlim_vars.c b/nc_test4/tst_unlim_vars.c index e6f157a1ce..e488f36ad6 100644 --- a/nc_test4/tst_unlim_vars.c +++ b/nc_test4/tst_unlim_vars.c @@ -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; diff --git a/nc_test4/tst_vars.c b/nc_test4/tst_vars.c index a605da71ef..f94fc0dcbb 100644 --- a/nc_test4/tst_vars.c +++ b/nc_test4/tst_vars.c @@ -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}}; diff --git a/nc_test4/tst_xplatform2.c b/nc_test4/tst_xplatform2.c index 02b7dc7067..6d2043d9f4 100644 --- a/nc_test4/tst_xplatform2.c +++ b/nc_test4/tst_xplatform2.c @@ -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; } } diff --git a/ncdap_test/t_dap3a.c b/ncdap_test/t_dap3a.c index bbfd36252e..4ededc15c8 100644 --- a/ncdap_test/t_dap3a.c +++ b/ncdap_test/t_dap3a.c @@ -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 diff --git a/ncdap_test/test_cvt.c b/ncdap_test/test_cvt.c index 46f52de2a0..3485dd4f7a 100644 --- a/ncdap_test/test_cvt.c +++ b/ncdap_test/test_cvt.c @@ -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 diff --git a/ncdap_test/test_varm3.c b/ncdap_test/test_varm3.c index 707bf53011..740d6fa6f6 100644 --- a/ncdap_test/test_varm3.c +++ b/ncdap_test/test_varm3.c @@ -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 diff --git a/ncdump/nccopy.c b/ncdump/nccopy.c index 2ac4a73d9c..ae041547e4 100644 --- a/ncdump/nccopy.c +++ b/ncdump/nccopy.c @@ -7,6 +7,7 @@ *********************************************************************/ #include "config.h" /* for USE_NETCDF4 macro */ +#include #include #include #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': diff --git a/ncdump/ncdump.c b/ncdump/ncdump.c index f577079813..abaa20e387 100644 --- a/ncdump/ncdump.c +++ b/ncdump/ncdump.c @@ -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); diff --git a/ncdump/tst_create_files.c b/ncdump/tst_create_files.c index c8122042a9..e4cee78e40 100644 --- a/ncdump/tst_create_files.c +++ b/ncdump/tst_create_files.c @@ -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; diff --git a/ncdump/tst_vlen_data.c b/ncdump/tst_vlen_data.c index ad5d18388e..f11b3932b7 100644 --- a/ncdump/tst_vlen_data.c +++ b/ncdump/tst_vlen_data.c @@ -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 */ diff --git a/nczarr_test/test_zchunks2.c b/nczarr_test/test_zchunks2.c index 7b471a2b9f..54963761c8 100644 --- a/nczarr_test/test_zchunks2.c +++ b/nczarr_test/test_zchunks2.c @@ -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");