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

Method AddSingleValueToDataset

IO/HDF/vtkHDFWriterImplementation.cxx:523–580  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

521
522//------------------------------------------------------------------------------
523bool vtkHDFWriter::Implementation::AddSingleValueToDataset(
524 hid_t dataset, vtkIdType value, bool offset, bool trim)
525{
526 vtkDebugWithObjectMacro(this->Writer, "Adding 1 value to " << this->GetGroupName(dataset));
527 // Create a new dataspace containing a single value
528 constexpr hsize_t addedDims[1] = { 1 };
529 vtkHDF::ScopedH5SHandle newDataspace = H5Screate_simple(1, addedDims, nullptr);
530 if (newDataspace == H5I_INVALID_HID)
531 {
532 return false;
533 }
534
535 // Recover dataset and dataspace
536 vtkHDF::ScopedH5SHandle currentDataspace = H5Dget_space(dataset);
537 if (currentDataspace == H5I_INVALID_HID)
538 {
539 return false;
540 }
541
542 // Retrieve current dataspace dimensions
543 hsize_t currentdims[1] = { 0 };
544 H5Sget_simple_extent_dims(currentDataspace, currentdims, nullptr);
545 const hsize_t newdims[1] = { currentdims[0] + addedDims[0] };
546
547 // Add the last value of the dataset if we want an offset (only for arrays of stride 1)
548 if (offset && currentdims[0] > 0)
549 {
550 std::vector<vtkIdType> allValues;
551 allValues.resize(currentdims[0]);
552 H5Dread(dataset, H5T_STD_I64LE, currentDataspace, H5S_ALL, H5P_DEFAULT, allValues.data());
553 value += allValues.back();
554 }
555
556 // Resize dataset
557 if (!trim)
558 {
559 if (H5Dset_extent(dataset, newdims) < 0)
560 {
561 return false;
562 }
563 currentDataspace = H5Dget_space(dataset);
564 if (currentDataspace == H5I_INVALID_HID)
565 {
566 return false;
567 }
568 }
569 hsize_t start[1] = { currentdims[0] - trim };
570 hsize_t count[1] = { addedDims[0] };
571 H5Sselect_hyperslab(currentDataspace, H5S_SELECT_SET, start, nullptr, count, nullptr);
572
573 // Write new data to the dataset
574 if (H5Dwrite(dataset, H5T_STD_I64LE, newDataspace, currentDataspace, H5P_DEFAULT, &value) < 0)
575 {
576 return false;
577 }
578
579 return true;
580}

Callers 2

WriteSumStepsMethod · 0.95

Calls 6

GetGroupNameMethod · 0.95
H5Sselect_hyperslabFunction · 0.85
backMethod · 0.80
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected