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

Method AddFieldDataSizeValueToDataset

IO/HDF/vtkHDFWriterImplementation.cxx:583–664  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

581
582//------------------------------------------------------------------------------
583bool vtkHDFWriter::Implementation::AddFieldDataSizeValueToDataset(
584 hid_t dataset, vtkIdType* value, vtkIdType size, bool offset)
585{
586 if (size <= 1)
587 {
588 vtkLog(
589 WARNING, "Size given in this method shouldn't be less than 2, got : " + vtk::to_string(size));
590 return false;
591 }
592
593 // Specific value linked to how the VTKHDF File Format works for temporal field data offset
594 std::vector<hsize_t> addedDims{ 1, 2 };
595 std::vector<hsize_t> maxDims{ H5S_UNLIMITED, 2 };
596
597 vtkHDF::ScopedH5SHandle newDataspace = H5Screate_simple(1, addedDims.data(), maxDims.data());
598 if (newDataspace == H5I_INVALID_HID)
599 {
600 return false;
601 }
602
603 // Recover dataset and dataspace
604 vtkHDF::ScopedH5SHandle currentDataspace = H5Dget_space(dataset);
605 if (currentDataspace == H5I_INVALID_HID)
606 {
607 return false;
608 }
609
610 // Retrieve current dataspace dimensions
611 int nbDims = H5Sget_simple_extent_ndims(currentDataspace);
612 if (nbDims <= 0)
613 {
614 return true;
615 }
616
617 std::vector<hsize_t> currentdims(nbDims);
618 H5Sget_simple_extent_dims(currentDataspace, currentdims.data(), nullptr);
619
620 std::vector<hsize_t> newdims(nbDims);
621 newdims[0] = { currentdims[0] + addedDims[0] };
622 for (int i = 1; i < nbDims; i++)
623 {
624 newdims[i] = currentdims[i];
625 }
626
627 // Add the last value of the dataset if we want an offset (only for arrays of stride 1)
628 if (offset && currentdims[0] > 0)
629 {
630 std::vector<int> allValues(size);
631 H5Dread(dataset, H5T_STD_I64LE, currentDataspace, H5S_ALL, H5P_DEFAULT, allValues.data());
632 if (size == 1)
633 {
634 value[0] += allValues.back();
635 }
636 }
637
638 // Resize dataset
639 if (H5Dset_extent(dataset, newdims.data()) < 0)
640 {

Calls 6

H5Sselect_hyperslabFunction · 0.85
backMethod · 0.80
to_stringFunction · 0.50
dataMethod · 0.45

Tested by

no test coverage detected