add code to compute and provide a "comparable" numeric version id in Universe

This commit is contained in:
Axel Kohlmeyer
2015-08-31 17:42:51 -04:00
parent b15ee604a0
commit b6c07bddc6
2 changed files with 45 additions and 0 deletions

View File

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