NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NcVar.h
Go to the documentation of this file.
1 
16 #ifndef INC_netcdf_NcVar_h
17 #define INC_netcdf_NcVar_h
18 
19 #include <typeinfo>
20 #include "NcConfig.h"
21 #include "NcVarAtt.h"
22 #include "NcGroup.h"
23 #include "NcByte.h"
24 #include "NcUbyte.h"
25 #include "NcChar.h"
26 #include "NcShort.h"
27 #include "NcUshort.h"
28 #include "NcInt.h"
29 #include "NcUint.h"
30 #include "NcInt64.h"
31 #include "NcUint64.h"
32 #include "NcFloat.h"
33 #include "NcDouble.h"
34 #include "NcString.h"
35 
36 namespace netcdf {
37 
38 
39  class NcDim;
40  class NcType;
41 
42 
43  class NcVar : public NcItem
44  {
45  public:
46 
47  typedef std::multimap<std::string, NcType> NcTypeMap;
48  typedef std::map<std::string, NcVarAtt> NcVarAttMap;
49  typedef std::pair<std::string, NcVarAtt> NcVarAttPair;
50 
52  enum ChunkMode
53  {
55  nc_CHUNKED = NC_CHUNKED,
56 
62  nc_CONTIGUOUS = NC_CONTIGUOUS
63  };
64 
68  {
69  ENDIAN_NATIVE = NC_ENDIAN_NATIVE,
70  ENDIAN_LITTLE = NC_ENDIAN_LITTLE,
71  ENDIAN_BIG = NC_ENDIAN_BIG
72  };
73 
76  {
77  nc_NOCHECKSUM = NC_NOCHECKSUM,
78  nc_FLETCHER32 = NC_FLETCHER32
79  };
80 
81 
82  NcVar ();
83 
86  NcVar (
87  int const useFileID,
88  NcGroup const & grp,
89  const int& varID,
90  #ifdef USE_PARALLEL
91  NcType::ncType const varType,
92  bool const ioIsCollective = false);
93  #else
94  NcType::ncType const varType);
95  #endif // USE_PARALLEL
96 
97  NcVar (NcVar const & ncVar);
98 
99  NcGroup GetParentGroup() const;
100  NcType GetType() const;
101  NcType::ncType getClassType () const { return myType; }
102 
103  void Rename( std::string const & newname );
104 
105  NcVar & operator= (NcVar const & rhs)
106  {
107  NcItem::operator= (rhs);
108  myType = rhs.myType;
109  return *this;
110  }
111  bool operator== ( NcVar const & rhs ) const
112  {
113  return NcItem::operator==(rhs) &&
114  myType == rhs.myType;
115  }
116  bool operator!=(NcVar const & rhs) const
117  { return !operator==(rhs); }
118 
119  //-----------------------------------------------------------------------
120  // parallel I/O
121  //-----------------------------------------------------------------------
122 
123 #ifdef USE_PARALLEL
124 
128  void DoCollectiveIO ( bool const ioIsCollective );
129  bool DoCollectiveIO () const { return doCollectiveIO; }
130 
131 #endif // USE_PARALLEL
132 
133  //-----------------------------------------------------------------------
134  // dimensions
135  //-----------------------------------------------------------------------
136 
137  int GetDimCount () const;
138  bool IsScalar () const { return GetDimCount() == 0; }
139  NcDim GetDim ( int const index ) const;
140  NcDim GetDim ( std::string const name ) const;
141  std::vector<NcDim> GetDims () const;
142 
143  //-----------------------------------------------------------------------
144  // performance: chunking
145  //-----------------------------------------------------------------------
146 
148  void SetChunking (
149  ChunkMode const chunkMode,
150  std::vector<size_t> const & chunksizes) const;
151 
153  void GetChunking (
154  ChunkMode & chunkMode,
155  std::vector<size_t> & chunkSizes) const;
156 
157  //-----------------------------------------------------------------------
158  // compression
159  //-----------------------------------------------------------------------
160 
168  void SetCompression (
169  bool const enableShuffleFilter,
170  bool const enableDeflateFilter,
171  int const deflateLevel) const;
172 
174  void GetCompression (
175  bool & shuffleFilterEnabled,
176  bool & deflateFilterEnabled,
177  int & deflateLevel) const;
178 
179  bool IsCompressionEnabled () const;
180 
181  //-----------------------------------------------------------------------
182  // initialization
183  //-----------------------------------------------------------------------
184 
186  template<class T> void SetFillMode (
187  bool const fillMode,
188  T const fillValue
189  ) const
190  {
191  NcCHECK( nc_def_var_fill( GetGroupID(), GetID(),
192  static_cast<int> (!fillMode),
193  (void const *) &fillValue) );
194  }
195 
200  void SetFillMode (
201  bool const fillMode,
202  void const * fillValue
203  ) const;
204 
206  template <class T> void GetFillMode (
207  bool & fillMode,
208  T & fillValue
209  ) const
210  {
211  int noFillMode = 0;
212  NcCHECK( nc_inq_var_fill( GetGroupID(), GetID(), &noFillMode, &fillValue) );
213  fillMode = (noFillMode == 0);
214  }
215 
223  void GetFillMode (bool& fillMode, void* fillValue=0) const;
224 
228  void SetEndianness(EndianMode endianMode) const;
229 
233  EndianMode GetEndianness() const;
234 
238  void SetChecksum(ChecksumMode checksumMode) const;
239 
243  ChecksumMode GetChecksum() const;
244 
245  //-----------------------------------------------------------------------
246  // attributes
247  //-----------------------------------------------------------------------
248 
253  int GetAttCount () const;
254 
260  bool HaveAttribute (std::string const name) const;
261 
267  NcVarAtt GetAtt (std::string const name) const;
268 
273  NcVarAttMap GetAttributes () const;
274 
275  // NcUbyte
276  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const unsigned char* dataValues) const;
277 
278  // NcByte
279  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const signed char* dataValues) const;
280 
281  // NcChar
282  NcVarAtt PutAtt ( std::string const name, char const aChar ) const;
283 
284  // NcShort
285  NcVarAtt PutAtt (std::string const name, NcType const & type, short datumValue) const;
286  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const short* dataValues) const;
287 
288  // NcUshort
289  NcVarAtt PutAtt (std::string const name, NcType const & type, unsigned short datumValue) const;
290  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const unsigned short* dataValues) const;
291 
292  // NcInt as int
293  NcVarAtt PutAtt (std::string const name, NcType const & type, int datumValue) const;
294  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const int* dataValues) const;
295 
296  // NcInt as long
297  NcVarAtt PutAtt (std::string const name, NcType const & type, long datumValue) const;
298  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const long* dataValues) const;
299 
300  // NcUint as int
301  NcVarAtt PutAtt (std::string const name, NcType const & type, unsigned int datumValue) const;
302  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const unsigned int* dataValues) const;
303 
304  // NcUint as long
305 
306  // NcFloat
307  NcVarAtt PutAtt (std::string const name, NcType const & type, float datumValue) const;
308  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const float* dataValues) const;
309 
310  // NcDouble
311  NcVarAtt PutAtt (std::string const name, NcType const & type, double datumValue) const;
312  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const double* dataValues) const;
313 
314  // NcInt64
315  NcVarAtt PutAtt (std::string const name, NcType const & type, long long datumValue) const;
316  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const long long* dataValues) const;
317 
318  // NcUint64
319  NcVarAtt PutAtt (std::string const name, NcType const & type, unsigned long long datumValue) const;
320  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const unsigned long long* dataValues) const;
321 
322  // NcString
323  NcVarAtt PutAtt (std::string const name, size_t len, const char** dataValues) const;
324  NcVarAtt PutAtt (std::string const name, std::string const textData) const;
325 
326  // vectors
327  NcVarAtt PutAtt (std::string const name, TVecUbyte const & data);
328  NcVarAtt PutAtt (std::string const name, TVecByte const & data);
329  NcVarAtt PutAtt (std::string const name, TVecChar const & data);
330  NcVarAtt PutAtt (std::string const name, TVecShort const & data);
331  NcVarAtt PutAtt (std::string const name, TVecUshort const & data);
332  NcVarAtt PutAtt (std::string const name, TVecInt const & data);
333  NcVarAtt PutAtt (std::string const name, TVecUint const & data);
334  NcVarAtt PutAtt (std::string const name, TVecFloat const & data);
335  NcVarAtt PutAtt (std::string const name, TVecDouble const & data);
336  NcVarAtt PutAtt (std::string const name, TVecInt64 const & data);
337  NcVarAtt PutAtt (std::string const name, TVecUint64 const & data);
338  NcVarAtt PutAtt (std::string const name, TVecString const & data);
339 
355  NcVarAtt PutAtt (std::string const name, NcType const & type, size_t len, const void* dataValues) const;
356 
362  NcVarAtt PutAtt ( NcVarAtt const & att );
363 
364  //-----------------------------------------------------------------------
365  // read data
366  //-----------------------------------------------------------------------
367 
369  template
370  <
371  class TC // container value_type (e.g., T in std::vector<T>)
372  >
373  void Get ( std::vector<TC> & data );
374 
375  // specializations
376  // template<> void Get<std::string> ( std::vector<std::string> & data );
377 
394  void Get (signed char* data);
395  void Get (unsigned char* data);
396  void Get (char* data);
397  void Get (char** &data, int const numRecords);
398  void Get (short* data);
399  void Get (unsigned short* data);
400  void Get (int* data);
401  void Get (long* data);
402  void Get (unsigned int* data);
403  void Get (long long* data);
404  void Get (unsigned long long* data);
405  void Get (float* data);
406  void Get (double* data);
407  void Get (void* data);
408 
410  void Get (signed char & data) { Get( &data ); }
411  void Get (unsigned char & data) { Get( &data ); }
412  void Get (char & data) { Get( &data ); }
413  void Get (short & data) { Get( &data ); }
414  void Get (unsigned short & data) { Get( &data ); }
415  void Get (int & data) { Get( &data ); }
416  void Get (long & data) { Get( &data ); }
417  void Get (unsigned int & data) { Get( &data ); }
418  void Get (long long & data) { Get( &data ); }
419  void Get (unsigned long long & data) { Get( &data ); }
420  void Get (float & data) { Get( &data ); }
421  void Get (double & data) { Get( &data ); }
422  void Get (std::string & str);
423 
437  void Get (const std::vector<size_t>& index, void* data);
438  void Get (const std::vector<size_t>& index, char** data);
439  void Get (const std::vector<size_t>& index, char* data);
440  void Get (const std::vector<size_t>& index, unsigned char* data);
441  void Get (const std::vector<size_t>& index, signed char* data);
442  void Get (const std::vector<size_t>& index, short* data);
443  void Get (const std::vector<size_t>& index, int* data);
444  void Get (const std::vector<size_t>& index, long* data);
445  void Get (const std::vector<size_t>& index, float* data);
446  void Get (const std::vector<size_t>& index, double* data);
447  void Get (const std::vector<size_t>& index, unsigned short* data);
448  void Get (const std::vector<size_t>& index, unsigned int* data);
449  void Get (const std::vector<size_t>& index, unsigned long long* data);
450  void Get (const std::vector<size_t>& index, long long* data);
452  void Get (const std::vector<size_t>& index, std::string & str);
453 
455  template
456  <
457  class TC // container type (e.g., T in std::vector<T>)
458  >
459  void Get (
460  TVecIndex const & start,
461  TVecIndex const & count,
462  std::vector<TC> & data );
463 
488  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, void* data);
489  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, char** data);
490  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, char* data);
491  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, unsigned char* data);
492  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, signed char* data);
493  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, short* data);
494  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, int* data);
495  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, long* data);
496  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, float* data);
497  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, double* data);
498  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, unsigned short* data);
499  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, unsigned int* data);
500  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, unsigned long long* data);
501  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, long long* data);
502  void Get (
503  std::size_t const start,
504  std::string & data);
505  void Get (
506  std::size_t const start,
507  std::size_t const count,
508  std::vector<std::string> & data);
509 
510  // Reads a subsampled (strided) array section of values from a netCDF variable.
541  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, void* dataValues);
542  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, char** dataValues);
543  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, char* dataValues);
544  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, unsigned char* dataValues);
545  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, signed char* dataValues);
546  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, short* dataValues);
547  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, int* dataValues);
548  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, long* dataValues);
549  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, float* dataValues);
550  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, double* dataValues);
551  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, unsigned short* dataValues);
552  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, unsigned int* dataValues);
553  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, unsigned long long* dataValues);
554  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, long long* dataValues);
555 
556  // Reads a mapped array section of values from a netCDF variable.
598  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, void* dataValues);
599  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, char** dataValues);
600  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, char* dataValues);
601  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, unsigned char* dataValues);
602  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, signed char* dataValues);
603  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, short* dataValues);
604  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, int* dataValues);
605  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, long* dataValues);
606  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, float* dataValues);
607  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, double* dataValues);
608  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, unsigned short* dataValues);
609  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, unsigned int* dataValues);
610  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, unsigned long long* dataValues);
611  void Get (const std::vector<size_t>& start, const std::vector<size_t>& count, const std::vector<ptrdiff_t>& stride, const std::vector<ptrdiff_t>& imap, long long* dataValues);
612 
613  //-----------------------------------------------------------------------
614  // write data
615  //-----------------------------------------------------------------------
616 
618  template
619  <
620  class TC // container type (e.g., T in std::vector<T>)
621  >
622  void Put ( std::vector<TC> const & data );
623 
648  void Put (const void* data);
649  void Put (const char* data);
650  void Put (const unsigned char* data);
651  void Put (const signed char* data);
652  void Put (const short* data);
653  void Put (const int* data);
654  void Put (const long* data);
655  void Put (const float* data);
656  void Put (const double* data);
657  void Put (const unsigned short* data);
658  void Put (const unsigned int* data);
659  void Put (const unsigned long long* data);
660  void Put (const long long* data);
661  void Put (char const * const * data, int const numRecords);
662  void Put (std::string const & str);
663 
665  void Put (signed char const & data) { Put( &data ); }
666  void Put (unsigned char const & data) { Put( &data ); }
667  void Put (char const & data) { Put( &data ); }
668  void Put (short const & data) { Put( &data ); }
669  void Put (unsigned short const & data) { Put( &data ); }
670  void Put (int const & data) { Put( &data ); }
671  void Put (long const & data) { Put( &data ); }
672  void Put (unsigned int const & data) { Put( &data ); }
673  void Put (long long const & data) { Put( &data ); }
674  void Put (unsigned long long const & data) { Put( &data ); }
675  void Put (float const & data) { Put( &data ); }
676  void Put (double const & data) { Put( &data ); }
677 
678  // Writes a single datum into the netCDF variable.
696  void Put (const std::vector<size_t>& index, const void* data);
697  void Put (const std::vector<size_t>& index, const char** data);
698  void Put (const std::vector<size_t>& index, const char* data);
699  void Put (const std::vector<size_t>& index, const unsigned char* data);
700  void Put (const std::vector<size_t>& index, const signed char* data);
701  void Put (const std::vector<size_t>& index, const short data);
702  void Put (const std::vector<size_t>& index, const int data);
703  void Put (const std::vector<size_t>& index, const long data);
704  void Put (const std::vector<size_t>& index, const float data);
705  void Put (const std::vector<size_t>& index, const double data);
706  void Put (const std::vector<size_t>& index, const unsigned short data);
707  void Put (const std::vector<size_t>& index, const unsigned int data);
708  void Put (const std::vector<size_t>& index, const unsigned long long data);
709  void Put (const std::vector<size_t>& index, const long long data);
711  void Put (const std::vector<size_t>& index, std::string const & str);
712 
714  template
715  <
716  class TC // container type (e.g., T in std::vector<T>)
717  >
718  void Put (
719  TVecIndex const & start,
720  TVecIndex const & count,
721  std::vector<TC> const & data );
722 
751  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const void* data);
752  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const char** data);
753  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const char* data);
754  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const unsigned char* data);
755  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const signed char* data);
756  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const short* data);
757  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const int* data);
758  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const long* data);
759  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const float* data);
760  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const double* data);
761  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const unsigned short* data);
762  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const unsigned int* data);
763  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const unsigned long long* data);
764  void Put(const std::vector<size_t>& startp, const std::vector<size_t>& countp, const long long* data);
766  void Put (const std::vector<size_t>& start, const std::vector<size_t>& count, std::string const & str);
767 
768  // Writes a set of subsampled array values into the netCDF variable.
799  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const void* dataValues);
800  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const char** dataValues);
801  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const char* dataValues);
802  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const unsigned char* dataValues);
803  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const signed char* dataValues);
804  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const short* dataValues);
805  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const int* dataValues);
806  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const long* dataValues);
807  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const float* dataValues);
808  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const double* dataValues);
809  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const unsigned short* dataValues);
810  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const unsigned int* dataValues);
811  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const unsigned long long* dataValues);
812  void Put(const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const long long* dataValues);
813 
814  // Writes a mapped array section of values into the netCDF variable.
821  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const void* dataValues);
822  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const char** dataValues);
823  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const char* dataValues);
824  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const unsigned char* dataValues);
825  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const signed char* dataValues);
826  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const short* dataValues);
827  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const int* dataValues);
828  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const long* dataValues);
829  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const float* dataValues);
830  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const double* dataValues);
831  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const unsigned short* dataValues);
832  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const unsigned int* dataValues);
833  void Put (const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const unsigned long long* dataValues);
863  void Put(const std::vector<size_t>& startp, const std::vector<size_t>& countp, const std::vector<ptrdiff_t>& stridep, const std::vector<ptrdiff_t>& imapp, const long long* dataValues);
864 
865  private:
866 
867  NcType::ncType myType;
868 #ifdef USE_PARALLEL
869  // netcdf does provide an inquire function for setting of collective access
870  // so track it here
871  bool doCollectiveIO;
872 #endif // USE_PARALLEL
873 
874  std::string retrieveMyName() const;
875 
876  };
877 
878 
879 
881 template
882 <
883  class TC // container value_type (e.g., T in std::vector<T>)
884 >
885 inline void NcVar::Get ( std::vector<TC> & data )
886 {
887  switch( getClassType() )
888  {
889  case NcType::nc_BYTE : ncByte.Get ( GetGroupID(), GetID(), (TVecByte &) data ); break;
890  case NcType::nc_SHORT : ncShort.Get ( GetGroupID(), GetID(), (TVecShort &) data ); break;
891  case NcType::nc_INT : ncInt.Get ( GetGroupID(), GetID(), (TVecInt &) data ); break;
892  case NcType::nc_FLOAT : ncFloat.Get ( GetGroupID(), GetID(), (TVecFloat &) data ); break;
893  case NcType::nc_DOUBLE: ncDouble.Get ( GetGroupID(), GetID(), (TVecDouble &) data ); break;
894  case NcType::nc_UBYTE : ncUbyte.Get ( GetGroupID(), GetID(), (TVecUbyte &) data ); break;
895  case NcType::nc_USHORT: ncUshort.Get ( GetGroupID(), GetID(), (TVecUshort &) data ); break;
896  case NcType::nc_UINT : ncUint.Get ( GetGroupID(), GetID(), (TVecUint &) data ); break;
897  case NcType::nc_INT64 : ncInt64.Get ( GetGroupID(), GetID(), (TVecInt64 &) data ); break;
898  case NcType::nc_UINT64: ncUint64.Get ( GetGroupID(), GetID(), (TVecUint64 &) data ); break;
899  // specializations follow
900  //case NcType::nc_STRING: ncString.Get ( GetGroupID(), GetID(), (TVecString &) data ); break;
901  //case NcType::nc_CHAR : ncChar.Get ( GetGroupID(), GetID(), data ); break;
902  default: break;
903  }
904 }
905 
906 // specializations
907 template<> inline void NcVar::Get ( std::vector<std::string> & data )
908 {
909  if ( getClassType() == NcType::nc_STRING )
910  ncString.Get ( GetGroupID(), GetID(), (TVecString &) data );
911  else if ( getClassType() == NcType::nc_CHAR )
912  ncChar.Get ( GetGroupID(), GetID(), data );
913  // else error
914 }
915 
917 template
918 <
919  class TC // container value_type (e.g., T in std::vector<T>)
920 >
921 inline void NcVar::Get (
922  TVecIndex const & start, // zero-based indices to start write
923  TVecIndex const & count, // count along each edge (>= 1)
924  std::vector<TC> & data )
925 {
926  switch( getClassType() )
927  {
928  case NcType::nc_BYTE : ncByte.Get ( GetGroupID(), GetID(), start, count, (TVecByte &) data ); break;
929  case NcType::nc_SHORT : ncShort.Get ( GetGroupID(), GetID(), start, count, (TVecShort &) data ); break;
930  case NcType::nc_INT : ncInt.Get ( GetGroupID(), GetID(), start, count, (TVecInt &) data ); break;
931  case NcType::nc_FLOAT : ncFloat.Get ( GetGroupID(), GetID(), start, count, (TVecFloat &) data ); break;
932  case NcType::nc_DOUBLE: ncDouble.Get ( GetGroupID(), GetID(), start, count, (TVecDouble &) data ); break;
933  case NcType::nc_UBYTE : ncUbyte.Get ( GetGroupID(), GetID(), start, count, (TVecUbyte &) data ); break;
934  case NcType::nc_USHORT: ncUshort.Get ( GetGroupID(), GetID(), start, count, (TVecUshort &) data ); break;
935  case NcType::nc_UINT : ncUint.Get ( GetGroupID(), GetID(), start, count, (TVecUint &) data ); break;
936  case NcType::nc_INT64 : ncInt64.Get ( GetGroupID(), GetID(), start, count, (TVecInt64 &) data ); break;
937  case NcType::nc_UINT64: ncUint64.Get ( GetGroupID(), GetID(), start, count, (TVecUint64 &) data ); break;
938  case NcType::nc_STRING: ncString.Get ( GetGroupID(), GetID(), start, count, (TVecString &) data ); break;
939  // specializations follow
940  //case NcType::nc_CHAR : ncChar.Get ( GetGroupID(), GetID(), start, count, (TVecChar &) data ); break;
941  default: break;
942  }
943 }
944 
945 // specializations
946 
947 inline void NcVar::Get (
948  std::size_t const start,
949  std::string & data)
950 {
951  TVecIndex index;
952  index.push_back( start );
953  if ( getClassType() == NcType::nc_STRING )
954  ncString.Get ( GetGroupID(), GetID(), index, data );
955  else if ( getClassType() == NcType::nc_CHAR )
956  ncChar.Get ( GetGroupID(), GetID(), index, data );
957  // else error
958 }
959 
960 inline void NcVar::Get (
961  std::size_t const start, // zero-based index to start reading
962  std::size_t const count, // number of strings to read
963  std::vector<std::string> & data )
964 {
965  if ( getClassType() == NcType::nc_STRING )
966  ncString.Get ( GetGroupID(), GetID(), (TVecString &) data );
967  else if ( getClassType() == NcType::nc_CHAR )
968  ncChar.Get ( GetGroupID(), GetID(), data );
969  // else error
970 }
971 
973 template
974 <
975  class TC // container value_type (e.g., T in std::vector<T>)
976 >
977 inline void NcVar::Put ( std::vector<TC> const & data )
978 {
979  switch( getClassType() )
980  {
981  case NcType::nc_BYTE : ncByte.Put ( GetGroupID(), GetID(), (TVecByte const &) data ); break;
982  case NcType::nc_SHORT : ncShort.Put ( GetGroupID(), GetID(), (TVecShort const &) data ); break;
983  case NcType::nc_INT : ncInt.Put ( GetGroupID(), GetID(), (TVecInt const &) data ); break;
984  case NcType::nc_FLOAT : ncFloat.Put ( GetGroupID(), GetID(), (TVecFloat const &) data ); break;
985  case NcType::nc_DOUBLE: ncDouble.Put ( GetGroupID(), GetID(), (TVecDouble const &) data ); break;
986  case NcType::nc_UBYTE : ncUbyte.Put ( GetGroupID(), GetID(), (TVecUbyte const &) data ); break;
987  case NcType::nc_USHORT: ncUshort.Put ( GetGroupID(), GetID(), (TVecUshort const &) data ); break;
988  case NcType::nc_UINT : ncUint.Put ( GetGroupID(), GetID(), (TVecUint const &) data ); break;
989  case NcType::nc_INT64 : ncInt64.Put ( GetGroupID(), GetID(), (TVecInt64 const &) data ); break;
990  case NcType::nc_UINT64: ncUint64.Put ( GetGroupID(), GetID(), (TVecUint64 const &) data ); break;
991  case NcType::nc_STRING: ncString.Put ( GetGroupID(), GetID(), (TVecString const &) data ); break;
992  case NcType::nc_CHAR : ncChar.Put ( GetGroupID(), GetID(), (TVecChar const &) data ); break;
993  default: break;
994  }
995 }
996 
998 template
999 <
1000  class TC // container value_type (e.g., T in std::vector<T>)
1001 >
1002 inline void NcVar::Put (
1003  TVecIndex const & start, // zero-based indices to start write
1004  TVecIndex const & count, // count along each edge (>= 1)
1005  std::vector<TC> const & data )
1006 {
1007  switch( getClassType() )
1008  {
1009  case NcType::nc_BYTE : ncByte.Put ( GetGroupID(), GetID(), start, count, (TVecByte const &) data ); break;
1010  case NcType::nc_SHORT : ncShort.Put ( GetGroupID(), GetID(), start, count, (TVecShort const &) data ); break;
1011  case NcType::nc_INT : ncInt.Put ( GetGroupID(), GetID(), start, count, (TVecInt const &) data ); break;
1012  case NcType::nc_FLOAT : ncFloat.Put ( GetGroupID(), GetID(), start, count, (TVecFloat const &) data ); break;
1013  case NcType::nc_DOUBLE: ncDouble.Put ( GetGroupID(), GetID(), start, count, (TVecDouble const &) data ); break;
1014  case NcType::nc_UBYTE : ncUbyte.Put ( GetGroupID(), GetID(), start, count, (TVecUbyte const &) data ); break;
1015  case NcType::nc_USHORT: ncUshort.Put ( GetGroupID(), GetID(), start, count, (TVecUshort const &) data ); break;
1016  case NcType::nc_UINT : ncUint.Put ( GetGroupID(), GetID(), start, count, (TVecUint const &) data ); break;
1017  case NcType::nc_INT64 : ncInt64.Put ( GetGroupID(), GetID(), start, count, (TVecInt64 const &) data ); break;
1018  case NcType::nc_UINT64: ncUint64.Put ( GetGroupID(), GetID(), start, count, (TVecUint64 const &) data ); break;
1019  case NcType::nc_STRING: ncString.Put ( GetGroupID(), GetID(), start, count, (TVecString const &) data ); break;
1020  case NcType::nc_CHAR : ncChar.Put ( GetGroupID(), GetID(), start, count, (TVecChar const &) data ); break;
1021  default: break;
1022  }
1023 }
1024 
1025 
1026 class NcNullVar : public NcVar
1027 {
1028  public:
1029 
1031  : NcVar ()
1032  {
1033  }
1034 
1035 };
1036 
1038 extern NcNullVar nullVar;
1039 
1040 
1041 } // namespace netcdf
1042 
1043 #endif
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcString.cpp:120
NcUint ncUint
Definition: NcUint.cpp:24
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcUint64.cpp:34
ncType
Definition: NcType.h:56
NcType GetType() const
Definition: NcVar.cpp:112
EndianMode GetEndianness() const
Definition: NcVar.cpp:251
std::vector< unsigned int > TVecUint
Definition: NcType.h:37
void GetChunking(ChunkMode &chunkMode, std::vector< size_t > &chunkSizes) const
Get chunking parameters.
Definition: NcVar.cpp:230
signed 1 byte integer
Definition: NcType.h:59
void Get(int &data)
get NcInt
Definition: NcVar.h:415
void Get(long long &data)
get NcInt64
Definition: NcVar.h:418
NcItem & operator=(NcItem const &rhs)
Definition: NcItem.h:70
ChecksumMode
Used for checksum specification.
Definition: NcVar.h:75
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcUint.cpp:90
void Get(double &data)
get NcDouble
Definition: NcVar.h:421
bool HaveAttribute(std::string const name) const
Definition: NcVar.cpp:362
std::vector< long long > TVecInt64
Definition: NcType.h:40
double precision floating point number
Definition: NcType.h:64
void Put(unsigned int const &data)
get NcUint
Definition: NcVar.h:672
bool operator==(NcItem const &rhs) const
Definition: NcItem.h:76
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcInt64.cpp:34
void Get(signed char &data)
get scalar values
Definition: NcVar.h:410
signed 4 byte integer
Definition: NcType.h:62
NcInt64 ncInt64
Definition: NcInt64.cpp:24
void Get(char &data)
get NcChar
Definition: NcVar.h:412
void Put(unsigned short const &data)
get NcUshort
Definition: NcVar.h:669
void Put(char const &data)
get NcChar
Definition: NcVar.h:667
void Get(unsigned short &data)
get NcUshort
Definition: NcVar.h:414
unsigned 2-byte int
Definition: NcType.h:66
NcShort ncShort
Definition: NcShort.cpp:24
std::vector< char > TVecChar
Definition: NcType.h:33
int GetAttCount() const
Definition: NcVar.cpp:354
Represents a netCDF dimension.
Definition: NcDim.h:26
NcInt ncInt
Definition: NcInt.cpp:24
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcInt64.cpp:90
Contiguous storage is used for this variable. Variables with one or more unlimited dimensions cannot ...
Definition: NcVar.h:62
single precision floating point number
Definition: NcType.h:63
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcDouble.cpp:92
NcVar()
Definition: NcVar.cpp:38
std::vector< signed char > TVecByte
Definition: NcType.h:28
NcVarAtt GetAtt(std::string const name) const
Definition: NcVar.cpp:387
int GetGroupID() const
Definition: NcItem.h:65
bool IsScalar() const
is scalar variable?
Definition: NcVar.h:138
string
Definition: NcType.h:70
ChunkMode
Chunking specifications flags.
Definition: NcVar.h:52
signed 8-byte int
Definition: NcType.h:68
void Put(std::vector< TC > const &data)
Writes the entire data into the netCDF variable.
Definition: NcVar.h:977
void Get(long &data)
get NcInt
Definition: NcVar.h:416
NcChar ncChar
Definition: NcChar.cpp:24
ChecksumMode GetChecksum() const
Definition: NcVar.cpp:265
void Put(long long const &data)
get NcInt64
Definition: NcVar.h:673
bool operator!=(NcVar const &rhs) const
Definition: NcVar.h:116
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcUbyte.cpp:34
Big endian.
Definition: NcVar.h:71
NcVar & operator=(NcVar const &rhs)
Definition: NcVar.h:105
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcFloat.cpp:36
NcUshort ncUshort
Definition: NcUshort.cpp:24
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcUbyte.cpp:90
signed 2 byte integer
Definition: NcType.h:61
NcDim GetDim(int const index) const
get dimension at index
Definition: NcVar.cpp:328
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcShort.cpp:33
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcByte.cpp:89
NcNullVar()
Definition: NcVar.h:1030
unsigned 1 byte int
Definition: NcType.h:65
void Get(float &data)
get NcFloat
Definition: NcVar.h:420
std::vector< unsigned long long > TVecUint64
Definition: NcType.h:41
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcUshort.cpp:34
std::map< std::string, NcVarAtt > NcVarAttMap
Definition: NcVar.h:48
std::vector< short > TVecShort
Definition: NcType.h:34
unsigned 4-byte int
Definition: NcType.h:67
Represents a netCDF variable.
Definition: NcVar.h:43
void Put(double const &data)
get NcDouble
Definition: NcVar.h:676
void Rename(std::string const &newname)
Definition: NcVar.cpp:166
Native endian (default)
Definition: NcVar.h:69
void Put(long const &data)
get NcInt
Definition: NcVar.h:671
std::vector< std::size_t > TVecIndex
Definition: NcType.h:43
std::vector< unsigned char > TVecUbyte
Definition: NcType.h:32
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcUint64.cpp:90
#define NcCHECK(a_)
Definition: NcCheck.h:45
NcFloat ncFloat
Definition: NcFloat.cpp:24
NcType::ncType getClassType() const
Definition: NcVar.h:101
Definition: NcVar.h:1026
void Put(int const &data)
get NcInt
Definition: NcVar.h:670
void Put(unsigned long long const &data)
get NcUint64
Definition: NcVar.h:674
void Get(std::vector< TC > &data)
Reads the entire data into the netCDF variable.
Definition: NcVar.h:885
EndianMode
Used to specifying the endianess of the data, Default is ENDIAN_NATIVE.
Definition: NcVar.h:67
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcDouble.cpp:36
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcUshort.cpp:90
std::vector< std::string > TVecString
Definition: NcType.h:42
NcNullVar nullVar
global null variable
Definition: NcVar.cpp:34
bool operator==(NcVar const &rhs) const
Definition: NcVar.h:111
bool IsCompressionEnabled() const
Definition: NcVar.cpp:207
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcFloat.cpp:92
NcUbyte ncUbyte
Definition: NcUbyte.cpp:24
std::pair< std::string, NcVarAtt > NcVarAttPair
Definition: NcVar.h:49
Little endian.
Definition: NcVar.h:70
No checksum (the default).
Definition: NcVar.h:77
std::vector< NcDim > GetDims() const
get all dimensions
Definition: NcVar.cpp:310
ISO/ASCII character.
Definition: NcType.h:60
NcVarAtt PutAtt(std::string const name, NcType const &type, size_t len, const unsigned char *dataValues) const
Definition: NcVar.cpp:403
void Get(unsigned int &data)
get NcUint
Definition: NcVar.h:417
void Get(short &data)
get NcShort
Definition: NcVar.h:413
NcGroup GetParentGroup() const
Definition: NcVar.cpp:104
Selects the Fletcher32 checksum filter.
Definition: NcVar.h:78
int GetDimCount() const
number of dimensions
Definition: NcVar.cpp:301
unsigned 8-byte int
Definition: NcType.h:69
NcVarAttMap GetAttributes() const
Definition: NcVar.cpp:370
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcInt.cpp:89
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcByte.cpp:33
void Put(short const &data)
get NcShort
Definition: NcVar.h:668
NcUint64 ncUint64
Definition: NcUint64.cpp:24
void SetChunking(ChunkMode const chunkMode, std::vector< size_t > const &chunksizes) const
Set chunking parameters.
Definition: NcVar.cpp:222
void GetFillMode(bool &fillMode, T &fillValue) const
Get the fill value.
Definition: NcVar.h:206
std::vector< float > TVecFloat
Definition: NcType.h:38
std::multimap< std::string, NcType > NcTypeMap
Definition: NcVar.h:47
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcChar.cpp:189
int GetID() const
Definition: NcItem.h:64
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcInt.cpp:33
std::vector< unsigned short > TVecUshort
Definition: NcType.h:35
void Get(int const groupID, int const varID, char **&data)
receives data; free with FreeCStringArray
Definition: NcChar.cpp:33
void Get(unsigned char &data)
get NcUbyte
Definition: NcVar.h:411
std::vector< int > TVecInt
Definition: NcType.h:36
NcString ncString
Definition: NcString.cpp:27
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcString.cpp:38
void SetFillMode(bool const fillMode, T const fillValue) const
Sets the fill parameters.
Definition: NcVar.h:186
void Get(int const groupID, int const varID, vector_type &data)
receives data
Definition: NcUint.cpp:34
void Put(signed char const &data)
put scalar values
Definition: NcVar.h:665
NcDouble ncDouble
Definition: NcDouble.cpp:24
Base class for NcAtt, NcVar, NcDim, NcGroup.
Definition: NcItem.h:22
Base class for all netCDF data types.
Definition: NcType.h:47
void Get(unsigned long long &data)
get NcUint64
Definition: NcVar.h:419
void SetEndianness(EndianMode endianMode) const
Definition: NcVar.cpp:245
std::vector< double > TVecDouble
Definition: NcType.h:39
void SetCompression(bool const enableShuffleFilter, bool const enableDeflateFilter, int const deflateLevel) const
Set compression parameters for this variable. Compression should not be used for variables which will...
Definition: NcVar.cpp:176
void Put(float const &data)
get NcFloat
Definition: NcVar.h:675
void Put(int const groupID, int const varID, vector_type const &data)
data to write
Definition: NcShort.cpp:89
Represents a netCDF variable attribute.
Definition: NcVarAtt.h:27
void SetChecksum(ChecksumMode checksumMode) const
Definition: NcVar.cpp:259
Represents a netCDF group.
Definition: NcGroup.h:36
Chunked storage is used for this variable.
Definition: NcVar.h:55
bool DoCollectiveIO() const
Definition: NcVar.h:129
NcByte ncByte
Definition: NcByte.cpp:24
void GetCompression(bool &shuffleFilterEnabled, bool &deflateFilterEnabled, int &deflateLevel) const
Get compression parameters for this variable.
Definition: NcVar.cpp:193
void Put(unsigned char const &data)
get NcUbyte
Definition: NcVar.h:666