From 023ccd9d7c190e962acf743f4e35e8e370abe70a Mon Sep 17 00:00:00 2001 From: sjplimp Date: Tue, 19 Jun 2012 14:01:40 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8321 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/fix_ave_correlate.cpp | 10 +++++++++- src/fix_ave_correlate.h | 3 ++- src/fix_ave_histo.cpp | 8 ++++++++ src/fix_ave_histo.h | 3 ++- src/fix_ave_spatial.cpp | 8 ++++++++ src/fix_ave_spatial.h | 3 ++- src/fix_ave_time.cpp | 12 +++++++++++- src/fix_ave_time.h | 3 ++- 8 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/fix_ave_correlate.cpp b/src/fix_ave_correlate.cpp index 5e8f1ab4b4..3a946ac7e9 100644 --- a/src/fix_ave_correlate.cpp +++ b/src/fix_ave_correlate.cpp @@ -99,6 +99,7 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg): startstep = 0; prefactor = 1.0; fp = NULL; + overwrite = 0; char *title1 = NULL; char *title2 = NULL; char *title3 = NULL; @@ -139,6 +140,9 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg): } } iarg += 2; + } else if (strcmp(arg[iarg],"rewrite") == 0) { + overwrite = 1; + iarg += 1; } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command"); delete [] title1; @@ -172,6 +176,8 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg): error->all(FLERR,"Illegal fix ave/correlate command"); if (ave == ONE && nfreq < (nrepeat-1)*nevery) error->all(FLERR,"Illegal fix ave/correlate command"); + if (ave != RUNNING && overwrite) + error->all(FLERR,"Illegal fix ave/correlate command"); for (int i = 0; i < nvalues; i++) { if (which[i] == COMPUTE) { @@ -255,6 +261,7 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg): fprintf(fp," %s*%s",arg[6+i],arg[6+j]); fprintf(fp,"\n"); } + filepos = ftell(fp); } delete [] title1; @@ -461,9 +468,10 @@ void FixAveCorrelate::end_of_step() save_corr[i][j] = 0.0; } - // output to file + // output result to file if (fp && me == 0) { + if (overwrite) fseek(fp,filepos,SEEK_SET); fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrepeat); for (i = 0; i < nrepeat; i++) { fprintf(fp,"%d %d %d",i+1,i*nevery,count[i]); diff --git a/src/fix_ave_correlate.h b/src/fix_ave_correlate.h index 5f960de30c..108074dd59 100644 --- a/src/fix_ave_correlate.h +++ b/src/fix_ave_correlate.h @@ -44,9 +44,10 @@ class FixAveCorrelate : public Fix { char **ids; FILE *fp; - int type,ave,startstep; + int type,ave,startstep,overwrite; double prefactor; char *title1,*title2,*title3; + long filepos; int firstindex; // index in values ring of earliest time sample int lastindex; // index in values ring of latest time sample diff --git a/src/fix_ave_histo.cpp b/src/fix_ave_histo.cpp index ac0da7e981..1f9a453a5f 100644 --- a/src/fix_ave_histo.cpp +++ b/src/fix_ave_histo.cpp @@ -241,6 +241,8 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal fix ave/histo command"); if (lo >= hi) error->all(FLERR,"Illegal fix ave/histo command"); if (nbins <= 0) error->all(FLERR,"Illegal fix ave/histo command"); + if (ave != RUNNING && overwrite) + error->all(FLERR,"Illegal fix ave/histo command"); int kindflag; for (int i = 0; i < nvalues; i++) { @@ -419,6 +421,7 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) : "Total-counts Missing-counts Min-value Max-value\n"); if (title3) fprintf(fp,"%s\n",title3); else fprintf(fp,"# Bin Coord Count Count/Total\n"); + filepos = ftell(fp); } delete [] title1; @@ -780,6 +783,7 @@ void FixAveHisto::end_of_step() // output result to file if (fp && me == 0) { + if (overwrite) fseek(fp,filepos,SEEK_SET); fprintf(fp,BIGINT_FORMAT " %d %g %g %g %g\n",ntimestep,nbins, stats_total[0],stats_total[1],stats_total[2],stats_total[3]); if (stats_total[0] != 0.0) @@ -886,6 +890,7 @@ void FixAveHisto::options(int narg, char **arg) startstep = 0; mode = SCALAR; beyond = IGNORE; + overwrite = 0; title1 = NULL; title2 = NULL; title3 = NULL; @@ -935,6 +940,9 @@ void FixAveHisto::options(int narg, char **arg) else if (strcmp(arg[iarg+1],"extra") == 0) beyond = EXTRA; else error->all(FLERR,"Illegal fix ave/histo command"); iarg += 2; + } else if (strcmp(arg[iarg],"rewrite") == 0) { + overwrite = 1; + iarg += 1; } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command"); delete [] title1; diff --git a/src/fix_ave_histo.h b/src/fix_ave_histo.h index 218d1c0705..3bac90c3a9 100644 --- a/src/fix_ave_histo.h +++ b/src/fix_ave_histo.h @@ -45,7 +45,8 @@ class FixAveHisto : public Fix { char **ids; FILE *fp; double lo,hi,binsize,bininv; - int kind,beyond; + int kind,beyond,overwrite; + long filepos; double stats[4],stats_total[4],stats_all[4]; double **stats_list; diff --git a/src/fix_ave_spatial.cpp b/src/fix_ave_spatial.cpp index d9f315a9f1..4bde5d2782 100644 --- a/src/fix_ave_spatial.cpp +++ b/src/fix_ave_spatial.cpp @@ -165,6 +165,7 @@ FixAveSpatial::FixAveSpatial(LAMMPS *lmp, int narg, char **arg) : fp = NULL; ave = ONE; nwindow = 0; + overwrite = 0; char *title1 = NULL; char *title2 = NULL; char *title3 = NULL; @@ -217,6 +218,9 @@ FixAveSpatial::FixAveSpatial(LAMMPS *lmp, int narg, char **arg) : } iarg += 2; if (ave == WINDOW) iarg++; + } else if (strcmp(arg[iarg],"rewrite") == 0) { + overwrite = 1; + iarg += 1; } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command"); delete [] title1; @@ -252,6 +256,8 @@ FixAveSpatial::FixAveSpatial(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal fix ave/spatial command"); if (ndim == 3 && delta[2] <= 0.0) error->all(FLERR,"Illegal fix ave/spatial command"); + if (ave != RUNNING && overwrite) + error->all(FLERR,"Illegal fix ave/spatial command"); for (int i = 0; i < nvalues; i++) { if (which[i] == COMPUTE) { @@ -313,6 +319,7 @@ FixAveSpatial::FixAveSpatial(LAMMPS *lmp, int narg, char **arg) : for (int i = 0; i < nvalues; i++) fprintf(fp," %s",arg[6+3*ndim+i]); fprintf(fp,"\n"); } + filepos = ftell(fp); } delete [] title1; @@ -790,6 +797,7 @@ void FixAveSpatial::end_of_step() // output result to file if (fp && me == 0) { + if (overwrite) fseek(fp,filepos,SEEK_SET); fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nbins); if (ndim == 1) for (m = 0; m < nbins; m++) { diff --git a/src/fix_ave_spatial.h b/src/fix_ave_spatial.h index 8eb260534c..a1cc59d7f2 100644 --- a/src/fix_ave_spatial.h +++ b/src/fix_ave_spatial.h @@ -41,7 +41,7 @@ class FixAveSpatial : public Fix { int me,nvalues; int nrepeat,nfreq,irepeat; bigint nvalid; - int ndim,normflag,regionflag,iregion; + int ndim,normflag,regionflag,iregion,overwrite; char *tstring,*sstring,*idregion; int *which,*argindex,*value2index; char **ids; @@ -53,6 +53,7 @@ class FixAveSpatial : public Fix { double xscale,yscale,zscale; double bin_volume; + long filepos; int dim[3],originflag[3],nlayers[3]; double origin[3],delta[3]; double offset[3],invdelta[3]; diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index 9fbcb97068..a595965b08 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -169,6 +169,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal fix ave/time command"); if (nfreq % nevery || (nrepeat-1)*nevery >= nfreq) error->all(FLERR,"Illegal fix ave/time command"); + if (ave != RUNNING && overwrite) + error->all(FLERR,"Illegal fix ave/time command"); for (int i = 0; i < nvalues; i++) { if (which[i] == COMPUTE && mode == SCALAR) { @@ -220,7 +222,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) : if (argindex[i] && argindex[i] > modify->fix[ifix]->size_array_cols) error->all(FLERR,"Fix ave/time fix array is accessed out-of-range"); if (nevery % modify->fix[ifix]->global_freq) - error->all(FLERR,"Fix for fix ave/time not computed at compatible time"); + error->all(FLERR, + "Fix for fix ave/time not computed at compatible time"); } else if (which[i] == VARIABLE) { int ivariable = input->variable->find(ids[i]); @@ -281,6 +284,7 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) : } fprintf(fp,"\n"); } + filepos = ftell(fp); } delete [] title1; @@ -626,6 +630,7 @@ void FixAveTime::invoke_scalar(bigint ntimestep) // output result to file if (fp && me == 0) { + if (overwrite) fseek(fp,filepos,SEEK_SET); fprintf(fp,BIGINT_FORMAT,ntimestep); for (i = 0; i < nvalues; i++) fprintf(fp," %g",vector_total[i]/norm); fprintf(fp,"\n"); @@ -764,6 +769,7 @@ void FixAveTime::invoke_vector(bigint ntimestep) // output result to file if (fp && me == 0) { + if (overwrite) fseek(fp,filepos,SEEK_SET); fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrows); for (i = 0; i < nrows; i++) { fprintf(fp,"%d",i+1); @@ -821,6 +827,7 @@ void FixAveTime::options(int narg, char **arg) mode = SCALAR; noff = 0; offlist = NULL; + overwrite = 0; title1 = NULL; title2 = NULL; title3 = NULL; @@ -868,6 +875,9 @@ void FixAveTime::options(int narg, char **arg) memory->grow(offlist,noff+1,"ave/time:offlist"); offlist[noff++] = atoi(arg[iarg+1]); iarg += 2; + } else if (strcmp(arg[iarg],"rewrite") == 0) { + overwrite = 1; + iarg += 1; } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command"); delete [] title1; diff --git a/src/fix_ave_time.h b/src/fix_ave_time.h index badec28d91..a1e6e2b93c 100644 --- a/src/fix_ave_time.h +++ b/src/fix_ave_time.h @@ -48,9 +48,10 @@ class FixAveTime : public Fix { int nrows; int ave,nwindow,nsum,startstep,mode; - int noff; + int noff,overwrite; int *offlist; char *title1,*title2,*title3; + long filepos; int norm,iwindow,window_limit; double *vector;