source: XIOS/trunk/src/io/inetcdf4.hpp @ 685

Last change on this file since 685 was 685, checked in by rlacroix, 9 years ago

Merge "output" and "input" folders into one "io" folder.

Some files were used for both output and input so the separation was not valid anymore.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 8.8 KB
Line 
1#ifndef __XIOS_INETCDF4__
2#define __XIOS_INETCDF4__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "exception.hpp"
7#include "array_new.hpp"
8
9#include "mpi.hpp"
10#include "netcdf.hpp"
11
12#ifndef UNLIMITED_DIM
13#define UNLIMITED_DIM (size_t)(-1)
14#endif  // UNLIMITED_DIM
15
16namespace xios
17{
18  typedef std::vector<StdString> CVarPath;
19
20  class CINetCDF4
21  {
22    public:
23      /// Constructors ///
24      CINetCDF4(const StdString& filename, const MPI_Comm* comm = NULL, bool multifile = true);
25      CINetCDF4(const CINetCDF4& inetcdf4);       // Not implemented.
26      CINetCDF4(const CINetCDF4* const inetcdf4); // Not implemented.
27
28      //-------------------------------------------------------------
29
30      /// Destructor ///
31      virtual ~CINetCDF4(void);
32
33      //-------------------------------------------------------------
34
35      void close(void);
36
37      //-------------------------------------------------------------
38
39      /// Getters ///
40      StdSize getNbOfTimestep(const CVarPath* const path = NULL);
41
42      StdString getUnlimitedDimensionName(const CVarPath* const path = NULL);
43
44      StdString getCoordinatesId(const StdString& name, const CVarPath* const path = NULL);
45
46      StdString getBoundsId(const StdString& name, const CVarPath* const path = NULL);
47
48      StdString getLonCoordName(const StdString& varname, const CVarPath* const path = NULL);
49      StdString getLatCoordName(const StdString& varname, const CVarPath* const path = NULL);
50      StdString getVertCoordName(const StdString& varname, const CVarPath* const path = NULL);
51
52      std::set<StdString> getCoordVariables(const CVarPath* const path = NULL);
53      std::set<StdString> getBoundVariables(const CVarPath* const path = NULL);
54
55      std::list<StdString> getGroups   (const CVarPath* const path = NULL);
56      std::list<StdString> getVariables(const CVarPath* const path = NULL);
57
58      std::list<StdString> getDataVariables(bool _is3D       = true,
59                                            bool _isRecti    = true,
60                                            bool _isCurvi    = true,
61                                            bool _isUnstr    = true,
62                                            bool _isCellData = true,
63                                            bool _isTemporal = true,
64                                            const CVarPath* const path = NULL);
65
66      std::list<StdString> getAttributes(const StdString* const var  = NULL,
67                                         const CVarPath* const path = NULL);
68
69      std::list<StdString> getDimensionsList(const StdString* const var  = NULL,
70                                             const CVarPath* const path = NULL);
71
72      std::list<StdString> getCoordinatesIdList(const StdString& name,
73                                                const CVarPath* const path = NULL);
74
75      std::map<StdString, StdSize> getDimensions(const StdString* const var  = NULL,
76                                                 const CVarPath* const path = NULL);
77
78      StdSize getNbVertex(const StdString& name, const CVarPath* const path = NULL);
79
80      //-------------------------------------------------------------
81
82      template <class T>
83      T getMissingValue(const StdString& name, const CVarPath* const path = NULL);
84
85      template <class T>
86      T getAttributeValue(const StdString& name,
87                          const StdString* const var  = NULL,
88                          const CVarPath* const path = NULL);
89
90      template <class T>
91      void getData(CArray<T, 1>& data,
92                   const StdString& var,
93                   const CVarPath* const path = NULL,
94                   StdSize record = UNLIMITED_DIM);
95
96      template <class T>
97      void getData(CArray<T, 1>& data, const StdString& var,
98                   bool collective, StdSize record,
99                   const std::vector<StdSize>* start = NULL,
100                   const std::vector<StdSize>* count = NULL);
101
102      //-------------------------------------------------------------
103
104      /// Tests ///
105      bool hasMissingValue(const StdString& name, const CVarPath* const path = NULL);
106
107      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL);
108
109      bool hasVariable(const StdString& name, const CVarPath* const path = NULL);
110
111      bool hasCoordinates(const StdString& name, const CVarPath* const path = NULL);
112
113      bool hasTemporalDim(const CVarPath* const path = NULL);
114
115      bool hasBounds(const StdString& name, const CVarPath* const path = NULL);
116
117      //-------------------------------------------------------------
118
119      bool isBound(const StdString& name, const CVarPath* const path = NULL);
120      bool isCoordinate(const StdString& name, const CVarPath* const path = NULL);
121      bool isRectilinear(const StdString& name, const CVarPath* const path = NULL);
122      bool isCurvilinear(const StdString& name, const CVarPath* const path = NULL);
123      bool isUnknown(const StdString& name, const CVarPath* const path = NULL);
124      bool isUnstructured(const StdString& name, const CVarPath* const path = NULL);
125
126      bool isTemporal(const StdString& name, const CVarPath* const path = NULL);
127      bool is3Dim(const StdString& name, const CVarPath* const path = NULL);
128      bool isCellGrid(const StdString& name, const CVarPath* const path = NULL);
129
130    protected:
131      /// Getters ///
132      int getGroup   (const CVarPath* const path = NULL);
133      int getVariable(const StdString& varname, const CVarPath* const path = NULL);
134      int getDimension(const StdString& dimname, const CVarPath* const path = NULL);
135      int getUnlimitedDimension(const CVarPath* const path = NULL);
136      int getAttributeId(const StdString& name,
137                         const StdString* const var = NULL,
138                         const CVarPath* const path = NULL);
139
140      std::pair<nc_type , StdSize> getAttribute(const StdString& attname,
141                                                const StdString* const var  = NULL,
142                                                const CVarPath* const path = NULL);
143
144      //-------------------------------------------------------------
145
146      void getDataInfo(const StdString& var, const CVarPath* const path, StdSize record,
147                       std::vector<StdSize>& sstart, std::vector<StdSize>& scount, StdSize& array_size,
148                       const std::vector<StdSize>* start = NULL, const std::vector<StdSize>* count = NULL);
149
150    private:
151      /// Vérification des erreurs NetCDF ///
152      static void CheckError(int status);
153
154      int ncidp; // Identifiant de fichier netcdf.
155      bool mpi; //< Whether parallel file access is used
156  }; // class CINetCDF4
157
158  ///--------------------------------------------------------------
159
160  template <>
161  StdString CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var,
162                                         const CVarPath* const path);
163
164  template <>
165  std::vector<double> CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var,
166                                                   const CVarPath* const path);
167
168  template <>
169  std::vector<float> CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var,
170                                                  const CVarPath* const path);
171
172  template <>
173  std::vector<int> CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var,
174                                                const CVarPath* const path);
175
176  template <>
177  std::vector<char> CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var,
178                                                 const CVarPath* const path);
179
180  //---------------------------------------------------------------
181
182  template <>
183  int CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path);
184
185  template <>
186  double CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path);
187
188  template <>
189  float CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path);
190
191  //---------------------------------------------------------------
192
193  template <>
194  void CINetCDF4::getData(CArray<int, 1>& data, const StdString& var,
195                          const CVarPath* const path, StdSize record);
196
197  template <>
198  void CINetCDF4::getData(CArray<double, 1>& data, const StdString& var,
199                          const CVarPath* const path, StdSize record);
200
201  template <>
202  void CINetCDF4::getData(CArray<float, 1>& data, const StdString& var,
203                          const CVarPath* const path, StdSize record);
204
205  template <>
206  void CINetCDF4::getData(CArray<double, 1>& data, const StdString& var,
207                          bool collective, StdSize record,
208                          const std::vector<StdSize>* start /*= NULL*/,
209                          const std::vector<StdSize>* count /*= NULL*/);
210} // namespace xios
211
212#endif //__XIOS_INETCDF4__
Note: See TracBrowser for help on using the repository browser.