diff --git a/src/universe.cpp b/src/universe.cpp index e5876e4f6c..860394de4c 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -12,6 +12,7 @@ ------------------------------------------------------------------------- */ #include "mpi.h" +#include "ctype.h" #include "stdlib.h" #include "string.h" #include "stdio.h" @@ -25,6 +26,8 @@ using namespace LAMMPS_NS; #define MAXLINE 256 +static char *date2num(const char *version); + /* ---------------------------------------------------------------------- create & initialize the universe of processors in communicator ------------------------------------------------------------------------- */ @@ -32,6 +35,7 @@ using namespace LAMMPS_NS; Universe::Universe(LAMMPS *lmp, MPI_Comm communicator) : Pointers(lmp) { version = (const char *) LAMMPS_VERSION "-ICMS"; + num_ver = date2num(version); uworld = uorig = communicator; MPI_Comm_rank(uworld,&me); @@ -57,6 +61,7 @@ Universe::~Universe() memory->destroy(procs_per_world); memory->destroy(root_proc); memory->destroy(uni2orig); + delete [] num_ver; } /* ---------------------------------------------------------------------- @@ -194,3 +199,41 @@ int Universe::consistent() if (n == nprocs) return 1; else return 0; } + +// helper function to convert LAMMPS data string to version id +// that can be used for both string and numerical comparisons +// where newer versions are "larger" than older ones. + +char *date2num(const char *version) +{ + int day,month,year; + day = month = year = 0; + + if (version) { + + while (*version != '\0' && isdigit(*version)) + ++version; + + if (strncmp(version,"Jan",3) == 0) month = 1; + if (strncmp(version,"Feb",3) == 0) month = 2; + if (strncmp(version,"Mar",3) == 0) month = 3; + if (strncmp(version,"Apr",3) == 0) month = 4; + if (strncmp(version,"May",3) == 0) month = 5; + if (strncmp(version,"Jun",3) == 0) month = 6; + if (strncmp(version,"Jul",3) == 0) month = 7; + if (strncmp(version,"Aug",3) == 0) month = 8; + if (strncmp(version,"Sep",3) == 0) month = 9; + if (strncmp(version,"Oct",3) == 0) month = 10; + if (strncmp(version,"Nov",3) == 0) month = 11; + if (strncmp(version,"Dec",3) == 0) month = 12; + + while (*version != '\0' && !isdigit(*version)) + ++version; + + year = atoi(version); + } + + char *ver = new char[10]; + sprintf(ver,"%04d%02d%02d", year % 10000, month, day % 100); + return ver; +} diff --git a/src/universe.h b/src/universe.h index ffd8aa32d9..acda345ab9 100644 --- a/src/universe.h +++ b/src/universe.h @@ -22,6 +22,8 @@ namespace LAMMPS_NS { class Universe : protected Pointers { public: const char *version; // LAMMPS version string = date + const char *num_ver; // numeric version id derived from version that + // can be used for string or numeric comparisons MPI_Comm uworld; // communicator for entire universe int me,nprocs; // my place in universe