Skip to content

Commit

Permalink
Handle PATHS
Browse files Browse the repository at this point in the history
  • Loading branch information
moyner committed Sep 27, 2024
1 parent 6d2af92 commit 05d759f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/InputParser/keywords/runspec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,39 @@ function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:CART})
data["CART"] = true
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:CART})
data["CART"] = true
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:SAVE})
data["SAVE"] = read_record(f)
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:PATHS})
defaults = ["Default", "Default"]
if !haskey(data, "PATHS")
data["PATHS"] = Dict{String, String}()
end
pths = data["PATHS"]
while true
rec = readline(f)
# Some custom parsing here because of slashes inside entries here
rec = rstrip(rec, ' ')
rec = rstrip(rec, '/')
rec = rstrip(rec, ' ')
rec = split(rec, " ", keepempty = false)
if length(rec) == 0
break
end
@assert length(rec) == 2 "PATHS must have exactly two entries per line."
alias, subst = rec
alias = strip(alias, '\'')
subst = strip(subst, '\'')
pths[alias] = subst
end
return pths
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:EHYSTR})
rec = read_record(f)
defaults = [0.1, -1000, 1.0, 0.1, "BOTH", "RETR", "DRAIN", "DEFAULT", "NO", "NO", "NO", 0.0, 0]
Expand Down
11 changes: 11 additions & 0 deletions src/InputParser/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ function parse_data_file!(outer_data, filename, data = outer_data;
else
readline(f)
end
next = substitute_paths(next, outer_data)
include_path = clean_include_path(basedir, next)
parser_message(cfg, outer_data, "$m", "Including file: $include_path. Basedir: $basedir with INCLUDE = $next", color = :green)
outer_data, data = parse_data_file!(
Expand Down Expand Up @@ -321,3 +322,13 @@ function finish_current_section!(data, units, cfg, outer_data)
finish_current_section!(data, units, cfg, outer_data, Val(v))
end
end

function substitute_paths(pth, outer_data)
rs = outer_data["RUNSPEC"]
if haskey(rs, "PATHS")
for (k, v) in pairs(rs["PATHS"])
pth = replace(pth, "\$$k" => v)
end
end
return pth
end

0 comments on commit 05d759f

Please sign in to comment.