Skip to content

Commit

Permalink
initial format
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Jul 6, 2022
1 parent d4441a1 commit 228e355
Show file tree
Hide file tree
Showing 49 changed files with 6,677 additions and 3,497 deletions.
84 changes: 57 additions & 27 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,42 @@ import Mmap

### PUBLIC API ###

export
@read, @write,
h5open, h5read, h5write, h5rewrite, h5writeattr, h5readattr,
create_attribute, open_attribute, read_attribute, write_attribute, delete_attribute, rename_attribute, attributes, attrs,
create_dataset, open_dataset, read_dataset, write_dataset,
create_group, open_group,
copy_object, open_object, delete_object, move_link,
create_datatype, commit_datatype, open_datatype,
create_property,
group_info, object_info,
dataspace, datatype,
Filters, Drivers
export @read,
@write,
h5open,
h5read,
h5write,
h5rewrite,
h5writeattr,
h5readattr,
create_attribute,
open_attribute,
read_attribute,
write_attribute,
delete_attribute,
rename_attribute,
attributes,
attrs,
create_dataset,
open_dataset,
read_dataset,
write_dataset,
create_group,
open_group,
copy_object,
open_object,
delete_object,
move_link,
create_datatype,
commit_datatype,
open_datatype,
create_property,
group_info,
object_info,
dataspace,
datatype,
Filters,
Drivers

### The following require module scoping ###

Expand Down Expand Up @@ -100,7 +124,12 @@ function h5read(filename, name_type_pair::Pair{<:AbstractString,DataType}; pv...
dat
end

function h5read(filename, name::AbstractString, indices::Tuple{Vararg{Union{AbstractRange{Int},Int,Colon}}}; pv...)
function h5read(
filename,
name::AbstractString,
indices::Tuple{Vararg{Union{AbstractRange{Int},Int,Colon}}};
pv...,
)
local dat
fapl = FileAccessProperties(; fclose_degree = :strong)
pv = setproperties!(fapl; pv...)
Expand All @@ -115,8 +144,6 @@ function h5read(filename, name::AbstractString, indices::Tuple{Vararg{Union{Abst
dat
end



function Base.getindex(parent::Union{File,Group}, path::AbstractString; pv...)
haskey(parent, path) || throw(KeyError(path))
# Faster than below if defaults are OK
Expand All @@ -139,7 +166,12 @@ end

# Assign syntax: obj[path] = value
# Create a dataset with properties: obj[path, prop = val, ...] = val
function Base.setindex!(parent::Union{File,Group}, val, path::Union{AbstractString,Nothing}; pv...)
function Base.setindex!(
parent::Union{File,Group},
val,
path::Union{AbstractString,Nothing};
pv...,
)
need_chunks = any(k in keys(chunked_props) for k in keys(pv))
have_chunks = any(k == :chunk for k in keys(pv))

Expand All @@ -157,17 +189,12 @@ function Base.setindex!(parent::Union{File,Group}, val, path::Union{AbstractStri
write(parent, path, val; pv...)
end



# end of high-level interface


include("api_midlevel.jl")


#API.h5s_get_simple_extent_ndims(space_id::API.hid_t) = API.h5s_get_simple_extent_ndims(space_id, C_NULL, C_NULL)


# Functions that require special handling

const libversion = API.h5_get_libversion()
Expand All @@ -180,7 +207,6 @@ get_create_properties(g::Group) = GroupCreateProperties(API.h5g_get_create_p
get_create_properties(f::File) = FileCreateProperties(API.h5f_get_create_plist(f))
get_create_properties(a::Attribute) = AttributeCreateProperties(API.h5a_get_create_plist(a))


const HAS_PARALLEL = Ref(false)

"""
Expand All @@ -204,12 +230,16 @@ function __init__()
ASCII_ATTRIBUTE_PROPERTIES.char_encoding = :ascii
UTF8_ATTRIBUTE_PROPERTIES.char_encoding = :utf8

@require FileIO="5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" begin
@require OrderedCollections="bac558e1-5e72-5ebc-8fee-abe8a469f55d" include("fileio.jl")
@require FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" begin
@require OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" include(
"fileio.jl",
)
end
@require H5Zblosc="c8ec2601-a99c-407f-b158-e79c03c2f5f7" begin
set_blosc!(p::Properties, val::Bool) = val && push!(Filters.FilterPipeline(p), H5Zblosc.BloscFilter())
set_blosc!(p::Properties, level::Integer) = push!(Filters.FilterPipeline(p), H5Zblosc.BloscFilter(level=level))
@require H5Zblosc = "c8ec2601-a99c-407f-b158-e79c03c2f5f7" begin
set_blosc!(p::Properties, val::Bool) =
val && push!(Filters.FilterPipeline(p), H5Zblosc.BloscFilter())
set_blosc!(p::Properties, level::Integer) =
push!(Filters.FilterPipeline(p), H5Zblosc.BloscFilter(level = level))
end

return nothing
Expand Down
6 changes: 4 additions & 2 deletions src/api/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const depsfile = joinpath(@__DIR__, "..", "..", "deps", "deps.jl")
if isfile(depsfile)
include(depsfile)
else
error("HDF5 is not properly installed. Please run Pkg.build(\"HDF5\") ",
"and restart Julia.")
error(
"HDF5 is not properly installed. Please run Pkg.build(\"HDF5\") ",
"and restart Julia.",
)
end

include("types.jl")
Expand Down
10 changes: 8 additions & 2 deletions src/api/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ function Base.showerror(io::IO, err::H5Error)
errval = unsafe_load(errptr)
print(io, "\n", lpad("[$n] ", 4 + ndigits(n_total)))
if errval.func_name != C_NULL
printstyled(io, unsafe_string(errval.func_name); bold=true)
printstyled(io, unsafe_string(errval.func_name); bold = true)
print(io, ": ")
end
major = h5e_get_msg(errval.maj_num)[2]
minor = h5e_get_msg(errval.min_num)[2]
print(io, major, "/", minor)
if errval.desc != C_NULL
printstyled(io, "\n", " "^(4 + ndigits(n_total)), unsafe_string(errval.desc), color=:light_black)
printstyled(
io,
"\n",
" "^(4 + ndigits(n_total)),
unsafe_string(errval.desc),
color = :light_black,
)
end
if SHORT_ERROR[]
if n_total > 1
Expand Down
Loading

0 comments on commit 228e355

Please sign in to comment.