source: XIOS/dev/branch_yushan_merged/src/io/onetcdf4.hpp @ 1205

Last change on this file since 1205 was 1205, checked in by yushan, 7 years ago

branch merged with trunk @1200

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