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

Method LoadVariable

IO/NetCDF/vtkNetCDFReader.cxx:784–951  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

782
783//------------------------------------------------------------------------------
784int vtkNetCDFReader::LoadVariable(int ncFD, const char* varName, double time, vtkDataSet* output)
785{
786 // Get the variable id.
787 int varId;
788 CALL_NETCDF_INT(this->Accessor->inq_varid(ncFD, varName, &varId));
789
790 // Get dimension info.
791 int numDims;
792 CALL_NETCDF_INT(this->Accessor->inq_varndims(ncFD, varId, &numDims));
793 if (numDims > 4)
794 {
795 vtkErrorMacro(<< "More than 3 dims + time not supported in variable " << varName);
796 return 0;
797 }
798 int dimIds[4];
799 CALL_NETCDF_INT(this->Accessor->inq_vardimid(ncFD, varId, dimIds));
800
801 // Number of values to read.
802 vtkIdType arraySize = 1;
803
804 // Indices to read from.
805 size_t start[4], count[4];
806
807 // Are we using time?
808 int timeIndexOffset = 0;
809 if ((numDims > 0) && this->IsTimeDimension(ncFD, dimIds[0]))
810 {
811 vtkSmartPointer<vtkDoubleArray> timeValues = this->GetTimeValues(ncFD, dimIds[0]);
812 timeIndexOffset = 1;
813 // Find the index for the given time.
814 // We could speed this up with a binary search or something.
815 for (start[0] = 0; start[0] < static_cast<size_t>(timeValues->GetNumberOfTuples()); start[0]++)
816 {
817 if (timeValues->GetValue(static_cast<vtkIdType>(start[0])) >= time)
818 break;
819 }
820 count[0] = 1;
821 numDims--;
822 }
823
824 if (numDims > 3)
825 {
826 vtkErrorMacro(<< "More than 3 dims without time not supported in variable " << varName);
827 return 0;
828 }
829
830 bool loadingPointData = this->DimensionsAreForPointData(this->LoadingDimensions);
831
832 // Set up read indices. Also check to make sure the dimensions are consistent
833 // with other loaded variables.
834 int extent[6];
835 this->GetUpdateExtentForOutput(output, extent);
836 if (numDims != this->LoadingDimensions->GetNumberOfTuples())
837 {
838 vtkWarningMacro(<< "Variable " << varName << " dimensions ("
839 << this->DescribeDimensions(ncFD, dimIds + timeIndexOffset, numDims)
840 << ") are different than the other variable dimensions ("
841 << this->DescribeDimensions(ncFD, this->LoadingDimensions->GetPointer(0),

Callers 1

RequestDataMethod · 0.95

Calls 15

IsTimeDimensionMethod · 0.95
GetTimeValuesMethod · 0.95
DescribeDimensionsMethod · 0.95
NanFunction · 0.85
GetTuple1Method · 0.80
NetCDFTypeToVTKTypeFunction · 0.70
CreateDataArrayFunction · 0.50
assertFunction · 0.50
FastDownCastFunction · 0.50

Tested by

no test coverage detected