source: XIOS/trunk/src/output/onetcdf4.hpp @ 528

Last change on this file since 528 was 528, checked in by rlacroix, 10 years ago

Add the ability to append data to existing output file(s).

By default existing file(s) will still be overwritten. Set the new file attribute "append" to true if you wish to append data to existing NetCDF file(s).

Note that the append mode is currently not supported when file splitting is used and that the structure of the output file cannot be changed.

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