From ce8f0898592a056a0fe2993b2c00b2732a0c0f3e Mon Sep 17 00:00:00 2001
From: sjplimp <sjplimp@f3b2605a-c512-4ea7-a41b-209d697bcdaa>
Date: Sat, 19 May 2012 00:34:04 +0000
Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8105
 f3b2605a-c512-4ea7-a41b-209d697bcdaa

---
 src/fix.h         |   4 ++
 src/read_data.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++-
 src/read_data.h   |   7 +++
 3 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/src/fix.h b/src/fix.h
index f507cb5752..5919ed882e 100644
--- a/src/fix.h
+++ b/src/fix.h
@@ -146,6 +146,10 @@ class Fix : protected Pointers {
   virtual void reset_target(double) {}
   virtual void reset_dt() {}
 
+  virtual void read_data_header(char *) {}
+  virtual void read_data_section(char *, int, char *) {}
+  virtual int read_data_skip_lines(char *) {}
+
   virtual int modify_param(int, char **) {return 0;}
 
   virtual double memory_usage() {return 0.0;}
diff --git a/src/read_data.cpp b/src/read_data.cpp
index 73cc47b81a..2862c5d07a 100644
--- a/src/read_data.cpp
+++ b/src/read_data.cpp
@@ -25,6 +25,8 @@
 #include "atom_vec_tri.h"
 #include "comm.h"
 #include "update.h"
+#include "modify.h"
+#include "fix.h"
 #include "force.h"
 #include "pair.h"
 #include "domain.h"
@@ -82,13 +84,46 @@ ReadData::~ReadData()
 
 void ReadData::command(int narg, char **arg)
 {
-  if (narg != 1) error->all(FLERR,"Illegal read_data command");
+  if (narg < 1) error->all(FLERR,"Illegal read_data command");
 
   if (domain->box_exist) 
     error->all(FLERR,"Cannot read_data after simulation box is defined");
   if (domain->dimension == 2 && domain->zperiodic == 0)
     error->all(FLERR,"Cannot run 2d simulation with nonperiodic Z dimension");
 
+  // fixes that process data file info
+
+  nfix = 0;
+  fix_index = NULL;
+  fix_header = NULL;
+  fix_section = NULL;
+
+  int iarg = 1;
+  while (iarg < narg) {
+    if (strcmp(arg[iarg],"fix") == 0) {
+      if (iarg+4 > narg)
+	error->all(FLERR,"Illegal read_data command");
+      memory->grow(fix_index,nfix+1,"read_data:fix_index");
+      fix_header = (char **) 
+	memory->srealloc(fix_header,(nfix+1)*sizeof(char *),
+			 "read_data:fix_header");
+      fix_section = (char **) 
+	memory->srealloc(fix_section,(nfix+1)*sizeof(char *),
+			 "read_data:fix_section");
+      fix_index[nfix] = modify->find_fix(arg[iarg+1]);
+      if (fix_index[nfix] < 0) 
+	error->all(FLERR,"Fix ID for Read_data does not exist");
+      int n = strlen(arg[iarg+2]) + 1;
+      fix_header[nfix] = new char[n];
+      strcpy(fix_header[nfix],arg[iarg+2]);
+      n = strlen(arg[iarg+3]) + 1;
+      fix_section[nfix] = new char[n];
+      strcpy(fix_section[nfix],arg[iarg+3]);
+      nfix++;
+      iarg += 4;
+    } else error->all(FLERR,"Illegal read_data command");
+  }
+
   // scan data file to determine max topology needed per atom 
   // allocate initial topology arrays
 
@@ -146,6 +181,21 @@ void ReadData::command(int narg, char **arg)
   int atomflag = 0;
 
   while (strlen(keyword)) {
+
+    // allow special fixes first chance to match and process the section
+    // if fix matches, continue to next section
+
+    if (nfix) {
+      for (n = 0; n < nfix; n++)
+	if (strstr(line,fix_section[n])) {
+	  int nlines = modify->fix[fix_index[n]]->read_data_skip_lines(keyword);
+	  fix(n,keyword,nlines);
+	  parse_keyword(0,1);
+	  break;
+	}
+      if (n < nfix) continue;
+    }
+
     if (strcmp(keyword,"Atoms") == 0) {
       atoms();
       atomflag = 1;
@@ -370,6 +420,18 @@ void ReadData::header(int flag)
     if (ptr = strchr(line,'#')) *ptr = '\0';
     if (strspn(line," \t\n\r") == strlen(line)) continue;
 
+    // allow special fixes first chance to match and process the line
+    // if fix matches, continue to next header line
+
+    if (nfix) {
+      for (n = 0; n < nfix; n++)
+	if (strstr(line,fix_header[n])) {
+	  modify->fix[fix_index[n]]->read_data_header(line);
+	  break;
+	}
+      if (n < nfix) continue;
+    }
+
     // search line for header keyword and set corresponding variable
 
     if (strstr(line,"atoms")) sscanf(line,BIGINT_FORMAT,&atom->natoms);
@@ -1028,6 +1090,38 @@ void ReadData::impropercoeffs(int which)
   delete [] original;
 }
 
+/* ----------------------------------------------------------------------
+   read fix section, pass lines to fix to process
+   n = index of fix
+------------------------------------------------------------------------- */
+
+void ReadData::fix(int ifix, char *line, int nlines)
+{
+  int i,m,nchunk;
+
+  bigint nread = 0;
+
+  while (nread < nlines) {
+    if (nlines-nread > CHUNK) nchunk = CHUNK;
+    else nchunk = nlines-nread;
+    if (me == 0) {
+      char *eof;
+      m = 0;
+      for (i = 0; i < nchunk; i++) {
+	eof = fgets(&buffer[m],MAXLINE,fp);
+	if (eof == NULL) error->one(FLERR,"Unexpected end of data file");
+	m += strlen(&buffer[m]);
+      }
+      m++;
+    }
+    MPI_Bcast(&m,1,MPI_INT,0,world);
+    MPI_Bcast(buffer,m,MPI_CHAR,0,world);
+
+    modify->fix[ifix]->read_data_section(line,nchunk,buffer);
+    nread += nchunk;
+  }
+}
+
 /* ----------------------------------------------------------------------
    proc 0 scans the data file for topology maximums 
 ------------------------------------------------------------------------- */
@@ -1060,6 +1154,23 @@ void ReadData::scan(int &bond_per_atom, int &angle_per_atom,
 
   while (strlen(keyword)) {
 
+    // allow special fixes first chance to match and process the section
+    // if fix matches, continue to next section
+
+    if (nfix) {
+      for (i = 0; i < nfix; i++) {
+	printf("LINE SECTION %s %s\n",line,fix_section[i]);
+	if (strstr(line,fix_section[i])) {
+	  int n = modify->fix[fix_index[i]]->read_data_skip_lines(keyword);
+	  printf("NLINES SKIP %d\n",n);
+	  skip_lines(n);
+	  parse_keyword(0,0);
+	  break;
+	}
+      }
+      if (i < nfix) continue;
+    }
+
     if (strcmp(keyword,"Masses") == 0) skip_lines(atom->ntypes);
     else if (strcmp(keyword,"Atoms") == 0) skip_lines(natoms);
     else if (strcmp(keyword,"Velocities") == 0) skip_lines(natoms);
diff --git a/src/read_data.h b/src/read_data.h
index cc5d413468..2d29fc8fcc 100644
--- a/src/read_data.h
+++ b/src/read_data.h
@@ -38,6 +38,11 @@ class ReadData : protected Pointers {
   int narg,maxarg,compressed;
   char **arg;
 
+  int nfix;           // # of extra fixes that process/store info in data file
+  int *fix_index;
+  char **fix_header;
+  char **fix_section;
+
   bigint nellipsoids;
   class AtomVecEllipsoid *avec_ellipsoid;
   bigint nlines;
@@ -68,6 +73,8 @@ class ReadData : protected Pointers {
   void anglecoeffs(int);
   void dihedralcoeffs(int);
   void impropercoeffs(int);
+
+  void fix(int, char *, int);
 };
 
 }
-- 
GitLab