diff --git a/cxx4/test_type.cpp b/cxx4/test_type.cpp index d40b9db..435bee0 100644 --- a/cxx4/test_type.cpp +++ b/cxx4/test_type.cpp @@ -409,17 +409,9 @@ try dummyFill.mem3[1]=97; dummyFill.mem3[2]=98; - struct3 dummyStruct2[2]; - dummyStruct2[0].mem1=1; - dummyStruct2[0].mem2=-1.23456; - dummyStruct2[0].mem3[0]=1; - dummyStruct2[0].mem3[1]=-6; - dummyStruct2[0].mem3[2]=20; - var_3.setFill(true,dummyFill); vector index(1);index[0]=1; - //var_3.putVar(&dummyStruct2); var_3.putVar(index,&dummyStruct); NcVar var_4(ncFile.getVar("var_3")); diff --git a/examples/pres_temp_4D_plugin_rd.cpp b/examples/pres_temp_4D_plugin_rd.cpp index fc5a309..c6ce5b1 100644 --- a/examples/pres_temp_4D_plugin_rd.cpp +++ b/examples/pres_temp_4D_plugin_rd.cpp @@ -100,8 +100,8 @@ int main() for (int lat = 0; lat < NLAT; lat++) for (int lon = 0; lon < NLON; lon++) { - if(pres_in[lvl][lat][lon] != (float) (SAMPLE_PRESSURE + i)) return NC_ERR; - if(temp_in[lvl][lat][lon] != (float)(SAMPLE_TEMP + i++)) return NC_ERR; + if(pres_in[lvl][lat][lon] != SAMPLE_PRESSURE + static_cast(i)) return NC_ERR; + if(temp_in[lvl][lat][lon] != SAMPLE_TEMP + static_cast(i++)) return NC_ERR; } } // next record diff --git a/examples/pres_temp_4D_plugin_wr.cpp b/examples/pres_temp_4D_plugin_wr.cpp index 832d2a6..d3f6c58 100644 --- a/examples/pres_temp_4D_plugin_wr.cpp +++ b/examples/pres_temp_4D_plugin_wr.cpp @@ -41,18 +41,18 @@ unsigned int idp = BZIP2_ID; size_t nparamsp = BZIP2_NPARAMS; // Names of things. -#define LVL_NAME "level" -#define LAT_NAME "latitude" -#define LON_NAME "longitude" -#define REC_NAME "time" -#define PRES_NAME "pressure" -#define TEMP_NAME "temperature" -#define MAX_ATT_LEN 80 +constexpr auto LVL_NAME = "level"; +constexpr auto LAT_NAME = "latitude"; +constexpr auto LON_NAME = "longitude"; +constexpr auto REC_NAME = "time"; +constexpr auto PRES_NAME = "pressure"; +constexpr auto TEMP_NAME = "temperature"; +constexpr auto MAX_ATT_LEN = 80; // 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 +constexpr float SAMPLE_PRESSURE = 900; +constexpr float SAMPLE_TEMP = 9.0; +constexpr float START_LAT = 25.0; +constexpr float START_LON = -125.0; string UNITS = "units"; @@ -84,17 +84,19 @@ int main() // create some pretend data. If this wasn't an example program, we // would have some real data to write for example, model output. - for (int lat = 0; lat < NLAT; lat++) - lats[lat] = START_LAT + 5. * lat; - for (int lon = 0; lon < NLON; lon++) - lons[lon] = START_LON + 5. * lon; + for (int lat = 0; lat < NLAT; lat++) { + lats[lat] = START_LAT + 5.f * static_cast(lat); + } + for (int lon = 0; lon < NLON; lon++) { + lons[lon] = START_LON + 5.f * static_cast(lon); + } for (int lvl = 0; lvl < NLVL; lvl++) for (int lat = 0; lat < NLAT; lat++) for (int lon = 0; lon < NLON; lon++) { - pres_out[lvl][lat][lon] =(float) (SAMPLE_PRESSURE + i); - temp_out[lvl][lat][lon] = (float)(SAMPLE_TEMP + i++); + pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + static_cast(i); + temp_out[lvl][lat][lon] = SAMPLE_TEMP + static_cast(i++); } try diff --git a/examples/pres_temp_4D_rd.cpp b/examples/pres_temp_4D_rd.cpp index fc5a309..6b34979 100644 --- a/examples/pres_temp_4D_rd.cpp +++ b/examples/pres_temp_4D_rd.cpp @@ -100,8 +100,8 @@ int main() for (int lat = 0; lat < NLAT; lat++) for (int lon = 0; lon < NLON; lon++) { - if(pres_in[lvl][lat][lon] != (float) (SAMPLE_PRESSURE + i)) return NC_ERR; - if(temp_in[lvl][lat][lon] != (float)(SAMPLE_TEMP + i++)) return NC_ERR; + if(pres_in[lvl][lat][lon] != SAMPLE_PRESSURE + static_cast(i)) return NC_ERR; + if(temp_in[lvl][lat][lon] != SAMPLE_TEMP + static_cast(i++)) return NC_ERR; } } // next record diff --git a/examples/pres_temp_4D_wr.cpp b/examples/pres_temp_4D_wr.cpp index b5a906d..ba5e3d4 100644 --- a/examples/pres_temp_4D_wr.cpp +++ b/examples/pres_temp_4D_wr.cpp @@ -26,25 +26,25 @@ using namespace netCDF::exceptions; // We are writing 4D data, a 2 x 6 x 12 lvl-lat-lon grid, with 2 // timesteps of data. -#define NDIMS 4 -#define NLVL 2 -#define NLAT 6 -#define NLON 12 -#define NREC 2 +constexpr int NDIMS = 4; +constexpr int NLVL = 2; +constexpr int NLAT = 6; +constexpr int NLON = 12; +constexpr int NREC = 2; // Names of things. -#define LVL_NAME "level" -#define LAT_NAME "latitude" -#define LON_NAME "longitude" -#define REC_NAME "time" -#define PRES_NAME "pressure" -#define TEMP_NAME "temperature" -#define MAX_ATT_LEN 80 +constexpr auto LVL_NAME = "level"; +constexpr auto LAT_NAME = "latitude"; +constexpr auto LON_NAME = "longitude"; +constexpr auto REC_NAME = "time"; +constexpr auto PRES_NAME = "pressure"; +constexpr auto TEMP_NAME = "temperature"; +constexpr auto MAX_ATT_LEN = 80; // 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 +constexpr float SAMPLE_PRESSURE = 900; +constexpr float SAMPLE_TEMP = 9.0; +constexpr float START_LAT = 25.0; +constexpr float START_LON = -125.0; string UNITS = "units"; @@ -64,7 +64,8 @@ string LON_UNITS = "degrees_east"; int main() { // We will write latitude and longitude fields. - float lats[NLAT],lons[NLON]; + float lats[NLAT]; + float lons[NLON]; // Program variables to hold the data we will write out. We will // only need enough space to hold one timestep of data; one record. @@ -75,18 +76,20 @@ int main() // create some pretend data. If this wasn't an example program, we // would have some real data to write for example, model output. - for (int lat = 0; lat < NLAT; lat++) - lats[lat] = START_LAT + 5. * lat; - for (int lon = 0; lon < NLON; lon++) - lons[lon] = START_LON + 5. * lon; + for (int lat = 0; lat < NLAT; lat++) { + lats[lat] = START_LAT + 5.f * static_cast(lat); + } + for (int lon = 0; lon < NLON; lon++) { + lons[lon] = START_LON + 5.f * static_cast(lon); + } for (int lvl = 0; lvl < NLVL; lvl++) for (int lat = 0; lat < NLAT; lat++) for (int lon = 0; lon < NLON; lon++) - { - pres_out[lvl][lat][lon] =(float) (SAMPLE_PRESSURE + i); - temp_out[lvl][lat][lon] = (float)(SAMPLE_TEMP + i++); - } + { + pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + static_cast(i); + temp_out[lvl][lat][lon] = SAMPLE_TEMP + static_cast(i++); + } try { diff --git a/examples/sfc_pres_temp_rd.cpp b/examples/sfc_pres_temp_rd.cpp index 2ccbeb6..3a0a2b6 100644 --- a/examples/sfc_pres_temp_rd.cpp +++ b/examples/sfc_pres_temp_rd.cpp @@ -93,8 +93,8 @@ int main(void) // Check the data. for (int lat = 0; lat < NLAT; lat++) for (int lon = 0; lon < NLON; lon++) - if (presIn[lat][lon] != SAMPLE_PRESSURE + (lon * NLAT + lat) - || tempIn[lat][lon] != SAMPLE_TEMP + .25 * (lon * NLAT + lat)) + if (presIn[lat][lon] != SAMPLE_PRESSURE + static_cast(lon * NLAT + lat) + || tempIn[lat][lon] != SAMPLE_TEMP + .25f * static_cast(lon * NLAT + lat)) return NC_ERR; // Each of the netCDF variables has a "units" attribute. Let's read diff --git a/examples/sfc_pres_temp_wr.cpp b/examples/sfc_pres_temp_wr.cpp index 762ddc9..db2307b 100644 --- a/examples/sfc_pres_temp_wr.cpp +++ b/examples/sfc_pres_temp_wr.cpp @@ -41,10 +41,10 @@ string LAT_NAME = "latitude"; string LON_NAME ="longitude"; // 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 +constexpr float SAMPLE_PRESSURE = 900; +constexpr float SAMPLE_TEMP = 9.0; +constexpr float START_LAT = 25.0; +constexpr float START_LON = -125.0; // Return this to OS if there is a failure. #define NC_ERR 2 @@ -62,11 +62,13 @@ int main(void) // hold the actual latitudes and longitudes. Since they hold data // about the coordinate system, the netCDF term for these is: // "coordinate variables." - for(int lat = 0;lat < NLAT; lat++) - lats[lat] = START_LAT + 5.*lat; + for(int lat = 0;lat < NLAT; lat++) { + lats[lat] = START_LAT + 5.f*static_cast(lat); + } - for(int lon = 0; lon < NLON; lon++) - lons[lon] = START_LON + 5.*lon; + for(int lon = 0; lon < NLON; lon++) { + lons[lon] = START_LON + 5.f*static_cast(lon); + } // Create some pretend data. If this wasn't an example program, we // would have some real data to write, for example, model @@ -74,8 +76,8 @@ int main(void) for (int lat = 0; lat < NLAT; lat++) for(int lon = 0;lon < NLON; lon++) { - presOut[lat][lon] = SAMPLE_PRESSURE + (lon * NLAT + lat); - tempOut[lat][lon] = SAMPLE_TEMP + .25 * (lon * NLAT +lat); + presOut[lat][lon] = SAMPLE_PRESSURE + static_cast(lon * NLAT + lat); + tempOut[lat][lon] = SAMPLE_TEMP + .25f * static_cast(lon * NLAT +lat); } try diff --git a/examples/simple_xy_wr_formats.cpp b/examples/simple_xy_wr_formats.cpp index 79faa94..971e473 100644 --- a/examples/simple_xy_wr_formats.cpp +++ b/examples/simple_xy_wr_formats.cpp @@ -88,20 +88,24 @@ int create_file(string filename, NcFile::FileFormat format) { int main() { int ret; - if(ret = create_file("simple_xy_nc4.nc", NcFile::nc4)) - return ret; + if ((ret = create_file("simple_xy_nc4.nc", NcFile::nc4))) { + return ret; + } cout << "*** SUCCESS creating nc4 file" << endl; - if(ret = create_file("simple_xy_nc4classic.nc", NcFile::nc4classic)) - return ret; + if ((ret = create_file("simple_xy_nc4classic.nc", NcFile::nc4classic))) { + return ret; + } cout << "*** SUCCESS creating nc4classic file" << endl; - if(ret = create_file("simple_xy_classic.nc", NcFile::classic)) - return ret; + if ((ret = create_file("simple_xy_classic.nc", NcFile::classic))) { + return ret; + } cout << "*** SUCCESS creating classic file" << endl; - if(ret = create_file("simple_xy_classic64.nc", NcFile::classic64)) - return ret; + if ((ret = create_file("simple_xy_classic64.nc", NcFile::classic64))) { + return ret; + } cout << "*** SUCCESS creating classic64 file" << endl; return 0;