source: XIOS/dev/branch_openmp/src/io/nc4_data_input.hpp @ 1545

Last change on this file since 1545 was 1545, checked in by yushan, 6 years ago

branch_openmp merged with trunk r1544

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 3.9 KB
Line 
1#ifndef __XIOS_NC4_DATA_INPUT__
2#define __XIOS_NC4_DATA_INPUT__
3
4/// XIOS headers ///
5#include "mpi_std.hpp"
6#include "xios_spl.hpp"
7#include "data_input.hpp"
8#include "inetcdf4.hpp"
9
10namespace xios
11{
12  class CDomain;
13  class CAxis;
14  class CScalar;
15
16  class CNc4DataInput
17    : protected CINetCDF4
18    , public virtual CDataInput
19  {
20  public:
21    /// Type definitions ///
22    typedef CINetCDF4  SuperClassWriter;
23    typedef CDataInput SuperClass;
24
25    /// Constructors ///
26    CNc4DataInput(const StdString& filename, ep_lib::MPI_Comm comm_file, bool multifile, bool isCollective = true,
27                  bool readMetaDataPar = false, bool ugridConvention = false, const StdString& timeCounterName = "time_counter");
28    CNc4DataInput(const CNc4DataInput& dataInput);       // Not implemented.
29    CNc4DataInput(const CNc4DataInput* const dataInput); // Not implemented.
30
31    /// Destructor ///
32    virtual ~CNc4DataInput(void);
33
34    /// Getters ///
35    const StdString& getFileName(void) const;
36
37  protected:
38    // Read methods
39    virtual StdSize getFieldNbRecords_(CField* field);
40    virtual void readFieldData_(CField* field);
41    virtual void readFieldAttributes_(CField* field, bool readAttributeValues);
42    virtual void closeFile_(void);
43
44  private:
45    void readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
46                                      int elementPosition, const StdString& fieldId);
47    void readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
48                                          int elementPosition, const StdString& fieldId);
49
50    void readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
51                                    int elementPosition, const StdString& fieldId);
52    void readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
53                                        int elementPosition, const StdString& fieldId);
54
55    void readScalarAttributesFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
56                                      int elementPosition, const StdString& fieldId);
57    void readScalarAttributeValueFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap,
58                                          int elementPosition, const StdString& fieldId);
59
60    template <typename T, int Ndim>
61    void readFieldVariableValue(CArray<T, Ndim>& var, const StdString& varId,
62                                const std::vector<StdSize>& nBegin,
63                                const std::vector<StdSize>& nSize,
64                                bool forceIndependent = false);
65
66  private:
67    std::set<StdString> readMetaDataDomains_, readValueDomains_;
68    std::set<StdString> readMetaDataAxis_, readValueAxis_;
69    std::set<StdString> readMetaDataScalar_, readValueScalar_;
70
71  private:
72    /// Private attributes ///
73    ep_lib::MPI_Comm comm_file;
74    const StdString filename;
75    bool isCollective;
76    bool ugridConvention;
77  }; // class CNc4DataInput
78
79template <typename T, int Ndim>
80void CNc4DataInput::readFieldVariableValue(CArray<T,Ndim>& var, const StdString& varId,
81                                           const std::vector<StdSize>& nBegin,
82                                           const std::vector<StdSize>& nSize,
83                                           bool forceIndependent)
84{
85  if (SuperClass::type==MULTI_FILE || !isCollective) return;
86
87  bool openCollective = isCollective;
88  if (forceIndependent) openCollective = !isCollective;
89  switch (SuperClass::type)
90  {
91    case MULTI_FILE:
92      ERROR("CINetCDF4::readFieldVariableValue(...)",
93            << "Only support attributes reading with one_file mode");
94      break;
95    case ONE_FILE:
96    {
97      SuperClassWriter::getData(var, varId, openCollective, 0, &nBegin, &nSize);
98      break;
99    }
100  }
101}
102} // namespace xios
103
104#endif //__XIOS_NC4_DATA_INPUT__
Note: See TracBrowser for help on using the repository browser.