Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions src/common_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ function parse_c(d::Dict, cmd::String)::Tuple{String, String}
if ((val = find_in_dict(d, [:c :panel])[1]) !== nothing)
if (isa(val, Tuple) || isa(val, Array{<:Real}) || isa(val, Integer))
opt_val = arg2str(val .- 1, ',')
elseif (isa(val, String) || isa(val, Symbol))
elseif (isa(val, StrSymb))
_val::String = string(val) # In case it was a symbol
if ((ind = findfirst(",", _val)) !== nothing) # Shit, user really likes complicating
opt_val = string(parse(Int, val[1:ind[1]-1]) - 1, ',', parse(Int, _val[ind[1]+1:end]) - 1)
Expand Down Expand Up @@ -1648,8 +1648,8 @@ end

# ---------------------------------------------------------------------------------------------------
function parse_write(d::Dict, cmd::String)::String
if ((val = find_in_dict(d, [:write :savefile :|>], true)[1]) !== nothing)
cmd *= " > " * val::String
if ((val = hlp_desnany_str(d, [:write :savefile :|>])) !== "")
cmd *= " > " * val
end
return cmd
end
Expand Down Expand Up @@ -1744,7 +1744,7 @@ function parse_common_opts(d::Dict, cmd::String, opts::VMs; first::Bool=true, is
CURRENT_VIEW[1] = "" # Ensure we start empty
end
end
((val = find_in_dict(d, [:pagecolor])[1]) !== nothing) && (cmd *= string(" --PS_PAGE_COLOR=", val)::String)
((val = hlp_desnany_str(d, [:pagecolor])) !== "") && (cmd *= string(" --PS_PAGE_COLOR=", val))
return cmd, o
end

Expand All @@ -1753,7 +1753,7 @@ function parse_theme(d::Dict, del::Bool=true)
# This must always be processed before parse_B so it's the first call in that function
if ((val = find_in_dict(d, [:theme], del)[1]) !== nothing)
isa(val, NamedTuple) && theme(string(val[1])::String; nt2dict(val)...)
(isa(val, String) || isa(val, Symbol)) && theme(string(val)::String)
(isa(val, StrSymb)) && theme(string(val)::String)
end
end

Expand Down Expand Up @@ -2223,7 +2223,7 @@ end

# ---------------------------------------------------------------------------------------------------
function finish_PS(d::Dict, cmd::String, output::String, K::Bool, O::Bool)::String
if (!O && ((val = find_in_dict(d, [:P :portrait])[1]) === nothing)) cmd *= " -P" end
if (!O && ((val = hlp_desnany_str(d, [:P :portrait])) === "")) cmd *= " -P" end

opt = (K && !O) ? " -K" : ((K && O) ? " -K -O" : "")

Expand Down Expand Up @@ -2666,7 +2666,7 @@ function add_opt_cpt(d::Dict, cmd::String, symbs::VMs, opt::Char, N_args::Int=0,
cmd, arg1, arg2, N_args = helper_add_cpt(cmd, opt, N_args, arg1, arg2, CURRENT_CPT[1], false)
end
if (occursin(" -C", cmd))
if ((val = find_in_dict(d, [:hinge])[1]) !== nothing) cmd *= string("+h", val)::String end
if ((val = hlp_desnany_str(d, [:hinge])) !== "") cmd *= string("+h", val) end
if ((val = find_in_dict(d, [:meter2unit])[1]) !== nothing) cmd *= "+U" * parse_unit_unit(val)::String end
if ((val = find_in_dict(d, [:unit2meter])[1]) !== nothing) cmd *= "+u" * parse_unit_unit(val)::String end
end
Expand Down Expand Up @@ -2906,7 +2906,7 @@ end

# ---------------------------
function parse_unit_unit(str)::String
!isa(str, StrSymb) && error("Argument data type must be String or Symbol but was: $(typeof(str))")
@assert isa(str, StrSymb) error("Argument data type must be String or Symbol but was: $(typeof(str))")
if (isa(str, Symbol)) str = string(str) end

if (str == "e" || str == "meter") out = "e";
Expand Down Expand Up @@ -3313,8 +3313,8 @@ function vector_attrib(d::Dict)::String
end
end

if ((val = find_in_dict(d, [:half :half_arrow])[1]) !== nothing)
cmd = (val == "left" || val == :left) ? cmd * "+l" : cmd * "+r"
if ((val = hlp_desnany_str(d, [:half :half_arrow])) !== "")
cmd = (val == "left") ? cmd * "+l" : cmd * "+r"
end

if (haskey(d, :fill))
Expand Down Expand Up @@ -3364,8 +3364,8 @@ function vector4_attrib(; kwargs...)::String
# Old GMT4 vectors (still supported in GMT6)
d = KW(kwargs)
cmd::String = "t"
if ((val = find_in_dict(d, [:align :center])[1]) !== nothing)
c::Char = string(val)[1]
if ((val = hlp_desnany_str(d, [:align :center])) !== "")
c::Char = val[1]
if (c == 'h' || c == 'b') cmd = "h" # Head
elseif (c == 'm' || c == 'c') cmd = "b" # Middle
elseif (c == 'p') cmd = "s" # Point
Expand Down Expand Up @@ -3519,10 +3519,10 @@ function helper_decorated(d::Dict, compose=false)
end
end
if (cmd == "" && optD == "")
optD = ((val = find_in_dict(d, [:n_labels :n_symbols])[1]) !== nothing) ? string("n",val) : "n1"
optD = ((val = hlp_desnany_str(d, [:n_labels :n_symbols])) !== "") ? string("n",val) : "n1"
end
if (cmd == "")
if ((val = find_in_dict(d, [:N_labels :N_symbols])[1]) !== nothing)
if ((val = hlp_desnany_str(d, [:N_labels :N_symbols])) !== "")
optD = string("N", val);
end
end
Expand Down Expand Up @@ -3581,8 +3581,8 @@ function fname_out(d::Dict, del::Bool=false)
# Create a file name in the TMP dir when OUT holds only a known extension. The name is: GMT_user.ext

EXT::String = FMT[1]; fname::AbstractString = ""
if ((val = find_in_dict(d, [:savefig :figname :name], del)[1]) !== nothing)
fname, EXT = splitext(string(val)::String)
if ((val = hlp_desnany_str(d, [:savefig :figname :name], del)) !== "")
fname, EXT = splitext(val)
EXT = (EXT == "") ? FMT[1] : EXT[2:end]
end
if (EXT == FMT[1] && haskey(d, :fmt))
Expand Down Expand Up @@ -4063,9 +4063,9 @@ end
# ---------------------------------------------------------------------------------------------------
function write_data(d::Dict, cmd::String)::String
# Check if we need to save to file (redirect stdout)
if ((val = find_in_dict(d, [:|>])[1]) !== nothing) cmd = string(cmd, " > ", val)
elseif ((val = find_in_dict(d, [:write])[1]) !== nothing) cmd = string(cmd, " > ", val)
elseif ((val = find_in_dict(d, [:append])[1]) !== nothing) cmd = string(cmd, " >> ", val)
if ((val = hlp_desnany_str(d, [:|>])) !== "") cmd = string(cmd, " > ", val)
elseif ((val = hlp_desnany_str(d, [:write])) !== "") cmd = string(cmd, " > ", val)
elseif ((val = hlp_desnany_str(d, [:append])) !== "") cmd = string(cmd, " >> ", val)
end
return cmd
end
Expand Down Expand Up @@ -4103,8 +4103,9 @@ function dbg_print_cmd(d::Dict, cmd::Vector{String})

if (SHOW_KWARGS[1]) SHOW_KWARGS[1] = false; return "" end # If in HELP mode

if ( ((Vd = find_in_dict(d, [:Vd])[1]) !== nothing) || CONVERT_SYNTAX[1])
if ( ((val = find_in_dict(d, [:Vd])[1]) !== nothing) || CONVERT_SYNTAX[1])
(CONVERT_SYNTAX[1]) && return update_cmds_history(cmd) # For movies mainly.
Vd::Int = Int(val)
(Vd <= 0) && (d[:Vd] = 0) # Later, if Vd == 0, do not print the "not consumed" warnings
(Vd <= 0) && return nothing

Expand Down Expand Up @@ -4190,7 +4191,7 @@ function showfig(d::Dict, fname_ps::String, fname_ext::String, opt_T::String, K:

if (opt_T != "")
(K) && close_PS_file(fname_ps) # Close the PS file first
((val = find_in_dict(d, [:dpi :DPI])[1]) !== nothing) && (opt_T *= string(" -E", val))
((val = hlp_desnany_str(d, [:dpi :DPI])) !== "") && (opt_T *= " -E" * val)
gmt(pscvt_cmd * fname_ps * opt_T * " *")
reset_theme()
out::String = fname_ps[1:end-2] * fname_ext
Expand Down Expand Up @@ -4680,8 +4681,8 @@ function put_in_legend_bag(d::Dict, cmd, arg, O::Bool=false, opt_l::String="")
elseif (_valLabel !== nothing)
valLabel_vec = [string.(_valLabel)...] # We may have shits here
end
if ((ribs = find_in_dict(dd, [:ribbon :band], false)[1]) !== nothing)
(valLabel != "") && (valLabel_vec = [valLabel, string(ribs)::String]; valLabel="") # *promote* valLabel
if ((ribs = hlp_desnany_str(dd, [:ribbon :band], false)) !== "")
(valLabel != "") && (valLabel_vec = [valLabel, ribs]; valLabel="") # *promote* valLabel
have_ribbon = true
end

Expand Down
4 changes: 2 additions & 2 deletions src/extras/whittaker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ plot(t, v, legend="Noisy", plot=(data=[t _v], lc=:green, lt=1, legend="Original"
plot!(t, z, lc=:red, lt=1, legend="Degree 3", show=1)
```
"""
function whittaker(D::GMTdataset, lambda, d=2; weights=nothing)
function whittaker(D::GMTdataset, lambda::Real, d::Int=2; weights=nothing)
indNaN = isnan.(view(D.data, :, 2))
gotNaN = any(indNaN)
if (!gotNaN)
Expand All @@ -59,7 +59,7 @@ function whittaker(D::GMTdataset, lambda, d=2; weights=nothing)
end

# ------------------------------------------------------------------------------------
function whittaker(x::AbstractVecOrMat{<:Real}, y::AbstractVecOrMat{<:Real}, lambda, d=2; weights=nothing, checkedNaN::Bool=false)
function whittaker(x::AbstractVecOrMat{<:Real}, y::AbstractVecOrMat{<:Real}, lambda::Real, d::Int=2; weights=nothing, checkedNaN::Bool=false)
y, gotNaN, indNaN, weights = helper_whits(y, weights, checkedNaN) # Check NaNs and take measures if yes
m = length(y)
D = ddmat(x, d)
Expand Down
4 changes: 2 additions & 2 deletions src/potential/gmtgravmag3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ function gravmag3d_helper(cmd0::String, arg1; kwargs...)
arg1 = v
end
isa(arg1, Matrix{<:AbstractFloat}) && (arg1 = mat2ds(arg1)) # Ensure we always send a GMTdataset
gravmag3d_helper(arg1, d)
_gravmag3d_helper(arg1, d)
end

# ---------------------------------------------------------------------------------------------------
function gravmag3d_helper(arg1, d::Dict{Symbol,Any})
function _gravmag3d_helper(arg1, d::Dict{Symbol,Any})

cmd = parse_common_opts(d, "", [:G :RIr :V_params :bi :f])[1]
cmd = parse_these_opts(cmd, d, [[:C :density], [:E :thickness], [:L :z_obs :observation_level], [:S :radius], [:Z :level :reference_level]])
Expand Down
15 changes: 11 additions & 4 deletions src/utils_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ end
function _mat2ds(mat::Array{T,N}, txt::Union{String,Vector{String}}, hdr::Vector{String}, geom::Int, d::Dict)::GDtype where {T<:Real, N}

(!isempty(txt)) && return text_record(mat, txt, hdr)
((_text = find_in_dict(d, [:text])[1]) !== nothing) && return text_record(mat, _text, hdr)
if ((_text = find_in_dict(d, [:text])[1]) !== nothing && !isempty(_text))
Dt = text_record(mat, _text, hdr); Dt.geom = geom
return Dt
end

is3D = (find_in_dict(d, [:is3D])[1] === nothing) ? false : true # Should account for is3D == false?
isa(mat, Vector) && (mat = reshape(mat, length(mat), 1))

Expand Down Expand Up @@ -486,7 +490,7 @@ function add2ds!(D::GMTdataset{T,2}, mat, ind::Int=0; name::AbstractString="", n
if (!isempty(D.colnames))
t_col = (!isempty(D.text) && length(D.colnames) > size(D,2)) ? D.colnames[end] : ""
end
if (ind == 0 || ind == size(D,2))
if (ind == 0)
if (!isempty(D.colnames))
(size(D,2) > length(D.colnames)) && (append!(D.colnames, ["Bug"])) # I fck cant get rid of this
D.colnames = !isempty(t_col) ? [D.colnames[1:size(D,2)]..., _names..., t_col] : [D.colnames[1:size(D,2)]..., _names...]
Expand All @@ -496,8 +500,8 @@ function add2ds!(D::GMTdataset{T,2}, mat, ind::Int=0; name::AbstractString="", n
D.data = hcat(isvector(mat) ? mat[:] : mat, D.data)
!isempty(D.colnames) && (D.colnames = [_names..., D.colnames...])
else
D.data = isvector(mat) ? hcat(D.data[:,1:ind-1], mat[:], D.data[:,ind+1:end]) : hcat(D.data[:,1:ind-1], mat, D.data[:,ind+1:end])
!isempty(D.colnames) && (D.colnames = [D.colnames[1:ind-1]..., _names..., D.colnames[ind+1:end]...])
D.data = isvector(mat) ? hcat(D.data[:,1:ind-1], mat[:], D.data[:,ind:end]) : hcat(D.data[:,1:ind-1], mat, D.data[:,ind:end])
!isempty(D.colnames) && (D.colnames = [D.colnames[1:ind-1]..., _names..., D.colnames[ind:end]...])
end
set_dsBB!(D)
return nothing
Expand Down Expand Up @@ -2534,6 +2538,9 @@ mksymbol(f::Function, arg1; kw...) = mksymbol(f, "", arg1; kw...)
function hlp_desnany_str(d, s, del=true)::String
((val = find_in_dict(d, s, del)[1]) === nothing) ? "" : string(val)
end
function hlp_desnany_arg2str(d, s, del=true)::String
((val = find_in_dict(d, s, del)[1]) === nothing) ? "" : arg2str(val)
end

# ---------------------------------------------------------------------------------------------------
function hlp_desnany_vstr(d, s)::Vector{String}
Expand Down
Loading