Debian Codegraph @

src/atlas/grid/detail/spacing/gaussian/N.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 /// @author Willem Deconinck
12 /// @date Nov 2014
13
14 #pragma once
15
16 #include <cstddef>
17 #include <vector>
18
19 #include "atlas/util/Factory.h"
20
21 namespace atlas {
22 namespace grid {
23 namespace spacing {
24 namespace gaussian {
25
26 class GaussianLatitudes {
27 public:
28 /// @pre nlats has enough allocated memory to store the latitudes
29 /// @param size of lats vector
30 void assign(double lats[], const size_t size) const;
31
32 /// @post resizes the vector to the number of latitutes
33 void assign(std::vector<double>& lats) const;
34
35 size_t N() const { return lats_.size(); }
36
37 protected:
38 std::vector<double> lats_;
39 };
40
41 class GaussianLatitudesFactory : public util::Factory<GaussianLatitudesFactory> {
42 public:
43 static std::string className() { return "GaussianLatitudesFactory"; }
44 static const GaussianLatitudes* build(const std::string& builder) { return get(builder)->make(); }
45 using Factory::Factory;
46
47 private:
48 virtual const GaussianLatitudes* make() const = 0;
49 };
50
51 template <typename T>
52 class GaussianLatitudesBuilder : public GaussianLatitudesFactory {
53 public:
54 using GaussianLatitudesFactory::GaussianLatitudesFactory;
55
56 private:
57 virtual const GaussianLatitudes* make() const override { return new T(); }
58 };
59
60 #define DECLARE_GAUSSIAN_LATITUDES(NUMBER) \
61 class N##NUMBER : public GaussianLatitudes { \
62 public: \
63 N##NUMBER(); \
64 };
65
66 #define LIST(...) __VA_ARGS__
67 #define DEFINE_GAUSSIAN_LATITUDES(NUMBER, LATS) \
68 N##NUMBER::N##NUMBER() { \
69 size_t N = NUMBER; \
70 double lat[] = {LATS}; \
71 lats_.assign(lat, lat + N); \
72 } \
73 namespace { \
74 static GaussianLatitudesBuilder<N##NUMBER> builder_N##NUMBER(#NUMBER); \
75 }
76
77
78 DECLARE_GAUSSIAN_LATITUDES(16);
79 DECLARE_GAUSSIAN_LATITUDES(24);
80 DECLARE_GAUSSIAN_LATITUDES(32);
81 DECLARE_GAUSSIAN_LATITUDES(48);
82 DECLARE_GAUSSIAN_LATITUDES(64);
83 DECLARE_GAUSSIAN_LATITUDES(80);
84 DECLARE_GAUSSIAN_LATITUDES(96);
85 DECLARE_GAUSSIAN_LATITUDES(128);
86 DECLARE_GAUSSIAN_LATITUDES(160);
87 DECLARE_GAUSSIAN_LATITUDES(200);
88 DECLARE_GAUSSIAN_LATITUDES(256);
89 DECLARE_GAUSSIAN_LATITUDES(320);
90 DECLARE_GAUSSIAN_LATITUDES(400);
91 DECLARE_GAUSSIAN_LATITUDES(512);
92 DECLARE_GAUSSIAN_LATITUDES(576);
93 DECLARE_GAUSSIAN_LATITUDES(640);
94 DECLARE_GAUSSIAN_LATITUDES(800);
95 DECLARE_GAUSSIAN_LATITUDES(1024);
96 DECLARE_GAUSSIAN_LATITUDES(1280);
97 DECLARE_GAUSSIAN_LATITUDES(1600);
98 DECLARE_GAUSSIAN_LATITUDES(2000);
99 DECLARE_GAUSSIAN_LATITUDES(4000);
100 DECLARE_GAUSSIAN_LATITUDES(8000);
101
102 #undef DECLARE_GAUSSIAN_LATITUDES
103
104 } // namespace gaussian
105 } // namespace spacing
106 } // namespace grid
107 } // namespace atlas