diff --git a/src/NETCDF/dump_netcdf.cpp b/src/NETCDF/dump_netcdf.cpp index bc715c7b1d..f455678925 100644 --- a/src/NETCDF/dump_netcdf.cpp +++ b/src/NETCDF/dump_netcdf.cpp @@ -66,7 +66,6 @@ static const char NC_SCALE_FACTOR_STR[] = "scale_factor"; static constexpr int THIS_IS_A_FIX = -1; static constexpr int THIS_IS_A_COMPUTE = -2; static constexpr int THIS_IS_A_VARIABLE = -3; -static constexpr int THIS_IS_A_BIGINT = -4; /* ---------------------------------------------------------------------- */ @@ -104,8 +103,8 @@ DumpNetCDF::DumpNetCDF(LAMMPS *lmp, int narg, char **arg) : int idim = 0; int ndims = 1; std::string mangled = earg[i]; - Quantity quantity = Quantity::UNKNOWN; bool constant = false; + int quantity = Quantity::UNKNOWN; // name mangling // in the AMBER specification @@ -889,7 +888,7 @@ void DumpNetCDF::ncerr(int err, const char *descr, int line) { if (err != NC_NOERR) { if (descr) error->one(__FILE__, line, "NetCDF failed with error '{}' (while accessing '{}') ", - nc_strerror(err), descr, line); + nc_strerror(err), descr); else error->one(__FILE__, line,"NetCDF failed with error '{}' in line {} of {}.", nc_strerror(err)); } diff --git a/src/NETCDF/dump_netcdf.h b/src/NETCDF/dump_netcdf.h index 0ee1f63d6d..8e468692c5 100644 --- a/src/NETCDF/dump_netcdf.h +++ b/src/NETCDF/dump_netcdf.h @@ -24,17 +24,11 @@ DumpStyle(netcdf,DumpNetCDF); #else #ifndef LMP_DUMP_NETCDF_H -#define LMP_DUMP_NETCDFC_H +#define LMP_DUMP_NETCDF_H #include "dump_custom.h" namespace LAMMPS_NS { -namespace NetCDFUnits { - enum Quantity : int; -} // namespace NetCDFUnits - -const int NC_FIELD_NAME_MAX = 100; -const int DUMP_NC_MAX_DIMS = 100; class DumpNetCDF : public DumpCustom { public: @@ -43,13 +37,16 @@ class DumpNetCDF : public DumpCustom { virtual void write(); private: + static constexpr int NC_FIELD_NAME_MAX = 100; + static constexpr int DUMP_NC_MAX_DIMS = 100; + // per-atoms quantities (positions, velocities, etc.) struct nc_perat_t { int dims; // number of dimensions int field[DUMP_NC_MAX_DIMS]; // field indices corresponding to the dim. char name[NC_FIELD_NAME_MAX]; // field name int var; // NetCDF variable - NetCDFUnits::Quantity quantity; // type of the quantity + int quantity; // type of the quantity bool constant; // is this property per file (not per frame) int ndumped; // number of enties written for this prop. diff --git a/src/NETCDF/dump_netcdf_mpiio.cpp b/src/NETCDF/dump_netcdf_mpiio.cpp index de5c3e3e4a..6d381dcba2 100644 --- a/src/NETCDF/dump_netcdf_mpiio.cpp +++ b/src/NETCDF/dump_netcdf_mpiio.cpp @@ -66,7 +66,6 @@ static const char NC_SCALE_FACTOR_STR[] = "scale_factor"; static constexpr int THIS_IS_A_FIX = -1; static constexpr int THIS_IS_A_COMPUTE = -2; static constexpr int THIS_IS_A_VARIABLE = -3; -static constexpr int THIS_IS_A_BIGINT = -4; /* ---------------------------------------------------------------------- */ @@ -104,8 +103,7 @@ DumpNetCDFMPIIO::DumpNetCDFMPIIO(LAMMPS *lmp, int narg, char **arg) : int idim = 0; int ndims = 1; std::string mangled = earg[i]; - bool constant = false; - Quantity quantity = Quantity::UNKNOWN; + int quantity = Quantity::UNKNOWN; // name mangling // in the AMBER specification @@ -123,7 +121,7 @@ DumpNetCDFMPIIO::DumpNetCDFMPIIO(LAMMPS *lmp, int narg, char **arg) : idim = mangled[0] - 'x'; ndims = 3; mangled = "scaled_coordinates"; - // no quantity for scaled_coordinates + // no unit for scaled coordinates } else if ((mangled == "xu") || (mangled == "yu") || (mangled == "zu")) { idim = mangled[0] - 'x'; ndims = 3; @@ -222,8 +220,7 @@ void DumpNetCDFMPIIO::openfile() char *ptr = strchr(filestar,'*'); *ptr = '\0'; if (padflag == 0) - sprintf(filecurrent,"%s" BIGINT_FORMAT "%s", - filestar,update->ntimestep,ptr+1); + sprintf(filecurrent,"%s" BIGINT_FORMAT "%s", filestar,update->ntimestep,ptr+1); else { char bif[8],pad[16]; strcpy(bif,BIGINT_FORMAT); @@ -286,8 +283,6 @@ void DumpNetCDFMPIIO::openfile() if (!platform::file_is_readable(filecurrent)) error->all(FLERR, "cannot append to non-existent file {}", filecurrent); - MPI_Offset index[NC_MAX_VAR_DIMS], count[NC_MAX_VAR_DIMS]; - if (singlefile_opened) return; singlefile_opened = 1; @@ -352,7 +347,6 @@ void DumpNetCDFMPIIO::openfile() int dims[NC_MAX_VAR_DIMS]; MPI_Offset index[NC_MAX_VAR_DIMS], count[NC_MAX_VAR_DIMS]; - float d[1]; if (singlefile_opened) return; singlefile_opened = 1; @@ -367,18 +361,18 @@ void DumpNetCDFMPIIO::openfile() NCERRX( ncmpi_def_dim(ncid, NC_LABEL_STR, 10, &label_dim), NC_LABEL_STR ); for (int i = 0; i < n_perat; i++) { - int dims = perat[i].dims; - if (vector_dim[dims] < 0) { + int dim = perat[i].dims; + if (vector_dim[dim] < 0) { char dimstr[1024]; - if (dims == 3) { + if (dim == 3) { strcpy(dimstr, NC_SPATIAL_STR); - } else if (dims == 6) { + } else if (dim == 6) { strcpy(dimstr, NC_VOIGT_STR); } else { - sprintf(dimstr, "vec%i", dims); + sprintf(dimstr, "vec%i", dim); } - if (dims != 1) { - NCERRX( ncmpi_def_dim(ncid, dimstr, dims, &vector_dim[dims]), dimstr ); + if (dim != 1) { + NCERRX( ncmpi_def_dim(ncid, dimstr, dim, &vector_dim[dim]), dimstr ); } } } @@ -489,16 +483,13 @@ void DumpNetCDFMPIIO::openfile() index[1] = 0; count[0] = 1; count[1] = 5; - NCERR( ncmpi_put_vara_text(ncid, cell_angular_var, index, count, - "alpha") ); + NCERR( ncmpi_put_vara_text(ncid, cell_angular_var, index, count, "alpha") ); index[0] = 1; count[1] = 4; - NCERR( ncmpi_put_vara_text(ncid, cell_angular_var, index, count, - "beta") ); + NCERR( ncmpi_put_vara_text(ncid, cell_angular_var, index, count, "beta") ); index[0] = 2; count[1] = 5; - NCERR( ncmpi_put_vara_text(ncid, cell_angular_var, index, count, - "gamma") ); + NCERR( ncmpi_put_vara_text(ncid, cell_angular_var, index, count, "gamma") ); } NCERR( ncmpi_end_indep_data(ncid) ); @@ -886,8 +877,7 @@ void DumpNetCDFMPIIO::ncerr(int err, const char *descr, int line) if (err != NC_NOERR) { if (descr) error->one(__FILE__, line, "NetCDF failed with error '{}' (while accessing '{}') ", ncmpi_strerror(err), descr); - else error->one(__FILE__, line,"NetCDF failed with error '{}' in line {} of {}.", - ncmpi_strerror(err)); + else error->one(__FILE__, line,"NetCDF failed with error '{}'.", ncmpi_strerror(err)); } } diff --git a/src/NETCDF/dump_netcdf_mpiio.h b/src/NETCDF/dump_netcdf_mpiio.h index 1046b86c85..ec6cbaec04 100644 --- a/src/NETCDF/dump_netcdf_mpiio.h +++ b/src/NETCDF/dump_netcdf_mpiio.h @@ -29,12 +29,6 @@ DumpStyle(netcdf/mpiio,DumpNetCDFMPIIO); #include "dump_custom.h" namespace LAMMPS_NS { -namespace NetCDFUnits { - enum Quantity : int; -} // namespace NetCDFUnits - -const int NC_MPIIO_FIELD_NAME_MAX = 100; -const int DUMP_NC_MPIIO_MAX_DIMS = 100; class DumpNetCDFMPIIO : public DumpCustom { public: @@ -43,17 +37,18 @@ class DumpNetCDFMPIIO : public DumpCustom { virtual void write(); private: + static constexpr int NC_MPIIO_FIELD_NAME_MAX = 100; + static constexpr int DUMP_NC_MPIIO_MAX_DIMS = 100; + // per-atoms quantities (positions, velocities, etc.) struct nc_perat_t { int dims; // number of dimensions int field[DUMP_NC_MPIIO_MAX_DIMS]; // field indices corresponding to the dim. char name[NC_MPIIO_FIELD_NAME_MAX]; // field name int var; // NetCDF variable - NetCDFUnits::Quantity quantity; // type of the quantity + int quantity; // type of the quantity }; - typedef void (DumpNetCDFMPIIO::*funcptr_t)(void *); - int framei; // current frame index int blocki; // current block index int ndata; // number of data blocks to expect diff --git a/src/NETCDF/netcdf_units.cpp b/src/NETCDF/netcdf_units.cpp index 47ae184e42..0ee0ebbde0 100644 --- a/src/NETCDF/netcdf_units.cpp +++ b/src/NETCDF/netcdf_units.cpp @@ -23,7 +23,7 @@ using namespace LAMMPS_NS; -std::string NetCDFUnits::get_unit_for(const char *unit_style, Quantity quantity, Error *error) +std::string NetCDFUnits::get_unit_for(const char *unit_style, int quantity, Error *error) { if (!strcmp(unit_style, "lj")) { if (quantity == Quantity::UNKNOWN) { diff --git a/src/NETCDF/netcdf_units.h b/src/NETCDF/netcdf_units.h index abba927d94..abb48965ef 100644 --- a/src/NETCDF/netcdf_units.h +++ b/src/NETCDF/netcdf_units.h @@ -27,7 +27,7 @@ class Error; namespace NetCDFUnits { // type of quantity for per-atom values (used to get the unit) - enum Quantity : int { + enum Quantity { UNKNOWN = 0, TIME, DISTANCE, @@ -38,7 +38,7 @@ namespace NetCDFUnits { // get the name of the unit for the given `quantity` in the given LAMMPS // `unit_style` any error will be reported through `error` - std::string get_unit_for(const char *unit_style, Quantity quantity, Error *error); + std::string get_unit_for(const char *unit_style, int quantity, Error *error); } // namespace NetCDFUnits } // namespace LAMMPS_NS