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

Method WriteData

IO/NetCDF/vtkNetCDFCFWriter.cxx:613–712  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

611
612//------------------------------------------------------------------------------
613void vtkNetCDFCFWriter::WriteData()
614{
615 try
616 {
617 int status;
618 vtkDataSet* dataset = vtkDataSet::SafeDownCast(this->GetInput(0));
619 vtkImageData* id = vtkImageData::SafeDownCast(dataset);
620 if (!id)
621 {
622 throw std::runtime_error("Writer expects an input of type vtkImageData");
623 }
624 vtkDataSetAttributes* attributes = dataset->GetAttributes(this->AttributeType);
625 if (!attributes || !attributes->GetNumberOfArrays())
626 {
627 std::ostringstream ostr;
628 ostr << "There are no array for attribute " << this->AttributeType
629 << "POINT (0) and CELL (1). Try the other attribute type.";
630 throw std::runtime_error(ostr.str());
631 }
632
633 if (this->FillBlankedAttributes)
634 {
635 for (int i = 0; i < attributes->GetNumberOfArrays(); ++i)
636 {
637 vtkDataArray* array = attributes->GetArray(i);
638 std::string name(array->GetName());
639 if (name.rfind("vtk", 0) == 0)
640 {
641 // if its an array that starts with vtk, skip it.
642 continue;
643 }
644 auto newArray = vtk::TakeSmartPointer(array->NewInstance());
645 newArray->SetNumberOfTuples(array->GetNumberOfTuples());
646 newArray->SetNumberOfComponents(array->GetNumberOfComponents());
647 newArray->SetName(array->GetName());
648 BlankToFillValue(dataset->GetGhostArray(this->AttributeType), array, newArray,
649 this->AttributeType, this->FillValue);
650 attributes->AddArray(newArray);
651 }
652 }
653
654 // needed for POINTs and CELLs
655 std::array<std::vector<double>, 3> coords;
656 std::array<int, 3> dimid, coordid;
657 std::vector<int> attributeid;
658
659 // needed only for CELLs
660 std::array<std::vector<std::array<double, 2>>, 3> bounds;
661 std::array<int, 3> boundsid;
662
663 // create the nc file
664 int ncid = this->Impl->CreateFile();
665
666 GetCoords(id, this->AttributeType, &coords, &bounds);
667 this->Impl->DefineCoords(ncid, this->AttributeType, coords, dimid, coordid, boundsid);
668 attributeid.resize(attributes->GetNumberOfArrays());
669 for (int i = 0; i < attributes->GetNumberOfArrays(); ++i)
670 {

Callers

nothing calls this directly

Calls 15

BlankToFillValueFunction · 0.85
GetCoordsFunction · 0.85
VTKTypeToNetCDFTypeFunction · 0.85
nc_enddefFunction · 0.85
nc_strerrorFunction · 0.85
SaveCoordsFunction · 0.85
nc_closeFunction · 0.85
DefineCoordsMethod · 0.80
DefineAttributeMethod · 0.80
SaveAttributeMethod · 0.80
GetInputMethod · 0.45
GetAttributesMethod · 0.45

Tested by

no test coverage detected