simplify processing for "*" in filenames for embedding timestep by using utility function

This commit is contained in:
Axel Kohlmeyer
2022-03-29 06:06:48 -04:00
parent 015257889d
commit 27d2fab951
22 changed files with 102 additions and 446 deletions

View File

@ -81,44 +81,18 @@ DumpAtomADIOS::~DumpAtomADIOS()
void DumpAtomADIOS::openfile()
{
if (multifile) {
// if one file per timestep, replace '*' with current timestep
char *filestar = strdup(filename);
char *filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
snprintf(filecurrent, sizeof(filecurrent), "%s" BIGINT_FORMAT "%s",
filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
snprintf(pad, sizeof(pad), "%%s%%0%d%s%%s", padflag, &bif[1]);
snprintf(filecurrent, sizeof(filecurrent), pad, filestar,
update->ntimestep, ptr + 1);
}
internal->fh =
internal->io.Open(filecurrent, adios2::Mode::Write, world);
if (!internal->fh) {
char str[128];
snprintf(str, sizeof(str), "Cannot open dump file %s", filecurrent);
error->one(FLERR, str);
}
free(filestar);
delete[] filecurrent;
} else {
if (!singlefile_opened) {
internal->fh =
internal->io.Open(filename, adios2::Mode::Write, world);
if (!internal->fh) {
char str[128];
snprintf(str, sizeof(str), "Cannot open dump file %s",
filename);
error->one(FLERR, str);
}
singlefile_opened = 1;
}
if (multifile) {
// if one file per timestep, replace '*' with current timestep
auto filecurrent = utils::star_subst(filename, update->ntimestep, padflag);
internal->fh = internal->io.Open(filecurrent, adios2::Mode::Write, world);
if (!internal->fh) error->one(FLERR, "Cannot open dump file {}", filecurrent);
} else {
if (!singlefile_opened) {
internal->fh = internal->io.Open(filename, adios2::Mode::Write, world);
if (!internal->fh) error->one(FLERR, "Cannot open dump file {}", filename);
singlefile_opened = 1;
}
}
}
/* ---------------------------------------------------------------------- */

View File

@ -93,42 +93,18 @@ DumpCustomADIOS::~DumpCustomADIOS()
void DumpCustomADIOS::openfile()
{
if (multifile) {
// if one file per timestep, replace '*' with current timestep
char *filestar = strdup(filename);
char *filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar,
update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
internal->fh =
internal->io.Open(filecurrent, adios2::Mode::Write, world);
if (!internal->fh) {
char str[128];
sprintf(str, "Cannot open dump file %s", filecurrent);
error->one(FLERR, str);
}
free(filestar);
delete[] filecurrent;
} else {
if (!singlefile_opened) {
internal->fh =
internal->io.Open(filename, adios2::Mode::Write, world);
if (!internal->fh) {
char str[128];
sprintf(str, "Cannot open dump file %s", filename);
error->one(FLERR, str);
}
singlefile_opened = 1;
}
if (multifile) {
// if one file per timestep, replace '*' with current timestep
auto filecurrent = utils::star_subst(filename, update->ntimestep, padflag);
internal->fh = internal->io.Open(filecurrent, adios2::Mode::Write, world);
if (!internal->fh) error->one(FLERR, "Cannot open dump file {}", filecurrent);
} else {
if (!singlefile_opened) {
internal->fh = internal->io.Open(filename, adios2::Mode::Write, world);
if (!internal->fh) error->one(FLERR, "Cannot open dump file {}", filename);
singlefile_opened = 1;
}
}
}
/* ---------------------------------------------------------------------- */

View File

@ -46,19 +46,7 @@ void DumpAtomGZ::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -52,19 +52,7 @@ void DumpAtomZstd::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -48,19 +48,7 @@ void DumpCFGGZ::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -54,19 +54,7 @@ void DumpCFGZstd::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -46,19 +46,7 @@ void DumpCustomGZ::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -56,20 +56,7 @@ void DumpCustomZstd::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -46,19 +46,7 @@ void DumpLocalGZ::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -52,19 +52,7 @@ void DumpLocalZstd::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -45,19 +45,7 @@ void DumpXYZGZ::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -51,19 +51,7 @@ void DumpXYZZstd::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);

View File

@ -274,29 +274,12 @@ void DumpMolfile::openfile()
// if one file per timestep, replace '*' with current timestep
char *filecurrent = new char[strlen(filename) + 16];
if (multifile == 0) {
strcpy(filecurrent,filename);
} else {
char *ptr = strchr(filename,'*');
char *p1 = filename;
char *p2 = filecurrent;
while (p1 != ptr)
*p2++ = *p1++;
std::string filecurrent = filename;
if (multifile == 1)
filecurrent = utils::star_subst(filename, update->ntimestep, padflag);
if (padflag == 0) {
sprintf(p2,BIGINT_FORMAT "%s",update->ntimestep,ptr+1);
} else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%0%d%s%%s",padflag,&bif[1]);
sprintf(p2,pad,update->ntimestep,ptr+1);
}
}
if (mf->open(filecurrent,&natoms))
error->one(FLERR,"Cannot open dump file");
delete[] filecurrent;
if (mf->open(filecurrent.c_str(), &natoms))
error->one(FLERR,"Cannot open dump file {}: {}", filecurrent, utils::getsyserror());
}
}

