| 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/config/Parametrisation.h" |
| 12 |
|
| 13 |
#include "atlas/grid/detail/spacing/GaussianSpacing.h" |
| 14 |
#include "atlas/grid/detail/spacing/SpacingFactory.h" |
| 15 |
#include "atlas/grid/detail/spacing/gaussian/Latitudes.h" |
| 16 |
#include "atlas/runtime/Exception.h" |
| 17 |
|
| 18 |
namespace atlas { |
| 19 |
namespace grid { |
| 20 |
namespace spacing { |
| 21 |
|
| 22 |
GaussianSpacing::GaussianSpacing(long N) { |
| 23 |
// perform checks |
| 24 |
ATLAS_ASSERT(N % 2 == 0); |
| 25 |
|
| 26 |
// initialize latitudes during setup, to avoid repeating it. |
| 27 |
x_.resize(N); |
| 28 |
gaussian::gaussian_latitudes_npole_spole(N / 2, x_.data()); |
| 29 |
|
| 30 |
min_ = -90.; |
| 31 |
max_ = 90.; |
| 32 |
} |
| 33 |
|
| 34 |
GaussianSpacing::GaussianSpacing(const eckit::Parametrisation& params) { |
| 35 |
// retrieve N from params |
| 36 |
long N; |
| 37 |
if (!params.get("N", N)) { |
| 38 |
throw_Exception("N missing in Params", Here()); |
| 39 |
} |
| 40 |
|
| 41 |
// perform checks |
| 42 |
ATLAS_ASSERT(N % 2 == 0); |
| 43 |
|
| 44 |
// initialize latitudes during setup, to avoid repeating it. |
| 45 |
x_.resize(N); |
| 46 |
gaussian::gaussian_latitudes_npole_spole(N / 2, x_.data()); |
| 47 |
|
| 48 |
// Not yet implemented: specify different bounds or direction (e.g from south |
| 49 |
// to north pole) |
| 50 |
double start = 90.; |
| 51 |
double end = -90.; |
| 52 |
params.get("start", start); |
| 53 |
params.get("end", end); |
| 54 |
|
| 55 |
std::vector<double> interval; |
| 56 |
if (params.get("interval", interval)) { |
| 57 |
start = interval[0]; |
| 58 |
end = interval[1]; |
| 59 |
} |
| 60 |
if (start != 90. && end != -90.) { |
| 61 |
ATLAS_NOTIMPLEMENTED; |
| 62 |
} |
| 63 |
|
| 64 |
min_ = std::min(start, end); |
| 65 |
max_ = std::max(start, end); |
| 66 |
} |
| 67 |
|
| 68 |
GaussianSpacing::Spec GaussianSpacing::spec() const { |
| 69 |
Spec spacing_specs; |
| 70 |
spacing_specs.set("type", static_type()); |
| 71 |
spacing_specs.set("N", size()); |
| 72 |
return spacing_specs; |
| 73 |
} |
| 74 |
|
| 75 |
namespace { |
| 76 |
static SpacingBuilder<GaussianSpacing> __builder(GaussianSpacing::static_type()); |
| 77 |
} |
| 78 |
|
| 79 |
} // namespace spacing |
| 80 |
} // namespace grid |
| 81 |
} // namespace atlas |