18 #include "eckit/config/Configuration.h"
19 #include "eckit/exception/Exceptions.h"
30 #include "oops/util/abor1_cpp.h"
31 #include "oops/util/DateTime.h"
32 #include "oops/util/Duration.h"
33 #include "oops/util/Logger.h"
34 #include "oops/util/stringFunctions.h"
39 namespace sf = util::stringfunctions;
47 const util::DateTime & vt)
48 : fld_(resol), time_(vt), vars_(vars)
50 oops::Log::trace() <<
"StateL95::StateL95 created" << std::endl;
54 : fld_(resol), time_(conf.getString(
"date")), vars_({
"x"})
56 oops::Log::trace() <<
"StateL95::StateL95 conf " << conf << std::endl;
57 if (conf.has(
"filename")) {
62 oops::Log::trace() <<
"StateL95::StateL95 created and read in." << std::endl;
66 : fld_(resol), time_(xx.time_), vars_(xx.vars_)
69 oops::Log::trace() <<
"StateL95::StateL95 created by interpolation." << std::endl;
73 : fld_(xx.fld_), time_(xx.time_), vars_(xx.vars_)
75 oops::Log::trace() <<
"StateL95::StateL95 copy-created." << std::endl;
79 oops::Log::trace() <<
"StateL95::StateL95 destructed." << std::endl;
102 std::string filename(config.getString(
"filename"));
103 sf::swapNameMember(config, filename);
104 oops::Log::trace() <<
"StateL95::read opening " << filename << std::endl;
105 std::ifstream fin(filename.c_str());
106 if (!fin.is_open()) ABORT(
"StateL95::read: Error opening file: " + filename);
114 const util::DateTime tt(stime);
116 ABORT(
"StateL95::read: date and data file inconsistent.");
122 oops::Log::trace() <<
"StateL95::read: file closed." << std::endl;
126 std::string dir = config.getString(
"datadir");
127 std::string exp = config.getString(
"exp");
128 std::string type = config.getString(
"type");
129 std::string filename = dir+
"/"+exp+
"."+type;
132 std::string memb = config.getString(
"member");
133 filename +=
"."+memb;
136 if (type ==
"fc" || type ==
"ens") {
137 const util::DateTime antime(config.getString(
"date"));
138 filename +=
"."+antime.toString();
139 const util::Duration step =
time_ - antime;
140 filename +=
"."+step.toString();
144 filename +=
"."+
time_.toString();
147 sf::swapNameMember(config, filename);
149 oops::Log::trace() <<
"StateL95::write opening " << filename << std::endl;
150 std::ofstream fout(filename.c_str());
151 if (!fout.is_open()) ABORT(
"StateL95::write: Error opening file: " + filename);
154 fout <<
time_ << std::endl;
159 oops::Log::trace() <<
"StateL95::write file closed." << std::endl;
163 os << std::endl <<
" Valid time: " <<
time_;
164 os << std::endl <<
fld_;
182 nn +=
time_.serialSize();
187 vect.push_back(1001.0);
189 vect.push_back(2002.0);
190 time_.serialize(vect);
191 vect.push_back(3003.0);
196 ASSERT(vect.at(index) == 1001.0);
199 ASSERT(vect.at(index) == 2002.0);
201 time_.deserialize(vect, index);
202 ASSERT(vect.at(index) == 3003.0);