Debian Codegraph @

src/atlas/grid/Vertical.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
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 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <cassert>
14 #include <vector>
15
16 #include "atlas/library/config.h"
17 #include "atlas/util/Config.h"
18
19 namespace atlas {
20
21 //---------------------------------------------------------------------------------------------------------------------
22
23 class Vertical {
24 public:
25 template <typename vector_t> // expect "vector_t::size()" and "vector_t::operator[]"
26 Vertical(idx_t levels, const vector_t& z, const util::Config& config = util::NoConfig());
27
28 template <typename vector_t, typename Interval> // expect "vector_t::size()" and "vector_t::operator[]"
29 Vertical(idx_t levels, const vector_t& z, const Interval& interval, const util::Config& config = util::NoConfig());
30
31 Vertical(const util::Config& config = util::NoConfig());
32
33 public:
34 idx_t k_begin() const { return k_begin_; }
35 idx_t k_end() const { return k_end_; }
36 idx_t size() const { return size_; }
37
38 template <typename Int>
39 double operator()(const Int k) const {
40 return z_[k];
41 }
42
43 template <typename Int>
44 double operator[](const Int k) const {
45 return z_[k];
46 }
47
48 double min() const { return min_; }
49 double max() const { return max_; }
50
51 double front() const { return z_.front(); }
52 double back() const { return z_.back(); }
53
54 /// @brief Output information of field
55 friend std::ostream& operator<<(std::ostream& os, const Vertical& v);
56
57 private:
58 idx_t size_;
59 idx_t k_begin_;
60 idx_t k_end_;
61 std::vector<double> z_;
62 double min_;
63 double max_;
64 };
65
66 //---------------------------------------------------------------------------------------------------------------------
67
68 template <typename vector_t, typename Interval>
69 Vertical::Vertical(idx_t levels, const vector_t& z, const Interval& interval, const util::Config& config):
70 Vertical(levels, z, config) {
71 min_ = interval[0];
72 max_ = interval[1];
73 }
74
75 //---------------------------------------------------------------------------------------------------------------------
76
77 template <typename vector_t>
78 Vertical::Vertical(idx_t levels, const vector_t& z, const util::Config&): size_{levels}, k_begin_{0}, k_end_{size_} {
79 assert(size_ == static_cast<idx_t>(z.size()));
80 z_.resize(size_);
81 for (idx_t k = 0; k < size_; ++k) {
82 z_[k] = z[k];
83 }
84 min_ = (size_ ? z[0] : 0.);
85 max_ = (size_ ? z[size_ - 1] : 1.);
86 }
87
88 //---------------------------------------------------------------------------------------------------------------------
89
90 } // namespace atlas