View File

@ -69,19 +69,7 @@ void DumpAtomMPIIO::openfile()
filecurrent = filename;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0) {
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
} else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent) + 1];
@ -98,8 +86,8 @@ void DumpAtomMPIIO::openfile()
}
if (append_flag) { // append open
int err = MPI_File_open(world, filecurrent, MPI_MODE_CREATE | MPI_MODE_APPEND | MPI_MODE_WRONLY,
MPI_INFO_NULL, &mpifh);
int err = MPI_File_open(world, filecurrent, MPI_MODE_CREATE | MPI_MODE_APPEND |
MPI_MODE_WRONLY, MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS)
error->one(FLERR, "Cannot open dump file {}: {}", filecurrent, utils::getsyserror());
@ -112,8 +100,8 @@ void DumpAtomMPIIO::openfile()
} else { // replace open
int err =
MPI_File_open(world, filecurrent, MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &mpifh);
int err = MPI_File_open(world, filecurrent, MPI_MODE_CREATE | MPI_MODE_WRONLY,
MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS)
error->one(FLERR, "Cannot open dump file {}: {}", filecurrent, utils::getsyserror());

View File

@ -81,20 +81,7 @@ void DumpCFGMPIIO::openfile()
filecurrent = filename;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1];
@ -111,12 +98,10 @@ void DumpCFGMPIIO::openfile()
}
if (append_flag) { // append open
int err = MPI_File_open( world, filecurrent, MPI_MODE_CREATE | MPI_MODE_APPEND | MPI_MODE_WRONLY , MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS) {
char str[128];
sprintf(str,"Cannot open dump file %s",filecurrent);
error->one(FLERR,str);
}
int err = MPI_File_open( world, filecurrent, MPI_MODE_CREATE | MPI_MODE_APPEND |
MPI_MODE_WRONLY, MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS) error->one(FLERR, "Cannot open dump file {}", filecurrent);
int myrank;
MPI_Comm_rank(world,&myrank);
if (myrank == 0)
@ -125,15 +110,11 @@ void DumpCFGMPIIO::openfile()
MPI_File_set_size(mpifh,mpifo+headerSize+sumFileSize);
currentFileSize = mpifo+headerSize+sumFileSize;
}
else { // replace open
} else { // replace open
int err = MPI_File_open( world, filecurrent, MPI_MODE_CREATE | MPI_MODE_WRONLY , MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS) {
char str[128];
sprintf(str,"Cannot open dump file %s",filecurrent);
error->one(FLERR,str);
}
int err = MPI_File_open( world, filecurrent, MPI_MODE_CREATE | MPI_MODE_WRONLY,
MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS) error->one(FLERR, "Cannot open dump file {}", filecurrent);
mpifo = 0;
MPI_File_set_size(mpifh,(MPI_Offset) (headerSize+sumFileSize));

View File

@ -36,7 +36,6 @@
using namespace LAMMPS_NS;
#define MAX_TEXT_HEADER_SIZE 4096
#define DUMP_BUF_CHUNK_SIZE 16384
#define DUMP_BUF_INCREMENT_SIZE 4096
@ -71,7 +70,7 @@ DumpCustomMPIIO::~DumpCustomMPIIO()
void DumpCustomMPIIO::openfile()
{
if (singlefile_opened) { // single file already opened, so just return after resetting filesize
if (singlefile_opened) { // single file already opened, so just return after resetting filesize
mpifo = currentFileSize;
MPI_File_set_size(mpifh, mpifo + headerSize + sumFileSize);
currentFileSize = mpifo + headerSize + sumFileSize;
@ -84,19 +83,7 @@ void DumpCustomMPIIO::openfile()
filecurrent = filename;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar, '*');
*ptr = '\0';
if (padflag == 0) {
sprintf(filecurrent, "%s" BIGINT_FORMAT "%s", filestar, update->ntimestep, ptr + 1);
} else {
char bif[8], pad[16];
strcpy(bif, BIGINT_FORMAT);
sprintf(pad, "%%s%%0%d%s%%s", padflag, &bif[1]);
sprintf(filecurrent, pad, filestar, update->ntimestep, ptr + 1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent) + 1];

View File

@ -81,20 +81,7 @@ void DumpXYZMPIIO::openfile()
filecurrent = filename;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1];
@ -111,12 +98,10 @@ void DumpXYZMPIIO::openfile()
}
if (append_flag) { // append open
int err = MPI_File_open( world, filecurrent, MPI_MODE_CREATE | MPI_MODE_APPEND | MPI_MODE_WRONLY , MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS) {
char str[128];
sprintf(str,"Cannot open dump file %s",filecurrent);
error->one(FLERR,str);
}
int err = MPI_File_open( world, filecurrent, MPI_MODE_CREATE | MPI_MODE_APPEND |
MPI_MODE_WRONLY , MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS) error->one(FLERR, "Cannot open dump file {}",filecurrent);
int myrank;
MPI_Comm_rank(world,&myrank);
if (myrank == 0)
@ -124,20 +109,15 @@ void DumpXYZMPIIO::openfile()
MPI_Bcast(&mpifo, 1, MPI_LMP_BIGINT, 0, world);
MPI_File_set_size(mpifh,mpifo+headerSize+sumFileSize);
currentFileSize = mpifo+headerSize+sumFileSize;
}
else { // replace open
} else { // replace open
int err = MPI_File_open( world, filecurrent, MPI_MODE_CREATE | MPI_MODE_WRONLY , MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS) {
char str[128];
sprintf(str,"Cannot open dump file %s",filecurrent);
error->one(FLERR,str);
}
int err = MPI_File_open( world, filecurrent, MPI_MODE_CREATE | MPI_MODE_WRONLY,
MPI_INFO_NULL, &mpifh);
if (err != MPI_SUCCESS) error->one(FLERR, "Cannot open dump file {}",filecurrent);
mpifo = 0;
MPI_File_set_size(mpifh,(MPI_Offset) (headerSize+sumFileSize));
currentFileSize = (headerSize+sumFileSize);
}
}
@ -221,8 +201,8 @@ void DumpXYZMPIIO::write()
performEstimate = 0;
write_data(nme,buf);
if (multifile) MPI_File_close(&mpifh);
if (multifile) delete [] filecurrent;
if (multifile) MPI_File_close(&mpifh);
if (multifile) delete[] filecurrent;
}
/* ---------------------------------------------------------------------- */
@ -231,7 +211,7 @@ void DumpXYZMPIIO::init_style()
{
// format = copy of default or user-specified line format
delete [] format;
delete[] format;
char *str;
if (format_line_user) str = format_line_user;
else str = format_default;
@ -246,10 +226,8 @@ void DumpXYZMPIIO::init_style()
if (typenames == nullptr) {
typenames = new char*[ntypes+1];
for (int itype = 1; itype <= ntypes; itype++) {
typenames[itype] = new char[12];
sprintf(typenames[itype],"%d",itype);
}
for (int itype = 1; itype <= ntypes; itype++)
typenames[itype] = utils::strdup(std::to_string(itype));
}
// setup function ptr
@ -267,8 +245,7 @@ void DumpXYZMPIIO::write_header(bigint n)
headerSize = 0;
headerSize += sprintf(((char*)&((char*)headerBuffer)[headerSize]),BIGINT_FORMAT "\n",n);
headerSize += sprintf(&((char*)headerBuffer)[headerSize],"Atoms. Timestep: " BIGINT_FORMAT "\n",update->ntimestep);
}
else { // write data
} else { // write data
if (me == 0)
MPI_File_write_at(mpifh,mpifo,headerBuffer,headerSize,MPI_CHAR,MPI_STATUS_IGNORE);

View File

@ -178,7 +178,7 @@ DumpNetCDF::DumpNetCDF(LAMMPS *lmp, int narg, char **arg) :
for (int j = 0; j < DUMP_NC_MAX_DIMS; j++) {
perat[inc].field[j] = -1;
}
strncpy(perat[inc].name, mangled.c_str(), NC_FIELD_NAME_MAX);
strncpy(perat[inc].name, mangled.c_str(), NC_FIELD_NAME_MAX-1);
n_perat++;
}
@ -217,22 +217,9 @@ DumpNetCDF::~DumpNetCDF()
void DumpNetCDF::openfile()
{
char *filecurrent = filename;
if (multifile && !singlefile_opened) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s", filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
}
std::string filecurrent = filename;
if (multifile && !singlefile_opened)
filecurrent = utils::star_subst(filename, update->ntimestep, padflag);
if (thermo && !singlefile_opened) {
delete[] thermovar;
@ -291,7 +278,7 @@ void DumpNetCDF::openfile()
if (singlefile_opened) return;
singlefile_opened = 1;
NCERRX( nc_open(filecurrent, NC_WRITE, &ncid), filecurrent );
NCERRX( nc_open(filecurrent.c_str(), NC_WRITE, &ncid), filecurrent.c_str() );
// dimensions
NCERRX( nc_inq_dimid(ncid, NC_FRAME_STR, &frame_dim), NC_FRAME_STR );
@ -356,7 +343,7 @@ void DumpNetCDF::openfile()
if (singlefile_opened) return;
singlefile_opened = 1;
NCERRX( nc_create(filecurrent, NC_64BIT_DATA, &ncid), filecurrent );
NCERRX( nc_create(filecurrent.c_str(), NC_64BIT_DATA, &ncid), filecurrent.c_str() );
// dimensions
NCERRX( nc_def_dim(ncid, NC_FRAME_STR, NC_UNLIMITED, &frame_dim), NC_FRAME_STR );

View File

@ -177,7 +177,7 @@ DumpNetCDFMPIIO::DumpNetCDFMPIIO(LAMMPS *lmp, int narg, char **arg) :
for (int j = 0; j < DUMP_NC_MPIIO_MAX_DIMS; j++) {
perat[inc].field[j] = -1;
}
strncpy(perat[inc].name, mangled.c_str(), NC_MPIIO_FIELD_NAME_MAX);
strncpy(perat[inc].name, mangled.c_str(), NC_MPIIO_FIELD_NAME_MAX-1);
n_perat++;
}
@ -214,22 +214,9 @@ DumpNetCDFMPIIO::~DumpNetCDFMPIIO()
void DumpNetCDFMPIIO::openfile()
{
char *filecurrent = filename;
if (multifile && !singlefile_opened) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s", filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
}
std::string filecurrent = filename;
if (multifile && !singlefile_opened)
filecurrent = utils::star_subst(filename, update->ntimestep, padflag);
if (thermo && !singlefile_opened) {
delete[] thermovar;
@ -287,7 +274,8 @@ void DumpNetCDFMPIIO::openfile()
if (singlefile_opened) return;
singlefile_opened = 1;
NCERRX( ncmpi_open(world, filecurrent, NC_WRITE, MPI_INFO_NULL, &ncid), filecurrent );
NCERRX( ncmpi_open(world, filecurrent.c_str(), NC_WRITE, MPI_INFO_NULL, &ncid),
filecurrent.c_str() );
// dimensions
NCERRX( ncmpi_inq_dimid(ncid, NC_FRAME_STR, &frame_dim), NC_FRAME_STR );
@ -352,7 +340,8 @@ void DumpNetCDFMPIIO::openfile()
if (singlefile_opened) return;
singlefile_opened = 1;
NCERRX( ncmpi_create(world, filecurrent, NC_64BIT_DATA, MPI_INFO_NULL, &ncid), filecurrent );
NCERRX( ncmpi_create(world, filecurrent.c_str(), NC_64BIT_DATA, MPI_INFO_NULL, &ncid),
filecurrent.c_str() );
// dimensions
NCERRX( ncmpi_def_dim(ncid, NC_FRAME_STR, NC_UNLIMITED, &frame_dim), NC_FRAME_STR );

View File

@ -644,29 +644,15 @@ void FixReaxFFSpecies::WriteFormulas(int Nmole, int Nspec)
void FixReaxFFSpecies::OpenPos()
{
char *filecurrent;
bigint ntimestep = update->ntimestep;
filecurrent = (char*) malloc((strlen(filepos)+16)*sizeof(char));
char *ptr = strchr(filepos,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",filepos,ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filepos,ntimestep,ptr+1);
}
*ptr = '*';
if (me == 0) {
pos = fopen(filecurrent, "w");
if (pos == nullptr) error->one(FLERR,"Cannot open fix reaxff/species position file");
} else pos = nullptr;
auto filecurrent = utils::star_subst(filepos, update->ntimestep, padflag);
pos = fopen(filecurrent.c_str(), "w");
if (pos == nullptr)
error->one(FLERR, "Cannot open fix reaxff/species position file {}: {}", filecurrent,
utils::getsyserror());
} else
pos = nullptr;
multipos_opened = 1;
free(filecurrent);
}
/* ---------------------------------------------------------------------- */

