Skip to content

Commit 2734604

Browse files
joa-quimclaude
andauthored
kwargs protection: analysis, potential, spotter & MB modules (#1922)
Split entry points from main logic in analysis/potential/spotter/MB module wrappers so that kwargs are converted to Dict{Symbol,Any} via init_module in thin wrappers before calling the main function. Affected modules: gmtgravmag3d, gravfft, gravprisms, grdgravmag3d, grdseamount, grdrotater, spectrum1d, sphdistance, sphinterpolate, sphtriangulate, splitxyz, trend1d, trend2d, mbgetdata, mbimport, mblevitus, mbsvplist. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8913842 commit 2734604

17 files changed

Lines changed: 90 additions & 63 deletions

src/MB/mbgetdata.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ Parameters
3030
- $(opt_n)
3131
- $(_opt_t)
3232
"""
33-
function mbgetdata(cmd0::String=""; kwargs...)
34-
35-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
36-
33+
function mbgetdata(cmd0::String=""; kw...)
34+
d = init_module(false, kw...)[1] # Also checks if the user wants ONLY the HELP mode
35+
mbgetdata(cmd0, d)
36+
end
37+
function mbgetdata(cmd0::String, d::Dict{Symbol, Any})
3738
cmd, opt_R = parse_R(d, "")
3839
cmd, = parse_common_opts(d, cmd, [:UVXY :params]; first=true)
3940

src/MB/mbimport.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ Parameters
3737
- $(opt_n)
3838
- $(_opt_t)
3939
"""
40-
function mbimport(cmd0::String=""; kwargs...)
41-
42-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
43-
40+
function mbimport(cmd0::String=""; kw...)
41+
d = init_module(false, kw...)[1] # Also checks if the user wants ONLY the HELP mode
42+
mbimport(cmd0, d)
43+
end
44+
function mbimport(cmd0::String, d::Dict{Symbol, Any})
4445
cmd, opt_R = parse_R(d, "")
4546
cmd, opt_J = parse_J(d, cmd, default=" -JX15cd/0", map=true)
4647
cmd, = parse_common_opts(d, cmd, [:UVXY :params :n :t]; first=true)

src/MB/mblevitus.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ Parameters
2424
Makes Z axes positive down (default here is Z-up).
2525
- $(opt_V)
2626
"""
27-
function mblevitus(cmd0::String=""; kwargs...)
28-
29-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
30-
27+
function mblevitus(cmd0::String=""; kw...)
28+
d = init_module(false, kw...)[1] # Also checks if the user wants ONLY the HELP mode
29+
mblevitus(cmd0, d)
30+
end
31+
function mblevitus(cmd0::String, d::Dict{Symbol, Any})
3132
cmd = parse_common_opts(d, "", [:yx :V_params :o])[1]
3233
cmd = add_opt(d, cmd, "L", [:L :location :R])
3334
(!occursin("-L", cmd)) && (cmd *= " -L0/0")

src/MB/mbsvplist.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ Parameters
2424
- $(_opt_R)
2525
- $(opt_V)
2626
"""
27-
function mbsvplist(cmd0::String=""; kwargs...)
28-
29-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
30-
27+
function mbsvplist(cmd0::String=""; kw...)
28+
d = init_module(false, kw...)[1] # Also checks if the user wants ONLY the HELP mode
29+
mbsvplist(cmd0, d)
30+
end
31+
function mbsvplist(cmd0::String, d::Dict{Symbol, Any})
3132
cmd = parse_common_opts(d, "", [:R :yx :V_params :o])[1]
3233
cmd = parse_these_opts(cmd, d, [[:C :uniquesvp], [:F :format], [:H :help], [:M :mode], [:S :ssv], [:Z :firstiszero], [:z :z_down]])
3334
((val = find_in_dict(d, [:z :z_down])[1]) === nothing) && (cmd *= " -z") # Means here default is Z-up

src/potential/gmtgravmag3d.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ Parameters
4747
imshow(G)
4848
```
4949
"""
50-
gravmag3d(cmd0::String; kwargs...) = gravmag3d_helper(cmd0, nothing; kwargs...)
51-
gravmag3d(arg1; kwargs...) = gravmag3d_helper("", arg1; kwargs...)
52-
gravmag3d(; kwargs...) = gravmag3d_helper("", nothing; kwargs...)
50+
gravmag3d(cmd0::String; kw...) = gravmag3d_helper(cmd0, nothing; kw...)
51+
gravmag3d(arg1; kw...) = gravmag3d_helper("", arg1; kw...)
52+
gravmag3d(; kw...) = gravmag3d_helper("", nothing; kw...)
5353

54-
function gravmag3d_helper(cmd0::String, arg1; kwargs...)
55-
(cmd0 == "" && arg1 === nothing && length(kwargs) == 0) && return gmt("gmtgravmag3d")
56-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
54+
function gravmag3d_helper(cmd0::String, arg1; kw...)
55+
(cmd0 == "" && arg1 === nothing && length(kw) == 0) && return gmt("gmtgravmag3d")
56+
d = init_module(false, kw...)[1] # Also checks if the user wants ONLY the HELP mode
5757
(cmd0 != "") && (arg1 = gmtread(cmd0, data=true))
5858
if (isa(arg1, GMTfv))
59-
v = mat2ds(arg1.verts)
59+
v = mat2ds(arg1.verts)
6060
f = arg1.faces[1]# .- 1
6161
d[:Tf] = f
6262
d[:Q] = true

src/potential/gravfft.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ To see the full documentation type: ``@? gravfft``
4949
```
5050
"""
5151
gravfft(arg1, arg2=nothing; kw...) = gravfft("", arg1, arg2; kw...)
52-
function gravfft(cmd0::String="", arg1=nothing, arg2=nothing; kwargs...)
52+
function gravfft(cmd0::String="", arg1=nothing, arg2=nothing; kw...)
53+
d = init_module(false, kw...)[1]
54+
gravfft(cmd0, arg1, arg2, d)
55+
end
56+
function gravfft(cmd0::String, arg1, arg2, d::Dict{Symbol, Any})
5357

5458
arg3 = nothing
55-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
5659

5760
cmd::String = parse_common_opts(d, "", [:G :V_params :f])[1]
5861
cmd = add_opt(d, cmd, "C", [:C :tadmitt], (n="", lambda="", mean_depth="", from_top="_/t", from_below="_/b", wavelengths="_w"))

src/potential/gravprisms.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ Parameters
5555
5656
Give name of an output grid with spatially varying, vertically-averaged prism densities created by C and H.
5757
"""
58-
function gravprisms(cmd0::String="", arg1::GDtype=GMTdataset(); kwargs...)
58+
function gravprisms(cmd0::String="", arg1::GDtype=GMTdataset(); kw...)
59+
d = init_module(false, kw...)[1]
60+
gravprisms(cmd0, arg1, d)
61+
end
62+
function gravprisms(cmd0::String, arg1::GDtype, d::Dict{Symbol, Any})
5963

6064
Gs = Vector{GMTgrid}(undef, 5)
6165
N_used = 0
6266
arg2::GDtype=GMTdataset()
6367

64-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
65-
6668
function fish_grids(d, Gs, cmd, symbs, opt, N)
6769
if ((_val = find_in_dict(d, symbs)[1]) !== nothing)
6870
if (isa(_val, Real) || isa(_val, String))

src/potential/grdgravmag3d.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ Parameters
5050
```
5151
"""
5252
grdgravmag3d(arg1, arg2=nothing; kw...) = grdgravmag3d("", arg1, arg2; kw...)
53-
function grdgravmag3d(cmd0::String="", arg1=nothing, arg2=nothing; kwargs...)
54-
(cmd0 == "" && arg1 === nothing && arg2 === nothing && length(kwargs) == 0) && return gmt("grdgravmag3d")
53+
function grdgravmag3d(cmd0::String="", arg1=nothing, arg2=nothing; kw...)
54+
(cmd0 == "" && arg1 === nothing && arg2 === nothing && length(kw) == 0) && return gmt("grdgravmag3d")
55+
d = init_module(false, kw...)[1] # Also checks if the user wants ONLY the HELP mode
56+
grdgravmag3d(cmd0, arg1, arg2, d)
57+
end
58+
function grdgravmag3d(cmd0::String, arg1, arg2, d::Dict{Symbol, Any})
5559
arg3, arg4 = nothing, nothing
56-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
5760

5861
cmd::String = parse_common_opts(d, "", [:G :RIr :V_params :f :x])[1]
5962
cmd = parse_these_opts(cmd, d, [[:E :thickness], [:Q :pad], [:L :z_obs :observation_level], [:S :radius]])

src/potential/grdseamount.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
44
Create synthetic seamounts (Gaussian, parabolic, polynomial, cone or disc; circular or elliptical).
55
"""
6-
grdseamount(cmd0::String; kwargs...) = grdseamount_helper(cmd0, nothing; kwargs...)
7-
grdseamount(arg1; kwargs...) = grdseamount_helper("", arg1; kwargs...)
6+
grdseamount(cmd0::String; kw...) = grdseamount_helper(cmd0, nothing; kw...)
7+
grdseamount(arg1; kw...) = grdseamount_helper("", arg1; kw...)
88

9-
function grdseamount_helper(cmd0::String, arg1; kwargs...)
10-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
9+
function grdseamount_helper(cmd0::String, arg1; kw...)
10+
d = init_module(false, kw...)[1] # Also checks if the user wants ONLY the HELP mode
1111
(cmd0 != "") && (arg1 = gmtread(cmd0))
1212
isa(arg1, Matrix{<:Real}) && (arg1 = mat2ds(Float64.(arg1)))
13-
grdseamount_helper(arg1, d)
13+
grdseamount_helper(arg1, d)
1414
end
1515

1616
# ---------------------------------------------------------------------------------------------------

src/spectrum1d.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ spectrum1d(cmd0::String; kw...) = spectrum1d_helper(cmd0, nothing; kw...)
4848
spectrum1d(arg1; kw...) = spectrum1d_helper("", arg1; kw...)
4949

5050
# ---------------------------------------------------------------------------------------------------
51-
function spectrum1d_helper(cmd0::String, arg1; kwargs...)
52-
53-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
51+
function spectrum1d_helper(cmd0::String, arg1; kw...)
52+
d = init_module(false, kw...)[1] # Also checks if the user wants ONLY the HELP mode
53+
spectrum1d_helper(cmd0, arg1, d)
54+
end
55+
function spectrum1d_helper(cmd0::String, arg1, d::Dict{Symbol, Any})
5456
cmd = parse_common_opts(d, "", [:V_params :b :d :e :g :h :i :yx])[1]
5557
cmd = parse_these_opts(cmd, d, [[:D :sample_dist], [:L :leave_trend], [:N :name], [:S :size], [:T :multifiles], [:W :wavelength]])
5658
opt_C = add_opt(d, "", "C", [:C :components :output],

0 commit comments

Comments
 (0)