Skip to content

Commit

Permalink
Merge branch 'fix-links'
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Aug 9, 2022
2 parents 635d9a6 + 1e247ae commit c9a5dce
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
68 changes: 65 additions & 3 deletions Source/HDF5FileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,69 @@ int HDF5FileBase::setAttribute(BaseDataType type, const void* data, String path,
return setAttributeArray(type, data, 1, path, name);
}

int HDF5FileBase::setAttributeRef(String referencePath, String attributePath, String attributeName)
{

H5Object* loc;
Group gloc;
DataSet dloc;
Attribute attr;

if (!opened) return -1;

try
{
try
{
gloc = file->openGroup(attributePath.toUTF8());
loc = &gloc;
}
catch (FileIException error) //If there is no group with that path, try a dataset
{
dloc = file->openDataSet(attributePath.toUTF8());
loc = &dloc;
}

if (loc->attrExists(attributeName.toUTF8()))
{
attr = loc->openAttribute(attributeName.toUTF8());
}
else
{
DataType data_type(H5T_STD_REF_OBJ);
DataSpace attr_space(H5S_SCALAR);
attr = loc->createAttribute(attributeName.toUTF8(), data_type, attr_space);
}

hobj_ref_t* rdata = (hobj_ref_t*) malloc(sizeof(hobj_ref_t));

file->reference(rdata, referencePath.getCharPointer());

attr.write(H5T_STD_REF_OBJ, rdata);

free(rdata);

}
catch (GroupIException error)
{
PROCESS_ERROR;
}
catch (AttributeIException error)
{
PROCESS_ERROR;
}
catch (DataSetIException error)
{
PROCESS_ERROR;
}
catch (FileIException error)
{
PROCESS_ERROR;
}

return 0;
}


int HDF5FileBase::setAttributeArray(BaseDataType type, const void* data, int size, String path, String name)
{
Expand Down Expand Up @@ -346,9 +409,8 @@ HDF5RecordingData* HDF5FileBase::getDataSet(String path)
void HDF5FileBase::createReference(String path, String reference)
{

H5Lcreate_hard(file->getLocId(),
reference.getCharPointer(),
file->getLocId(),
herr_t error = H5Lcreate_soft(reference.getCharPointer(),
file->getLocId(),
path.getCharPointer(),
H5P_DEFAULT,
H5P_DEFAULT);
Expand Down
3 changes: 3 additions & 0 deletions Source/HDF5FileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class COMMON_LIB HDF5FileBase
/** Sets a string attribute at a given location in the file */
int setAttributeStr(const String& value, String path, String name);

/** Sets an object reference attribute for a given location in the file */
int setAttributeRef(String referencePath, String attributePath, String attributeName);

/** Sets an array attribute (of any data type) at a given location in the file */
int setAttributeArray(BaseDataType type, const void* data, int size, String path, String name);

Expand Down

0 comments on commit c9a5dce

Please sign in to comment.