[219] | 1 | #ifndef __XMLIO_INETCDF4__ |
---|
| 2 | #define __XMLIO_INETCDF4__ |
---|
| 3 | |
---|
[335] | 4 | /// xios headers /// |
---|
[219] | 5 | #include "xmlioserver_spl.hpp" |
---|
| 6 | #include "exception.hpp" |
---|
| 7 | #include "data_output.hpp" |
---|
[369] | 8 | #include "array_new.hpp" |
---|
[219] | 9 | |
---|
| 10 | #include <mpi.h> |
---|
| 11 | #define MPI_INCLUDED |
---|
| 12 | #include <netcdf.h> |
---|
[354] | 13 | #ifdef NETCDF_PAR_HEADER |
---|
[251] | 14 | extern "C" { |
---|
| 15 | #include <netcdf_par.h> |
---|
| 16 | } |
---|
[354] | 17 | #endif |
---|
[219] | 18 | |
---|
[251] | 19 | |
---|
[219] | 20 | #ifndef UNLIMITED_DIM |
---|
| 21 | #define UNLIMITED_DIM (size_t)(-1) |
---|
| 22 | #endif //UNLIMITED_DIM |
---|
| 23 | |
---|
[335] | 24 | namespace xios |
---|
[219] | 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 /// |
---|
[286] | 36 | CONetCDF4(const StdString & filename, bool exist, const MPI_Comm * comm = NULL, bool multifile=true); |
---|
[219] | 37 | |
---|
| 38 | CONetCDF4(const CONetCDF4 & onetcdf4); // Not implemented. |
---|
| 39 | CONetCDF4(const CONetCDF4 * const onetcdf4); // Not implemented. |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | /// Initialisation /// |
---|
[286] | 43 | void initialize(const StdString & filename, bool exist, const MPI_Comm * comm, bool multifile); |
---|
| 44 | void close(void) ; |
---|
| 45 | void sync(void) ; |
---|
[219] | 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 /// |
---|
[369] | 68 | template <class T, int ndim> |
---|
| 69 | void writeData(const CArray<T,ndim>& data, const StdString & name, |
---|
[219] | 70 | bool collective, StdSize record, |
---|
| 71 | const std::vector<StdSize> * start = NULL, |
---|
| 72 | const std::vector<StdSize> * count = NULL); |
---|
| 73 | |
---|
[369] | 74 | void writeData(const CArray<int, 2>& data, const StdString & name); |
---|
[219] | 75 | |
---|
| 76 | /// Accesseur /// |
---|
| 77 | const CONetCDF4Path & getCurrentPath(void) const; |
---|
| 78 | |
---|
| 79 | /// Destructeur /// |
---|
| 80 | virtual ~CONetCDF4(void); |
---|
| 81 | |
---|
| 82 | //---------------------------------------------------------------- |
---|
| 83 | |
---|
| 84 | protected : |
---|
| 85 | |
---|
| 86 | /// Ecriture /// |
---|
[347] | 87 | virtual void writeField_ (CField* field) = 0; |
---|
| 88 | virtual void writeDomain_(CDomain* domain) = 0; |
---|
| 89 | virtual void writeAxis_ (CAxis* axis) = 0; |
---|
[219] | 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); |
---|
[266] | 96 | std::vector<StdSize> getDimensions (const StdString & varname); |
---|
| 97 | std::vector<StdString> getDimensionsIdList (const StdString * varname); |
---|
| 98 | int getUnlimitedDimension(void); |
---|
| 99 | StdString getUnlimitedDimensionName(void); |
---|
[219] | 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 | |
---|
[335] | 132 | } // namespace xios |
---|
[219] | 133 | |
---|
| 134 | #endif //__XMLIO_INETCDF4__ |
---|