source: XIOS/trunk/src/output/netCdfInterface.hpp @ 517

Last change on this file since 517 was 517, checked in by rlacroix, 8 years ago

Add a new attribute to the file definition so that the output format can be controlled.

Currently the supported formats are "netcdf4" and "netcdf4_classic". The "format" attribute is optional. The "netcdf4" format will be used when no format is explicitly defined. Since "netcdf4" is the format which was previously used by XIOS, existing configuration files will not be affected by this change.

If "netcdf4_classic" is used, the output file(s) will be created using the classic NetCDF format. This format can be used with the attribute "type" set to "one_file" if the NetCDF4 library was compiled with Parallel NetCDF support (--enable-pnetcdf).

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