MCPcopy Create free account
hub / github.com/Kitware/VTK / LoadMetaData

Method LoadMetaData

IO/NetCDF/vtkNetCDFCFReader.cxx:112–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112int vtkNetCDFCFReader::vtkDimensionInfo::LoadMetaData(int ncFD)
113{
114 this->Units = UNDEFINED_UNITS;
115
116 char name[NC_MAX_NAME + 1];
117 CALL_NETCDF_GW(this->Accessor->inq_dimname(ncFD, this->DimId, name));
118 this->Name = name;
119
120 size_t dimLen;
121 CALL_NETCDF_GW(this->Accessor->inq_dimlen(ncFD, this->DimId, &dimLen));
122 this->Coordinates = vtkSmartPointer<vtkDoubleArray>::New();
123 this->Coordinates->SetName((this->Name + "_Coordinates").c_str());
124 this->Coordinates->SetNumberOfComponents(1);
125 this->Coordinates->SetNumberOfTuples(static_cast<vtkIdType>(dimLen));
126
127 this->Bounds = vtkSmartPointer<vtkDoubleArray>::New();
128 this->Bounds->SetName((this->Name + "_Bounds").c_str());
129 this->Bounds->SetNumberOfComponents(1);
130 this->Bounds->SetNumberOfTuples(static_cast<vtkIdType>(dimLen + 1));
131
132 this->SpecialVariables = vtkSmartPointer<vtkStringArray>::New();
133
134 int varId;
135 int varNumDims;
136 int varDim;
137 // By convention if there is a single dimension variable with the same name as
138 // its dimension, then the data contains the coordinates for the dimension.
139 if ((this->Accessor->inq_varid(ncFD, name, &varId) == NC_NOERR) &&
140 (this->Accessor->inq_varndims(ncFD, varId, &varNumDims) == NC_NOERR) && (varNumDims == 1) &&
141 (this->Accessor->inq_vardimid(ncFD, varId, &varDim) == NC_NOERR) && (varDim == this->DimId))
142 {
143 this->SpecialVariables->InsertNextValue(name);
144
145 // Read coordinates
146 CALL_NETCDF_GW(this->Accessor->get_var_double(ncFD, varId, this->Coordinates->GetPointer(0)));
147
148 // Check to see if the spacing is regular.
149 this->Origin = this->Coordinates->GetValue(0);
150 this->Spacing =
151 (this->Coordinates->GetValue(static_cast<vtkIdType>(dimLen - 1)) - this->Origin) /
152 (dimLen - 1);
153 this->HasRegularSpacing = true; // Then check to see if it is false.
154 double tolerance = 0.01 * this->Spacing;
155 for (size_t i = 1; i < dimLen; i++)
156 {
157 double expectedValue = this->Origin + i * this->Spacing;
158 double actualValue = this->Coordinates->GetValue(static_cast<vtkIdType>(i));
159 if ((actualValue < expectedValue - tolerance) || (actualValue > expectedValue + tolerance))
160 {
161 this->HasRegularSpacing = false;
162 break;
163 }
164 }
165
166 // Check units.
167 std::string units;
168 if (this->Accessor->ReadTextAttribute(ncFD, varId, "units", units))
169 {

Callers 3

vtkDimensionInfoMethod · 0.95
RequestInformationMethod · 0.80

Calls 15

LoadBoundsVariableMethod · 0.95
ReadTextAttributeMethod · 0.80
NewFunction · 0.50
RegularExpressionClass · 0.50
inq_dimnameMethod · 0.45
inq_dimlenMethod · 0.45
SetNameMethod · 0.45
c_strMethod · 0.45
SetNumberOfComponentsMethod · 0.45
SetNumberOfTuplesMethod · 0.45

Tested by

no test coverage detected