8 #ifndef SABER_OOPS_STATSVARIABLECHANGE_H_
9 #define SABER_OOPS_STATSVARIABLECHANGE_H_
15 #include "eckit/config/Configuration.h"
17 #include "oops/base/LinearVariableChangeBase.h"
18 #include "oops/base/Variables.h"
19 #include "oops/interface/Geometry.h"
20 #include "oops/interface/Increment.h"
21 #include "oops/interface/State.h"
40 template <
typename MODEL>
49 static const std::string
classname() {
return "saber::StatsVariableChange";}
52 const Geometry_ &,
const eckit::Configuration &);
63 void print(std::ostream &)
const override;
66 std::string& modelVarToCalcString,
67 std::string& varRegrByString);
69 std::vector<std::string>& modelVarToCalcList,
70 std::vector<std::string>& varRegrByList);
77 template<
typename MODEL>
80 const eckit::Configuration & conf)
81 :
oops::LinearVariableChangeBase<MODEL>(conf), ooBump_()
83 oops::Log::trace() <<
"StatsVariableChange<MODEL>::StatsVariableChange starting" << std::endl;
86 const oops::Variables vars(conf,
"input variables");
94 oops::Log::trace() <<
"StatsVariableChange<MODEL>::StatsVariableChange done" << std::endl;
97 template<
typename MODEL>
99 oops::Log::trace() <<
"StatsVariableChange<MODEL>::~StatsVariableChange starting" << std::endl;
100 util::Timer timer(classname(),
"~StatsVariableChange");
101 oops::Log::trace() <<
"StatsVariableChange<MODEL>::~StatsVariableChange done" << std::endl;
104 template<
typename MODEL>
106 oops::Log::trace() <<
"StatsVariableChange<MODEL>::multiply starting" << std::endl;
108 ooBump_->multiplyVbal(in, out);
110 oops::Log::trace() <<
"StatsVariableChange<MODEL>::multiply done" << std::endl;
113 template<
typename MODEL>
115 oops::Log::trace() <<
"StatsVariableChange<MODEL>::multiplyInverse starting" << std::endl;
117 ooBump_->multiplyVbalInv(in, out);
119 oops::Log::trace() <<
"StatsVariableChange<MODEL>::multiplyInverse done" << std::endl;
122 template<
typename MODEL>
124 oops::Log::trace() <<
"StatsVariableChange<MODEL>::multiplyAD starting" << std::endl;
126 ooBump_->multiplyVbalAd(in, out);
128 oops::Log::trace() <<
"StatsVariableChange<MODEL>::multiplyAD done" << std::endl;
131 template<
typename MODEL>
133 oops::Log::trace() <<
"StatsVariableChange<MODEL>::multiplyInverseAD starting" << std::endl;
135 ooBump_->multiplyVbalInvAd(in, out);
137 oops::Log::trace() <<
"StatsVariableChange<MODEL>::multiplyInverseAD done" << std::endl;
140 template<
typename MODEL>
144 template<
typename MODEL>
148 for (
int iCharIndex = pathString.length(); iCharIndex > 0; --iCharIndex)
150 if (pathString.substr(iCharIndex - 1, 1) ==
"/")
152 return pathString.substr(iCharIndex, pathString.length() - iCharIndex);
154 tempIndex = iCharIndex;
156 std::cout <<
"ExtractFileName: tempIndex = " << tempIndex << std::endl;
157 throw std::runtime_error(
"FileName not extracted from path " + pathString);
163 template<
typename MODEL>
165 std::string& modelVarToCalcString,
166 std::string& varRegrByString)
170 int firstUnderscoreIndex, lastUnderscoreIndex;
171 for (
int iCharIndex = 0; iCharIndex < fileString.length() - 1; ++iCharIndex)
173 firstUnderscoreIndex = iCharIndex;
174 if (fileString.substr(iCharIndex, 2) ==
"__")
179 for (
int iCharIndex = fileString.length(); iCharIndex > 0; --iCharIndex)
181 lastUnderscoreIndex = iCharIndex - 1;
182 if (fileString.substr(iCharIndex-1, 2) ==
"__")
187 modelVarToCalcString = fileString.substr(0, firstUnderscoreIndex);
188 varRegrByString = fileString.substr(firstUnderscoreIndex + 2,
189 lastUnderscoreIndex - firstUnderscoreIndex - 2);
193 template<
typename MODEL>
195 std::vector<std::string>& modelVarToCalcList,
196 std::vector<std::string>& varRegrByList)
198 std::string modelVarToCalcString;
199 std::string varRegrByString;
200 std::string filename;
201 for (
auto pathString : pathStrList)
203 modelVarToCalcString.clear();
204 varRegrByString.clear();
205 filename = ExtractFilename(pathString);
206 ExtractModelVarForCalc(filename, modelVarToCalcString, varRegrByString);
207 modelVarToCalcList.push_back(modelVarToCalcString);
208 varRegrByList.push_back(varRegrByString);
215 #endif // SABER_OOPS_STATSVARIABLECHANGE_H_