atlas
Vertical.h
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 class Field;
22 
23 //---------------------------------------------------------------------------------------------------------------------
24 
25 class Vertical {
26 public:
27  template <typename vector_t> // expect "vector_t::size()" and "vector_t::operator[]"
28  Vertical( idx_t levels, const vector_t& z, const util::Config& config = util::NoConfig() );
29 
30  template <typename vector_t, typename Interval> // expect "vector_t::size()" and "vector_t::operator[]"
31  Vertical( idx_t levels, const vector_t& z, const Interval& interval,
32  const util::Config& config = util::NoConfig() );
33 
34  Vertical( const util::Config& config = util::NoConfig() );
35 
36  Field z() const;
37 
38 public:
39  idx_t k_begin() const { return k_begin_; }
40  idx_t k_end() const { return k_end_; }
41  idx_t size() const { return size_; }
42 
43  template <typename Int>
44  double operator()( const Int k ) const {
45  return z_[k];
46  }
47 
48  template <typename Int>
49  double operator[]( const Int k ) const {
50  return z_[k];
51  }
52 
53  double min() const { return min_; }
54  double max() const { return max_; }
55 
56  double front() const { return z_.front(); }
57  double back() const { return z_.back(); }
58 
60  friend std::ostream& operator<<( std::ostream& os, const Vertical& v );
61 
62 private:
63  idx_t size_;
64  idx_t k_begin_;
65  idx_t k_end_;
66  std::vector<double> z_;
67  double min_;
68  double max_;
69 };
70 
71 //---------------------------------------------------------------------------------------------------------------------
72 
73 template <typename vector_t, typename Interval>
74 Vertical::Vertical( idx_t levels, const vector_t& z, const Interval& interval, const util::Config& config ) :
75  Vertical( levels, z, config ) {
76  min_ = interval[0];
77  max_ = interval[1];
78 }
79 
80 //---------------------------------------------------------------------------------------------------------------------
81 
82 template <typename vector_t>
83 Vertical::Vertical( idx_t levels, const vector_t& z, const util::Config& ) : size_{levels}, k_begin_{0}, k_end_{size_} {
84  assert( size_ == static_cast<idx_t>( z.size() ) );
85  z_.resize( size_ );
86  for ( idx_t k = 0; k < size_; ++k ) {
87  z_[k] = z[k];
88  }
89  min_ = ( size_ ? z[0] : 0. );
90  max_ = ( size_ ? z[size_ - 1] : 1. );
91 }
92 
93 //---------------------------------------------------------------------------------------------------------------------
94 
95 } // namespace atlas
A Field contains an Array, Metadata, and a reference to a FunctionSpace.
Definition: Field.h:59
Definition: Vertical.h:25
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
friend std::ostream & operator<<(std::ostream &os, const Vertical &v)
Output information of field.
Definition: Vertical.cc:69
Definition: Config.h:148
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42
Configuration class used to construct various atlas components.
Definition: Config.h:27