Debian Codegraph @

src/atlas/grid/detail/pl/classic_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 Mar 2016
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 detail {
24 namespace pl {
25 namespace classic_gaussian {
26
27 class PointsPerLatitude {
28 public:
29 /// @pre nlats has enough allocated memory to store the latitudes
30 /// @param size of lats vector
31 void assign(long nlon[], const size_t size) const;
32
33 /// @pre nlats has enough allocated memory to store the latitudes
34 /// @param size of lats vector
35 void assign(int nlon[], const size_t size) const;
36
37 /// @post resizes the vector to the number of latitutes
38 void assign(std::vector<long>& nlon) const;
39
40 /// @post resizes the vector to the number of latitutes
41 void assign(std::vector<int>& nlon) const;
42
43 size_t N() const { return nlon_.size(); }
44
45 protected:
46 std::vector<long> nlon_;
47 };
48
49
50 class PointsPerLatitudeFactory : public util::Factory<PointsPerLatitudeFactory> {
51 public:
52 static std::string className() { return "PointsPerLatitudeFactory"; }
53 static const PointsPerLatitude* build(const std::string& builder) { return get(builder)->make(); }
54 using Factory::Factory;
55
56 private:
57 virtual const PointsPerLatitude* make() const = 0;
58 };
59
60 template <typename T>
61 class PointsPerLatitudeBuilder : public PointsPerLatitudeFactory {
62 public:
63 using PointsPerLatitudeFactory::PointsPerLatitudeFactory;
64
65 private:
66 virtual const PointsPerLatitude* make() const override { return new T(); }
67 };
68
69
70 #define DECLARE_POINTS_PER_LATITUDE(NUMBER) \
71 class N##NUMBER : public PointsPerLatitude { \
72 public: \
73 N##NUMBER(); \
74 };
75
76 #define LIST(...) __VA_ARGS__
77 #define DEFINE_POINTS_PER_LATITUDE(NUMBER, NLON) \
78 N##NUMBER::N##NUMBER() { \
79 size_t N = NUMBER; \
80 long nlon[] = {NLON}; \
81 nlon_.assign(nlon, nlon + N); \
82 } \
83 namespace { \
84 static PointsPerLatitudeBuilder<N##NUMBER> builder_N##NUMBER(#NUMBER); \
85 }
86
87
88 DECLARE_POINTS_PER_LATITUDE(16);
89 DECLARE_POINTS_PER_LATITUDE(24);
90 DECLARE_POINTS_PER_LATITUDE(32);
91 DECLARE_POINTS_PER_LATITUDE(48);
92 DECLARE_POINTS_PER_LATITUDE(64);
93 DECLARE_POINTS_PER_LATITUDE(80);
94 DECLARE_POINTS_PER_LATITUDE(96);
95 DECLARE_POINTS_PER_LATITUDE(128);
96 DECLARE_POINTS_PER_LATITUDE(160);
97 DECLARE_POINTS_PER_LATITUDE(200);
98 DECLARE_POINTS_PER_LATITUDE(256);
99 DECLARE_POINTS_PER_LATITUDE(320);
100 DECLARE_POINTS_PER_LATITUDE(400);
101 DECLARE_POINTS_PER_LATITUDE(512);
102 DECLARE_POINTS_PER_LATITUDE(576);
103 DECLARE_POINTS_PER_LATITUDE(640);
104 DECLARE_POINTS_PER_LATITUDE(800);
105 DECLARE_POINTS_PER_LATITUDE(1024);
106 DECLARE_POINTS_PER_LATITUDE(1280);
107 DECLARE_POINTS_PER_LATITUDE(1600);
108 DECLARE_POINTS_PER_LATITUDE(2000);
109 DECLARE_POINTS_PER_LATITUDE(4000);
110 DECLARE_POINTS_PER_LATITUDE(8000);
111
112 #undef DECLARE_POINTS_PER_LATITUDE
113
114 } // namespace classic_gaussian
115 } // namespace pl
116 } // namespace detail
117 } // namespace grid
118 } // namespace atlas