source: XMLIO_V2/dev/dev_rv/src/xmlio/output/onetcdf4.hpp @ 189

Last change on this file since 189 was 189, checked in by hozdoba, 13 years ago
File size: 5.3 KB
RevLine 
[152]1#ifndef __XMLIO_INETCDF4__
2#define __XMLIO_INETCDF4__
3
4/// xmlioserver headers ///
5#include "xmlioserver_spl.hpp"
6#include "exception.hpp"
7#include "array.hpp"
[157]8#include "data_output.hpp"
9#include "mpi_manager.hpp"
[152]10
11#include <mpi.h>
12#define MPI_INCLUDED
13#include <netcdf.h>
14
15#ifndef UNLIMITED_DIM
16   #define UNLIMITED_DIM (size_t)(-1)
17#endif  //UNLIMITED_DIM
18
19namespace xmlioserver
20{
21   namespace io
22   {
23      /// ////////////////////// Déclarations ////////////////////// ///
24      class CONetCDF4
25         : public virtual CDataOutput
26      {
27         public :
28
29            /// Définition de type ///
30            typedef std::vector<StdString> CONetCDF4Path;
31
32            /// Constructeurs ///
33            CONetCDF4(const StdString & filename, bool exist, const MPI_Comm * comm = NULL);
34            CONetCDF4(const StdString & filename, bool exist, const comm::MPIComm * comm, bool);
35
36            CONetCDF4(const CONetCDF4 & onetcdf4);       // Not implemented.
37            CONetCDF4(const CONetCDF4 * const onetcdf4); // Not implemented.
38
39
40            /// Initialisation ///
41            void initialize(const StdString & filename, bool exist, const MPI_Comm * comm);
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,
[189]51                            const std::vector<StdString> & dim);
52                           
53      //----------------------------------------------------------------
54         public :
55         
[152]56            template <class T>
57               void addAttribute
58                  (const StdString & name, const T & value, const StdString * varname = NULL);
59
60            /// Ecriture des données ///
[189]61            template <class T, StdSize ndim>
62               void writeData(const ARRAY(T, ndim) data, const StdString & name,
[152]63                              bool collective, StdSize record,
64                              const std::vector<StdSize> * start = NULL,
65                              const std::vector<StdSize> * count = NULL);
66
[183]67            void writeData(const ARRAY(int, 2) data, const StdString & name);
[152]68
69            /// Accesseur ///
70            const CONetCDF4Path & getCurrentPath(void) const;
71
72            /// Destructeur ///
73            virtual ~CONetCDF4(void);
[189]74           
75      //----------------------------------------------------------------
76     
[152]77         protected :
78
79            /// Ecriture ///
80            virtual void writeField_ (const boost::shared_ptr<tree::CField>  field)  = 0;
81            virtual void writeDomain_(const boost::shared_ptr<tree::CDomain> domain) = 0;
82            virtual void writeAxis_  (const boost::shared_ptr<tree::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            int getUnlimitedDimension(void);
[189]91           
92      //----------------------------------------------------------------
93     
[152]94         private :
[189]95         
96            template <class T>
97               void writeData_(int grpid, int varid,
98                               const std::vector<StdSize> & sstart,
99                               const std::vector<StdSize> & scount, T * data);
[152]100
101            void getWriteDataInfos(const StdString & name, StdSize record, StdSize & array_size,
102                                   std::vector<StdSize> & sstart,
103                                   std::vector<StdSize> & scount,
104                                   const std::vector<StdSize> * start,
105                                   const std::vector<StdSize> * count);
106
107            /// Vérification des erreurs NetCDF ///
108            void CheckError(int status);
109
110            /// Propriétés privées ///
111            CONetCDF4Path path;
112            int ncidp;
113            bool wmpi;
114
115      }; // class CONetCDF4
116
[189]117      ///---------------------------------------------------------------
118           
119      template <class T, StdSize ndim>
120         void CONetCDF4::writeData(const ARRAY(T, ndim) data, const StdString & name,
121                                   bool collective, StdSize record,
122                                   const std::vector<StdSize> * start,
123                                   const std::vector<StdSize> * count)
124      {
125         int grpid = this->getCurrentGroup();
126         int varid = this->getVariable(name);
127         StdSize array_size = 1;
128         std::vector<StdSize> sstart, scount;
129
130         if (this->wmpi && collective)
131            CheckError(nc_var_par_access(grpid, varid, NC_COLLECTIVE));
132         if (this->wmpi && !collective)
133            CheckError(nc_var_par_access(grpid, varid, NC_INDEPENDENT));
134
135         this->getWriteDataInfos
136         (name, record, array_size,  sstart, scount, start, count);
137         this->writeData_(grpid, varid, sstart, scount, data->data());
138      }
139     
140      ///---------------------------------------------------------------
141
[152]142   } // namespace io
143} // namespace xmlioserver
144
145#endif //__XMLIO_INETCDF4__
Note: See TracBrowser for help on using the repository browser.