-
Notifications
You must be signed in to change notification settings - Fork 55
/
NetCDFWriter.hpp
120 lines (105 loc) · 3.88 KB
/
NetCDFWriter.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* @file
* This file is part of SWE.
*
* @author Alexander Breuer (breuera AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer)
* @author Sebastian Rettenberger (rettenbs AT in.tum.de,
* http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
*
* @section LICENSE
*
* SWE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SWE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SWE. If not, see <http://www.gnu.org/licenses/>.
*
*
* @section DESCRIPTION
*
* A writer for the netCDF-format: http://www.unidata.ucar.edu/software/netcdf/
*/
#pragma once
#include "Writer.hpp"
namespace Writers {
#ifdef ENABLE_NETCDF
class NetCDFWriter: public Writer {
private:
int dataFile_;
int timeVar_, hVar_, huVar_, hvVar_, bVar_;
/** Flush after every x write operation? */
unsigned int flush_;
/**
* Writes time dependent data to a netCDF-file (-> constructor) with respect to the boundary sizes.
*
* boundarySize[0] == left
* boundarySize[1] == right
* boundarySize[2] == bottom
* boundarySize[3] == top
*
* @param matrix array which contains time dependent data.
* @param boundarySize size of the boundaries.
* @param ncVariable time dependent netCDF-variable to which the output is written to.
*/
void writeVarTimeDependent(const Tools::Float2D<RealType>& matrix, int ncVariable);
/**
* Write time independent data to a netCDF-file (-> constructor) with respect to the boundary sizes.
* Variable is time-independent
* boundarySize[0] == left
* boundarySize[1] == right
* boundarySize[2] == bottom
* boundarySize[3] == top
*
* @param matrix array which contains time independent data.
* @param boundarySize size of the boundaries.
* @param ncVariable time independent netCDF-variable to which the output is written to.
*/
void writeVarTimeIndependent(const Tools::Float2D<RealType>& matrix, int ncVariable);
/**
* This is a small wrapper for `nc_put_att_text` which automatically sets the length.
*/
void ncPutAttText(int varid, const char* name, const char* value);
public:
NetCDFWriter(
const std::string& fileName,
const Tools::Float2D<RealType>& bathymetry,
const BoundarySize& boundarySize,
int nX,
int nY,
RealType dX,
RealType dY,
RealType originX = 0.,
RealType originY = 0.,
unsigned int flush = 0
);
~NetCDFWriter() override;
/**
* Writes the unknwons to a netCDF-file (-> constructor) with respect to the boundary sizes.
*
* boundarySize[0] == left
* boundarySize[1] == right
* boundarySize[2] == bottom
* boundarySize[3] == top
*
* @param h water heights at a given time step.
* @param hu momentums in x-direction at a given time step.
* @param hv momentums in y-direction at a given time step.
* @param boundarySize size of the boundaries.
* @param time simulation time of the time step.
*/
void writeTimeStep(
const Tools::Float2D<RealType>& h,
const Tools::Float2D<RealType>& hu,
const Tools::Float2D<RealType>& hv,
double time
) override;
};
#endif
} // namespace Writers