atlas
Domain.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 <array>
14 #include <string>
15 
16 #include "atlas/library/config.h"
17 #include "atlas/util/ObjectHandle.h"
18 
19 //---------------------------------------------------------------------------------------------------------------------
20 
21 // Forward declarations
22 namespace eckit {
23 class Parametrisation;
24 class Hash;
25 } // namespace eckit
26 
27 //---------------------------------------------------------------------------------------------------------------------
28 
29 namespace atlas {
30 class PointXY;
31 
32 namespace util {
33 class Config;
34 } // namespace util
35 
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 namespace domain {
38 class Domain;
39 class GlobalDomain;
40 class ZonalBandDomain;
41 class RectangularDomain;
42 class RectangularLonLatDomain;
43 } // namespace domain
44 #endif
45 
46 //---------------------------------------------------------------------------------------------------------------------
47 
48 class Domain : DOXYGEN_HIDE( public util::ObjectHandle<atlas::domain::Domain> ) {
49 public:
50  using Spec = util::Config;
51 
52 public:
53  using Handle::Handle;
54  Domain() = default;
55  Domain( const eckit::Parametrisation& );
56 
58  std::string type() const;
59 
61  bool contains( double x, double y ) const;
62 
64  bool contains( const PointXY& p ) const;
65 
66  // Specification of Domain
67  Spec spec() const;
68 
70  bool global() const;
71 
73  bool empty() const;
74 
76  void hash( eckit::Hash& ) const;
77 
80  bool containsNorthPole() const;
81 
84  bool containsSouthPole() const;
85 
87  std::string units() const;
88 
89 private:
91  void print( std::ostream& ) const;
92 
93  friend std::ostream& operator<<( std::ostream& s, const Domain& d );
94 };
95 
96 //---------------------------------------------------------------------------------------------------------------------
97 
98 class RectangularDomain : public Domain {
99 public:
100  using Interval = std::array<double, 2>;
101 
102 public:
103  using Domain::Domain;
104  RectangularDomain() : Domain() {}
105  RectangularDomain( const Interval& x, const Interval& y, const std::string& units = "degrees" );
106 
107  RectangularDomain( const Domain& );
108 
109  operator bool() const { return domain_; }
110 
112  bool contains_x( double x ) const;
113 
115  bool contains_y( double y ) const;
116 
117  bool zonal_band() const;
118 
119  double xmin() const;
120  double xmax() const;
121  double ymin() const;
122  double ymax() const;
123 
124 private:
125  const ::atlas::domain::RectangularDomain* domain_;
126 };
127 
128 //---------------------------------------------------------------------------------------------------------------------
129 
131 public:
132  using RectangularDomain::RectangularDomain;
133  RectangularLonLatDomain( const Interval& x, const Interval& y ) : RectangularDomain( x, y, "degrees" ) {}
134  RectangularLonLatDomain( const double& north, const double& west, const double& south, const double& east ) :
135  RectangularLonLatDomain( {west, east}, {south, north} ) {}
136 
137  operator bool() const { return RectangularDomain::operator bool() && units() == "degrees"; }
138 
139  double west() const { return xmin(); }
140  double east() const { return xmax(); }
141  double north() const { return ymax(); }
142  double south() const { return ymin(); }
143 };
144 
145 //---------------------------------------------------------------------------------------------------------------------
146 
148 public:
149  using Interval = std::array<double, 2>;
150 
151 public:
152  using RectangularLonLatDomain::RectangularLonLatDomain;
153  ZonalBandDomain( const Interval& y, const double& west );
154  ZonalBandDomain( const Interval& y );
155  ZonalBandDomain( const Domain& );
156 
157  operator bool() const { return domain_; }
158 
159 private:
160  const ::atlas::domain::ZonalBandDomain* domain_;
161 };
162 
163 //---------------------------------------------------------------------------------------------------------------------
164 
166 public:
167  GlobalDomain( const double& west );
168  GlobalDomain();
169  GlobalDomain( const Domain& );
170 
171  operator bool() const { return domain_; }
172 
173 private:
174  const ::atlas::domain::GlobalDomain* domain_;
175 };
176 
177 //---------------------------------------------------------------------------------------------------------------------
178 
179 } // namespace atlas
Definition: Domain.h:147
Definition: Domain.h:130
Definition: Domain.h:19
Definition: Domain.h:165
Definition: Domain.h:48
Point in arbitrary XY-coordinate system.
Definition: Point.h:40
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
Configuration class used to construct various atlas components.
Definition: Config.h:27
Definition: Domain.h:98