Skip to content

Commit

Permalink
Reverted to the previous method to read inputs from a file specified …
Browse files Browse the repository at this point in the history
…by the command line - macro method not working with more complex inputs
  • Loading branch information
markowkes committed Jul 30, 2024
1 parent 8625826 commit 731bb51
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,6 @@ function checkParameters(p)
end


"""
Macro that loads a file with input parameters
"""
macro include(filename)
return quote
file_contents = read($filename, String)
load_expr = Meta.parse(file_contents)
return Meta.eval(load_expr)
end |> esc
end

"""
Reads a file (ARGS[1]), extracts p, and processes p
"""
Expand All @@ -277,11 +266,41 @@ function process_command_line_args(ARGS)
filename = ARGS[1]

# Load file containing parameters
@include(filename)
include(filename)

# Check file loaded parameter variable p
(@isdefined p) || error("Parameter file should contain a NamedTuple with name `p`")
(p isa NamedTuple) || error("Parameter file contains p, but p is not a NamedTuple")

return p
# Copy variables into new tuple and process functions
d = NamedTuple()
for (key,val) in zip(keys(p), p)
# Check if this parameter contains a vector
if val isa Vector
# Process vector entries
val_vec = Any[]
for n in eachindex(val)
# Process each entry in the vector
push!(val_vec,process_var(val[n]))
end
# Copy entries into d
d = merge(d, NamedTuple{(key,)}((val_vec,)))
else
# Process value and copy into d
d = merge(d, NamedTuple{(key,)}((process_var(val),)))
end
end
return d
end

"""
Takes a variable, and makes functions executable
"""
function process_var(var)
if var isa Function
_func(x...) = Base.invokelatest(var, x...)
return _func
else
return var
end
end

0 comments on commit 731bb51

Please sign in to comment.