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

@ -547,7 +547,7 @@ void PairADP::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fp = open_potential(filename);
fp = force->open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open ADP potential file %s",filename);

View File

@ -3327,7 +3327,7 @@ void PairAIREBO::read_file(char *filename)
// read file on proc 0
if (me == 0) {
FILE *fp = open_potential(filename);
FILE *fp = force->open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open AIREBO potential file %s",filename);

View File

@ -8204,7 +8204,7 @@ void PairBOP::read_file(char *filename)
rcore=0.1;
if (me == 0) {
FILE *fp = open_potential(filename);
FILE *fp = force->open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open BOP potential file %s",filename);
@ -8264,7 +8264,7 @@ void PairBOP::read_file(char *filename)
if (me == 0) {
words = new char*[bop_types];
for(i=0;i<bop_types;i++) words[i]=NULL;
FILE *fp = open_potential(filename);
FILE *fp = force->open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open BOP potential file %s",filename);
@ -8428,7 +8428,7 @@ void PairBOP::read_table(char *filename)
MPI_Comm_rank(world,&me);
if (me == 0) {
FILE *fp = open_potential(filename);
FILE *fp = force->open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open BOP potential file %s",filename);
@ -8477,7 +8477,7 @@ void PairBOP::read_table(char *filename)
allocate();
if (me == 0) {
FILE *fp = open_potential(filename);
FILE *fp = force->open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open BOP potential file %s",filename);

View File

@ -592,7 +592,7 @@ void PairComb::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = open_potential(file);
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open COMB potential file %s",file);

View File

@ -320,7 +320,7 @@ void PairComb3::read_lib()
// open libraray file on proc 0
if(comm->me == 0) {
FILE *fp = open_potential("lib.comb3");
FILE *fp = force->open_potential("lib.comb3");
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open COMB3 C library file \n");

View File

@ -439,7 +439,7 @@ void PairEAM::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = open_potential(filename);
fptr = force->open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

View File

@ -21,6 +21,7 @@
#include "pair_eam_alloy.h"
#include "atom.h"
#include "comm.h"
#include "force.h"
#include "memory.h"
#include "error.h"
@ -122,7 +123,7 @@ void PairEAMAlloy::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = open_potential(filename);
fptr = force->open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

View File

@ -21,6 +21,7 @@
#include "pair_eam_fs.h"
#include "atom.h"
#include "comm.h"
#include "force.h"
#include "memory.h"
#include "error.h"
@ -122,7 +123,7 @@ void PairEAMFS::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = open_potential(filename);
fptr = force->open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

View File

@ -457,7 +457,7 @@ void PairEIM::read_file(char *filename)
FILE *fptr;
if (me == 0) {
fptr = open_potential(filename);
fptr = force->open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EIM potential file %s",filename);

View File

@ -975,7 +975,7 @@ void PairLCBOP::read_file(char *filename)
// read file on proc 0
if (me == 0) {
FILE *fp = open_potential(filename);
FILE *fp = force->open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open LCBOP potential file %s",filename);

View File

@ -327,7 +327,7 @@ void PairNb3bHarmonic::read_file(char *file)
FILE *fp = NULL;
if (comm->me == 0) {
fp = open_potential(file);
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open nb3b/harmonic potential file %s",file);

View File

@ -337,7 +337,7 @@ void PairSW::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = open_potential(file);
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Stillinger-Weber potential file %s",file);

View File

@ -377,7 +377,7 @@ void PairTersoff::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = open_potential(file);
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Tersoff potential file %s",file);

View File

@ -57,7 +57,7 @@ void PairTersoffMOD::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = open_potential(file);
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Tersoff potential file %s",file);

View File

@ -74,7 +74,7 @@ void PairTersoffZBL::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = open_potential(file);
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Tersoff potential file %s",file);

View File

@ -460,7 +460,7 @@ void PairMEAM::read_files(char *globalfile, char *userfile)
FILE *fp;
if (comm->me == 0) {
fp = open_potential(globalfile);
fp = force->open_potential(globalfile);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open MEAM potential file %s",globalfile);
@ -641,7 +641,7 @@ void PairMEAM::read_files(char *globalfile, char *userfile)
// open user param file on proc 0
if (comm->me == 0) {
fp = open_potential(userfile);
fp = force->open_potential(userfile);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open MEAM potential file %s",userfile);

View File

@ -366,7 +366,7 @@ void AngleTable::read_table(Table *tb, char *file, char *keyword)
// open file
FILE *fp = fopen(file,"r");
FILE *fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open file %s",file);

View File

@ -292,7 +292,7 @@ void BondTable::read_table(Table *tb, char *file, char *keyword)
// open file
FILE *fp = fopen(file,"r");
FILE *fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open file %s",file);

View File

@ -1011,7 +1011,7 @@ void DihedralTable::read_table(Table *tb, char *file, char *keyword)
// open file
FILE *fp = fopen(file,"r");
FILE *fp = force->open_potential(file);
if (fp == NULL) {
string err_msg = string("Cannot open file ") + string(file);
error->one(FLERR,err_msg.c_str());

View File

@ -461,7 +461,7 @@ void PairCDEAM::read_h_coeff(char *filename)
FILE *fp;
char line[MAXLINE];
char nextline[MAXLINE];
fp = open_potential(filename);
fp = force->open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s", filename);

View File

@ -877,7 +877,7 @@ void PairEDIP::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = open_potential(file);
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open EDIP potential file %s",file);

View File

@ -218,7 +218,7 @@ void PairList::settings(int narg, char **arg)
if (strcmp(arg[2],"check") == 0) check_flag = 1;
}
FILE *fp = open_potential(arg[0]);
FILE *fp = force->open_potential(arg[0]);
char line[1024];
if (fp == NULL)
error->all(FLERR,"Cannot open pair list file");

View File

@ -434,7 +434,7 @@ void PairMEAMSpline::coeff(int narg, char **arg)
void PairMEAMSpline::read_file(const char* filename)
{
if(comm->me == 0) {
FILE *fp = open_potential(filename);
FILE *fp = force->open_potential(filename);
if(fp == NULL) {
char str[1024];
sprintf(str,"Cannot open spline MEAM potential file %s", filename);

View File

@ -463,7 +463,7 @@ void PairMEAMSWSpline::coeff(int narg, char **arg)
void PairMEAMSWSpline::read_file(const char* filename)
{
if(comm->me == 0) {
FILE *fp = open_potential(filename);
FILE *fp = force->open_potential(filename);
if(fp == NULL) {
char str[1024];
sprintf(str,"Cannot open spline MEAM potential file %s", filename);

View File

@ -851,7 +851,7 @@ void PairTersoffTable::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = open_potential(file);
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Tersoff potential file %s",file);

View File

@ -21,6 +21,7 @@
#include "pair_eam_alloy_omp.h"
#include "atom.h"
#include "comm.h"
#include "force.h"
#include "memory.h"
#include "error.h"
@ -121,7 +122,7 @@ void PairEAMAlloyOMP::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = open_potential(filename);
fptr = force->open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

View File

@ -21,6 +21,7 @@
#include "pair_eam_fs_omp.h"
#include "atom.h"
#include "comm.h"
#include "force.h"
#include "memory.h"
#include "error.h"
@ -121,7 +122,7 @@ void PairEAMFSOMP::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = open_potential(filename);
fptr = force->open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

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
------------------------------------------------------------------------- */

View File

@ -104,6 +104,10 @@ class Force : protected Pointers {
double numeric(const char *, int, char *);
int inumeric(const char *, int, char *);
bigint bnumeric(const char *, int, char *);
FILE *open_potential(const char *);
const char *potname(const char *);
bigint memory_usage();
private:

View File

@ -1624,77 +1624,6 @@ void Pair::init_bitmap(double inner, double outer, int ntablebits,
masklo = rsq_lookup.i & ~(nmask);
}
/* ----------------------------------------------------------------------
open a potential file as specified by name
failing that, search in dir specified by env variable LAMMPS_POTENTIALS
------------------------------------------------------------------------- */
FILE *Pair::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 *Pair::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;
}
/* ---------------------------------------------------------------------- */
double Pair::memory_usage()

View File

@ -213,9 +213,6 @@ class Pair : protected Pointers {
double, double, double, double, double, double);
void virial_fdotr_compute();
FILE *open_potential(const char *);
const char *potname(const char *);
inline int sbmask(int j) {
return j >> SBBITS & 3;
}

View File

@ -343,7 +343,7 @@ void PairTable::read_table(Table *tb, char *file, char *keyword)
// open file
FILE *fp = open_potential(file);
FILE *fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open file %s",file);