Skip to content

Commit

Permalink
allow keyword args to open_group, open_dataset, open_datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Aug 30, 2023
1 parent 4357231 commit 9fde807
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
12 changes: 10 additions & 2 deletions src/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ a file or group with `name`.
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
9 changes: 6 additions & 3 deletions src/datatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ 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))

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
8 changes: 5 additions & 3 deletions src/groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ end
Open an existing [`Group`](@ref) at `path` under the `parent` object.
"""
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, path, 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

0 comments on commit 9fde807

Please sign in to comment.