source: XIOS/dev/branch_openmp/src/io/inetcdf4.hpp @ 1460

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

branch_openmp merged with XIOS_DEV_CMIP6@1459

  • 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: 7.0 KB
RevLine 
[591]1#ifndef __XIOS_INETCDF4__
2#define __XIOS_INETCDF4__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[219]6#include "exception.hpp"
[369]7#include "array_new.hpp"
[219]8
[1134]9#include "mpi_std.hpp"
[382]10#include "netcdf.hpp"
[219]11
12#ifndef UNLIMITED_DIM
[599]13#define UNLIMITED_DIM (size_t)(-1)
14#endif  // UNLIMITED_DIM
[219]15
[335]16namespace xios
[219]17{
[599]18  typedef std::vector<StdString> CVarPath;
[219]19
[599]20  class CINetCDF4
21  {
22    public:
23      /// Constructors ///
[1328]24      CINetCDF4(const StdString& filename, const ep_lib::MPI_Comm* comm = NULL, bool multifile = true,
[802]25                const StdString& timeCounterName = "time_counter");
[599]26      CINetCDF4(const CINetCDF4& inetcdf4);       // Not implemented.
27      CINetCDF4(const CINetCDF4* const inetcdf4); // Not implemented.
[219]28
[599]29      //-------------------------------------------------------------
[219]30
[599]31      /// Destructor ///
32      virtual ~CINetCDF4(void);
[219]33
[599]34      //-------------------------------------------------------------
[219]35
[599]36      void close(void);
[219]37
[599]38      //-------------------------------------------------------------
[219]39
[599]40      /// Getters ///
41      StdSize getNbOfTimestep(const CVarPath* const path = NULL);
[219]42
[599]43      StdString getUnlimitedDimensionName(const CVarPath* const path = NULL);
[219]44
[802]45      const StdString& getTimeCounterName(void) const { return timeCounterName; };
46
[599]47      StdString getCoordinatesId(const StdString& name, const CVarPath* const path = NULL);
[219]48
[599]49      StdString getBoundsId(const StdString& name, const CVarPath* const path = NULL);
[219]50
[599]51      StdString getLonCoordName(const StdString& varname, const CVarPath* const path = NULL);
52      StdString getLatCoordName(const StdString& varname, const CVarPath* const path = NULL);
53      StdString getVertCoordName(const StdString& varname, const CVarPath* const path = NULL);
[219]54
[599]55      std::set<StdString> getCoordVariables(const CVarPath* const path = NULL);
56      std::set<StdString> getBoundVariables(const CVarPath* const path = NULL);
[219]57
[599]58      std::list<StdString> getGroups   (const CVarPath* const path = NULL);
59      std::list<StdString> getVariables(const CVarPath* const path = NULL);
[219]60
[599]61      std::list<StdString> getDataVariables(bool _is3D       = true,
62                                            bool _isRecti    = true,
63                                            bool _isCurvi    = true,
64                                            bool _isUnstr    = true,
65                                            bool _isCellData = true,
66                                            bool _isTemporal = true,
67                                            const CVarPath* const path = NULL);
[219]68
[599]69      std::list<StdString> getAttributes(const StdString* const var  = NULL,
70                                         const CVarPath* const path = NULL);
[219]71
[599]72      std::list<StdString> getDimensionsList(const StdString* const var  = NULL,
73                                             const CVarPath* const path = NULL);
[219]74
[599]75      std::list<StdString> getCoordinatesIdList(const StdString& name,
76                                                const CVarPath* const path = NULL);
[219]77
[599]78      std::map<StdString, StdSize> getDimensions(const StdString* const var  = NULL,
79                                                 const CVarPath* const path = NULL);
[219]80
[599]81      StdSize getNbVertex(const StdString& name, const CVarPath* const path = NULL);
[219]82
[599]83      //-------------------------------------------------------------
[219]84
[599]85      template <class T>
86      T getMissingValue(const StdString& name, const CVarPath* const path = NULL);
[219]87
[599]88      template <class T>
[686]89      std::vector<T> getAttributeValue(const StdString& name,
90                                       const StdString* const var  = NULL,
91                                       const CVarPath* const path = NULL);
[219]92
[686]93      StdString getAttributeValue(const StdString& name,
94                                  const StdString* const var,
95                                  const CVarPath* const path);
96
[599]97      template <class T>
98      void getData(CArray<T, 1>& data,
99                   const StdString& var,
100                   const CVarPath* const path = NULL,
101                   StdSize record = UNLIMITED_DIM);
[219]102
[782]103      template <class T, int Ndim>
104      void getData(CArray<T, Ndim>& data, const StdString& var,
[599]105                   bool collective, StdSize record,
106                   const std::vector<StdSize>* start = NULL,
107                   const std::vector<StdSize>* count = NULL);
[219]108
[599]109      //-------------------------------------------------------------
[219]110
[599]111      /// Tests ///
112      bool hasMissingValue(const StdString& name, const CVarPath* const path = NULL);
[219]113
[599]114      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL);
[219]115
[599]116      bool hasVariable(const StdString& name, const CVarPath* const path = NULL);
[219]117
[599]118      bool hasCoordinates(const StdString& name, const CVarPath* const path = NULL);
[219]119
[599]120      bool hasTemporalDim(const CVarPath* const path = NULL);
[219]121
[599]122      bool hasBounds(const StdString& name, const CVarPath* const path = NULL);
[219]123
[599]124      //-------------------------------------------------------------
[219]125
[599]126      bool isBound(const StdString& name, const CVarPath* const path = NULL);
127      bool isCoordinate(const StdString& name, const CVarPath* const path = NULL);
128      bool isRectilinear(const StdString& name, const CVarPath* const path = NULL);
129      bool isCurvilinear(const StdString& name, const CVarPath* const path = NULL);
130      bool isUnknown(const StdString& name, const CVarPath* const path = NULL);
131      bool isUnstructured(const StdString& name, const CVarPath* const path = NULL);
[219]132
[599]133      bool isTemporal(const StdString& name, const CVarPath* const path = NULL);
134      bool is3Dim(const StdString& name, const CVarPath* const path = NULL);
135      bool isCellGrid(const StdString& name, const CVarPath* const path = NULL);
[219]136
[1460]137      bool isLonOrLat(const StdString& varname, const CVarPath* const path = NULL);
138
[599]139    protected:
140      /// Getters ///
141      int getGroup   (const CVarPath* const path = NULL);
142      int getVariable(const StdString& varname, const CVarPath* const path = NULL);
143      int getDimension(const StdString& dimname, const CVarPath* const path = NULL);
144      int getUnlimitedDimension(const CVarPath* const path = NULL);
145      int getAttributeId(const StdString& name,
146                         const StdString* const var = NULL,
147                         const CVarPath* const path = NULL);
[219]148
[599]149      std::pair<nc_type , StdSize> getAttribute(const StdString& attname,
150                                                const StdString* const var  = NULL,
151                                                const CVarPath* const path = NULL);
[219]152
[599]153      //-------------------------------------------------------------
[219]154
[599]155      void getDataInfo(const StdString& var, const CVarPath* const path, StdSize record,
156                       std::vector<StdSize>& sstart, std::vector<StdSize>& scount, StdSize& array_size,
157                       const std::vector<StdSize>* start = NULL, const std::vector<StdSize>* count = NULL);
[219]158
[599]159    private:
[686]160      int ncidp; //< Id of the NetCDF file
161      bool mpi;  //< Whether parallel file access is used
[802]162      StdString timeCounterName;
[599]163  }; // class CINetCDF4
[591]164} // namespace xios
[219]165
[591]166#endif //__XIOS_INETCDF4__
Note: See TracBrowser for help on using the repository browser.