23#if !defined(LOOS_TRAJWRITER_HPP)
24#define LOOS_TRAJWRITER_HPP
35#include <loos_defs.hpp>
36#include <AtomicGroup.hpp>
37#include <exceptions.hpp>
58 : _filename(fname), appending_(false) {
61 if (append && !stat(fname.c_str(), &statbuf))
62 openStream(fname,
true);
76 : _filename(
"stream"), appending_(append), delete_(false) {}
86 virtual void setComments(
const std::vector<std::string>& comments) { }
90 std::vector<std::string> c(1, s);
126 std::iostream* stream_;
127 std::string _filename;
137 void openStream(
const std::string& fname,
const bool append =
false) {
141 std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary;
143 mode |= std::ios_base::in;
145 mode |= std::ios_base::trunc;
147 stream_ =
new std::fstream(fname.c_str(), mode);
149 stream_->seekp(0, std::ios_base::end);
151 if (stream_->tellp() == 0)
157 if (!stream_->good())
158 throw(FileOpenError(fname,
"Error while opening output trajectory file"));
Class for handling groups of Atoms (pAtoms, actually)
Definition AtomicGroup.hpp:108
Base class for writing trajectories.
Definition trajwriter.hpp:53
virtual bool hasFrameTime() const
Can format write time on a per-frame basis?
Definition trajwriter.hpp:110
virtual uint framesWritten() const =0
Total frames in output file.
virtual bool hasFrameStep() const
Can format write step on a per-frame basis?
Definition trajwriter.hpp:107
virtual void setComments(const std::vector< std::string > &comments)
Set comments in metadata (not all formats support)
Definition trajwriter.hpp:86
virtual void setComments(const std::string &s)
Set comment in metadata (not all formats support)
Definition trajwriter.hpp:89
virtual void writeFrame(const AtomicGroup &model)=0
Wirte a single frame.
bool isAppending() const
Returns true if appending to an existing trajectory.
Definition trajwriter.hpp:123
virtual bool hasComments() const
Does format support comments in metadata?
Definition trajwriter.hpp:113
virtual void writeFrame(const AtomicGroup &model, const uint step, const double time)
Write a single frame specifying the step and timepoint.
Definition trajwriter.hpp:102
TrajectoryWriter(std::iostream *s, const bool append=false)
Write a trajectory to a stream.
Definition trajwriter.hpp:75
TrajectoryWriter(const std::string &fname, const bool append=false)
Write a trajectory to a file, optionally appending.
Definition trajwriter.hpp:57
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3