| 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 <fstream> |
| 12 |
|
| 13 |
#include "atlas/field/Field.h" |
| 14 |
#include "atlas/field/FieldSet.h" |
| 15 |
#include "atlas/functionspace/FunctionSpace.h" |
| 16 |
#include "atlas/interpolation/Interpolation.h" |
| 17 |
#include "atlas/interpolation/method/MethodFactory.h" |
| 18 |
#include "atlas/runtime/Exception.h" |
| 19 |
|
| 20 |
namespace atlas { |
| 21 |
|
| 22 |
Interpolation::Interpolation(const Config& config, const FunctionSpace& source, const FunctionSpace& target): |
| 23 |
Handle([&]() -> Implementation* { |
| 24 |
std::string type; |
| 25 |
ATLAS_ASSERT(config.get("type", type)); |
| 26 |
Implementation* impl = interpolation::MethodFactory::build(type, config); |
| 27 |
impl->setup(source, target); |
| 28 |
return impl; |
| 29 |
}()) { |
| 30 |
std::string path; |
| 31 |
if (config.get("output", path)) { |
| 32 |
std::ofstream file(path); |
| 33 |
print(file); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
Interpolation::Interpolation(const Config& config, const Grid& source, const Grid& target): |
| 38 |
Handle([&]() -> Implementation* { |
| 39 |
std::string type; |
| 40 |
ATLAS_ASSERT(config.get("type", type)); |
| 41 |
Implementation* impl = interpolation::MethodFactory::build(type, config); |
| 42 |
impl->setup(source, target); |
| 43 |
return impl; |
| 44 |
}()) { |
| 45 |
std::string path; |
| 46 |
if (config.get("output", path)) { |
| 47 |
std::ofstream file(path); |
| 48 |
print(file); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
Interpolation::Interpolation(const Config& config, const FunctionSpace& source, const Field& target): |
| 53 |
Handle([&]() -> Implementation* { |
| 54 |
std::string type; |
| 55 |
ATLAS_ASSERT(config.get("type", type)); |
| 56 |
Implementation* impl = interpolation::MethodFactory::build(type, config); |
| 57 |
impl->setup(source, target); |
| 58 |
return impl; |
| 59 |
}()) { |
| 60 |
std::string path; |
| 61 |
if (config.get("output", path)) { |
| 62 |
std::ofstream file(path); |
| 63 |
print(file); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
Interpolation::Interpolation(const Interpolation::Config& config, const FunctionSpace& source, const FieldSet& target): |
| 68 |
Handle([&]() -> Implementation* { |
| 69 |
std::string type; |
| 70 |
ATLAS_ASSERT(config.get("type", type)); |
| 71 |
Implementation* impl = interpolation::MethodFactory::build(type, config); |
| 72 |
impl->setup(source, target); |
| 73 |
return impl; |
| 74 |
}()) { |
| 75 |
std::string path; |
| 76 |
if (config.get("output", path)) { |
| 77 |
std::ofstream file(path); |
| 78 |
print(file); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
Interpolation::Metadata Interpolation::execute(const FieldSet& source, FieldSet& target) const { |
| 83 |
return get()->execute(source, target); |
| 84 |
} |
| 85 |
|
| 86 |
Interpolation::Metadata Interpolation::execute(const Field& source, Field& target) const { |
| 87 |
return get()->execute(source, target); |
| 88 |
} |
| 89 |
|
| 90 |
Interpolation::Metadata Interpolation::execute_adjoint(FieldSet& source, const FieldSet& target) const { |
| 91 |
return get()->execute_adjoint(source, target); |
| 92 |
} |
| 93 |
|
| 94 |
Interpolation::Metadata Interpolation::execute_adjoint(Field& source, const Field& target) const { |
| 95 |
return get()->execute_adjoint(source, target); |
| 96 |
} |
| 97 |
|
| 98 |
void Interpolation::print(std::ostream& out) const { |
| 99 |
get()->print(out); |
| 100 |
} |
| 101 |
|
| 102 |
const FunctionSpace& Interpolation::source() const { |
| 103 |
return get()->source(); |
| 104 |
} |
| 105 |
|
| 106 |
const FunctionSpace& Interpolation::target() const { |
| 107 |
return get()->target(); |
| 108 |
} |
| 109 |
|
| 110 |
Interpolation::Cache Interpolation::createCache() const { |
| 111 |
return get()->createCache(); |
| 112 |
} |
| 113 |
|
| 114 |
Interpolation::Interpolation(const Interpolation::Config& config, const Grid& source, const Grid& target, |
| 115 |
const Interpolation::Cache& cache): |
| 116 |
Handle([&]() -> Implementation* { |
| 117 |
std::string type; |
| 118 |
ATLAS_ASSERT(config.get("type", type)); |
| 119 |
Implementation* impl = interpolation::MethodFactory::build(type, config); |
| 120 |
impl->setup(source, target, cache); |
| 121 |
return impl; |
| 122 |
}()) {} |
| 123 |
|
| 124 |
Interpolation::Interpolation(const Interpolation::Config& config, const FunctionSpace& fs_in, const FunctionSpace& fs_out, |
| 125 |
const Interpolation::Cache& cache): |
| 126 |
Handle([&]() -> Implementation* { |
| 127 |
std::string type; |
| 128 |
ATLAS_ASSERT(config.get("type", type)); |
| 129 |
Implementation* impl = interpolation::MethodFactory::build(type, config); |
| 130 |
impl->setup(fs_in, fs_out, cache); |
| 131 |
return impl; |
| 132 |
}()) {} |
| 133 |
|
| 134 |
extern "C" { |
| 135 |
Interpolation::Implementation* atlas__Interpolation__new(const eckit::Parametrisation* config, |
| 136 |
const functionspace::FunctionSpaceImpl* source, |
| 137 |
const functionspace::FunctionSpaceImpl* target) { |
| 138 |
Interpolation::Implementation* interpolator; |
| 139 |
{ |
| 140 |
Interpolation im(*config, FunctionSpace(source), FunctionSpace(target)); |
| 141 |
interpolator = const_cast<Interpolation::Implementation*>(im.get()); |
| 142 |
interpolator->attach(); |
| 143 |
} |
| 144 |
interpolator->detach(); |
| 145 |
return interpolator; |
| 146 |
} |
| 147 |
|
| 148 |
Interpolation::Implementation* atlas__Interpolation__new_tgt_field(const eckit::Parametrisation* config, |
| 149 |
const functionspace::FunctionSpaceImpl* source, |
| 150 |
const field::FieldImpl* target) { |
| 151 |
Interpolation::Implementation* interpolator; |
| 152 |
{ |
| 153 |
Interpolation im(*config, FunctionSpace(source), Field(target)); |
| 154 |
interpolator = const_cast<Interpolation::Implementation*>(im.get()); |
| 155 |
interpolator->attach(); |
| 156 |
} |
| 157 |
interpolator->detach(); |
| 158 |
return interpolator; |
| 159 |
} |
| 160 |
|
| 161 |
Interpolation::Implementation* atlas__Interpolation__new_tgt_fieldset(const eckit::Parametrisation* config, |
| 162 |
const functionspace::FunctionSpaceImpl* source, |
| 163 |
const field::FieldSetImpl* target) { |
| 164 |
Interpolation::Implementation* interpolator; |
| 165 |
{ |
| 166 |
Interpolation im(*config, FunctionSpace(source), FieldSet(target)); |
| 167 |
interpolator = const_cast<Interpolation::Implementation*>(im.get()); |
| 168 |
interpolator->attach(); |
| 169 |
} |
| 170 |
interpolator->detach(); |
| 171 |
return interpolator; |
| 172 |
} |
| 173 |
|
| 174 |
void atlas__Interpolation__delete(Interpolation::Implementation* This) { |
| 175 |
delete This; |
| 176 |
} |
| 177 |
|
| 178 |
void atlas__Interpolation__execute_field(Interpolation::Implementation* This, const field::FieldImpl* source, |
| 179 |
field::FieldImpl* target) { |
| 180 |
Field t(target); |
| 181 |
This->execute(Field(source), t); |
| 182 |
} |
| 183 |
|
| 184 |
void atlas__Interpolation__execute_fieldset(Interpolation::Implementation* This, const field::FieldSetImpl* source, |
| 185 |
field::FieldSetImpl* target) { |
| 186 |
FieldSet t(target); |
| 187 |
This->execute(FieldSet(source), t); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
void atlas__Interpolation__execute_adjoint_field(Interpolation::Implementation* This, field::FieldImpl* source, |
| 192 |
const field::FieldImpl* target) { |
| 193 |
Field s(source); |
| 194 |
This->execute_adjoint(s, Field(target)); |
| 195 |
} |
| 196 |
|
| 197 |
void atlas__Interpolation__execute_adjoint_fieldset(Interpolation::Implementation* This, field::FieldSetImpl* source, |
| 198 |
const field::FieldSetImpl* target) { |
| 199 |
FieldSet s(source); |
| 200 |
This->execute_adjoint(s, FieldSet(target)); |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
} // extern "C" |
| 205 |
|
| 206 |
} // namespace atlas |