make some more use of {fmt} in lammps.cpp
This commit is contained in:
@ -50,6 +50,7 @@
|
||||
#include "error.h"
|
||||
#include "memory.h"
|
||||
#include "utils.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
@ -275,11 +276,11 @@ void Input::file(const char *filename)
|
||||
return command name to caller
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
char *Input::one(const char *single)
|
||||
char *Input::one(const std::string &single)
|
||||
{
|
||||
int n = strlen(single) + 1;
|
||||
int n = single.size() + 1;
|
||||
if (n > maxline) reallocate(line,maxline,n);
|
||||
strcpy(line,single);
|
||||
strcpy(line,single.c_str());
|
||||
|
||||
// echo the command unless scanning for label
|
||||
|
||||
@ -300,11 +301,8 @@ char *Input::one(const char *single)
|
||||
|
||||
// execute the command and return its name
|
||||
|
||||
if (execute_command()) {
|
||||
char *str = new char[maxline+32];
|
||||
sprintf(str,"Unknown command: %s",line);
|
||||
error->all(FLERR,str);
|
||||
}
|
||||
if (execute_command())
|
||||
error->all(FLERR,fmt::format("Unknown command: {}",line).c_str());
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ class Input : protected Pointers {
|
||||
~Input();
|
||||
void file(); // process all input
|
||||
void file(const char *); // process an input script
|
||||
char *one(const char *); // process a single command
|
||||
char *one(const std::string&); // process a single command
|
||||
void substitute(char *&, char *&, int &, int &, int);
|
||||
// substitute for variables in a string
|
||||
int expand_args(int, char **, int, char **&); // expand args due to wildcard
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user