From 322f73bd50f557ebf4f27e8268bddcf070a8c86f Mon Sep 17 00:00:00 2001
From: Niklaus Johner <niklaus.johner@unibas.ch>
Date: Wed, 25 May 2016 13:10:22 +0200
Subject: [PATCH] Fix in dcd reader to allow reading of dcd files written by
 namd 2.11

We cannot rely on the header containing the number of frames in the
dcd files, as namd 2.11 sets this variable to 0.
---
 modules/io/src/mol/dcd_io.cc | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/modules/io/src/mol/dcd_io.cc b/modules/io/src/mol/dcd_io.cc
index f21b67afc..e81d31351 100644
--- a/modules/io/src/mol/dcd_io.cc
+++ b/modules/io/src/mol/dcd_io.cc
@@ -279,7 +279,7 @@ mol::CoordGroupHandle load_dcd(const mol::AtomHandleList& alist, // this atom li
   geom::Vec3 cell_size, cell_angles;
   size_t frame_size=calc_frame_size(ucell_flag, gap_flag, xlist.size());
   int i=0;
-  for(;i<header.num;i+=stride) {
+  while(true){
     if (!read_frame(istream, header, frame_size, ucell_flag, gap_flag, 
                     swap_flag, xlist, clist, i,cell_size,cell_angles)) {
       break;
@@ -292,11 +292,12 @@ mol::CoordGroupHandle load_dcd(const mol::AtomHandleList& alist, // this atom li
 
     // skip frames (defined by stride)
     if(stride>1) istream.seekg(frame_size*(stride-1),std::ios_base::cur);
-  }
-  istream.get();
-  if(!istream.eof()) {
-    LOG_VERBOSE("LoadCHARMMTraj: unexpected trailing file data, bytes read: " 
-                 << istream.tellg());
+    i+=stride;
+    istream.get();
+    if(istream.eof()){
+      break;
+    }
+    istream.unget();
   }
 
   LOG_VERBOSE("Loaded " << cg.GetFrameCount() << " frames with "
-- 
GitLab