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

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

Use the NetCDF wrapper for inputs for better error checking.

  • 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: 6.7 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      std::vector<T> getAttributeValue(const StdString& name,
87                                       const StdString* const var  = NULL,
88                                       const CVarPath* const path = NULL);
89
90      StdString getAttributeValue(const StdString& name,
91                                  const StdString* const var,
92                                  const CVarPath* const path);
93
94      template <class T>
95      void getData(CArray<T, 1>& data,
96                   const StdString& var,
97                   const CVarPath* const path = NULL,
98                   StdSize record = UNLIMITED_DIM);
99
100      template <class T>
101      void getData(CArray<T, 1>& data, const StdString& var,
102                   bool collective, StdSize record,
103                   const std::vector<StdSize>* start = NULL,
104                   const std::vector<StdSize>* count = NULL);
105
106      //-------------------------------------------------------------
107
108      /// Tests ///
109      bool hasMissingValue(const StdString& name, const CVarPath* const path = NULL);
110
111      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL);
112
113      bool hasVariable(const StdString& name, const CVarPath* const path = NULL);
114
115      bool hasCoordinates(const StdString& name, const CVarPath* const path = NULL);
116
117      bool hasTemporalDim(const CVarPath* const path = NULL);
118
119      bool hasBounds(const StdString& name, const CVarPath* const path = NULL);
120
121      //-------------------------------------------------------------
122
123      bool isBound(const StdString& name, const CVarPath* const path = NULL);
124      bool isCoordinate(const StdString& name, const CVarPath* const path = NULL);
125      bool isRectilinear(const StdString& name, const CVarPath* const path = NULL);
126      bool isCurvilinear(const StdString& name, const CVarPath* const path = NULL);
127      bool isUnknown(const StdString& name, const CVarPath* const path = NULL);
128      bool isUnstructured(const StdString& name, const CVarPath* const path = NULL);
129
130      bool isTemporal(const StdString& name, const CVarPath* const path = NULL);
131      bool is3Dim(const StdString& name, const CVarPath* const path = NULL);
132      bool isCellGrid(const StdString& name, const CVarPath* const path = NULL);
133
134    protected:
135      /// Getters ///
136      int getGroup   (const CVarPath* const path = NULL);
137      int getVariable(const StdString& varname, const CVarPath* const path = NULL);
138      int getDimension(const StdString& dimname, const CVarPath* const path = NULL);
139      int getUnlimitedDimension(const CVarPath* const path = NULL);
140      int getAttributeId(const StdString& name,
141                         const StdString* const var = NULL,
142                         const CVarPath* const path = NULL);
143
144      std::pair<nc_type , StdSize> getAttribute(const StdString& attname,
145                                                const StdString* const var  = NULL,
146                                                const CVarPath* const path = NULL);
147
148      //-------------------------------------------------------------
149
150      void getDataInfo(const StdString& var, const CVarPath* const path, StdSize record,
151                       std::vector<StdSize>& sstart, std::vector<StdSize>& scount, StdSize& array_size,
152                       const std::vector<StdSize>* start = NULL, const std::vector<StdSize>* count = NULL);
153
154    private:
155      int ncidp; //< Id of the NetCDF file
156      bool mpi;  //< Whether parallel file access is used
157  }; // class CINetCDF4
158} // namespace xios
159
160#endif //__XIOS_INETCDF4__
Note: See TracBrowser for help on using the repository browser.