implement 'dump_modify maxfiles' feature as discussed

This commit is contained in:
Axel Kohlmeyer
2018-05-10 23:25:26 -04:00
parent 724ade0af3
commit 7780d92823
3 changed files with 64 additions and 1 deletions

View File

@ -91,6 +91,11 @@ Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
pbcflag = 0;
delay_flag = 0;
maxfiles = -1;
numfiles = 0;
fileidx = 0;
nameslist = NULL;
maxbuf = maxids = maxsort = maxproc = 0;
buf = bufsort = NULL;
ids = idsort = NULL;
@ -187,6 +192,13 @@ Dump::~Dump()
if (multiproc) MPI_Comm_free(&clustercomm);
// delete storage for caching file names
if (maxfiles > 0) {
for (int idx=0; idx < numfiles; ++idx)
delete[] nameslist[idx];
delete[] nameslist;
}
// XTC style sets fp to NULL since it closes file in its destructor
if (multifile == 0 && fp != NULL) {
@ -549,6 +561,19 @@ void Dump::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1];
strcpy(nameslist[numfiles],filecurrent);
++numfiles;
} else {
remove(nameslist[fileidx]);
delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1];
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles;
}
}
}
// each proc with filewriter = 1 opens a file
@ -1003,6 +1028,27 @@ void Dump::modify_params(int narg, char **arg)
iarg += n;
}
} else if (strcmp(arg[iarg],"maxfiles") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command");
if (!multifile)
error->all(FLERR,"Cannot use dump_modify maxfiles "
"without * in dump file name");
// wipe out existing storage
if (maxfiles > 0) {
for (int idx=0; idx < numfiles; ++idx)
delete[] nameslist[idx];
delete[] nameslist;
}
maxfiles = force->inumeric(FLERR,arg[iarg+1]);
if (maxfiles == 0) error->all(FLERR,"Illegal dump_modify command");
if (maxfiles > 0) {
nameslist = new char*[maxfiles];
numfiles = 0;
for (int idx=0; idx < maxfiles; ++idx)
nameslist[idx] = NULL;
fileidx = 0;
}
iarg += 2;
} else if (strcmp(arg[iarg],"nfile") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command");
if (!multiproc)