Skip to content

Commit

Permalink
Added FileCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Wietek committed Aug 10, 2023
1 parent 82e62b2 commit ee8db6b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Dumper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ module Dumper
using HDF5
using Printf

export DumpFile, write_data!, dump!, read_data
export DumpFile, write_data!, dump!, read_data, FileCollection, filenames, read_collection_h5

include("create_extensible.jl")
include("append_extensible.jl")
include("file_collection.jl")

struct DumpFile
filename::AbstractString
Expand Down
38 changes: 38 additions & 0 deletions src/file_collection.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
struct FileCollection
directory::AbstractString
regex::Regex
end

function filenames(collection::FileCollection)
files = readdir(collection.directory)
matched_files = String[]
for file in files
m = match(collection.regex, file)
if !isnothing(m)
push!(matched_files, file)
end
end
return map(fl -> joinpath(collection.directory, fl), matched_files)
end

function read_collection_h5(collection::FileCollection, tag::AbstractString)
files = readdir(collection.directory)
data = Dict()
for file in files
m = match(collection.regex, file)
if !isnothing(m)
if length(m) == 1
param = m[keys(m)[1]]
else
param = ntuple(i -> m[keys(m)[i]], length(m))
end

# read hdf5 data
file = joinpath(collection.directory, file)
dset = h5read(file, tag)
ndims = length(size(dset))
data[param] = permutedims(dset, ndims:-1:1)
end
end
return sort(collect(data), by = x->x[1])
end

0 comments on commit ee8db6b

Please sign in to comment.