| 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 |
#pragma once |
| 12 |
|
| 13 |
#include <iosfwd> |
| 14 |
#include <string> |
| 15 |
|
| 16 |
#include "eckit/config/Parametrisation.h" |
| 17 |
#include "eckit/serialisation/FileStream.h" |
| 18 |
|
| 19 |
#include "atlas/library/config.h" |
| 20 |
#include "atlas/util/Config.h" |
| 21 |
#include "atlas/util/Object.h" |
| 22 |
#include "atlas/util/ObjectHandle.h" |
| 23 |
|
| 24 |
namespace eckit { |
| 25 |
class Parametrisation; |
| 26 |
class PathName; |
| 27 |
} // namespace eckit |
| 28 |
|
| 29 |
namespace atlas { |
| 30 |
class Mesh; |
| 31 |
namespace mesh { |
| 32 |
namespace detail { |
| 33 |
class MeshImpl; |
| 34 |
} |
| 35 |
} // namespace mesh |
| 36 |
} // namespace atlas |
| 37 |
|
| 38 |
namespace atlas { |
| 39 |
class Field; |
| 40 |
class FieldSet; |
| 41 |
namespace field { |
| 42 |
class FieldImpl; |
| 43 |
class FieldSetImpl; |
| 44 |
} // namespace field |
| 45 |
} // namespace atlas |
| 46 |
|
| 47 |
namespace atlas { |
| 48 |
class FunctionSpace; |
| 49 |
namespace functionspace { |
| 50 |
class FunctionSpaceImpl; |
| 51 |
} |
| 52 |
} // namespace atlas |
| 53 |
|
| 54 |
namespace atlas { |
| 55 |
namespace output { |
| 56 |
|
| 57 |
using PathName = eckit::PathName; |
| 58 |
|
| 59 |
// ----------------------------------------------------------------------------- |
| 60 |
|
| 61 |
namespace detail { |
| 62 |
class OutputImpl : public util::Object { |
| 63 |
public: |
| 64 |
typedef atlas::util::Config Parameters; |
| 65 |
|
| 66 |
public: |
| 67 |
OutputImpl(); |
| 68 |
|
| 69 |
virtual ~OutputImpl(); |
| 70 |
|
| 71 |
/// Write mesh file |
| 72 |
virtual void write(const Mesh&, const eckit::Parametrisation& = util::NoConfig()) const = 0; |
| 73 |
|
| 74 |
/// Write field to file |
| 75 |
virtual void write(const Field&, const eckit::Parametrisation& = util::NoConfig()) const = 0; |
| 76 |
|
| 77 |
/// Write fieldset to file using FunctionSpace |
| 78 |
virtual void write(const FieldSet&, const eckit::Parametrisation& = util::NoConfig()) const = 0; |
| 79 |
|
| 80 |
/// Write field to file using Functionspace |
| 81 |
virtual void write(const Field&, const FunctionSpace&, const eckit::Parametrisation& = util::NoConfig()) const = 0; |
| 82 |
|
| 83 |
/// Write fieldset to file using FunctionSpace |
| 84 |
virtual void write(const FieldSet&, const FunctionSpace&, |
| 85 |
const eckit::Parametrisation& = util::NoConfig()) const = 0; |
| 86 |
}; |
| 87 |
|
| 88 |
} // namespace detail |
| 89 |
|
| 90 |
class Output : DOXYGEN_HIDE(public util::ObjectHandle<detail::OutputImpl>) { |
| 91 |
public: |
| 92 |
using Handle::Handle; |
| 93 |
Output() = default; |
| 94 |
Output(const std::string&, std::ostream&, const eckit::Parametrisation& = util::NoConfig()); |
| 95 |
|
| 96 |
/// Write mesh file |
| 97 |
const Output& write(const Mesh&, const eckit::Parametrisation& = util::NoConfig()) const; |
| 98 |
|
| 99 |
/// Write field to file |
| 100 |
const Output& write(const Field&, const eckit::Parametrisation& = util::NoConfig()) const; |
| 101 |
|
| 102 |
/// Write fieldset to file using FunctionSpace |
| 103 |
const Output& write(const FieldSet&, const eckit::Parametrisation& = util::NoConfig()) const; |
| 104 |
|
| 105 |
/// Write field to file using Functionspace |
| 106 |
const Output& write(const Field&, const FunctionSpace&, const eckit::Parametrisation& = util::NoConfig()) const; |
| 107 |
|
| 108 |
/// Write fieldset to file using FunctionSpace |
| 109 |
const Output& write(const FieldSet&, const FunctionSpace&, const eckit::Parametrisation& = util::NoConfig()) const; |
| 110 |
}; |
| 111 |
|
| 112 |
namespace detail { |
| 113 |
|
| 114 |
class OutputFactory { |
| 115 |
public: |
| 116 |
/*! |
| 117 |
* \brief build Output with factory key, and default options |
| 118 |
* \return mesh generator |
| 119 |
*/ |
| 120 |
static const OutputImpl* build(const std::string&, std::ostream&); |
| 121 |
|
| 122 |
/*! |
| 123 |
* \brief build Output with factory key inside parametrisation, |
| 124 |
* and options specified in parametrisation as well |
| 125 |
* \return mesh generator |
| 126 |
*/ |
| 127 |
static const OutputImpl* build(const std::string&, std::ostream&, const eckit::Parametrisation&); |
| 128 |
|
| 129 |
/*! |
| 130 |
* \brief list all registered mesh generators |
| 131 |
*/ |
| 132 |
static void list(std::ostream&); |
| 133 |
|
| 134 |
private: |
| 135 |
std::string name_; |
| 136 |
virtual const OutputImpl* make(std::ostream&) = 0; |
| 137 |
virtual const OutputImpl* make(std::ostream&, const eckit::Parametrisation&) = 0; |
| 138 |
|
| 139 |
protected: |
| 140 |
OutputFactory(const std::string&); |
| 141 |
virtual ~OutputFactory(); |
| 142 |
}; |
| 143 |
|
| 144 |
template <class T> |
| 145 |
class OutputBuilder : public OutputFactory { |
| 146 |
virtual const OutputImpl* make(std::ostream& stream) { return new T(stream); } |
| 147 |
virtual const OutputImpl* make(std::ostream& stream, const eckit::Parametrisation& param) { |
| 148 |
return new T(stream, param); |
| 149 |
} |
| 150 |
|
| 151 |
public: |
| 152 |
OutputBuilder(const std::string& name): OutputFactory(name) {} |
| 153 |
}; |
| 154 |
|
| 155 |
// ----------------------------------------------------------------------------- |
| 156 |
|
| 157 |
extern "C" { |
| 158 |
void atlas__Output__delete(OutputImpl* This); |
| 159 |
const OutputImpl* atlas__Output__create(const char* factory_key, std::ostream* stream, |
| 160 |
const eckit::Parametrisation* params); |
| 161 |
void atlas__Output__write_mesh(const OutputImpl* This, mesh::detail::MeshImpl* mesh, |
| 162 |
const eckit::Parametrisation* params); |
| 163 |
void atlas__Output__write_fieldset(const OutputImpl* This, const field::FieldSetImpl* fieldset, |
| 164 |
const eckit::Parametrisation* params); |
| 165 |
void atlas__Output__write_field(const OutputImpl* This, const field::FieldImpl* field, |
| 166 |
const eckit::Parametrisation* params); |
| 167 |
void atlas__Output__write_fieldset_fs(const OutputImpl* This, const field::FieldSetImpl* fieldset, |
| 168 |
const functionspace::FunctionSpaceImpl* functionspace, |
| 169 |
const eckit::Parametrisation* params); |
| 170 |
void atlas__Output__write_field_fs(const OutputImpl* This, const field::FieldImpl* field, |
| 171 |
const functionspace::FunctionSpaceImpl* functionspace, |
| 172 |
const eckit::Parametrisation* params); |
| 173 |
} |
| 174 |
|
| 175 |
} // namespace detail |
| 176 |
} // namespace output |
| 177 |
} // namespace atlas |