File: ncDim.cpp

package info (click to toggle)
netcdf 1%3A4.1.3-7.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 46,040 kB
  • ctags: 25,265
  • sloc: ansic: 169,389; fortran: 17,742; sh: 13,203; cpp: 10,960; f90: 7,903; yacc: 2,832; xml: 2,129; makefile: 2,034; lex: 1,210
file content (116 lines) | stat: -rw-r--r-- 2,657 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "ncDim.h"
#include "ncGroup.h"
#include "ncCheck.h"
#include <algorithm>
using namespace std;


namespace netCDF {
  //  Global comparator operator ==============
  // comparator operator 
  bool operator<(const NcDim& lhs,const NcDim& rhs)
  {
    return false;
  }
  
  // comparator operator 
  bool operator>(const NcDim& lhs,const NcDim& rhs)
  {
    return true;
  }
}

using namespace netCDF;

// assignment operator
NcDim& NcDim::operator=(const NcDim & rhs)
{
  nullObject = rhs.nullObject;
  myId = rhs.myId;
  groupId = rhs.groupId;
  return *this;
}

// The copy constructor.
NcDim::NcDim(const NcDim& rhs): 
  nullObject(rhs.nullObject),
  myId(rhs.myId),
  groupId(rhs.groupId)
{}


// equivalence operator
bool NcDim::operator==(const NcDim& rhs) const
{
  if(nullObject) 
    return nullObject == rhs.nullObject;
  else
    return myId == rhs.myId && groupId == rhs.groupId;
}  

//  !=  operator
bool NcDim::operator!=(const NcDim & rhs) const
{
  return !(*this == rhs);
}  


// Gets parent group.
NcGroup  NcDim::getParentGroup() const {
  return NcGroup(groupId);
}

// Constructor generates a null object.
NcDim::NcDim() : 
  nullObject(true) 
{}

// Constructor for a dimension (must already exist in the netCDF file.)
NcDim::NcDim(const NcGroup& grp, int dimId) :
  nullObject(false)
{
  groupId = grp.getId();
  myId = dimId;
}

// gets the size of the dimension, for unlimited, this is the current number of records.
size_t NcDim::getSize() const
{
  size_t dimSize;
  ncCheck(nc_inq_dimlen(groupId, myId, &dimSize),__FILE__,__LINE__);
  return dimSize;
}


// returns true if this dimension is unlimited.
bool NcDim::isUnlimited() const
{
  int numlimdims;
  int* unlimdimidsp=NULL;
  // get the number of unlimited dimensions
  ncCheck(nc_inq_unlimdims(groupId,&numlimdims,unlimdimidsp),__FILE__,__LINE__);
  // get all the unlimited dimension ids in this group
  vector<int> unlimdimid(numlimdims);
  ncCheck(nc_inq_unlimdims(groupId,&numlimdims,&unlimdimid[0]),__FILE__,__LINE__);
  vector<int>::iterator it;
  // now look to see if this dimension is unlimited
  it = find(unlimdimid.begin(),unlimdimid.end(),myId);
  return it != unlimdimid.end();
}


// gets the name of the dimension.
const string NcDim::getName() const
{
  char dimName[NC_MAX_NAME+1];
  ncCheck(nc_inq_dimname(groupId, myId, dimName),__FILE__,__LINE__);
  return string(dimName);
}
  
// renames this dimension.
void NcDim::rename(const string& name)
{
  ncCheck(nc_rename_dim(groupId, myId, name.c_str()),__FILE__,__LINE__);
}