[599] | 1 | #ifndef __XIOS_ONETCDF4__ |
---|
| 2 | #define __XIOS_ONETCDF4__ |
---|
[219] | 3 | |
---|
[591] | 4 | /// XIOS headers /// |
---|
| 5 | #include "xios_spl.hpp" |
---|
[219] | 6 | #include "exception.hpp" |
---|
| 7 | #include "data_output.hpp" |
---|
[369] | 8 | #include "array_new.hpp" |
---|
[382] | 9 | #include "mpi.hpp" |
---|
[379] | 10 | #include "netcdf.hpp" |
---|
[219] | 11 | |
---|
| 12 | #ifndef UNLIMITED_DIM |
---|
| 13 | #define UNLIMITED_DIM (size_t)(-1) |
---|
| 14 | #endif //UNLIMITED_DIM |
---|
| 15 | |
---|
[335] | 16 | namespace xios |
---|
[219] | 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 /// |
---|
[707] | 28 | CONetCDF4(const StdString& filename, bool append, bool useClassicFormat = false, |
---|
| 29 | const MPI_Comm* comm = NULL, bool multifile = true); |
---|
[219] | 30 | |
---|
[707] | 31 | CONetCDF4(const CONetCDF4& onetcdf4); // Not implemented. |
---|
| 32 | CONetCDF4(const CONetCDF4* const onetcdf4); // Not implemented. |
---|
[219] | 33 | |
---|
| 34 | |
---|
| 35 | /// Initialisation /// |
---|
[707] | 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); |
---|
[219] | 40 | void definition_start(void); |
---|
| 41 | void definition_end(void); |
---|
| 42 | |
---|
| 43 | /// Mutateurs /// |
---|
[707] | 44 | void setCurrentPath(const CONetCDF4Path& path); |
---|
[219] | 45 | |
---|
[707] | 46 | int addGroup(const StdString& name); |
---|
[219] | 47 | int addDimension(const StdString& name, const StdSize size = UNLIMITED_DIM); |
---|
[707] | 48 | int addVariable(const StdString& name, nc_type type, |
---|
| 49 | const std::vector<StdString>& dim); |
---|
[606] | 50 | |
---|
[219] | 51 | //---------------------------------------------------------------- |
---|
| 52 | public : |
---|
[606] | 53 | |
---|
[219] | 54 | template <class T> |
---|
[707] | 55 | void setDefaultValue(const StdString& varname, const T* value = NULL); |
---|
[606] | 56 | |
---|
| 57 | void setCompressionLevel(const StdString& varname, int compressionLevel); |
---|
| 58 | |
---|
[707] | 59 | template <class T> void addAttribute (const StdString& name, const T& value, const StdString* varname = NULL); |
---|
[219] | 60 | |
---|
| 61 | /// Ecriture des données /// |
---|
[369] | 62 | template <class T, int ndim> |
---|
[707] | 63 | void writeData(const CArray<T,ndim>& data, const StdString& name, |
---|
[219] | 64 | bool collective, StdSize record, |
---|
[707] | 65 | const std::vector<StdSize>* start = NULL, |
---|
| 66 | const std::vector<StdSize>* count = NULL); |
---|
[219] | 67 | |
---|
[707] | 68 | void writeData(const CArray<int, 2>& data, const StdString& name); |
---|
| 69 | void writeTimeAxisData(const CArray<double,1>& data, const StdString& name, |
---|
| 70 | bool collective, StdSize record, bool Isroot); |
---|
[219] | 71 | /// Accesseur /// |
---|
[707] | 72 | const CONetCDF4Path& getCurrentPath(void) const; |
---|
[219] | 73 | |
---|
| 74 | /// Destructeur /// |
---|
| 75 | virtual ~CONetCDF4(void); |
---|
[606] | 76 | |
---|
[219] | 77 | //---------------------------------------------------------------- |
---|
[606] | 78 | |
---|
[219] | 79 | protected : |
---|
| 80 | |
---|
| 81 | /// Ecriture /// |
---|
[347] | 82 | virtual void writeField_ (CField* field) = 0; |
---|
| 83 | virtual void writeDomain_(CDomain* domain) = 0; |
---|
| 84 | virtual void writeAxis_ (CAxis* axis) = 0; |
---|
[219] | 85 | |
---|
| 86 | /// Accesseurs /// |
---|
| 87 | int getCurrentGroup(void); |
---|
[707] | 88 | int getGroup(const CONetCDF4Path& path); |
---|
| 89 | int getVariable(const StdString& varname); |
---|
| 90 | int getDimension(const StdString& dimname); |
---|
| 91 | std::vector<StdSize> getDimensions (const StdString& varname); |
---|
| 92 | std::vector<StdString> getDimensionsIdList (const StdString* varname); |
---|
[266] | 93 | int getUnlimitedDimension(void); |
---|
| 94 | StdString getUnlimitedDimensionName(void); |
---|
[219] | 95 | |
---|
[707] | 96 | void getTimeAxisBounds(CArray<double,2>& timeAxisBounds, const StdString& name, bool collective); |
---|
[219] | 97 | |
---|
[707] | 98 | bool varExist(const StdString& varname); |
---|
| 99 | |
---|
[517] | 100 | bool useClassicFormat; //!< If true, NetCDF4 will use the classic NetCDF3 format |
---|
| 101 | |
---|
[219] | 102 | //---------------------------------------------------------------- |
---|
[606] | 103 | |
---|
[219] | 104 | private : |
---|
| 105 | template <class T> |
---|
[707] | 106 | void writeData_(int grpid, int varid, |
---|
| 107 | const std::vector<StdSize>& sstart, |
---|
| 108 | const std::vector<StdSize>& scount, T* data); |
---|
[219] | 109 | |
---|
[707] | 110 | void getWriteDataInfos(const StdString& name, StdSize record, StdSize& array_size, |
---|
| 111 | std::vector<StdSize>& sstart, |
---|
| 112 | std::vector<StdSize>& scount, |
---|
| 113 | const std::vector<StdSize>* start, |
---|
| 114 | const std::vector<StdSize>* count); |
---|
[219] | 115 | |
---|
| 116 | /// Propriétés privées /// |
---|
| 117 | CONetCDF4Path path; |
---|
| 118 | int ncidp; |
---|
| 119 | bool wmpi; |
---|
[707] | 120 | map<int,size_t> timeAxis; |
---|
[219] | 121 | }; // class CONetCDF4 |
---|
| 122 | |
---|
| 123 | ///--------------------------------------------------------------- |
---|
| 124 | |
---|
| 125 | |
---|
[606] | 126 | |
---|
[335] | 127 | } // namespace xios |
---|
[219] | 128 | |
---|
[599] | 129 | #endif //__XIOS_ONETCDF4__ |
---|