| 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 <string> |
| 12 |
|
| 13 |
#include "eckit/utils/MD5.h" |
| 14 |
|
| 15 |
#include "atlas/domain/detail/Domain.h" |
| 16 |
#include "atlas/domain/detail/DomainFactory.h" |
| 17 |
#include "atlas/projection/Projection.h" |
| 18 |
#include "atlas/runtime/Exception.h" |
| 19 |
|
| 20 |
namespace atlas { |
| 21 |
namespace domain { |
| 22 |
|
| 23 |
const Domain* Domain::create() { |
| 24 |
// default: global domain |
| 25 |
util::Config projParams; |
| 26 |
projParams.set("type", "global"); |
| 27 |
return Domain::create(projParams); |
| 28 |
} |
| 29 |
|
| 30 |
const Domain* Domain::create(const eckit::Parametrisation& p) { |
| 31 |
std::string domain_type; |
| 32 |
if (p.get("type", domain_type)) { |
| 33 |
return DomainFactory::build(domain_type, p); |
| 34 |
} |
| 35 |
|
| 36 |
// should return error here |
| 37 |
throw_Exception("type missing in Params", Here()); |
| 38 |
} |
| 39 |
|
| 40 |
//--------------------------------------------------------------------------------------------------------------------- |
| 41 |
|
| 42 |
extern "C" { |
| 43 |
const Domain* atlas__Domain__ctor_config(const eckit::Parametrisation* config) { |
| 44 |
return Domain::create(*config); |
| 45 |
} |
| 46 |
void atlas__Domain__type(const Domain* This, char*& type, int& size) { |
| 47 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_Domain"); |
| 48 |
std::string s = This->type(); |
| 49 |
size = static_cast<int>(s.size()); |
| 50 |
type = new char[size + 1]; |
| 51 |
std::strncpy(type, s.c_str(), size + 1); |
| 52 |
} |
| 53 |
void atlas__Domain__hash(const Domain* This, char*& hash, int& size) { |
| 54 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_Domain"); |
| 55 |
eckit::MD5 md5; |
| 56 |
This->hash(md5); |
| 57 |
std::string s = md5.digest(); |
| 58 |
size = static_cast<int>(s.size()); |
| 59 |
hash = new char[size + 1]; |
| 60 |
std::strncpy(hash, s.c_str(), size + 1); |
| 61 |
} |
| 62 |
Domain::Spec* atlas__Domain__spec(const Domain* This) { |
| 63 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_Domain"); |
| 64 |
return new Domain::Spec(This->spec()); |
| 65 |
} |
| 66 |
|
| 67 |
} // extern "C" |
| 68 |
|
| 69 |
} // namespace domain |
| 70 |
} // namespace atlas |