Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for attributes #20

Closed
perkinsb1024 opened this issue Sep 8, 2016 · 1 comment
Closed

Add support for attributes #20

perkinsb1024 opened this issue Sep 8, 2016 · 1 comment

Comments

@perkinsb1024
Copy link

As far as I can tell, this library does not include support for reading/writing/deleting attributes ( https://www.hdfgroup.org/HDF5/doc1.6/UG/13_Attributes.html )

While it's not clean or complete, I was able to create attributes of type Double on groups by adding this code to Group.swift:

    /// Create an attribute
    public func createAttribute(name: String) -> hid_t {
        let dataspace = Dataspace.init(dims: [1, 1])
        let datatype = Datatype(type: Double.self)!
        let attributeId = name.withCString{
            return H5Acreate2(id, $0, datatype.id, dataspace.id, 0, 0)
        }
        return attributeId
    }

    /// Write an attribute
    public func writeAttribute(attributeId: hid_t, value: Double) {
        let datatype = Datatype(type: Double.self)!
        var cValue = CDouble(value)
        H5Awrite(attributeId, datatype.id, &cValue)
    }

    /// Close an attribute
    public func closeAttribute(attributeId: hid_t) {
        H5Aclose(attributeId)
    }
@alejandro-isaza
Copy link
Owner

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants