Skip to content

Commit 36c58e8

Browse files
authored
Add a top method to shelter the f recompilations to a tinny function. (#1901)
* Fix cases not foreseen in previous simplifications. * Remove first arg as a string in coast calls * Add a top method to shelter the f recompilations to a tinny function.
1 parent 515765f commit 36c58e8

4 files changed

Lines changed: 23 additions & 21 deletions

File tree

src/finish_PS_nested.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function add_opt_module_barr1(nt::NamedTuple, symb::Symbol)::Union{String, Vecto
143143
!contains(r, " -B") && (r = replace(r, "psscale" => "psscale -Baf")) # Add -B if not present
144144
elseif (symb == :clip) # Need lots of little shits to parse the clip options
145145
if ((isa(nt, NamedTuple) && (isa(nt[1], String) || isa(nt[1], Symbol))) || isa(nt[1], NamedTuple))
146-
r = (isa(nt, NamedTuple)) ? coast!(""; Vd=2, E=nt) : coast!(""; Vd=2, nt...)
146+
r = (isa(nt, NamedTuple)) ? coast!(; Vd=2, E=nt) : coast!(; Vd=2, nt...)
147147
opt_E = scan_opt(r, "-E") # We are clipping so opt_E must contain eith +c or +C. If not, add +c
148148
startswith(opt_E, "=land") && (r = replace(r, " -E"*opt_E => " -Gc")) # Stupid user mistakes. Try to recover
149149
startswith(opt_E, "=ocean") && (r = replace(r, " -E"*opt_E => " -Sc"))

src/psclip.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ clip!(cmd0::String; kwargs...) = clip_helper(cmd0, nothing; first=false, kwargs.
3333
clip!(arg1; kwargs...) = clip_helper("", arg1; first=false, kwargs...)
3434
clip!(; kwargs...) = clip_helper("", nothing; first=false, kwargs...)
3535
clip(; kwargs...) = clip_helper("", nothing; first=false, kwargs...) # For when user forgot to use clip! instead of clip
36+
function clip_helper(cmd0::String, arg1; first=true, kw...)
37+
d, K, O = init_module(first, kw...) # Also checks if the user wants ONLY the HELP mode
38+
clip_helper(cmd0, arg1, O, K, d)
39+
end
3640

3741
# ---------------------------------------------------------------------------------------------------
38-
function clip_helper(cmd0::String, arg1; first=true, kwargs...)
42+
function clip_helper(cmd0::String, arg1, O::Bool, K::Bool, d::Dict{Symbol, Any})
3943

4044
proggy = (IamModern[]) ? "clip " : "psclip "
4145

42-
d, K, O = init_module(first, kwargs...) # Also checks if the user wants ONLY the HELP mode
43-
4446
cmd, _, _, opt_R = parse_BJR(d, "", "", O, " -JX" * split(DEF_FIG_SIZE, '/')[1] * "/0")
45-
cmd, = parse_common_opts(d, cmd, [:UVXY :JZ :c :e :f :g :p :t :yx :params]; first=first)
47+
cmd, = parse_common_opts(d, cmd, [:UVXY :JZ :c :e :f :g :p :t :yx :params]; first=!O)
4648
cmd = parse_these_opts(cmd, d, [[:A :steps :straightlines], [:C :endclip], [:N :invert], [:T :clipregion :clip_limits]])
4749
cmd *= add_opt_pen(d, [:W :pen], opt="W")
4850

src/pscoast.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""
2-
coast(cmd0::String=""; kwargs...)
2+
coast(; kwargs...)
33
44
Plot continents, shorelines, rivers, and borders on maps.
55
66
Plots grayshaded, colored, or textured land-masses [or water-masses] on
7-
maps and [optionally] draws coastlines, rivers, and political
8-
boundaries. A map projection must be supplied.
7+
maps and [optionally] draws coastlines, rivers, and political boundaries.
98
109
Parameters
1110
----------
@@ -75,11 +74,13 @@ Parameters
7574
7675
To see the full documentation type: ``@? coast``
7776
"""
78-
function coast(cmd0::String=""; clip::StrSymb="", first=true, kwargs...)
79-
dbg_cmd, d, cmd, K, O, finish, get_largest, toTrack = coast_parser(first, string(clip); kwargs...)
77+
function coast(; clip::StrSymb="", first=true, kwargs...)
78+
d, K, O = init_module(first, kwargs...) # Also checks if the user wants ONLY the HELP mode
79+
dbg_cmd, d, cmd, O, finish, get_largest, toTrack = coast_parser(first==1, string(clip), O, d)
8080
(dbg_cmd !== nothing) && return dbg_cmd
81-
82-
# Have a big possible break here to allow PS_nested call only the parsing part and hence fck the Julia recompilation eagerness
81+
coast(cmd, K, O, finish, get_largest, toTrack, d)
82+
end
83+
function coast(cmd::Vector{String}, K::Bool, O::Bool, finish::Bool, get_largest::Bool, toTrack, d::Dict{Symbol, Any})
8384

8485
# Don't call finish_PS_module if -M because it returns a GDtype instead of a PS
8586
R = (length(cmd) == 1 && contains(cmd[1], " -M")) ? gmt(cmd[1]) : prep_and_call_finish_PS_module(d, cmd, "", K, O, finish)
@@ -105,14 +106,13 @@ function coast(cmd0::String=""; clip::StrSymb="", first=true, kwargs...)
105106
R
106107
end
107108

108-
function coast_parser(first::Bool, clip::String; kwargs...)
109+
function coast_parser(first::Bool, clip::String, O::Bool, d::Dict{Symbol, Any})
109110

110-
d, K, O = init_module(first, kwargs...) # Also checks if the user wants ONLY the HELP mode
111111
gmt_proggy = (IamModern[]) ? "coast " : "pscoast "
112112

113113
if ((val = hlp_desnany_str(d, [:getR :getregion :get_region], false)) !== "")
114114
t::String = string(gmt_proggy, " -E", val)
115-
resto = d, "", K, O, true, false, ""
115+
resto = d, "", O, true, false, ""
116116
((Vd = hlp_desnany_int(d, [:Vd])) !== -999) && (Vd == 1 ? println(t) : Vd > 1 ? (return t, resto...) : nothing)
117117
t = parse_V(d::Dict, t)
118118
return gmt(t).text[1]::String, resto...
@@ -124,7 +124,7 @@ function coast_parser(first::Bool, clip::String; kwargs...)
124124
twoORfour = have_opt_M && contains(cmd, "+z") && contains(cmd, '.') ? "4" : "2" # To use in gmt_main to decide CODE attrib
125125
if (cmd != "") # Check for a minimum of points that segments must have
126126
if ((val = hlp_desnany_str(d, [:minpts])) !== "") POSTMAN[]["minpts"] = val
127-
elseif (get(POSTMAN[], "minpts", "") != "") delete!(POSTMAN[], "minpts")
127+
elseif (get(POSTMAN[], "minpts", "") != "") delete!(POSTMAN[], "minpts")
128128
end
129129
end
130130

@@ -135,7 +135,7 @@ function coast_parser(first::Bool, clip::String; kwargs...)
135135
POSTMAN[]["DCWnames"] = twoORfour # When dumping, we want to add the country name as attribute
136136
if ((val = find_in_dict(d, [:Z])[1]) !== nothing)
137137
toTrack = (isa(val, GMTgrid) || (isa(val, String) && length(val) > 4)) ? val : ""
138-
toTrack == "" && (POSTMAN[]["plusZzero"] = "y")# If toTrack the extra column is added by the grdtrack call below
138+
toTrack == "" && (POSTMAN[]["plusZzero"] = "y") # If toTrack the extra column is added by the grdtrack call below
139139
end
140140
end
141141

@@ -193,7 +193,7 @@ function coast_parser(first::Bool, clip::String; kwargs...)
193193
end
194194

195195
r = check_dbg_print_cmd(d, _cmd)
196-
return r, d, _cmd, K, O, finish, get_largest, toTrack
196+
return r, d, _cmd, O, finish, get_largest, toTrack
197197
end
198198

199199
# ---------------------------------------------------------------------------------------------------
@@ -293,7 +293,7 @@ function parse_dcw(val::Tuple)::String
293293
end
294294

295295
# ---------------------------------------------------------------------------------------------------
296-
coast!(cmd0::String=""; clip::StrSymb="", kw...) = coast(cmd0; clip=clip, first=false, kw...)
296+
coast!(; clip::StrSymb="", kw...) = coast(; clip=clip, first=false, kw...)
297297

298298
const pscoast = coast # Alias
299299
const pscoast! = coast!

src/subplot.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function subplot(fim::String, stop::Bool, d::Dict{Symbol, Any})
7373
end
7474

7575
do_set = false; do_show = false
76-
if (fim !== nothing)
76+
if (fim !== "")
7777
if (fim == "end" || fim == "stop") stop = true
7878
elseif (fim == "show") stop, do_show = true, true
7979
elseif (fim == "set") do_set = true
@@ -82,7 +82,7 @@ function subplot(fim::String, stop::Bool, d::Dict{Symbol, Any})
8282
do_show = (d[:show] != 0)
8383
stop = true
8484
else
85-
if (!stop && has_options) stop = true end # To account for the subplot() call case
85+
if (!stop && !has_options) stop = true end # To account for the subplot() call case
8686
end
8787
# ------------------------------ End parsing inputs --------------------------------
8888

0 commit comments

Comments
 (0)