From 3092a34191d8e6450da3cc771c923d2f40e9a827 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Tue, 30 Jun 2009 19:31:16 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@2930 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/dump.cpp | 18 ++++++++++++++---- src/fix_tmd.cpp | 8 ++++++-- src/fix_tmd.h | 2 +- src/read_data.cpp | 10 +++++++--- src/read_data.h | 2 +- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/dump.cpp b/src/dump.cpp index dc81b24252..6a6bb62f0d 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -106,8 +106,13 @@ Dump::~Dump() // XTC style sets fp to NULL since it closes file in its destructor if (multifile == 0 && fp != NULL) { - if (multiproc) fclose(fp); - else if (me == 0) fclose(fp); + if (compressed) { + if (multiproc) pclose(fp); + else if (me == 0) pclose(fp); + } else { + if (multiproc) fclose(fp); + else if (me == 0) fclose(fp); + } } } @@ -205,8 +210,13 @@ void Dump::write() // if file per timestep, close file if (multifile) { - if (multiproc) fclose(fp); - else if (me == 0) fclose(fp); + if (compressed) { + if (multiproc) pclose(fp); + else if (me == 0) pclose(fp); + } else { + if (multiproc) fclose(fp); + else if (me == 0) fclose(fp); + } } } diff --git a/src/fix_tmd.cpp b/src/fix_tmd.cpp index 39a77f37a9..1dd6bb3831 100644 --- a/src/fix_tmd.cpp +++ b/src/fix_tmd.cpp @@ -500,7 +500,11 @@ void FixTMD::readfile(char *file) // clean up delete [] buffer; - if (me == 0) fclose(fp); + + if (me == 0) { + if (compressed) pclose(fp); + else fclose(fp); + } // check that all atoms in group were listed in target file // set xf = 0.0 for atoms not in group @@ -525,7 +529,7 @@ void FixTMD::readfile(char *file) void FixTMD::open(char *file) { - int compressed = 0; + compressed = 0; char *suffix = file + strlen(file) - 3; if (suffix > file && strcmp(suffix,".gz") == 0) compressed = 1; if (!compressed) fp = fopen(file,"r"); diff --git a/src/fix_tmd.h b/src/fix_tmd.h index 7ea5582fed..ffa916182a 100644 --- a/src/fix_tmd.h +++ b/src/fix_tmd.h @@ -37,7 +37,7 @@ class FixTMD : public Fix { private: int me; - int nfileevery,previous_stat; + int nfileevery,previous_stat,compressed; FILE *fp; double rho_start,rho_stop,rho_old,masstotal; double dtv,dtf; diff --git a/src/read_data.cpp b/src/read_data.cpp index 9673e94486..11e36fc830 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -86,7 +86,8 @@ void ReadData::command(int narg, char **arg) header(0); scan(atom->bond_per_atom,atom->angle_per_atom, atom->dihedral_per_atom,atom->improper_per_atom); - fclose(fp); + if (compressed) pclose(fp); + else fclose(fp); atom->bond_per_atom += atom->extra_bond_per_atom; } @@ -256,7 +257,10 @@ void ReadData::command(int narg, char **arg) // close file - if (me == 0) fclose(fp); + if (me == 0) { + if (compressed) pclose(fp); + else fclose(fp); + } // error if natoms > 0 yet no atoms were read @@ -1219,7 +1223,7 @@ int ReadData::reallocate(int **pcount, int cmax, int amax) void ReadData::open(char *file) { - int compressed = 0; + compressed = 0; char *suffix = file + strlen(file) - 3; if (suffix > file && strcmp(suffix,".gz") == 0) compressed = 1; if (!compressed) fp = fopen(file,"r"); diff --git a/src/read_data.h b/src/read_data.h index bff0c4d58d..50144694a3 100644 --- a/src/read_data.h +++ b/src/read_data.h @@ -29,7 +29,7 @@ class ReadData : protected Pointers { int me; char *line,*keyword,*buffer; FILE *fp; - int narg,maxarg; + int narg,maxarg,compressed; char **arg; void open(char *);