123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- /**
- * @file artis-star/observer/Output.hpp
- * @author See the AUTHORS file
- */
- /*
- * Copyright (C) 2013-2019 ULCO http://www.univ-littoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef ARTIS_COMMON_OBSERVER_OUTPUT_HPP
- #define ARTIS_COMMON_OBSERVER_OUTPUT_HPP
- #include <artis-star/common/observer/Iterator.hpp>
- #include <artis-star/common/observer/Observer.hpp>
- #include <artis-star/common/observer/View.hpp>
- #include <boost/format.hpp>
- #include <fstream>
- namespace artis {
- namespace observer {
- template<typename Time>
- class Output {
- public:
- Output(const Observer<Time>& observer)
- :_observer(observer) { }
- virtual ~Output() { }
- void operator()(double begin, double end, double step) const
- {
- const typename Observer<Time>::Views& views = _observer.views();
- for (typename Observer<Time>::Views::const_iterator it =
- views.begin(); it != views.end(); ++it) {
- std::ofstream o((boost::format("%1%.csv") % it->first).str());
- const typename View<Time>::SelectorValues& values = it->second->values();
- std::vector<artis::observer::DiscreteTimeIterator<artis::common::DoubleTime>> its;
- o.precision(10);
- // write header
- o << "time";
- for (typename View<Time>::SelectorValues::const_iterator itv = values.begin();
- itv != values.end(); ++itv) {
- const typename View<Time>::VariableValues& vv = itv->second;
- for (typename View<Time>::VariableValues::const_iterator itvv = vv.begin();
- itvv != vv.end(); ++itvv) {
- o << ";" << itvv->first;
- its.push_back(
- artis::observer::DiscreteTimeIterator<artis::common::DoubleTime>(
- itvv->second, begin, step));
- }
- }
- o << std::endl;
- // write values
- bool more = true;
- double t = begin;
- while (more and t <= end) {
- more = false;
- o << t;
- for (auto& dtt: its) {
- if (dtt.has_next()) {
- o << ";" << (*dtt).second.to_string();
- ++dtt;
- more = true;
- } else {
- o << ";";
- }
- }
- o << std::endl;
- t += step;
- }
- }
- }
- private:
- const Observer<Time>& _observer;
- };
- }
- }
- #endif
|