source: XIOS/dev/branch_openmp/src/io/onetcdf4.hpp @ 1460

Last change on this file since 1460 was 1460, checked in by yushan, 6 years ago

branch_openmp merged with XIOS_DEV_CMIP6@1459

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