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

@ -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;
}
}
}
/* ---------------------------------------------------------------------- */