| 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 <algorithm> |
| 12 |
|
| 13 |
#include "VerticalInterface.h" |
| 14 |
#include "atlas/field/Field.h" |
| 15 |
#include "atlas/field/detail/FieldImpl.h" |
| 16 |
#include "atlas/grid/Vertical.h" |
| 17 |
#include "atlas/runtime/Exception.h" |
| 18 |
|
| 19 |
namespace atlas { |
| 20 |
|
| 21 |
Vertical* atlas__Vertical__new(idx_t levels, const double z[]) { |
| 22 |
std::vector<double> zvec(z, z + levels); |
| 23 |
return new Vertical(levels, zvec); |
| 24 |
} |
| 25 |
|
| 26 |
Vertical* atlas__Vertical__new_interval(idx_t levels, const double z[], const double interval[]) { |
| 27 |
std::vector<double> zvec(z, z + levels); |
| 28 |
return new Vertical(levels, zvec, interval); |
| 29 |
} |
| 30 |
|
| 31 |
void atlas__Vertical__delete(Vertical* This) { |
| 32 |
delete This; |
| 33 |
} |
| 34 |
|
| 35 |
field::FieldImpl* atlas__Vertical__z(const Vertical* This) { |
| 36 |
ATLAS_ASSERT(This != nullptr); |
| 37 |
field::FieldImpl* field; |
| 38 |
{ |
| 39 |
auto zfield = Field("z", array::make_datatype<double>(), array::make_shape(This->size())); |
| 40 |
auto zview = array::make_view<double, 1>(zfield); |
| 41 |
for (idx_t k = 0; k < zview.size(); ++k) { |
| 42 |
zview(k) = (*This)[k]; |
| 43 |
} |
| 44 |
field = zfield.get(); |
| 45 |
field->attach(); |
| 46 |
} |
| 47 |
field->detach(); |
| 48 |
return field; |
| 49 |
} |
| 50 |
|
| 51 |
int atlas__Vertical__size(const Vertical* This) { |
| 52 |
return This->size(); |
| 53 |
} |
| 54 |
|
| 55 |
} // namespace atlas |