Mercurial > repos > public > sbplib_julia
diff src/SbpOperators/readoperator.jl @ 766:7624a1350ece operator_storage_array_of_table
Add parse_stencil
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 13 Feb 2021 22:17:55 +0100 |
parents | fdd48f6ace1c |
children | 210d3f58bd56 |
line wrap: on
line diff
--- a/src/SbpOperators/readoperator.jl Sun Feb 07 21:32:21 2021 +0100 +++ b/src/SbpOperators/readoperator.jl Sat Feb 13 22:17:55 2021 +0100 @@ -3,6 +3,8 @@ export read_stencil_set export get_stencil_set +export parse_stencil + export read_D2_operator export read_stencil export read_stencils @@ -85,6 +87,40 @@ return parsed_toml["stencil_set"][i] end +function parse_stencil(toml) + check_stencil_toml(toml) + + if toml isa Array + weights = Float64.(parse_rational.(toml)) + return CenteredStencil(weights...) + end + + weights = Float64.(parse_rational.(toml["s"])) + return Stencil(weights..., center = toml["c"]) +end + +function check_stencil_toml(toml) + if !(toml isa Dict || toml isa Vector{String}) + throw(ArgumentError("the TOML for a stecil must be a vector of strings or a table.")) + end + + if toml isa Vector{String} + return + end + + if !(haskey(toml, "s") && haskey(toml, "c")) + throw(ArgumentError("the table form of a stencil must have fields `s` and `c`.")) + end + + if !(toml["s"] isa Vector{String}) + throw(ArgumentError("a stencil must be specified as a vector of strings.")) + end + + if !(toml["c"] isa Int) + throw(ArgumentError("the center of a stencil must be specified as an integer.")) + end +end + """ read_stencil(fn, path...; [center])