New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
onetcdf4.hpp in branches/2012/dev_r3406_LOCEAN4_XIOS/NEMOGCM/EXTERNAL/XIOS/src/output – NEMO

source: branches/2012/dev_r3406_LOCEAN4_XIOS/NEMOGCM/EXTERNAL/XIOS/src/output/onetcdf4.hpp @ 3474

Last change on this file since 3474 was 3474, checked in by rblod, 12 years ago

Update IOSERVER to revision 357

File size: 4.5 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 "array.hpp"
8#include "data_output.hpp"
9
10#include <mpi.h>
11#define MPI_INCLUDED
12#include <netcdf.h>
13#ifdef NETCDF_PAR_HEADER
14extern "C" {
15#include <netcdf_par.h>
16}
17#endif
18
19
20#ifndef UNLIMITED_DIM
21   #define UNLIMITED_DIM (size_t)(-1)
22#endif  //UNLIMITED_DIM
23
24namespace xios
25{
26      /// ////////////////////// Déclarations ////////////////////// ///
27      class CONetCDF4
28         : public virtual CDataOutput
29      {
30         public :
31
32            /// Définition de type ///
33            typedef std::vector<StdString> CONetCDF4Path;
34
35            /// Constructeurs ///
36            CONetCDF4(const StdString & filename, bool exist, const MPI_Comm * comm = NULL, bool multifile=true);
37
38            CONetCDF4(const CONetCDF4 & onetcdf4);       // Not implemented.
39            CONetCDF4(const CONetCDF4 * const onetcdf4); // Not implemented.
40
41
42            /// Initialisation ///
43            void initialize(const StdString & filename, bool exist, const MPI_Comm * comm, bool multifile);
44            void close(void) ;
45            void sync(void) ;
46            void definition_start(void);
47            void definition_end(void);
48
49            /// Mutateurs ///
50            void setCurrentPath(const CONetCDF4Path & path);
51
52            int addGroup(const StdString & name);
53            int addDimension(const StdString& name, const StdSize size = UNLIMITED_DIM);
54            int addVariable(const StdString & name, nc_type type,
55                            const std::vector<StdString> & dim);
56                           
57      //----------------------------------------------------------------
58         public :
59         
60            template <class T>
61               void setDefaultValue(const StdString & varname, const T * value = NULL);
62         
63            template <class T>
64               void addAttribute
65                  (const StdString & name, const T & value, const StdString * varname = NULL);
66
67            /// Ecriture des données ///
68            template <class T, StdSize ndim>
69               void writeData(const ARRAY(T, ndim) data, const StdString & name,
70                              bool collective, StdSize record,
71                              const std::vector<StdSize> * start = NULL,
72                              const std::vector<StdSize> * count = NULL);
73
74            void writeData(const ARRAY(int, 2) data, const StdString & name);
75
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
101            bool varExist(const StdString & varname);
102
103      //----------------------------------------------------------------
104     
105         private :
106         
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            /// Vérification des erreurs NetCDF ///
119            void CheckError(int status);
120
121            /// Propriétés privées ///
122            CONetCDF4Path path;
123            int ncidp;
124            bool wmpi;
125
126      }; // class CONetCDF4
127
128      ///---------------------------------------------------------------
129           
130
131
132} // namespace xios
133
134#endif //__XMLIO_INETCDF4__
Note: See TracBrowser for help on using the repository browser.