Skip to content
Snippets Groups Projects
Commit 0fecfca9 authored by Marco Biasini's avatar Marco Biasini
Browse files

check for end of file more often

parent a978edb0
No related branches found
No related tags found
No related merge requests found
...@@ -153,7 +153,7 @@ bool read_frame(std::istream& istream, const DCDHeader& header, ...@@ -153,7 +153,7 @@ bool read_frame(std::istream& istream, const DCDHeader& header,
if(!istream) { if(!istream) {
/* premature EOF */ /* premature EOF */
LOG_ERROR("LoadCHARMMTraj: premature end of file while trying to read frame " LOG_ERROR("LoadCHARMMTraj: premature end of file while trying to read frame "
<< frame_num); << frame_num << "Nothing left to be read");
return false; return false;
} }
// x coord // x coord
...@@ -164,7 +164,12 @@ bool read_frame(std::istream& istream, const DCDHeader& header, ...@@ -164,7 +164,12 @@ bool read_frame(std::istream& istream, const DCDHeader& header,
for(uint j=0;j<frame.size();++j) { for(uint j=0;j<frame.size();++j) {
frame[j].x=xlist[j]; frame[j].x=xlist[j];
} }
if(!istream) {
/* premature EOF */
LOG_ERROR("LoadCHARMMTraj: premature end of file while trying to read frame "
<< frame_num << ". No y coordinates");
return false;
}
// y coord // y coord
if(gap_flag) istream.read(dummy,sizeof(dummy)); if(gap_flag) istream.read(dummy,sizeof(dummy));
istream.read(reinterpret_cast<char*>(&xlist[0]),sizeof(float)*xlist.size()); istream.read(reinterpret_cast<char*>(&xlist[0]),sizeof(float)*xlist.size());
...@@ -173,7 +178,12 @@ bool read_frame(std::istream& istream, const DCDHeader& header, ...@@ -173,7 +178,12 @@ bool read_frame(std::istream& istream, const DCDHeader& header,
for(uint j=0;j<frame.size();++j) { for(uint j=0;j<frame.size();++j) {
frame[j].y=xlist[j]; frame[j].y=xlist[j];
} }
if(!istream) {
/* premature EOF */
LOG_ERROR("LoadCHARMMTraj: premature end of file while trying to read frame "
<< frame_num << ". No z coordinates");
return false;
}
// z coord // z coord
if(gap_flag) istream.read(dummy,sizeof(dummy)); if(gap_flag) istream.read(dummy,sizeof(dummy));
istream.read(reinterpret_cast<char*>(&xlist[0]),sizeof(float)*xlist.size()); istream.read(reinterpret_cast<char*>(&xlist[0]),sizeof(float)*xlist.size());
...@@ -182,6 +192,12 @@ bool read_frame(std::istream& istream, const DCDHeader& header, ...@@ -182,6 +192,12 @@ bool read_frame(std::istream& istream, const DCDHeader& header,
for(uint j=0;j<frame.size();++j) { for(uint j=0;j<frame.size();++j) {
frame[j].z=xlist[j]; frame[j].z=xlist[j];
} }
if(!istream) {
/* premature EOF */
LOG_ERROR("LoadCHARMMTraj: premature end of file while trying to read frame "
<< frame_num);
return false;
}
return true; return true;
} }
...@@ -201,10 +217,6 @@ mol::CoordGroupHandle load_dcd(const mol::AtomHandleList& alist, // this atom li ...@@ -201,10 +217,6 @@ mol::CoordGroupHandle load_dcd(const mol::AtomHandleList& alist, // this atom li
DCDHeader header; DCDHeader header;
bool swap_flag=false, skip_flag=false, gap_flag=false; bool swap_flag=false, skip_flag=false, gap_flag=false;
read_dcd_header(istream, header, swap_flag, skip_flag, gap_flag); read_dcd_header(istream, header, swap_flag, skip_flag, gap_flag);
LOG_DEBUG("LoadCHARMMTraj: " << header.num << " trajectories with "
<< header.atom_count << " atoms (" << header.f_atom_count
<< " fixed) each");
if(alist.size() != static_cast<size_t>(header.t_atom_count)) { if(alist.size() != static_cast<size_t>(header.t_atom_count)) {
LOG_ERROR("LoadCHARMMTraj: atom count missmatch: " << alist.size() LOG_ERROR("LoadCHARMMTraj: atom count missmatch: " << alist.size()
<< " in coordinate file, " << header.t_atom_count << " in coordinate file, " << header.t_atom_count
...@@ -218,6 +230,7 @@ mol::CoordGroupHandle load_dcd(const mol::AtomHandleList& alist, // this atom li ...@@ -218,6 +230,7 @@ mol::CoordGroupHandle load_dcd(const mol::AtomHandleList& alist, // this atom li
size_t frame_size=calc_frame_size(skip_flag, gap_flag, xlist.size()); size_t frame_size=calc_frame_size(skip_flag, gap_flag, xlist.size());
int i=0; int i=0;
for(;i<header.num;i+=stride) { for(;i<header.num;i+=stride) {
std::cout << i << " " << header.num << std::endl;
if (!read_frame(istream, header, frame_size, skip_flag, gap_flag, if (!read_frame(istream, header, frame_size, skip_flag, gap_flag,
swap_flag, xlist, clist, i)) { swap_flag, xlist, clist, i)) {
break; break;
...@@ -234,7 +247,8 @@ mol::CoordGroupHandle load_dcd(const mol::AtomHandleList& alist, // this atom li ...@@ -234,7 +247,8 @@ mol::CoordGroupHandle load_dcd(const mol::AtomHandleList& alist, // this atom li
<< istream.tellg()); << istream.tellg());
} }
LOG_VERBOSE("Loaded " << cg.GetFrameCount() << " frames with " << cg.GetAtomCount() << " atoms each"); LOG_VERBOSE("Loaded " << cg.GetFrameCount() << " frames with "
<< cg.GetAtomCount() << " atoms each");
return cg; return cg;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment