source: XIOS/trunk/src/io/inetcdf4.hpp @ 2338

Last change on this file since 2338 was 2280, checked in by ymipsl, 2 years ago

Improve file reading reading

  • add_offset and scaling_factor attributes are set when present in reading file
  • Add new attribute for axis to scale axis_value when read from file : convert_from_factor
  • fix bugs when time dimension in reading file is not unlimited

YM

  • 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.2 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
[382]9#include "mpi.hpp"
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 ///
[1639]24      CINetCDF4(const StdString& filename, const MPI_Comm* comm = NULL, bool multifile = true,
[1485]25                bool readMetaDataPar = false, const StdString& timeCounterName = "time_counter");
26
[599]27      CINetCDF4(const CINetCDF4& inetcdf4);       // Not implemented.
28      CINetCDF4(const CINetCDF4* const inetcdf4); // Not implemented.
[219]29
[599]30      //-------------------------------------------------------------
[219]31
[599]32      /// Destructor ///
33      virtual ~CINetCDF4(void);
[219]34
[599]35      //-------------------------------------------------------------
[219]36
[599]37      void close(void);
[219]38
[599]39      //-------------------------------------------------------------
[219]40
[599]41      /// Getters ///
[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);
113      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL);
[2280]114     
115      template <class T>
116      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL);
[219]117
[599]118      bool hasVariable(const StdString& name, const CVarPath* const path = NULL);
[219]119
[599]120      bool hasCoordinates(const StdString& name, const CVarPath* const path = NULL);
[219]121
[599]122      bool hasTemporalDim(const CVarPath* const path = NULL);
[219]123
[599]124      bool hasBounds(const StdString& name, const CVarPath* const path = NULL);
[219]125
[599]126      //-------------------------------------------------------------
[219]127
[599]128      bool isBound(const StdString& name, const CVarPath* const path = NULL);
129      bool isCoordinate(const StdString& name, const CVarPath* const path = NULL);
130      bool isRectilinear(const StdString& name, const CVarPath* const path = NULL);
131      bool isCurvilinear(const StdString& name, const CVarPath* const path = NULL);
132      bool isUnknown(const StdString& name, const CVarPath* const path = NULL);
133      bool isUnstructured(const StdString& name, const CVarPath* const path = NULL);
[219]134
[599]135      bool isTemporal(const StdString& name, const CVarPath* const path = NULL);
136      bool is3Dim(const StdString& name, const CVarPath* const path = NULL);
137      bool isCellGrid(const StdString& name, const CVarPath* const path = NULL);
[219]138
[1445]139      bool isLonOrLat(const StdString& varname, const CVarPath* const path = NULL);
140
[599]141    protected:
142      /// Getters ///
143      int getGroup   (const CVarPath* const path = NULL);
144      int getVariable(const StdString& varname, const CVarPath* const path = NULL);
145      int getDimension(const StdString& dimname, const CVarPath* const path = NULL);
146      int getUnlimitedDimension(const CVarPath* const path = NULL);
[2280]147      bool hasUnlimitedDimension(const CVarPath* const path = NULL);
148
[599]149      int getAttributeId(const StdString& name,
150                         const StdString* const var = NULL,
151                         const CVarPath* const path = NULL);
[219]152
[599]153      std::pair<nc_type , StdSize> getAttribute(const StdString& attname,
154                                                const StdString* const var  = NULL,
155                                                const CVarPath* const path = NULL);
[219]156
[599]157      //-------------------------------------------------------------
[219]158
[599]159      void getDataInfo(const StdString& var, const CVarPath* const path, StdSize record,
160                       std::vector<StdSize>& sstart, std::vector<StdSize>& scount, StdSize& array_size,
161                       const std::vector<StdSize>* start = NULL, const std::vector<StdSize>* count = NULL);
[219]162
[599]163    private:
[686]164      int ncidp; //< Id of the NetCDF file
165      bool mpi;  //< Whether parallel file access is used
[802]166      StdString timeCounterName;
[599]167  }; // class CINetCDF4
[591]168} // namespace xios
[219]169
[591]170#endif //__XIOS_INETCDF4__
Note: See TracBrowser for help on using the repository browser.