View File

@ -1009,13 +1009,13 @@ void DumpVTK::write_data(int n, double *mybuf)
/* ---------------------------------------------------------------------- */
void DumpVTK::setFileCurrent() {
delete [] filecurrent;
delete[] filecurrent;
filecurrent = nullptr;
char *filestar = filename;
if (multiproc) {
if (multiproc > 1) { // if dump_modify fileper or nfile was used
delete [] multiname_ex;
delete[] multiname_ex;
multiname_ex = nullptr;
char *ptr = strchr(filename,'%');
if (ptr) {
@ -1034,26 +1034,13 @@ void DumpVTK::setFileCurrent() {
}
if (multifile == 0) {
filecurrent = new char[strlen(filestar) + 1];
strcpy(filecurrent, filestar);
filecurrent = utils::strdup(filestar);
} else {
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0) {
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
} else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filestar, update->ntimestep, padflag));
}
// filename of domain box data file
delete [] domainfilecurrent;
delete[] domainfilecurrent;
domainfilecurrent = nullptr;
if (multiproc) {
// remove '%' character
@ -1074,21 +1061,9 @@ void DumpVTK::setFileCurrent() {
domainfilecurrent = new char[strlen(filestar) + 1];
strcpy(domainfilecurrent, filestar);
} else {
domainfilecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0) {
sprintf(domainfilecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
} else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(domainfilecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
domainfilecurrent = utils::strdup(utils::star_subst(filestar, update->ntimestep, padflag));
}
delete [] filestar;
delete[] filestar;
filestar = nullptr;
} else {
domainfilecurrent = new char[strlen(filecurrent) + 16];
@ -1100,7 +1075,7 @@ void DumpVTK::setFileCurrent() {
// filename of parallel file
if (multiproc && me == 0) {
delete [] parallelfilecurrent;
delete[] parallelfilecurrent;
parallelfilecurrent = nullptr;
// remove '%' character and add 'p' to file extension
@ -1119,24 +1094,11 @@ void DumpVTK::setFileCurrent() {
*ptr++= 0;
if (multifile == 0) {
parallelfilecurrent = new char[strlen(filestar) + 1];
strcpy(parallelfilecurrent, filestar);
parallelfilecurrent = utils::strdup(filestar);
} else {
parallelfilecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0) {
sprintf(parallelfilecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
} else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(parallelfilecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
parallelfilecurrent = utils::strdup(utils::star_subst(filestar, update->ntimestep, padflag));
}
delete [] filestar;
delete[] filestar;
filestar = nullptr;
}
}

View File

@ -549,20 +549,7 @@ void Dump::openfile()
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
filecurrent = utils::strdup(utils::star_subst(filecurrent, update->ntimestep, padflag));
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = utils::strdup(filecurrent);
@ -594,7 +581,7 @@ void Dump::openfile()
// delete string with timestep replaced
if (multifile) delete [] filecurrent;
if (multifile) delete[] filecurrent;
}
/* ----------------------------------------------------------------------