NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NcFileMetaCF.h
Go to the documentation of this file.
1 
15 #ifndef INC_netcdf_NcFileMetaCF_h
16 #define INC_netcdf_NcFileMetaCF_h
17 
18 #include "NcFile.h"
19 #include <memory>
20 #include "stringutil.h"
21 
22 
23 namespace netcdf {
24 
25 
27 {
28  public:
29 
30  #ifndef USE_PARALLEL
31  NcFileMetaCF ( std::string const ncFileName );
32  #endif
33  // if parallel netCDF, must open the file elsewhere.
34  NcFileMetaCF ( netcdf::NcFile & useNcFile );
35 
36  enum MetaItem // items match elements of array attNames
37  {
47  Meta_Unknown // last item always
48  };
49 
50  void Set (
51  MetaItem const which,
52  std::string const & data);
53 
54  void Append (
55  MetaItem const which,
56  std::string const & data);
57 
58  void Get (
59  MetaItem const which,
60  std::string & data) const;
61 
62  void Get (
63  MetaItem const which,
64  TStringArray & data) const;
65 
66  static char const * const GetAttName (MetaItem const which)
67  { return attNames[which]; /* no checks */ }
68 
69  bool Exists (MetaItem const which) const;
70 
71  private:
72 
73  static char const * const attNames[];
74  std::auto_ptr< netcdf::NcFile > pNcFile;
75  netcdf::NcFile & nc;
76 
77  template< class T /* string or TStringArray */ >
78  void Read (
79  MetaItem const which,
80  T & data ) const
81  {
82  if ( which != Meta_Unknown )
83  nc.GetAtt( attNames[which] ).Get( data );
84  }
85 
86  template< class T /* string or TStringArray */ >
87  void Write (
88  MetaItem const which,
89  T const & data )
90  {
91  if ( which != Meta_Unknown )
92  nc.PutAtt( std::string( attNames[which] ), data );
93  }
94 
95  // not used
96  NcFileMetaCF ( NcFileMetaCF const & rhs );
97  NcFileMetaCF & operator= ( NcFileMetaCF const & rhs );
98 
99 };
100 
101 
102 inline bool NcFileMetaCF::Exists (MetaItem const which) const
103 {
104  return nc.HaveAttribute( GetAttName(which) );
105 }
106 
107 
108 
109 
110 } // namespace netcdf
111 
112 #endif // INC_netcdf_NcFileMetaCF_h
misc. comments about this file: string
Definition: NcFileMetaCF.h:45
URL or published information about this data: string.
Definition: NcFileMetaCF.h:43
copyright: string
Definition: NcFileMetaCF.h:41
char const *const ncFileName
Definition: Test_AttVectors.cpp:37
static char const *const GetAttName(MetaItem const which)
Definition: NcFileMetaCF.h:66
NcFileMetaCF(netcdf::NcFile &useNcFile)
Definition: NcFileMetaCF.cpp:46
title of dataset: string
Definition: NcFileMetaCF.h:38
bool Exists(MetaItem const which) const
Definition: NcFileMetaCF.h:102
MetaItem
Definition: NcFileMetaCF.h:36
NcGroupAtt PutAtt(std::string const name, NcType const &type, size_t len, const unsigned char *dataValues) const
Definition: NcGroup.cpp:802
void Get(MetaItem const which, std::string &data) const
Definition: NcFileMetaCF.cpp:102
source of data: string
Definition: NcFileMetaCF.h:44
bool HaveAttribute(std::string const name, NcGroup::Location const location=Current) const
Definition: NcGroup.cpp:670
conventions for netCDF file structure: string
Definition: NcFileMetaCF.h:42
Definition: NcFileMetaCF.h:47
Class for read/write CF-convention netCDF global metadata (aka attributes). A typical set of attribut...
Definition: NcFileMetaCF.h:26
institution name: string
Definition: NcFileMetaCF.h:39
void Get(TVecUbyte &data) const
get NcUbyte vector
Definition: NcAtt.cpp:155
Manages the opening, creating, and closing of netCDF files. Represents the netCDF root group...
Definition: NcFile.h:31
void Set(MetaItem const which, std::string const &data)
Definition: NcFileMetaCF.cpp:51
history of this data and file: string array
Definition: NcFileMetaCF.h:46
void Append(MetaItem const which, std::string const &data)
Definition: NcFileMetaCF.cpp:65
contact info of data maintainer: string
Definition: NcFileMetaCF.h:40
NcGroupAtt GetAtt(std::string const name, NcGroup::Location location=Current) const
Definition: NcGroup.cpp:768