source: XIOS/branchs/xios-1.0/src/output/netCdfInterface.hpp @ 606

Last change on this file since 606 was 606, checked in by rlacroix, 6 years ago

Support NetCDF4 compression.

Only available for non-parallel output so either if only one server is used or if the multiple file mode is enabled).

  • 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: 4.2 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 "xmlioserver_spl.hpp"
13
14#if !defined(USING_NETCDF_PAR)
15#include "exception.hpp"
16#endif
17
18#include "mpi.hpp"
19#include "netcdf.hpp"
20
21namespace xios
22{
23  /*!
24  \class CNetCdfInterface
25   This class is  wrapper of some common used functions of netCdf in Xios
26  */
27  class CNetCdfInterface
28  {
29  public:
30    //! Create a netcdf file
31    static int create(const StdString& path, int cmode, int& ncId);
32
33    //! Create a netcdf file on a parallel file system
34    static int createPar(const StdString& path, int cmode, MPI_Comm comm, MPI_Info info, int& ncId);
35
36    //! Open a netcdf file
37    static int open(const StdString& path, int oMode, int& ncId);
38
39    //! Open a netcdf file
40    static int openPar(const StdString& path, int cmode, MPI_Comm comm, MPI_Info info, int& ncId);
41
42    //! Close a netcdf file
43    static int close(int ncId);
44
45    //! Put netcdf file into define mode
46    static int reDef(int ncId);
47
48    //! End define mode of a netcdf file
49    static int endDef(int ncId);
50
51    //! Query identity of a named group
52    static int inqNcId(int ncid, const StdString& grpName, int& grpId);
53
54    //! Query identity of a named variable
55    static int inqVarId(int ncid, const StdString& varName, int& varId);
56
57    //! Query identity of a named dimension
58    static int inqDimId(int ncid,const StdString& dimName, int& dimId);
59
60    //! Query identity of unlimited dimension
61    static int inqUnLimDim(int ncid, int& dimId);
62
63    //! Query name of a dimension with its id
64    static int inqDimName(int ncid, int dimId, StdString& dimName);
65
66    //! Query length of dimension with its id
67    static int inqDimLen(int ncid, int dimId, StdSize& dimLen);
68
69    //! Query number of dimension of a variable with its id
70    static int inqVarNDims(int ncid, int varId, int& nDims);
71
72    //! Query list of dimension of a variable with its id
73    static int inqVarDimId(int, int, int*);
74
75    //! Query dimensions of a group
76    static int inqDimIds(int ncid, int& nDims, int* dimIds, int includeParents);
77
78
79    //! Define a group
80    static int defGrp(int parentNcid,const StdString& grpName, int& grpId);
81
82    //! Define a dimension
83    static int defDim(int ncid,const StdString& dimName, StdSize dimLen, int& dimId);
84
85    //! Define a variable
86    static int defVar(int ncid,const StdString& varName, nc_type xtype,
87                      int nDims, const int dimIds[], int& varId);
88
89    //! Define variable chunking size
90    static int defVarChunking(int ncid, int varId, int storage, StdSize chunkSize[]);
91
92    //! Define variable compression level
93    static int defVarDeflate(int ncid, int varId, int compressionLevel);
94
95    //! Define variable fill parameters
96    static int defVarFill(int ncid, int varId, int noFill, void* fillValue);
97
98
99    //! Change access type of a variable
100    static int varParAccess(int ncid, int varid, int access);
101
102    //! Syn
103    static int sync(int ncId);
104
105    //! Put attribute into variable
106    static int putAtt(int ncid, int varid, const StdString& attrName, nc_type xtype,
107                      StdSize numVal, const void* op);
108
109
110    //! Put attribute into variable with specific type
111    template<typename T>
112    static int putAttType(int ncid, int varid, const StdString& attrName, StdSize numVal, const T* op);
113
114    //! Put value into a variable with a specific type
115    template<typename T>
116    static int putVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* op);
117
118  private:
119    template<typename T>
120    static int ncPutAttType(int ncid, int varid, const char* attrName, StdSize numVal, const T* op);
121
122    template<typename T>
123    static int ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* op);
124
125  private:
126    static StdString openMode2String(int oMode);
127
128    static StdString creationMode2String(int cMode);
129
130
131  public:
132    // Some functions dedude from several special cases
133    //! Query the existence of a variable
134    static bool isVarExisted(int ncId, const StdString& varName);
135
136  };
137}
138
139
140#endif // NETCDFINTERFACE_HPP_
Note: See TracBrowser for help on using the repository browser.