FV3 Bundle
oops/base/Variables.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2018 UCAR
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 "oops/base/Variables.h"
9 
10 #include <iostream>
11 #include <string>
12 #include <vector>
13 
14 #include "eckit/config/Configuration.h"
15 #include "oops/util/abor1_cpp.h"
16 #include "oops/util/Logger.h"
17 
18 // -----------------------------------------------------------------------------
19 namespace oops {
20 // -----------------------------------------------------------------------------
21 
22 Variables::Variables(const eckit::Configuration & conf)
23  : convention_(""), vars_(0), conf_(), fconf_() {
24  Log::trace() << "Variables::Variables start " << conf << std::endl;
25  conf.get("variables", vars_);
26  conf_.set("nvars", vars_.size());
27  conf_.get("variables", vars_);
28 
29  std::string svars = "";
30  for (size_t jj = 0; jj < vars_.size(); ++jj) {
31  if (jj > 0) svars += ", ";
32  svars += vars_[jj];
33  }
34  fconf_.set("nvars", vars_.size());
35  fconf_.set("variables", svars);
36  Log::trace() << "Variables::Variables done" << std::endl;
37 }
38 
39 // -----------------------------------------------------------------------------
40 
41 Variables::Variables(const std::vector<std::string> & vars, const std::string & conv)
42  : convention_(conv), vars_(vars), conf_(), fconf_() {
43  Log::trace() << "Variables::Variables start " << vars << std::endl;
44  conf_.set("nvars", vars_.size());
45  conf_.set("variables", vars_);
46 
47  std::string svars = "";
48  for (size_t jj = 0; jj < vars_.size(); ++jj) {
49  if (jj > 0) svars += ", ";
50  svars += vars_[jj];
51  }
52  fconf_.set("nvars", vars_.size());
53  fconf_.set("variables", svars);
54  Log::trace() << "Variables::Variables done" << std::endl;
55 }
56 
57 // -----------------------------------------------------------------------------
58 
60  : convention_(other.convention_), vars_(other.vars_), conf_(other.conf_), fconf_(other.fconf_)
61 {}
62 
63 // -----------------------------------------------------------------------------
64 
66 
67 // -----------------------------------------------------------------------------
68 
69 void Variables::print(std::ostream & os) const {
70  os << vars_.size() << " variables: ";
71  for (size_t jj = 0; jj < vars_.size(); ++jj) {
72  if (jj > 0) os << ", ";
73  os << vars_[jj];
74  }
75  if (!convention_.empty()) os << " (" << convention_ << ")";
76 }
77 
78 // -----------------------------------------------------------------------------
79 
80 } // namespace oops
Variables(const eckit::Configuration &)
Definition: conf.py:1
The namespace for the main oops code.
void print(std::ostream &) const
eckit::LocalConfiguration conf_
Definition: Variables.h:43
eckit::LocalConfiguration fconf_
Definition: Variables.h:44
std::string convention_
Definition: Variables.h:41
std::vector< std::string > vars_
Definition: Variables.h:42