source: XIOS/dev/branch_openmp/src/io/inetcdf4.hpp @ 1460

Last change on this file since 1460 was 1460, checked in by yushan, 6 years ago

branch_openmp merged with XIOS_DEV_CMIP6@1459

  • 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: 7.0 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_std.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 ep_lib::MPI_Comm* comm = NULL, bool multifile = true,
25                const StdString& timeCounterName = "time_counter");
26      CINetCDF4(const CINetCDF4& inetcdf4);       // Not implemented.
27      CINetCDF4(const CINetCDF4* const inetcdf4); // Not implemented.
28
29      //-------------------------------------------------------------
30
31      /// Destructor ///
32      virtual ~CINetCDF4(void);
33
34      //-------------------------------------------------------------
35
36      void close(void);
37
38      //-------------------------------------------------------------
39
40      /// Getters ///
41      StdSize getNbOfTimestep(const CVarPath* const path = NULL);
42
43      StdString getUnlimitedDimensionName(const CVarPath* const path = NULL);
44
45      const StdString& getTimeCounterName(void) const { return timeCounterName; };
46
47      StdString getCoordinatesId(const StdString& name, const CVarPath* const path = NULL);
48
49      StdString getBoundsId(const StdString& name, const CVarPath* const path = NULL);
50
51      StdString getLonCoordName(const StdString& varname, const CVarPath* const path = NULL);
52      StdString getLatCoordName(const StdString& varname, const CVarPath* const path = NULL);
53      StdString getVertCoordName(const StdString& varname, const CVarPath* const path = NULL);
54
55      std::set<StdString> getCoordVariables(const CVarPath* const path = NULL);
56      std::set<StdString> getBoundVariables(const CVarPath* const path = NULL);
57
58      std::list<StdString> getGroups   (const CVarPath* const path = NULL);
59      std::list<StdString> getVariables(const CVarPath* const path = NULL);
60
61      std::list<StdString> getDataVariables(bool _is3D       = true,
62                                            bool _isRecti    = true,
63                                            bool _isCurvi    = true,
64                                            bool _isUnstr    = true,
65                                            bool _isCellData = true,
66                                            bool _isTemporal = true,
67                                            const CVarPath* const path = NULL);
68
69      std::list<StdString> getAttributes(const StdString* const var  = NULL,
70                                         const CVarPath* const path = NULL);
71
72      std::list<StdString> getDimensionsList(const StdString* const var  = NULL,
73                                             const CVarPath* const path = NULL);
74
75      std::list<StdString> getCoordinatesIdList(const StdString& name,
76                                                const CVarPath* const path = NULL);
77
78      std::map<StdString, StdSize> getDimensions(const StdString* const var  = NULL,
79                                                 const CVarPath* const path = NULL);
80
81      StdSize getNbVertex(const StdString& name, const CVarPath* const path = NULL);
82
83      //-------------------------------------------------------------
84
85      template <class T>
86      T getMissingValue(const StdString& name, const CVarPath* const path = NULL);
87
88      template <class T>
89      std::vector<T> getAttributeValue(const StdString& name,
90                                       const StdString* const var  = NULL,
91                                       const CVarPath* const path = NULL);
92
93      StdString getAttributeValue(const StdString& name,
94                                  const StdString* const var,
95                                  const CVarPath* const path);
96
97      template <class T>
98      void getData(CArray<T, 1>& data,
99                   const StdString& var,
100                   const CVarPath* const path = NULL,
101                   StdSize record = UNLIMITED_DIM);
102
103      template <class T, int Ndim>
104      void getData(CArray<T, Ndim>& data, const StdString& var,
105                   bool collective, StdSize record,
106                   const std::vector<StdSize>* start = NULL,
107                   const std::vector<StdSize>* count = NULL);
108
109      //-------------------------------------------------------------
110
111      /// Tests ///
112      bool hasMissingValue(const StdString& name, const CVarPath* const path = NULL);
113
114      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL);
115
116      bool hasVariable(const StdString& name, const CVarPath* const path = NULL);
117
118      bool hasCoordinates(const StdString& name, const CVarPath* const path = NULL);
119
120      bool hasTemporalDim(const CVarPath* const path = NULL);
121
122      bool hasBounds(const StdString& name, const CVarPath* const path = NULL);
123
124      //-------------------------------------------------------------
125
126      bool isBound(const StdString& name, const CVarPath* const path = NULL);
127      bool isCoordinate(const StdString& name, const CVarPath* const path = NULL);
128      bool isRectilinear(const StdString& name, const CVarPath* const path = NULL);
129      bool isCurvilinear(const StdString& name, const CVarPath* const path = NULL);
130      bool isUnknown(const StdString& name, const CVarPath* const path = NULL);
131      bool isUnstructured(const StdString& name, const CVarPath* const path = NULL);
132
133      bool isTemporal(const StdString& name, const CVarPath* const path = NULL);
134      bool is3Dim(const StdString& name, const CVarPath* const path = NULL);
135      bool isCellGrid(const StdString& name, const CVarPath* const path = NULL);
136
137      bool isLonOrLat(const StdString& varname, const CVarPath* const path = NULL);
138
139    protected:
140      /// Getters ///
141      int getGroup   (const CVarPath* const path = NULL);
142      int getVariable(const StdString& varname, const CVarPath* const path = NULL);
143      int getDimension(const StdString& dimname, const CVarPath* const path = NULL);
144      int getUnlimitedDimension(const CVarPath* const path = NULL);
145      int getAttributeId(const StdString& name,
146                         const StdString* const var = NULL,
147                         const CVarPath* const path = NULL);
148
149      std::pair<nc_type , StdSize> getAttribute(const StdString& attname,
150                                                const StdString* const var  = NULL,
151                                                const CVarPath* const path = NULL);
152
153      //-------------------------------------------------------------
154
155      void getDataInfo(const StdString& var, const CVarPath* const path, StdSize record,
156                       std::vector<StdSize>& sstart, std::vector<StdSize>& scount, StdSize& array_size,
157                       const std::vector<StdSize>* start = NULL, const std::vector<StdSize>* count = NULL);
158
159    private:
160      int ncidp; //< Id of the NetCDF file
161      bool mpi;  //< Whether parallel file access is used
162      StdString timeCounterName;
163  }; // class CINetCDF4
164} // namespace xios
165
166#endif //__XIOS_INETCDF4__
Note: See TracBrowser for help on using the repository browser.