source: XIOS3/trunk/src/io/onetcdf4.hpp

Last change on this file was 2529, checked in by jderouillat, 12 months ago

Enable parallel compression regarding NetCDF & HDF5 configurations at compile time. Implement an API to use HDF5 lossy compression plugins (SZ is available for now).

  • 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#ifndef __XIOS_ONETCDF4__
2#define __XIOS_ONETCDF4__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "exception.hpp"
7#include "data_output.hpp"
8#include "array_new.hpp"
9#include "mpi.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      /// ////////////////////// Déclarations ////////////////////// ///
19      class CONetCDF4
20         : public virtual CDataOutput
21      {
22         public :
23
24            /// Définition de type ///
25            typedef std::vector<StdString> CONetCDF4Path;
26
27            /// Constructeurs ///
28            CONetCDF4(const StdString& filename, bool append, bool useClassicFormat = false,
29                          bool useCFConvention = true,
30                      const MPI_Comm* comm = NULL, bool multifile = true,
31                      const StdString& timeCounterName = "time_counter");
32
33            CONetCDF4(const CONetCDF4& onetcdf4);       // Not implemented.
34            CONetCDF4(const CONetCDF4* const onetcdf4); // Not implemented.
35
36
37            /// Initialisation ///
38            void initialize(const StdString& filename, bool append, bool useClassicFormat, bool useCFConvention,
39                            const MPI_Comm* comm, bool multifile, const StdString& timeCounterName);
40            void close(void);
41            void sync(void);
42            void definition_start(void);
43            void definition_end(void);
44
45            /// Mutateurs ///
46            void setCurrentPath(const CONetCDF4Path& path);
47
48            int addGroup(const StdString& name);
49            int addDimension(const StdString& name, const StdSize size = UNLIMITED_DIM);
50            int addVariable(const StdString& name, nc_type type,
51                            const std::vector<StdString>& dim, bool defineChunking=true);
52            int addChunk(CField* field, nc_type type,
53                         const std::vector<StdString>& dim, int compressionLevel=0);
54
55      //----------------------------------------------------------------
56         public :
57
58            template <class T>
59               void setDefaultValue(const StdString& varname, const T* value = NULL);
60
61            void setCompressionLevel(const StdString& varname, const StdString& compressionType, int compressionLevel, 
62                                     const CArray<double,1>& compressionParam );
63
64            template <class T>  void addAttribute (const StdString& name, const T& value, const StdString* varname = NULL);
65
66            /// Ecriture des données ///
67            template <class T, int ndim>
68               void writeData(const CArray<T,ndim>& data, const StdString& name,
69                              bool collective, StdSize record,
70                              const std::vector<StdSize>* start = NULL,
71                              const std::vector<StdSize>* count = NULL);
72
73            void writeData(const CArray<int, 2>& data, const StdString& name);
74            void writeTimeAxisData(const CArray<double,1>& data, const StdString& name,
75                                   bool collective, StdSize record, bool Isroot);
76            void writeTimeAxisDataBounds(const CArray<double,1>& data, const StdString& name,
77                                   bool collective, StdSize record, bool Isroot);
78            /// Accesseur ///
79            const CONetCDF4Path& getCurrentPath(void) const;
80
81            /// Destructeur ///
82            virtual ~CONetCDF4(void);
83
84      //----------------------------------------------------------------
85
86         protected :
87
88            /// Ecriture ///
89            virtual void writeField_ (CField*  field)  = 0;
90            virtual void writeDomain_(CDomain* domain) = 0;
91            virtual void writeAxis_  (CAxis*   axis)   = 0;
92
93            /// Accesseurs ///
94            int getCurrentGroup(void);
95            int getGroup(const CONetCDF4Path& path);
96            int getVariable(const StdString& varname);
97            int getDimension(const StdString& dimname);
98            std::vector<StdSize>   getDimensions       (const StdString& varname);
99            std::vector<StdString> getDimensionsIdList (const StdString* varname);
100            int       getUnlimitedDimension(void);
101            StdString getUnlimitedDimensionName(void);
102            const StdString& getTimeCounterName(void) const { return timeCounterName; };
103
104            void getTimeAxisBounds(CArray<double,2>& timeAxisBounds, const StdString& name, bool collective );
105            void getTimeAxisBounds(CArray<double,2>& timeAxisBounds, const StdString& name, bool collective, size_t record);
106
107            bool varExist(const StdString& varname);
108            bool dimExist(const StdString& dimname);
109
110            bool useClassicFormat; //!< If true, NetCDF4 will use the classic NetCDF3 format
111            bool useCFConvention;  //!< If true data is written in the CF convention otherwise in UGRID
112
113      //----------------------------------------------------------------
114
115         private :
116            template <class T>
117            void writeData_(int grpid, int varid,
118                            const std::vector<StdSize>& sstart,
119                            const std::vector<StdSize>& scount, T* data);
120
121            void getWriteDataInfos(const StdString& name, StdSize record, StdSize& array_size,
122                                   std::vector<StdSize>& sstart,
123                                   std::vector<StdSize>& scount,
124                                   const std::vector<StdSize>* start,
125                                   const std::vector<StdSize>* count);
126
127            /// Propriétés privées ///
128            CONetCDF4Path path;
129            int ncidp;
130            bool wmpi;
131            map<int,size_t> timeAxis;
132            StdString timeCounterName;
133      }; // class CONetCDF4
134
135      ///---------------------------------------------------------------
136
137
138
139} // namespace xios
140
141#endif //__XIOS_ONETCDF4__
Note: See TracBrowser for help on using the repository browser.