45#include "io/ZConsReader.hpp"
48#include "utils/simError.h"
52 ZConsReader::ZConsReader(SimInfo* info) : info_(info) {
53 std::string zconsFileName_ =
54 getPrefix(info_->getFinalConfigFileName()) +
".fz";
55 istream_.open(zconsFileName_.c_str());
58 std::cerr <<
"open " << zconsFileName_ <<
"error" << std::endl;
62 Globals* simParam = info_->getSimParams();
63 int nZconstraints = simParam->getNZconsStamps();
64 std::vector<ZConsStamp*> stamp = simParam->getZconsStamps();
65 for (
int i = 0; i < nZconstraints; i++) {
66 allZmols_.push_back(stamp[i]->getMolIndex());
70 void ZConsReader::readNextFrame() {
71 char line[MAXBUFFERSIZE];
75 fixedZmolData_.clear();
77 while (istream_.getline(line, MAXBUFFERSIZE) && line[0] ==
'/' &&
80 sscanfCount = sscanf(line,
"%lf", &curTime_);
81 if (sscanfCount != 1) {
82 std::cerr <<
"ZConsReader Error : reading file error" << std::endl;
86 istream_.getline(line, MAXBUFFERSIZE);
87 sscanfCount = sscanf(line,
"%d", &nFixedZmol);
88 if (sscanfCount != 1) {
89 std::cerr <<
"ZConsReader Error : reading file error" << std::endl;
94 for (
int i = 0; i < nFixedZmol; i++) {
95 istream_.getline(line, MAXBUFFERSIZE);
96 sscanfCount = sscanf(line,
"%d\t%lf\t%lf\t%lf", &data.zmolIndex,
97 &data.zforce, &data.zpos, &data.zconsPos);
98 if (sscanfCount != 4) {
99 std::cerr <<
"ZConsReader Error : reading file error" << std::endl;
103 fixedZmolData_.push_back(data);
107 bool ZConsReader::hasNextFrame() {
108 return istream_.peek() != EOF ? true :
false;
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)