------------------------------------------------------------------------------
| 459 | |
| 460 | //------------------------------------------------------------------------------ |
| 461 | vtkHDF::ScopedH5DHandle vtkHDFWriter::Implementation::CreateDatasetFromDataArray( |
| 462 | hid_t group, const char* name, hid_t type, vtkAbstractArray* dataArray) |
| 463 | { |
| 464 | // Create dataspace from array |
| 465 | vtkHDF::ScopedH5SHandle dataspace = CreateDataspaceFromArray(dataArray); |
| 466 | if (dataspace == H5I_INVALID_HID) |
| 467 | { |
| 468 | vtkErrorWithObjectMacro(this->Writer, "Could not create dataspace for array " << name); |
| 469 | return H5I_INVALID_HID; |
| 470 | } |
| 471 | // Create dataset from dataspace and other arguments |
| 472 | vtkHDF::ScopedH5DHandle dataset = this->CreateHdfDataset(group, name, type, dataspace); |
| 473 | if (dataset == H5I_INVALID_HID) |
| 474 | { |
| 475 | vtkErrorWithObjectMacro(this->Writer, "Could not create Dataset"); |
| 476 | return H5I_INVALID_HID; |
| 477 | } |
| 478 | |
| 479 | auto da = vtkDataArray::FastDownCast(dataArray); |
| 480 | // If it is not a vtkDataArray, return either an invalid id or the dataset depending on the number |
| 481 | // of values in the dataArray |
| 482 | if (da == nullptr) |
| 483 | { |
| 484 | if (dataArray->GetNumberOfValues() == 0) |
| 485 | { |
| 486 | return dataset; |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | vtkErrorWithObjectMacro(this->Writer, "Dataset " << name << " is null"); |
| 491 | return H5I_INVALID_HID; |
| 492 | } |
| 493 | } |
| 494 | // Find which HDF type corresponds to the dataArray type |
| 495 | // It is different from the `type` in the argument list which defines which type should be used to |
| 496 | // store the data in the HDF file |
| 497 | hid_t source_type = vtkHDFUtilities::getH5TypeFromVtkType(dataArray->GetDataType()); |
| 498 | if (source_type == H5I_INVALID_HID) |
| 499 | { |
| 500 | vtkErrorWithObjectMacro(this->Writer, "Source type " << source_type << " is invalid"); |
| 501 | return H5I_INVALID_HID; |
| 502 | } |
| 503 | // Write vtkAbstractArray data to the HDF dataset |
| 504 | auto aos = da->ToAOSDataArray(); // NOLINTNEXTLINE(bugprone-unsafe-functions) |
| 505 | if (H5Dwrite(dataset, source_type, H5S_ALL, dataspace, H5P_DEFAULT, aos->GetVoidPointer(0)) < 0) |
| 506 | { |
| 507 | vtkErrorWithObjectMacro(this->Writer, "Could not write dataset " << name); |
| 508 | return H5I_INVALID_HID; |
| 509 | } |
| 510 | return dataset; |
| 511 | } |
| 512 | |
| 513 | //------------------------------------------------------------------------------ |
| 514 | vtkHDF::ScopedH5DHandle vtkHDFWriter::Implementation::CreateSingleValueDataset( |
no test coverage detected