source: XIOS/trunk/src/io/netCdfInterface.hpp @ 685

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

Merge "output" and "input" folders into one "io" folder.

Some files were used for both output and input so the separation was not valid anymore.

  • 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 "xios_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    //! Set or unset the fill mode
96    static int setFill(int ncid, bool fill);
97
98    //! Define variable fill parameters
99    static int defVarFill(int ncid, int varId, int noFill, void* fillValue);
100
101
102    //! Change access type of a variable
103    static int varParAccess(int ncid, int varid, int access);
104
105    //! Syn
106    static int sync(int ncId);
107
108    //! Put attribute into variable
109    static int putAtt(int ncid, int varid, const StdString& attrName, nc_type xtype,
110                      StdSize numVal, const void* op);
111
112
113    //! Put attribute into variable with specific type
114    template<typename T>
115    static int putAttType(int ncid, int varid, const StdString& attrName, StdSize numVal, const T* op);
116
117    //! Put value into a variable with a specific type
118    template<typename T>
119    static int putVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* op);
120
121  private:
122    template<typename T>
123    static int ncPutAttType(int ncid, int varid, const char* attrName, StdSize numVal, const T* op);
124
125    template<typename T>
126    static int ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* op);
127
128  private:
129    static StdString openMode2String(int oMode);
130
131    static StdString creationMode2String(int cMode);
132
133
134  public:
135    // Some functions dedude from several special cases
136    //! Query the existence of a variable
137    static bool isVarExisted(int ncId, const StdString& varName);
138
139  };
140}
141
142
143#endif // NETCDFINTERFACE_HPP_
Note: See TracBrowser for help on using the repository browser.