11 #ifndef OOPS_ASSIMILATION_STATE4D_H_
12 #define OOPS_ASSIMILATION_STATE4D_H_
19 #include "eckit/config/LocalConfiguration.h"
20 #include "eckit/exception/Exceptions.h"
24 #include "oops/util/Logger.h"
25 #include "oops/util/Printable.h"
35 template<
typename MODEL>
class State4D :
public util::Printable {
40 static const std::string
classname() {
return "State4D";}
47 void read(
const eckit::Configuration &);
48 void write(
const eckit::Configuration &)
const;
59 const std::vector<util::DateTime>
validTimes()
const;
66 void print(std::ostream &)
const;
73 template<
typename MODEL>
75 Log::trace() <<
"State4D config : " << config << std::endl;
77 if (config.has(
"states")) {
78 std::vector<eckit::LocalConfiguration> confs;
79 config.get(
"states", confs);
80 state4d_.reserve(confs.size());
81 for (
auto & conf : confs) {
82 state4d_.emplace_back(
State_(resol, conf));
86 state4d_.emplace_back(
State_(resol, config));
88 for (
size_t jj = 1; jj < state4d_.size(); ++jj) {
89 ASSERT(state4d_[jj].variables() == state4d_[0].variables());
91 Log::trace() <<
"State4D constructed." << std::endl;
96 template<
typename MODEL>
98 state4d_.emplace_back(state3d);
99 Log::trace() <<
"State4D constructed." << std::endl;
104 template<
typename MODEL>
107 if (config.has(
"states")) {
108 std::vector<eckit::LocalConfiguration> confs;
109 config.get(
"states", confs);
110 ASSERT(state4d_.size() == confs.size());
111 for (
size_t jj = 0; jj < state4d_.size(); ++jj) {
112 state4d_[jj].read(confs[jj]);;
116 ASSERT(state4d_.size() == 1);
117 state4d_[0].read(config);
119 for (
size_t jj = 1; jj < state4d_.size(); ++jj) {
120 ASSERT(state4d_[jj].variables() == state4d_[0].variables());
126 template<
typename MODEL>
129 if (config.has(
"states")) {
130 std::vector<eckit::LocalConfiguration> confs;
131 config.get(
"states", confs);
132 ASSERT(state4d_.size() == confs.size());
133 for (
size_t jj = 0; jj < state4d_.size(); ++jj) {
134 if (config.has(
"member")) confs[jj].set(
"member", config.getInt(
"member"));
135 state4d_[jj].write(confs[jj]);
139 ASSERT(state4d_.size() == 1);
140 state4d_[0].write(config);
146 template<
typename MODEL>
148 std::vector<util::DateTime> times;
149 times.reserve(state4d_.size());
150 for (
const State_ & state : state4d_) {
151 times.push_back(state.validTime());
158 template<
typename MODEL>
160 Log::trace() <<
"State4D<MODEL>::zero starting" << std::endl;
161 for (
State_ & state : state4d_) {
164 Log::trace() <<
"State4D<MODEL>::zero done" << std::endl;
169 template<
typename MODEL>
171 Log::trace() <<
"State4D<MODEL>::accumul starting" << std::endl;
172 ASSERT(xx.
size() == state4d_.size());
173 for (
size_t jj = 0; jj < state4d_.size(); ++jj) {
174 state4d_[jj].accumul(zz, xx[jj]);
176 Log::trace() <<
"State4D<MODEL>::accumul done" << std::endl;
181 template <
typename MODEL>
183 for (
const State_ & state : state4d_) {
184 outs << state << std::endl;
190 template<
typename MODEL>
193 for (
const State_ & state : state4d_) {
194 double zz = state.norm();
204 #endif // OOPS_ASSIMILATION_STATE4D_H_