MDAL
mdal_netcdf.hpp
1 /*
2  MDAL - Mesh Data Abstraction Library (MIT License)
3  Copyright (C) 2018 Peter Petrik (zilolv at gmail dot com)
4 */
5 
6 #ifndef MDAL_NETCDF_HPP
7 #define MDAL_NETCDF_HPP
8 
9 #include <string>
10 #include <vector>
11 
12 
15 {
16  public:
18  NetCDFFile();
20  ~NetCDFFile();
21 
22  int handle() const;
23  void openFile( const std::string &fileName );
24 
25  std::vector<int> readIntArr( const std::string &name, size_t dim ) const;
27  std::vector<int> readIntArr( int arr_id,
28  size_t start_dim1,
29  size_t start_dim2,
30  size_t count_dim1,
31  size_t count_dim2
32  ) const;
33 
35  std::vector<int> readIntArr( int arr_id,
36  size_t start_dim,
37  size_t count_dim
38  ) const;
39 
40  std::vector<double> readDoubleArr( const std::string &name, size_t dim ) const;
41 
43  std::vector<double> readDoubleArr( int arr_id,
44  size_t start_dim1,
45  size_t start_dim2,
46  size_t count_dim1,
47  size_t count_dim2
48  ) const;
49 
51  std::vector<double> readDoubleArr( int arr_id,
52  size_t start_dim,
53  size_t count_dim
54  ) const;
55 
56  bool hasArr( const std::string &name ) const;
57  int arrId( const std::string &name ) const;
58 
59  std::vector<std::string> readArrNames() const;
60 
61  bool hasAttrInt( const std::string &name, const std::string &attr_name ) const;
62  int getAttrInt( const std::string &name, const std::string &attr_name ) const;
63  bool hasAttrDouble( int varid, const std::string &attr_name ) const;
64  double getAttrDouble( int varid, const std::string &attr_name ) const;
71  std::string getAttrStr( const std::string &name, const std::string &attr_name ) const;
72  std::string getAttrStr( const std::string &attr_name, int varid ) const;
73 
74  double getFillValue( int varid ) const;
75  int getVarId( const std::string &name );
76  void getDimension( const std::string &name, size_t *val, int *ncid_val ) const;
77  void getDimensions( const std::string &variableName, std::vector<size_t> &dimensionsId, std::vector<int> &dimensionIds );
78  bool hasDimension( const std::string &name ) const;
79 
80  void createFile( const std::string &fileName );
81  int defineDimension( const std::string &name, size_t size );
82  int defineVar( const std::string &varName, int ncType, int dimensionCount, const int *dimensions );
83  void putAttrStr( int varId, const std::string &attrName, const std::string &value );
84  void putAttrInt( int varId, const std::string &attrName, int value );
85  void putAttrDouble( int varId, const std::string &attrName, double value );
86  void putDataDouble( int varId, const size_t index, const double value );
87  void putDataArrayInt( int varId, size_t line, size_t faceVerticesMax, int *values );
88 
89  std::string getFileName() const;
90 
91  private:
92  int mNcid; // C handle to the file
93  std::string mFileName;
94 };
95 
96 #endif // MDAL_NETCDF_HPP
C++ Wrapper around netcdf C library.
Definition: mdal_netcdf.hpp:15
~NetCDFFile()
Closes the file.
Definition: mdal_netcdf.cpp:19
NetCDFFile()
Create file with invalid handle.
Definition: mdal_netcdf.cpp:17
std::string getAttrStr(const std::string &name, const std::string &attr_name) const
Get string attribute.
Definition: mdal_netcdf.cpp:272