1 | #ifndef __XIOS_NC4_DATA_INPUT__ |
---|
2 | #define __XIOS_NC4_DATA_INPUT__ |
---|
3 | |
---|
4 | /// XIOS headers /// |
---|
5 | #include "xios_spl.hpp" |
---|
6 | #include "data_input.hpp" |
---|
7 | #include "inetcdf4.hpp" |
---|
8 | |
---|
9 | namespace xios |
---|
10 | { |
---|
11 | class CDomain; |
---|
12 | class CAxis; |
---|
13 | |
---|
14 | class CNc4DataInput |
---|
15 | : protected CINetCDF4 |
---|
16 | , public virtual CDataInput |
---|
17 | { |
---|
18 | public: |
---|
19 | /// Type definitions /// |
---|
20 | typedef CINetCDF4 SuperClassWriter; |
---|
21 | typedef CDataInput SuperClass; |
---|
22 | |
---|
23 | /// Constructors /// |
---|
24 | CNc4DataInput(const StdString& filename, MPI_Comm comm_file, bool multifile, bool isCollective = true, |
---|
25 | const StdString& timeCounterName = "time_counter"); |
---|
26 | CNc4DataInput(const CNc4DataInput& dataInput); // Not implemented. |
---|
27 | CNc4DataInput(const CNc4DataInput* const dataInput); // Not implemented. |
---|
28 | |
---|
29 | /// Destructor /// |
---|
30 | virtual ~CNc4DataInput(void); |
---|
31 | |
---|
32 | /// Getters /// |
---|
33 | const StdString& getFileName(void) const; |
---|
34 | |
---|
35 | protected: |
---|
36 | // Read methods |
---|
37 | virtual StdSize getFieldNbRecords_(CField* field); |
---|
38 | virtual void readFieldData_(CField* field); |
---|
39 | virtual void readFieldAttributes_(CField* field, bool readAttributeValues); |
---|
40 | virtual void closeFile_(void); |
---|
41 | |
---|
42 | private: |
---|
43 | void readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
44 | int elementPosition, const StdString& fieldId); |
---|
45 | void readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
46 | int elementPosition, const StdString& fieldId); |
---|
47 | |
---|
48 | void readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
49 | int elementPosition, const StdString& fieldId); |
---|
50 | void readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
51 | int elementPosition, const StdString& fieldId); |
---|
52 | |
---|
53 | template <typename T, int Ndim> |
---|
54 | void readFieldVariableValue(CArray<T, Ndim>& var, const StdString& varId, |
---|
55 | const std::vector<StdSize>& nBegin, |
---|
56 | const std::vector<StdSize>& nSize, |
---|
57 | bool forceIndependent = false); |
---|
58 | |
---|
59 | private: |
---|
60 | std::set<StdString> readMetaDataDomains_, readValueDomains_; |
---|
61 | std::set<StdString> readMetaDataAxis_, readValueAxis_; |
---|
62 | |
---|
63 | private: |
---|
64 | /// Private attributes /// |
---|
65 | MPI_Comm comm_file; |
---|
66 | const StdString filename; |
---|
67 | bool isCollective; |
---|
68 | }; // class CNc4DataInput |
---|
69 | |
---|
70 | template <typename T, int Ndim> |
---|
71 | void CNc4DataInput::readFieldVariableValue(CArray<T,Ndim>& var, const StdString& varId, |
---|
72 | const std::vector<StdSize>& nBegin, |
---|
73 | const std::vector<StdSize>& nSize, |
---|
74 | bool forceIndependent) |
---|
75 | { |
---|
76 | if (SuperClass::type==MULTI_FILE || !isCollective) return; |
---|
77 | |
---|
78 | bool openCollective = isCollective; |
---|
79 | if (forceIndependent) openCollective = !isCollective; |
---|
80 | switch (SuperClass::type) |
---|
81 | { |
---|
82 | case MULTI_FILE: |
---|
83 | ERROR("CINetCDF4::readFieldVariableValue(...)", |
---|
84 | << "Only support attributes reading with one_file mode"); |
---|
85 | break; |
---|
86 | case ONE_FILE: |
---|
87 | { |
---|
88 | SuperClassWriter::getData(var, varId, openCollective, 0, &nBegin, &nSize); |
---|
89 | break; |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | } // namespace xios |
---|
94 | |
---|
95 | #endif //__XIOS_NC4_DATA_INPUT__ |
---|