UFO
OperatorUtils.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2021 Met Office UK
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #include <map>
9 #include <string>
10 
11 #include "ioda/ObsSpace.h"
12 #include "ufo/filters/Variables.h"
14 
15 namespace ufo {
16 
17 void getOperatorVariables(const eckit::Configuration &conf,
18  const oops::Variables &simulatedVariables,
19  oops::Variables &operatorVariables,
20  std::vector<int> &operatorVariableIndices) {
21  if (conf.has("variables")) {
22  operatorVariables =
23  ufo::Variables(conf.getSubConfigurations("variables")).toOopsVariables();
24 
25  std::map<std::string, int> simulatedVariableIndices;
26  for (int i = 0; i < simulatedVariables.size(); ++i)
27  simulatedVariableIndices[simulatedVariables[i]] = i;
28 
29  for (int i = 0; i < operatorVariables.size(); ++i) {
30  auto it = simulatedVariableIndices.find(operatorVariables[i]);
31  if (it == simulatedVariableIndices.end())
32  throw eckit::BadValue("Operator variable '" + operatorVariables[i] +
33  "' isn't one of the simulated variables", Here());
34  operatorVariableIndices.push_back(it->second);
35  }
36  } else {
37  operatorVariables = simulatedVariables;
38  operatorVariableIndices.resize(operatorVariables.size());
39  std::iota(operatorVariableIndices.begin(), operatorVariableIndices.end(), 0);
40  }
41 }
42 
43 } // namespace ufo
oops::Variables toOopsVariables() const
Definition: Variables.cc:156
Definition: RunCRTM.h:27
void getOperatorVariables(const eckit::Configuration &conf, const oops::Variables &simulatedVariables, oops::Variables &operatorVariables, std::vector< int > &operatorVariableIndices)