| 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 |
#include "eckit/types/Types.h" |
| 12 |
|
| 13 |
#include "atlas/array/ArrayView.h" |
| 14 |
#include "atlas/field/Field.h" |
| 15 |
#include "atlas/grid/Vertical.h" |
| 16 |
|
| 17 |
namespace atlas { |
| 18 |
|
| 19 |
//--------------------------------------------------------------------------------------------------------------------- |
| 20 |
|
| 21 |
namespace { |
| 22 |
|
| 23 |
std::vector<double> linspace(double start, double end, idx_t N, bool endpoint) { |
| 24 |
std::vector<double> x_; |
| 25 |
if (N > 0) { |
| 26 |
volatile double _N = N; // volatile keyword prevents agressive optimization by Cray compiler |
| 27 |
x_.resize(N); |
| 28 |
|
| 29 |
double step; |
| 30 |
if (endpoint && N > 1) { |
| 31 |
step = (end - start) / (_N - 1); |
| 32 |
} |
| 33 |
else if (N > 0) { |
| 34 |
step = (end - start) / _N; |
| 35 |
} |
| 36 |
else { |
| 37 |
step = 0.; |
| 38 |
} |
| 39 |
|
| 40 |
for (idx_t i = 0; i < N; ++i) { |
| 41 |
x_[i] = start + i * step; |
| 42 |
} |
| 43 |
} |
| 44 |
return x_; |
| 45 |
} |
| 46 |
|
| 47 |
idx_t get_levels(const util::Config& config) { |
| 48 |
return config.getInt("levels", 0); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
} // namespace |
| 53 |
|
| 54 |
//--------------------------------------------------------------------------------------------------------------------- |
| 55 |
|
| 56 |
Vertical::Vertical(const util::Config& config): |
| 57 |
Vertical(get_levels(config), linspace(0., 1., get_levels(config), true), config) {} |
| 58 |
|
| 59 |
std::ostream& operator<<(std::ostream& os, const Vertical& v) { |
| 60 |
os << v.z_; |
| 61 |
return os; |
| 62 |
} |
| 63 |
|
| 64 |
//--------------------------------------------------------------------------------------------------------------------- |
| 65 |
|
| 66 |
} // namespace atlas |