Skip to content

Commit

Permalink
Get parameters dictionnary
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuRoule committed Apr 5, 2023
1 parent a5a6629 commit d7fd7a2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/AstroBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ using HDF5
# @WARNING: Should be defined before any basis definition
abstract type AbstractAstroBasis end

# Documentation of the function needed in a basis
include("Utils/IO.jl")

# Documentation of the function needed in a basis
include("Basisdoc.jl")

Expand Down
23 changes: 21 additions & 2 deletions src/Utils/IO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using HDF5

"""
WriteParameters(filename,params,mode)
WriteParameters(file,params)
WriteParameters(filename,basis,mode)
WriteParameters(file,basis)
write all the parameters to a file
"""
Expand All @@ -28,4 +28,23 @@ function WriteParameters(file::HDF5.File,
write(group,varname,getfield(basis,i))
end
end
end

"""
GetParameters(basis)
gives all the basis parameters in a dictionnary
"""
function GetParameters(basis::AB) where {AB <: AbstractAstroBasis}

paramsdict = Dict{String,Union{String,Number}}()
for i = 1:fieldcount(AB)
# If this field is a string or a number, it is a parameter
# (Prevent from dumping arrays)
if fieldtype(AB,i) <: Union{String,Number}
varname = string(fieldname(AB,i))
paramsdict[varname] = getfield(basis,i)
end
end
return paramsdict
end

0 comments on commit d7fd7a2

Please sign in to comment.