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 a461be0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ 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
11 changes: 10 additions & 1 deletion src/datatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ datatype(dt::Datatype) = dt
open_datatype(
parent::Union{File,Group},
name::AbstractString,
tapl::DatatypeAccessProperties=DatatypeAccessProperties()
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
11 changes: 10 additions & 1 deletion src/groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@ Open an existing [`Group`](@ref) at `path` under the `parent` object.
function open_group(
parent::Union{File,Group},
name::AbstractString,
gapl::GroupAccessProperties=GroupAccessProperties()
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 a461be0

Please sign in to comment.