size_t OFile::llwrite(const char*ptr,size_t s) { size_t r; if(linked) return linked->llwrite(ptr,s); if(! (comm && comm->Get_rank()>0)) { if(!fp) plumed_merror("writing on uninitilized File"); if(gzfp) { #ifdef __PLUMED_HAS_ZLIB r=gzwrite(gzFile(gzfp),ptr,s); #else plumed_merror("file " + getPath() + ": trying to use a gz file without zlib being linked"); #endif } else { r=fwrite(ptr,1,s,fp); } } // This barrier is apparently useless since it comes // just before a Bcast. // // Anyway, it looks like it is solving an issue that appeared on // TRAVIS (at least on my laptop) so I add it here. // GB if(comm) comm->Barrier(); if(comm) comm->Bcast(r,0); return r; }
FileBase::~FileBase() { if(plumed) plumed->eraseFile(*this); if(!cloned && fp) fclose(fp); #ifdef __PLUMED_HAS_ZLIB if(!cloned && gzfp) gzclose(gzFile(gzfp)); #endif }
void IFile::reset(bool reset){ eof = reset; err = reset; if(!reset && fp) clearerr(fp); #ifdef __PLUMED_HAS_ZLIB if(!reset && gzfp) gzclearerr(gzFile(gzfp)); #endif return; }
void FileBase::close(){ plumed_assert(!cloned); eof=false; err=false; if(fp) std::fclose(fp); #ifdef __PLUMED_HAS_ZLIB if(gzfp) gzclose(gzFile(gzfp)); #endif fp=NULL; gzfp=NULL; }
FileBase& OFile::flush() { if(heavyFlush) { if(gzfp) { #ifdef __PLUMED_HAS_ZLIB gzclose(gzFile(gzfp)); gzfp=(void*)gzopen(const_cast<char*>(path.c_str()),"a"); #endif } else { fclose(fp); fp=std::fopen(const_cast<char*>(path.c_str()),"a"); } } else { FileBase::flush(); // if(gzfp) gzflush(gzFile(gzfp),Z_FINISH); // for some reason flushing with Z_FINISH has problems on linux // I thus use this (incomplete) flush #ifdef __PLUMED_HAS_ZLIB if(gzfp) gzflush(gzFile(gzfp),Z_FULL_FLUSH); #endif } return *this; }
size_t OFile::llwrite(const char*ptr,size_t s){ size_t r; if(linked) return linked->llwrite(ptr,s); if(! (comm && comm->Get_rank()>0)){ if(!fp) plumed_merror("writing on uninitilized File"); if(gzfp){ #ifdef __PLUMED_HAS_ZLIB r=gzwrite(gzFile(gzfp),ptr,s); #else plumed_merror("trying to use a gz file without zlib being linked"); #endif } else { r=fwrite(ptr,1,s,fp); } } if(comm) comm->Bcast(r,0); return r; }
size_t IFile::llread(char*ptr,size_t s){ plumed_assert(fp); size_t r; if(gzfp){ #ifdef __PLUMED_HAS_ZLIB int rr=gzread(gzFile(gzfp),ptr,s); if(rr==0) eof=true; if(rr<0) err=true; r=rr; #else plumed_merror("trying to use a gz file without zlib being linked"); #endif } else { r=fread(ptr,1,s,fp); if(feof(fp)) eof=true; if(ferror(fp)) err=true; } return r; }