make some more use of {fmt} in lammps.cpp

This commit is contained in:
Axel Kohlmeyer
2020-05-27 05:29:42 -04:00
parent dd61ac80f7
commit 1930a8fd00
3 changed files with 52 additions and 61 deletions

View File

@ -456,62 +456,55 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
MPI_Comm_split(universe->uworld,universe->iworld,0,&world);
MPI_Comm_rank(world,&me);
if (me == 0)
if (partscreenflag == 0)
if (screenflag == 0) {
char str[32];
sprintf(str,"screen.%d",universe->iworld);
screen = fopen(str,"w");
if (screen == NULL) error->one(FLERR,"Cannot open screen file");
} else if (strcmp(arg[screenflag],"none") == 0)
screen = NULL;
else {
char str[128];
snprintf(str,128,"%s.%d",arg[screenflag],universe->iworld);
screen = fopen(str,"w");
if (screen == NULL) error->one(FLERR,"Cannot open screen file");
}
else if (strcmp(arg[partscreenflag],"none") == 0)
screen = NULL;
else {
char str[128];
snprintf(str,128,"%s.%d",arg[partscreenflag],universe->iworld);
screen = fopen(str,"w");
if (screen == NULL) error->one(FLERR,"Cannot open screen file");
} else screen = NULL;
if (me == 0)
if (partlogflag == 0)
if (logflag == 0) {
char str[32];
sprintf(str,"log.lammps.%d",universe->iworld);
logfile = fopen(str,"w");
if (logfile == NULL) error->one(FLERR,"Cannot open logfile");
} else if (strcmp(arg[logflag],"none") == 0)
logfile = NULL;
else {
char str[128];
snprintf(str,128,"%s.%d",arg[logflag],universe->iworld);
logfile = fopen(str,"w");
if (logfile == NULL) error->one(FLERR,"Cannot open logfile");
}
else if (strcmp(arg[partlogflag],"none") == 0)
logfile = NULL;
else {
char str[128];
snprintf(str,128,"%s.%d",arg[partlogflag],universe->iworld);
logfile = fopen(str,"w");
if (logfile == NULL) error->one(FLERR,"Cannot open logfile");
} else logfile = NULL;
screen = logfile = infile = NULL;
if (me == 0) {
std::string str;
if (partscreenflag == 0) {
if (screenflag == 0) {
str = fmt::format("screen.{}",universe->iworld);
screen = fopen(str.c_str(),"w");
if (screen == NULL) error->one(FLERR,"Cannot open screen file");
} else if (strcmp(arg[screenflag],"none") == 0) {
screen = NULL;
} else {
str = fmt::format("{}.{}",arg[screenflag],universe->iworld);
screen = fopen(str.c_str(),"w");
if (screen == NULL) error->one(FLERR,"Cannot open screen file");
}
} else if (strcmp(arg[partscreenflag],"none") == 0) {
screen = NULL;
} else {
str = fmt::format("{}.{}",arg[partscreenflag],universe->iworld);
screen = fopen(str.c_str(),"w");
if (screen == NULL) error->one(FLERR,"Cannot open screen file");
}
if (partlogflag == 0) {
if (logflag == 0) {
str = fmt::format("log.lammps.{}",universe->iworld);
logfile = fopen(str.c_str(),"w");
if (logfile == NULL) error->one(FLERR,"Cannot open logfile");
} else if (strcmp(arg[logflag],"none") == 0) {
logfile = NULL;
} else {
str = fmt::format("{}.{}",arg[logflag],universe->iworld);
logfile = fopen(str.c_str(),"w");
if (logfile == NULL) error->one(FLERR,"Cannot open logfile");
}
} else if (strcmp(arg[partlogflag],"none") == 0) {
logfile = NULL;
} else {
str = fmt::format("{}.{}",arg[partlogflag],universe->iworld);
logfile = fopen(str.c_str(),"w");
if (logfile == NULL) error->one(FLERR,"Cannot open logfile");
}
infile = fopen(arg[inflag],"r");
if (infile == NULL) {
char str[128];
snprintf(str,128,"Cannot open input script %s",arg[inflag]);
error->one(FLERR,str);
str = fmt::format("Cannot open input script {}",arg[inflag]);
error->one(FLERR,str.c_str());
}
} else infile = NULL;
}
// screen and logfile messages for universe and world