source: XIOS/dev/branch_openmp/src/io/netCdfInterface.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: 5.8 KB
Line 
1/*!
2   \file netCdfInterface.hpp
3   \author Ha NGUYEN
4   \date 08 Oct 2014
5   \since 03 Oct 2014
6
7   \brief Wrapper of netcdf functions.
8 */
9#ifndef __NETCDF_INTERFACE_HPP_
10#define __NETCDF_INTERFACE_HPP_
11
12#include "mpi_std.hpp"
13#include "xios_spl.hpp"
14
15#if !defined(USING_NETCDF_PAR)
16#include "exception.hpp"
17#endif
18
19//#include "mpi.hpp"
20#include "netcdf.hpp"
21
22namespace xios
23{
24  /*!
25  \class CNetCdfInterface
26   This class is  wrapper of some common used functions of netCdf in Xios
27  */
28  class CNetCdfInterface
29  {
30  public:
31    //! Create a netcdf file
32    static int create(const StdString& path, int cmode, int& ncId);
33
34    //! Create a netcdf file on a parallel file system
35    static int createPar(const StdString& path, int cmode, MPI_Comm comm, MPI_Info info, int& ncId);
36
37    //! Open a netcdf file
38    static int open(const StdString& path, int oMode, int& ncId);
39
40    //! Open a netcdf file
41    static int openPar(const StdString& path, int cmode, MPI_Comm comm, MPI_Info info, int& ncId);
42
43    //! Close a netcdf file
44    static int close(int ncId);
45
46    //! Put netcdf file into define mode
47    static int reDef(int ncId);
48
49    //! End define mode of a netcdf file
50    static int endDef(int ncId);
51
52    //! Query identity of a named group
53    static int inqNcId(int ncid, const StdString& grpName, int& grpId);
54
55    //! Query identity of a named variable
56    static int inqVarId(int ncid, const StdString& varName, int& varId);
57
58    //! Query the name of a variable given its id
59    static int inqVarName(int ncid, int varId, StdString& varName);
60
61    //! Query identity of a named dimension
62    static int inqDimId(int ncid, const StdString& dimName, int& dimId);
63
64    //! Query identity of unlimited dimension
65    static int inqUnLimDim(int ncid, int& dimId);
66
67    //! Query name of a dimension with its id
68    static int inqDimName(int ncid, int dimId, StdString& dimName);
69
70    //! Query length of dimension with its id
71    static int inqDimLen(int ncid, int dimId, StdSize& dimLen);
72
73    //! Query number of dimension of a variable with its id
74    static int inqVarNDims(int ncid, int varId, int& nDims);
75
76    //! Query list of dimension of a variable with its id
77    static int inqVarDimId(int, int, int*);
78
79    //! Query dimensions of a group
80    static int inqDimIds(int ncid, int& nDims, int* dimIds, int includeParents);
81
82    //! Query the full name of a group given its id
83    static int inqGrpFullName(int ncid, StdString& grpFullName);
84
85    //! Query the list of group ids given a location id
86    static int inqGrpIds(int ncid, int& numgrps, int* ncids);
87
88    //! Query the list of variable ids given a location id
89    static int inqVarIds(int ncid, int& nvars, int* varids);
90
91    //! Query the type and the size of an attribute given its name and the id of the variable to which it is attached.
92    static int inqAtt(int ncid, int varid, const StdString& name, nc_type& type, size_t& len);
93
94    //! Query the number of global attributes given a location id
95    static int inqNAtts(int ncid, int& ngatts);
96
97    //! Query the number of attributes given a location id and a variable id
98    static int inqVarNAtts(int ncid, int varid, int& natts);
99
100    //! Query the name of an attribute given a location id, a variable id and the attribute number
101    static int inqAttName(int ncid, int varid, int attnum, StdString& name);
102
103    //! Define a group
104    static int defGrp(int parentNcid, const StdString& grpName, int& grpId);
105
106    //! Define a dimension
107    static int defDim(int ncid, const StdString& dimName, StdSize dimLen, int& dimId);
108
109    //! Define a variable
110    static int defVar(int ncid, const StdString& varName, nc_type xtype,
111                      int nDims, const int dimIds[], int& varId);
112
113    //! Define variable chunking size
114    static int defVarChunking(int ncid, int varId, int storage, StdSize chunkSize[]);
115
116    //! Define variable compression level
117    static int defVarDeflate(int ncid, int varId, int compressionLevel);
118
119    //! Set or unset the fill mode
120    static int setFill(int ncid, bool fill);
121
122    //! Define variable fill parameters
123    static int defVarFill(int ncid, int varId, int noFill, void* fillValue);
124
125
126    //! Change access type of a variable
127    static int varParAccess(int ncid, int varid, int access);
128
129    //! Sync the file
130    static int sync(int ncId);
131
132    //! Read an attribute
133    template<typename T>
134    static int getAttType(int ncid, int varid, const StdString& attrName, T* data);
135
136    //! Set an attribute
137    template<typename T>
138    static int putAttType(int ncid, int varid, const StdString& attrName, StdSize numVal, const T* data);
139
140    //! Get data for a variable
141    template<typename T>
142    static int getVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, T* data);
143
144    //! Set data for a variable
145    template<typename T>
146    static int putVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* data);
147
148    //! Get the NetCDF type corresponding to a specific C type
149    template<typename T>
150    static nc_type getNcType();
151
152  private:
153    template<typename T>
154    static int ncGetAttType(int ncid, int varid, const char* attrName, T* data);
155
156    template<typename T>
157    static int ncPutAttType(int ncid, int varid, const char* attrName, StdSize numVal, const T* data);
158
159    template<typename T>
160    static int ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, T* data);
161
162    template<typename T>
163    static int ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* data);
164
165  private:
166    static StdString openMode2String(int oMode);
167
168    static StdString creationMode2String(int cMode);
169
170
171  public:
172    // Some functions dedude from several special cases
173    //! Query the existence of a variable
174    static bool isVarExisted(int ncId, const StdString& varName);
175    static bool isDimExisted(int ncId, const StdString& dimName);
176  };
177}
178
179
180#endif // NETCDFINTERFACE_HPP_
Note: See TracBrowser for help on using the repository browser.