print the last input line, when error->all() is called

this should help tracking down input file errors for many
common cases without having to repeat the run with -echo screen
and avoid having to explain how to use that feature all the time
This commit is contained in:
Axel Kohlmeyer
2017-01-09 17:03:06 -05:00
parent c31f1e9f22
commit 1a81da0f73
3 changed files with 15 additions and 6 deletions

View File

@ -17,6 +17,7 @@
#include "error.h" #include "error.h"
#include "universe.h" #include "universe.h"
#include "output.h" #include "output.h"
#include "input.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -107,11 +108,18 @@ void Error::all(const char *file, int line, const char *str)
MPI_Barrier(world); MPI_Barrier(world);
int me; int me;
const char *lastcmd = (const char*)"(unknown)";
MPI_Comm_rank(world,&me); MPI_Comm_rank(world,&me);
if (me == 0) { if (me == 0) {
if (screen) fprintf(screen,"ERROR: %s (%s:%d)\n",str,file,line); if (input && input->line) lastcmd = input->line;
if (logfile) fprintf(logfile,"ERROR: %s (%s:%d)\n",str,file,line); if (screen) fprintf(screen,"ERROR: %s (%s:%d)\n"
"Last command: %s\n",
str,file,line,lastcmd);
if (logfile) fprintf(logfile,"ERROR: %s (%s:%d)\n"
"Last command: %s\n",
str,file,line,lastcmd);
} }
#ifdef LAMMPS_EXCEPTIONS #ifdef LAMMPS_EXCEPTIONS

View File

@ -23,6 +23,7 @@ namespace LAMMPS_NS {
class Input : protected Pointers { class Input : protected Pointers {
friend class Info; friend class Info;
friend class Error;
public: public:
int narg; // # of command args int narg; // # of command args
char **arg; // parsed args for command char **arg; // parsed args for command