| 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 <iostream> |
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
#include "atlas/functionspace/CellColumns.h" |
| 18 |
#include "atlas/functionspace/NodeColumns.h" |
| 19 |
#include "atlas/functionspace/StructuredColumns.h" |
| 20 |
#include "atlas/util/Metadata.h" |
| 21 |
|
| 22 |
namespace atlas { |
| 23 |
class Field; |
| 24 |
class FieldSet; |
| 25 |
class Mesh; |
| 26 |
namespace field { |
| 27 |
class FieldImpl; |
| 28 |
class FieldSetImpl; |
| 29 |
} // namespace field |
| 30 |
namespace functionspace { |
| 31 |
class FunctionSpaceImpl; |
| 32 |
} |
| 33 |
} // namespace atlas |
| 34 |
|
| 35 |
namespace atlas { |
| 36 |
namespace array { |
| 37 |
class Array; |
| 38 |
} |
| 39 |
} // namespace atlas |
| 40 |
|
| 41 |
namespace atlas { |
| 42 |
namespace util { |
| 43 |
namespace io { |
| 44 |
class GmshFortranInterface; |
| 45 |
} |
| 46 |
} // namespace util |
| 47 |
} // namespace atlas |
| 48 |
namespace atlas { |
| 49 |
namespace output { |
| 50 |
class Gmsh; |
| 51 |
} |
| 52 |
} // namespace atlas |
| 53 |
|
| 54 |
namespace atlas { |
| 55 |
namespace output { |
| 56 |
namespace detail { |
| 57 |
|
| 58 |
//---------------------------------------------------------------------------------------------------------------------- |
| 59 |
|
| 60 |
class GmshIO { |
| 61 |
public: // members |
| 62 |
using Metadata = util::Metadata; |
| 63 |
Metadata options; |
| 64 |
|
| 65 |
private: // types |
| 66 |
typedef std::ios_base::openmode openmode; |
| 67 |
|
| 68 |
public: // methods |
| 69 |
GmshIO(); |
| 70 |
|
| 71 |
~GmshIO(); |
| 72 |
|
| 73 |
public: |
| 74 |
Mesh read(const eckit::PathName& file_path) const; |
| 75 |
|
| 76 |
void read(const eckit::PathName& file_path, Mesh& mesh) const; |
| 77 |
|
| 78 |
/// Write mesh file |
| 79 |
/// Extra file with available mesh information is written to: |
| 80 |
/// - filename_info.msh |
| 81 |
void write(const Mesh& mesh, const eckit::PathName& file_path) const; |
| 82 |
|
| 83 |
/// Write field to file |
| 84 |
/// Depending on argument "mode", the fields will be appended, |
| 85 |
/// or existing file will be overwritten |
| 86 |
void write(const Field& field, const eckit::PathName& file_path, openmode mode = std::ios::out) const; |
| 87 |
|
| 88 |
/// Write fieldset to file using FunctionSpace |
| 89 |
/// Depending on argument "mode", the fields will be appended, |
| 90 |
/// or existing file will be overwritten |
| 91 |
void write(const FieldSet& fieldset, const FunctionSpace&, const eckit::PathName& file_path, |
| 92 |
openmode mode = std::ios::out) const; |
| 93 |
|
| 94 |
/// Write field to file using Functionspace |
| 95 |
/// Depending on argument "mode", the fields will be appended, |
| 96 |
/// or existing file will be overwritten |
| 97 |
void write(const Field& field, const FunctionSpace&, const eckit::PathName& file_path, |
| 98 |
openmode mode = std::ios::out) const; |
| 99 |
|
| 100 |
private: |
| 101 |
/// Write fieldset to file using Nodes functionspace |
| 102 |
/// Depending on argument "mode", the fields will be appended, |
| 103 |
/// or existing file will be overwritten |
| 104 |
void write_delegate(const FieldSet& fieldset, const functionspace::NodeColumns&, const eckit::PathName& file_path, |
| 105 |
openmode mode = std::ios::out) const; |
| 106 |
|
| 107 |
/// Write fieldset to file using Nodes functionspace |
| 108 |
/// Depending on argument "mode", the fields will be appended, |
| 109 |
/// or existing file will be overwritten |
| 110 |
void write_delegate(const FieldSet& fieldset, const functionspace::NoFunctionSpace&, |
| 111 |
const eckit::PathName& file_path, openmode mode = std::ios::out) const; |
| 112 |
|
| 113 |
/// Write fieldset to file using Cells functionspace |
| 114 |
/// Depending on argument "mode", the fields will be appended, |
| 115 |
/// or existing file will be overwritten |
| 116 |
void write_delegate(const FieldSet& fieldset, const functionspace::CellColumns&, const eckit::PathName& file_path, |
| 117 |
openmode mode = std::ios::out) const; |
| 118 |
|
| 119 |
/// Write fieldset to file using StructuredColumns functionspace |
| 120 |
/// Depending on argument "mode", the fields will be appended, |
| 121 |
/// or existing file will be overwritten |
| 122 |
void write_delegate(const FieldSet& fieldset, const functionspace::StructuredColumns&, |
| 123 |
const eckit::PathName& file_path, openmode mode = std::ios::out) const; |
| 124 |
|
| 125 |
/// Write field to file using Nodes functionspace |
| 126 |
/// Depending on argument "mode", the fields will be appended, |
| 127 |
/// or existing file will be overwritten |
| 128 |
void write_delegate(const Field& field, const functionspace::NodeColumns&, const eckit::PathName& file_path, |
| 129 |
openmode mode = std::ios::out) const; |
| 130 |
|
| 131 |
/// Write field to file using Cells functionspace |
| 132 |
/// Depending on argument "mode", the fields will be appended, |
| 133 |
/// or existing file will be overwritten |
| 134 |
void write_delegate(const Field& field, const functionspace::CellColumns&, const eckit::PathName& file_path, |
| 135 |
openmode mode = std::ios::out) const; |
| 136 |
|
| 137 |
/// Write field to file using Nodes functionspace |
| 138 |
/// Depending on argument "mode", the fields will be appended, |
| 139 |
/// or existing file will be overwritten |
| 140 |
void write_delegate(const Field& field, const functionspace::NoFunctionSpace&, const eckit::PathName& file_path, |
| 141 |
openmode mode = std::ios::out) const; |
| 142 |
|
| 143 |
/// Write field to file using StructuredColumns functionspace |
| 144 |
/// Depending on argument "mode", the fields will be appended, |
| 145 |
/// or existing file will be overwritten |
| 146 |
void write_delegate(const Field& field, const functionspace::StructuredColumns&, const eckit::PathName& file_path, |
| 147 |
openmode mode = std::ios::out) const; |
| 148 |
}; |
| 149 |
|
| 150 |
//---------------------------------------------------------------------------------------------------------------------- |
| 151 |
|
| 152 |
// C wrapper interfaces to C++ routines |
| 153 |
|
| 154 |
extern "C" { |
| 155 |
GmshIO* atlas__Gmsh__new(); |
| 156 |
void atlas__Gmsh__delete(GmshIO* This); |
| 157 |
Mesh::Implementation* atlas__Gmsh__read(GmshIO* This, char* file_path); |
| 158 |
void atlas__Gmsh__write(GmshIO* This, Mesh::Implementation* mesh, char* file_path); |
| 159 |
Mesh::Implementation* atlas__read_gmsh(char* file_path); |
| 160 |
void atlas__write_gmsh_mesh(const Mesh::Implementation* mesh, char* file_path); |
| 161 |
void atlas__write_gmsh_fieldset(const field::FieldSetImpl* fieldset, functionspace::FunctionSpaceImpl* function_space, |
| 162 |
char* file_path, int mode); |
| 163 |
void atlas__write_gmsh_field(const field::FieldImpl* field, functionspace::FunctionSpaceImpl* function_space, |
| 164 |
char* file_path, int mode); |
| 165 |
} |
| 166 |
|
| 167 |
//---------------------------------------------------------------------------------------------------------------------- |
| 168 |
|
| 169 |
} // namespace detail |
| 170 |
} // namespace output |
| 171 |
} // namespace atlas |