source: XIOS/trunk/src/io/onetcdf4.hpp @ 802

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

Add a new file attribute time_counter_name.

Users can now modify the name of the time counter dimension and axis name.

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