-
Notifications
You must be signed in to change notification settings - Fork 30
/
netcdf.h
165 lines (127 loc) · 4.76 KB
/
netcdf.h
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
Copyright 2013--2018 James E. McClure, Virginia Polytechnic & State University
This file is part of the Open Porous Media project (OPM).
OPM 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.
OPM 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 OPM. If not, see <http:https://www.gnu.org/licenses/>.
*/
#ifndef NETCDF_READER
#define NETCDF_READER
#include <string>
#include <vector>
#include "common/Array.h"
#include "common/Communication.h"
#include "common/MPI.h"
namespace netcdf {
//! Enum to hold variable type
enum VariableType { BYTE, SHORT, USHORT, INT, UINT, INT64, UINT64, FLOAT, DOUBLE, STRING, UNKNOWN };
//! Enum to hold variable type
enum FileMode { READ, WRITE, CREATE };
//! Convert the VariableType to a string
std::string VariableTypeName( VariableType type );
/*!
* @brief Open netcdf file
* @details This function opens a netcdf file
* @return This function returns a handle to the file
* @param filename File to open
* @param mode Open the file for reading or writing
* @param comm MPI communicator to use (MPI_COMM_WORLD: don't use parallel netcdf)
*/
int open( const std::string &filename, FileMode mode, const Utilities::MPI &comm = MPI_COMM_NULL );
/*!
* @brief Close netcdf file
* @details This function closes a netcdf file
* @param fid Handle to the open file
*/
void close( int fid );
/*!
* @brief Read the variable names
* @details This function reads a list of the variable names in the file
* @param fid Handle to the open file
*/
std::vector<std::string> getVarNames( int fid );
/*!
* @brief Read the attribute names
* @details This function reads a list of the attribute names in the file
* @param fid Handle to the open file
*/
std::vector<std::string> getAttNames( int fid );
/*!
* @brief Return the variable type
* @details This function returns the type for a variable
* @param fid Handle to the open file
* @param var Variable to read
*/
VariableType getVarType( int fid, const std::string &var );
/*!
* @brief Return the attribute type
* @details This function returns the type for an attribute
* @param fid Handle to the open file
* @param att Attribute to read
*/
VariableType getAttType( int fid, const std::string &att );
/*!
* @brief Return the variable dimensions
* @details This function returns the die for a variable
* @param fid Handle to the open file
* @param var Variable to read
*/
std::vector<size_t> getVarDim( int fid, const std::string &var );
/*!
* @brief Read a variable
* @details This function reads a variable with the given name from the file
* @param fid Handle to the open file
* @param var Variable to read
*/
template<class TYPE>
Array<TYPE> getVar( int fid, const std::string &var );
/*!
* @brief Read a strided variable
* @details This function reads a strided variable with the given name from the file
* @param fid Handle to the open file
* @param var Variable to read
* @param start Starting corner for the read
* @param count Number of elements to read
* @param stride Stride size for the read
*/
template<class TYPE>
Array<TYPE> getVar( int fid, const std::string &var, const std::vector<int> &start,
const std::vector<int> &count, const std::vector<int> &stride );
/*!
* @brief Read an attribute
* @details This function reads an attribute with the given name from the file
* @param fid Handle to the open file
* @param att Attribute to read
*/
template<class TYPE>
Array<TYPE> getAtt( int fid, const std::string &att );
/*!
* @brief Write the dimensions
* @details This function writes the grid dimensions to netcdf.
* @param fid Handle to the open file
* @param names
* @param dims
*/
std::vector<int> defDim(
int fid, const std::vector<std::string> &names, const std::vector<int> &dims );
/*!
* @brief Write a variable
* @details This function writes a variable to netcdf.
* @param fid Handle to the open file
* @param var Variable to read
* @param dimids
* @param data
* @param rank_info
*/
template<class TYPE>
void write( int fid, const std::string &var, const std::vector<int> &dimids,
const Array<TYPE> &data, const RankInfoStruct &rank_info );
} // namespace netcdf
#endif