diff --git a/src/USER-NETCDF/dump_netcdf.cpp b/src/USER-NETCDF/dump_netcdf.cpp index 57404e40d6..af9f94a728 100644 --- a/src/USER-NETCDF/dump_netcdf.cpp +++ b/src/USER-NETCDF/dump_netcdf.cpp @@ -330,8 +330,7 @@ void DumpNetCDF::openfile() // Type mangling if (vtype[perat[i].field[0]] == INT) { xtype = NC_INT; - } - else { + } else { if (double_precision) xtype = NC_DOUBLE; else @@ -356,14 +355,12 @@ void DumpNetCDF::openfile() // framei == -1 means append to file, == -2 means override last frame // Note that in the input file this translates to 'yes', '-1', etc. - if (!append_flag) + if (framei <= 0) framei = nframes+framei+1; + if (framei < 1) framei = 1; + } else { + if (framei != 0) error->all(FLERR,"at keyword requires use of 'append yes'"); - if (framei < 0 || (append_flag && framei == 0)) - framei = nframes+framei+1; - if (framei < 1) framei = 1; - } - else { int dims[NC_MAX_VAR_DIMS]; size_t index[NC_MAX_VAR_DIMS], count[NC_MAX_VAR_DIMS]; double d[1]; @@ -933,7 +930,8 @@ int DumpNetCDF::modify_param(int narg, char **arg) if (iarg >= narg) error->all(FLERR,"expected additional arg after 'at' keyword."); framei = force->inumeric(FLERR,arg[iarg]); - if (framei < 0) framei--; + if (framei == 0) error->all(FLERR,"frame 0 not allowed for 'at' keyword."); + else if (framei < 0) framei--; iarg++; return 2; } diff --git a/src/USER-NETCDF/dump_netcdf_mpiio.cpp b/src/USER-NETCDF/dump_netcdf_mpiio.cpp index 746b904655..890029371e 100644 --- a/src/USER-NETCDF/dump_netcdf_mpiio.cpp +++ b/src/USER-NETCDF/dump_netcdf_mpiio.cpp @@ -351,10 +351,12 @@ void DumpNetCDFMPIIO::openfile() NCERR( ncmpi_inq_dimlen(ncid, frame_dim, &nframes) ); // framei == -1 means append to file, == -2 means override last frame // Note that in the input file this translates to 'yes', '-1', etc. - if (framei < 0 || (append_flag && framei == 0)) framei = nframes+framei+1; + if (framei <= 0) framei = nframes+framei+1; if (framei < 1) framei = 1; - } - else { + } else { + if (framei != 0) + error->all(FLERR,"at keyword requires use of 'append yes'"); + int dims[NC_MAX_VAR_DIMS]; MPI_Offset index[NC_MAX_VAR_DIMS], count[NC_MAX_VAR_DIMS]; double d[1]; @@ -920,11 +922,12 @@ int DumpNetCDFMPIIO::modify_param(int narg, char **arg) return 2; } else if (strcmp(arg[iarg],"at") == 0) { - if (!append_flag) - error->all(FLERR,"expected 'append yes' before 'at' keyword"); iarg++; + if (iarg >= narg) + error->all(FLERR,"expected additional arg after 'at' keyword."); framei = force->inumeric(FLERR,arg[iarg]); - if (framei < 0) framei--; + if (framei == 0) error->all(FLERR,"frame 0 not allowed for 'at' keyword."); + else if (framei < 0) framei--; iarg++; return 2; }