move date2num() convernience function from Universe class to utils namespace

This commit is contained in:
Axel Kohlmeyer
2020-09-03 17:46:59 -04:00
parent a72ebb2ab2
commit ce78be864a
5 changed files with 69 additions and 43 deletions

View File

@ -27,8 +27,6 @@ using namespace LAMMPS_NS;
#define MAXLINE 256
static char *date2num(const char *version);
/* ----------------------------------------------------------------------
create & initialize the universe of processors in communicator
------------------------------------------------------------------------- */
@ -36,7 +34,9 @@ static char *date2num(const char *version);
Universe::Universe(LAMMPS *lmp, MPI_Comm communicator) : Pointers(lmp)
{
version = (const char *) LAMMPS_VERSION;
num_ver = date2num(version);
auto tmp_ver = new char[10];
snprintf(tmp_ver,10,"%08d",utils::date2num(version));
num_ver = tmp_ver;
uworld = uorig = communicator;
MPI_Comm_rank(uworld,&me);
@ -237,43 +237,3 @@ int Universe::consistent()
if (n == nprocs) return 1;
else return 0;
}
// helper function to convert the LAMMPS date string to a 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) {
day = atoi(version);
while (*version != '\0' && (isdigit(*version) || *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[12];
snprintf(ver,12,"%04d%02d%02d", year % 10000, month, day % 100);
return ver;
}