From 276e3b2df10e5f3ea160986f090651182b56aa5d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Jul 2019 14:00:24 -0400 Subject: [PATCH] update fix tmd input similar to read_data --- src/fix_tmd.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/fix_tmd.cpp b/src/fix_tmd.cpp index 4cbb244bc0..10315a750d 100644 --- a/src/fix_tmd.cpp +++ b/src/fix_tmd.cpp @@ -30,6 +30,7 @@ #include "force.h" #include "memory.h" #include "error.h" +#include "utils.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -164,7 +165,7 @@ void FixTMD::init() dtv = update->dt; dtf = update->dt * force->ftm2v; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) step_respa = ((Respa *) update->integrate)->step; } @@ -423,21 +424,27 @@ void FixTMD::readfile(char *file) *next = '\0'; if (firstline) { - if (strstr(bufptr,"xlo xhi")) { + if (utils::strmatch(bufptr,"^\\s*\\f+\\s+\\f+\\s+xlo\\s+xhi")) { double lo,hi; - sscanf(bufptr,"%lg %lg",&lo,&hi); + n = sscanf(bufptr,"%lg %lg",&lo,&hi); + if (n != 2) + error->all(FLERR,"Incorrect format in TMD target file"); xprd = hi - lo; bufptr = next + 1; continue; - } else if (strstr(bufptr,"ylo yhi")) { + } else if (utils::strmatch(bufptr,"^\\s*\\f+\\s+\\f+\\s+ylo\\s+yhi")) { double lo,hi; - sscanf(bufptr,"%lg %lg",&lo,&hi); + n = sscanf(bufptr,"%lg %lg",&lo,&hi); + if (n != 2) + error->all(FLERR,"Incorrect format in TMD target file"); yprd = hi - lo; bufptr = next + 1; continue; - } else if (strstr(bufptr,"zlo zhi")) { + } else if (utils::strmatch(bufptr,"^\\s*\\f+\\s+\\f+\\s+zlo\\s+zhi")) { double lo,hi; - sscanf(bufptr,"%lg %lg",&lo,&hi); + n = sscanf(bufptr,"%lg %lg",&lo,&hi); + if (n != 2) + error->all(FLERR,"Incorrect format in TMD target file"); zprd = hi - lo; bufptr = next + 1; continue; @@ -455,14 +462,13 @@ void FixTMD::readfile(char *file) } if (imageflag) - n = sscanf(bufptr,TAGINT_FORMAT " %lg %lg %lg %d %d %d", - &itag,&x,&y,&z,&ix,&iy,&iz); + n = 7 - sscanf(bufptr,TAGINT_FORMAT " %lg %lg %lg %d %d %d", + &itag,&x,&y,&z,&ix,&iy,&iz); else - n = sscanf(bufptr,TAGINT_FORMAT " %lg %lg %lg",&itag,&x,&y,&z); + n = 4 - sscanf(bufptr,TAGINT_FORMAT " %lg %lg %lg",&itag,&x,&y,&z); - if (n < 0) { - if (me == 0) error->warning(FLERR,"Ignoring empty or incorrectly" - " formatted line in target file"); + if (n != 0) { + error->all(FLERR,"Incorrectly formatted line in TMD target file"); bufptr = next + 1; continue; }