git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@11701 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2014-04-04 16:40:17 +00:00
parent 1646c124b1
commit 0de9e4252b
32 changed files with 112 additions and 107 deletions

View File

@ -780,6 +780,77 @@ bigint Force::bnumeric(const char *file, int line, char *str)
return ATOLL(str);
}
/* ----------------------------------------------------------------------
open a potential file as specified by name; failing that,
search in dir specified by env variable LAMMPS_POTENTIALS
------------------------------------------------------------------------- */
FILE *Force::open_potential(const char *name)
{
FILE *fp;
if (name == NULL) return NULL;
// attempt to open file directly
// if successful, return ptr
fp = fopen(name,"r");
if (fp) return fp;
// try the environment variable directory
const char *path = getenv("LAMMPS_POTENTIALS");
if (path == NULL) return NULL;
const char *pot = potname(name);
if (pot == NULL) return NULL;
size_t len1 = strlen(path);
size_t len2 = strlen(pot);
char *newpath = new char[len1+len2+2];
strcpy(newpath,path);
#if defined(_WIN32)
newpath[len1] = '\\';
newpath[len1+1] = 0;
#else
newpath[len1] = '/';
newpath[len1+1] = 0;
#endif
strcat(newpath,pot);
fp = fopen(newpath,"r");
delete[] newpath;
return fp;
}
/* ----------------------------------------------------------------------
strip off leading part of path, return just the filename
------------------------------------------------------------------------- */
const char *Force::potname(const char *path)
{
const char *pot;
if (path == NULL) return NULL;
#if defined(_WIN32)
// skip over the disk drive part of windows pathnames
if (isalpha(path[0]) && path[1] == ':')
path += 2;
#endif
for (pot = path; *path != '\0'; ++path) {
#if defined(_WIN32)
if ((*path == '\\') || (*path == '/')) pot = path + 1;
#else
if (*path == '/') pot = path + 1;
#endif
}
return pot;
}
/* ----------------------------------------------------------------------
memory usage of force classes
------------------------------------------------------------------------- */