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

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

Branch EP merged with Dev_cmip6 @r1490

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