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

allow keyword args to open_group, open_dataset, open_datatype #1100

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/interface/datatype.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ CurrentModule = HDF5

```@docs
Datatype
open_datatype
```
2 changes: 2 additions & 0 deletions docs/src/interface/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ setproperties!
AttributeCreateProperties
FileAccessProperties
FileCreateProperties
GroupAccessProperties
GroupCreateProperties
DatasetCreateProperties
DatasetAccessProperties
DatatypeAccessProperties
DatasetTransferProperties
LinkCreateProperties
ObjectCreateProperties
Expand Down
20 changes: 15 additions & 5 deletions src/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@
dataspace(dset::Dataset) = Dataspace(API.h5d_get_space(checkvalid(dset)))

"""
open_dataset(parent::Union{File, Group}, name::AbstractString, [dapl, dxpl])
open_dataset(parent::Union{File, Group}, path::AbstractString; properties...)

Open a dataset and return a [`HDF5.Dataset`](@ref) handle. Alternatively , just use index
a file or group with `name`.
Open an existing [`HDF5.Dataset`](@ref) at `path` under `parent`

Optional keyword arguments include any keywords that that belong to
[`DatasetAccessProperties`](@ref) or [`DatasetTransferProperties`](@ref).
"""
open_dataset(
parent::Union{File,Group},
name::AbstractString,
dapl::DatasetAccessProperties=DatasetAccessProperties(),
dxpl::DatasetTransferProperties=DatasetTransferProperties()
dapl::DatasetAccessProperties,
dxpl::DatasetTransferProperties
) = Dataset(API.h5d_open(checkvalid(parent), name, dapl), file(parent), dxpl)

function open_dataset(parent::Union{File,Group}, name::AbstractString; pv...)
dapl = DatasetAccessProperties()
dxpl = DatasetTransferProperties()
pv = setproperties!(dapl, dxpl; pv...)
isempty(pv) || error("invalid keyword options $(keys(pv))")
open_dataset(parent, name, dapl, dxpl)
end

# Setting dset creation properties with name/value pairs
"""
create_dataset(parent, path, datatype, dataspace; properties...)
Expand Down
17 changes: 14 additions & 3 deletions src/datatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@ end
datatype(dt::Datatype) = dt

open_datatype(
parent::Union{File,Group},
name::AbstractString,
tapl::DatatypeAccessProperties=DatatypeAccessProperties()
parent::Union{File,Group}, name::AbstractString, tapl::DatatypeAccessProperties
) = Datatype(API.h5t_open(checkvalid(parent), name, tapl), file(parent))

"""
open_datatype(parent::Union{File,Group}, path::AbstractString; properties...)

Open an existing [`Datatype`](@ref) at `path` under the `parent` object.

Optional keyword arguments include any keywords that that belong to
[`DatatypeAccessProperties`](@ref).
"""
function open_datatype(parent::Union{File,Group}, name::AbstractString; pv...)
tapl = DatatypeAccessProperties(; pv...)
return open_datatype(parent, name, tapl)
end

# Note that H5Tcreate is very different; H5Tcommit is the analog of these others
create_datatype(class_id, sz) = Datatype(API.h5t_create(class_id, sz))

Expand Down
13 changes: 9 additions & 4 deletions src/groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,22 @@ function create_group(parent::Union{File,Group}, path::AbstractString; pv...)
end

"""
open_group(parent::Union{File,Group}, path::AbstratString)
open_group(parent::Union{File,Group}, path::AbstractString; properties...)

Open an existing [`Group`](@ref) at `path` under the `parent` object.

Optional keyword arguments include any keywords that that belong to
[`GroupAccessProperties`](@ref).
"""
function open_group(
parent::Union{File,Group},
name::AbstractString,
gapl::GroupAccessProperties=GroupAccessProperties()
parent::Union{File,Group}, name::AbstractString, gapl::GroupAccessProperties
)
return Group(API.h5g_open(checkvalid(parent), name, gapl), file(parent))
end
function open_group(parent::Union{File,Group}, name::AbstractString; pv...)
gapl = GroupAccessProperties(; pv...)
return open_group(parent, name, gapl)
end

# Get the root group
root(h5file::File) = open_group(h5file, "/")
Expand Down
12 changes: 3 additions & 9 deletions src/highlevel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,11 @@ function Base.getindex(parent::Union{File,Group}, path::AbstractString; pv...)
isempty(pv) && return open_object(parent, path)
obj_type = gettype(parent, path)
if obj_type == API.H5I_DATASET
dapl = DatasetAccessProperties()
dxpl = DatasetTransferProperties()
pv = setproperties!(dapl, dxpl; pv...)
isempty(pv) || error("invalid keyword options $pv")
return open_dataset(parent, path, dapl, dxpl)
return open_dataset(parent, path; pv...)
elseif obj_type == API.H5I_GROUP
gapl = GroupAccessProperties(; pv...)
return open_group(parent, path, gapl)
return open_group(parent, path; pv...)
else#if obj_type == API.H5I_DATATYPE # only remaining choice
tapl = DatatypeAccessProperties(; pv...)
return open_datatype(parent, path, tapl)
return open_datatype(parent, path; pv...)
end
end

Expand Down
12 changes: 12 additions & 0 deletions src/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ Properties used when creating a new `Dataset`. Inherits from
- `:never`: Never fill
- `:ifset`: Fill if a value is set

- `fill_value`: the fill value for a dataset. See $(h5doc("H5P_SET_FILL_VALUE")).

- `chunk`: a tuple containing the size of the chunks to store each dimension.
See $(h5doc("H5P_SET_CHUNK")) (note that this uses Julia's column-major
ordering).
Expand Down Expand Up @@ -772,9 +774,19 @@ end

@propertyclass LinkAccessProperties API.H5P_LINK_ACCESS

"""
GroupAccessProperties(;kws...)

Properties used when accessing datatypes. None are currently defined.
"""
@propertyclass GroupAccessProperties API.H5P_GROUP_ACCESS
superclass(::Type{GroupAccessProperties}) = LinkAccessProperties

"""
DatatypeAccessProperties(;kws...)

Properties used when accessing datatypes. None are currently defined.
"""
@propertyclass DatatypeAccessProperties API.H5P_DATATYPE_ACCESS
superclass(::Type{DatatypeAccessProperties}) = LinkAccessProperties

Expand Down
Loading