diff --git a/src/MOLECULE/dump_bond.cpp b/src/MOLECULE/dump_bond.cpp index ef3e55bfac..4ce8e907cb 100644 --- a/src/MOLECULE/dump_bond.cpp +++ b/src/MOLECULE/dump_bond.cpp @@ -34,10 +34,6 @@ DumpBond::DumpBond(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) int n = strlen(str) + 1; format_default = new char[n]; strcpy(format_default,str); - - // one-time file open - - if (multifile == 0) openfile(); } /* ---------------------------------------------------------------------- */ @@ -53,6 +49,10 @@ void DumpBond::init() format = new char[n]; strcpy(format,str); strcat(format,"\n"); + + // open single file, one time only + + if (multifile == 0) openfile(); } /* ---------------------------------------------------------------------- */ diff --git a/src/dump.cpp b/src/dump.cpp index 3f0b6c3ed6..e0d2271685 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -53,6 +53,7 @@ Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) format_user = NULL; sort_flag = 0; + append_flag = 0; maxbuf = 0; buf = NULL; @@ -65,6 +66,7 @@ Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) // else if ends in .gz = gzipped text file // else ASCII text file + singlefile_opened = 0; compressed = 0; binary = 0; multifile = 0; @@ -233,7 +235,22 @@ void Dump::modify_params(int narg, char **arg) int iarg = 0; while (iarg < narg) { - if (strcmp(arg[iarg],"format") == 0) { + if (strcmp(arg[iarg],"append") == 0) { + if (iarg+2 > narg) error->all("Illegal dump_modify command"); + if (strcmp(arg[iarg+1],"yes") == 0) append_flag = 1; + else if (strcmp(arg[iarg+1],"no") == 0) append_flag = 0; + else error->all("Illegal dump_modify command"); + iarg += 2; + } else if (strcmp(arg[iarg],"every") == 0) { + if (iarg+2 > narg) error->all("Illegal dump_modify command"); + int n = atoi(arg[iarg+1]); + if (n <= 0) error->all("Illegal dump_modify command"); + int idump; + for (idump = 0; idump < output->ndump; idump++) + if (strcmp(id,output->dump[idump]->id) == 0) break; + output->dump_every[idump] = n; + iarg += 2; + } else if (strcmp(arg[iarg],"format") == 0) { if (iarg+2 > narg) error->all("Illegal dump_modify command"); delete [] format_user; format_user = NULL; @@ -249,15 +266,6 @@ void Dump::modify_params(int narg, char **arg) else if (strcmp(arg[iarg+1],"no") == 0) flush_flag = 0; else error->all("Illegal dump_modify command"); iarg += 2; - } else if (strcmp(arg[iarg],"every") == 0) { - if (iarg+2 > narg) error->all("Illegal dump_modify command"); - int n = atoi(arg[iarg+1]); - if (n <= 0) error->all("Illegal dump_modify command"); - int idump; - for (idump = 0; idump < output->ndump; idump++) - if (strcmp(id,output->dump[idump]->id) == 0) break; - output->dump_every[idump] = n; - iarg += 2; } else if (strcmp(arg[iarg],"sort") == 0) { if (iarg+2 > narg) error->all("Illegal dump_modify command"); if (strcmp(arg[iarg+1],"yes") == 0) sort_flag = 1; @@ -290,6 +298,11 @@ double Dump::memory_usage() void Dump::openfile() { + // single file, already opened, so just return + + if (singlefile_opened) return; + if (multifile == 0) singlefile_opened = 1; + // if one file per timestep, replace '*' with current timestep char *filecurrent; @@ -315,6 +328,8 @@ void Dump::openfile() #endif } else if (binary) { fp = fopen(filecurrent,"wb"); + } else if (append_flag) { + fp = fopen(filecurrent,"a"); } else { fp = fopen(filecurrent,"w"); } diff --git a/src/dump.h b/src/dump.h index 8effa149ad..5823fc8a4e 100644 --- a/src/dump.h +++ b/src/dump.h @@ -35,6 +35,8 @@ class Dump : protected Pointers { int header_flag; // 0 = item, 2 = xyz int flush_flag; // 0 if no flush, 1 if flush every dump int sort_flag; // 1 if write in sorted order, 0 if not + int append_flag; // 1 if open file in append mode, 0 if not + int singlefile_opened; // 1 = one big file, already opened, else 0 char *format_default; // default format string char *format_user; // format string set by user diff --git a/src/dump_atom.cpp b/src/dump_atom.cpp index d4700ce86a..8635546ef3 100644 --- a/src/dump_atom.cpp +++ b/src/dump_atom.cpp @@ -30,10 +30,6 @@ DumpAtom::DumpAtom(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) scale_flag = 1; image_flag = 0; format_default = NULL; - - // one-time file open - - if (multifile == 0) openfile(); } /* ---------------------------------------------------------------------- */ @@ -99,6 +95,10 @@ void DumpAtom::init() if (binary) write_choice = &DumpAtom::write_binary; else if (image_flag == 0) write_choice = &DumpAtom::write_noimage; else if (image_flag == 1) write_choice = &DumpAtom::write_image; + + // open single file, one time only + + if (multifile == 0) openfile(); } /* ---------------------------------------------------------------------- */ diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 7501713264..81e1331297 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -112,10 +112,6 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) : strcat(columns,arg[iarg]); strcat(columns," "); } - - // one-time file open - - if (multifile == 0) openfile(); } /* ---------------------------------------------------------------------- */ @@ -219,6 +215,10 @@ void DumpCustom::init() if (ivariable < 0) error->all("Could not find dump custom variable name"); variable[i] = ivariable; } + + // open single file, one time only + + if (multifile == 0) openfile(); } /* ---------------------------------------------------------------------- */ diff --git a/src/dump_xyz.cpp b/src/dump_xyz.cpp index 0656843f5c..5aaca3c396 100644 --- a/src/dump_xyz.cpp +++ b/src/dump_xyz.cpp @@ -45,9 +45,6 @@ DumpXYZ::DumpXYZ(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) coords = (float *) memory->smalloc(3*natoms*sizeof(float),"dump:coords"); } - // one-time file open - - if (multifile == 0) openfile(); ntotal = 0; } @@ -74,6 +71,10 @@ void DumpXYZ::init() format = new char[n]; strcpy(format,str); strcat(format,"\n"); + + // open single file, one time only + + if (multifile == 0) openfile(); } /* ----------------------------------------------------------------------