Skip to content

Commit

Permalink
Merge pull request #463 from GenericMappingTools/more-types2
Browse files Browse the repository at this point in the history
More types2
  • Loading branch information
joa-quim authored Oct 14, 2020
2 parents 07fcc79 + ef0238f commit ac8fb5a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GMT"
uuid = "5752ebe1-31b9-557e-87aa-f909b540aa54"
authors = ["Joaquim Luis <jluis@ualg.pt>"]
version = "0.25.0"
version = "0.26.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
3 changes: 1 addition & 2 deletions src/GMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const def_fig_axes = " -Baf -BWSen" # Default fig axes for plot like pro
const def_fig_axes3 = " -Baf -Bza" # "" but for 3D views

if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@optlevel"))
@eval Base.Experimental.@optlevel 1
@eval Base.Experimental.@optlevel 1
end

export
Expand Down Expand Up @@ -165,7 +165,6 @@ end
if (GMTver >= 6) include("get_enums.jl") end # Needed to cheat the autoregister autobot

include("precompile_GMT_i.jl")
#include("c:\\v\\precompile\\precompile_GMT.jl")
_precompile_()

end # module
16 changes: 8 additions & 8 deletions src/common_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1476,15 +1476,15 @@ function add_opt(d::Dict, cmd::String, opt, symbs, need_symb::Symbol, args, nt_o
di = nt2dict(val)
((val = find_in_dict(di, [need_symb], false)[1]) === nothing) && error(string(need_symb, " member cannot be missing"))
if (isa(val, Number) || isa(val, String)) # So that this (psxy) also works: Z=(outline=true, data=3)
opt *= string(val)
opt::String = string(opt,val)
to_slot = false
end
cmd = add_opt(d, cmd, opt, symbs, nt_opts)
elseif (isa(val, Array{<:Real}) || isa(val, GMTdataset) || isa(val, Vector{<:GMTdataset}) || isa(val, GMTcpt) || typeof(val) <: AbstractRange)
if (typeof(val) <: AbstractRange) val = collect(val) end
cmd *= " -" * opt
cmd::String = string(cmd, " -", opt)
elseif (isa(val, String) || isa(val, Symbol) || isa(val, Number))
cmd *= " -" * opt * arg2str(val)
cmd = string(cmd, " -", opt * arg2str(val))
to_slot = false
else
error(@sprintf("Bad argument type (%s) to option %s", typeof(val), opt))
Expand Down Expand Up @@ -1599,7 +1599,7 @@ function add_opt_fill(val, cmd::String="", opt="")::String
end

# ---------------------------------------------------------------------------------------------------
function get_cpt_set_R(d::Dict, cmd0::String, cmd::String, opt_R::String, got_fname, arg1, arg2=nothing, arg3=nothing, prog::String="")
function get_cpt_set_R(d::Dict, cmd0::String, cmd::String, opt_R::String, got_fname::Int, arg1, arg2=nothing, arg3=nothing, prog::String="")
# Get CPT either from keyword input of from current_cpt.
# Also puts -R in cmd when accessing grids from grdimage|view|contour, etc... (due to a GMT bug that doesn't do it)
# Use CMD0 = "" to use this function from within non-grd modules
Expand All @@ -1608,12 +1608,12 @@ function get_cpt_set_R(d::Dict, cmd0::String, cmd::String, opt_R::String, got_fn
if (isa(arg1, GMTgrid) || isa(arg1, GMTimage)) # GMT bug, -R will not be stored in gmt.history
range = arg1.range
elseif (cmd0 != "" && cmd0[1] != '@')
info = grdinfo(cmd0 * " -C"); range = info[1].data
info::Array{GMT.GMTdataset,1} = grdinfo(cmd0 * " -C"); range = info[1].data
end
if (isa(arg1, GMTgrid) || isa(arg1, GMTimage) || (cmd0 != "" && cmd0[1] != '@'))
if (current_cpt === nothing && (val = find_in_dict(d, [:C :color :cmap], false)[1]) === nothing)
# If no cpt name sent in, then compute (later) a default cpt
cpt_opt_T = @sprintf(" -T%.16g/%.16g/128+n", range[5] - eps()*100, range[6] + eps()*100)
cpt_opt_T::String = @sprintf(" -T%.16g/%.16g/128+n", range[5] - eps()*100, range[6] + eps()*100)
end
if (opt_R == "" && (!IamModern[1] || (IamModern[1] && FirstModern[1])) ) # No -R ovewrite by accident
cmd *= @sprintf(" -R%.14g/%.14g/%.14g/%.14g", range[1], range[2], range[3], range[4])
Expand Down Expand Up @@ -2756,9 +2756,9 @@ function finish_PS_module(d::Dict, cmd::Vector{String}, opt_extra::String, K::Bo
if ((proj4 != "") && !startswith(proj4, "+proj=lat") && !startswith(proj4, "+proj=lon"))
opt_J = replace(proj4, " " => "")
lims = args[1].range
D = mapproject([lims[1] lims[3]; lims[2] lims[4]], J=opt_J, I=true)
D::Vector{GMTdataset} = mapproject([lims[1] lims[3]; lims[2] lims[4]], J=opt_J, I=true)
mm = extrema(D[1].data, dims=1)
opt_R = @sprintf(" -R%f/%f/%f/%f+r ", mm[1][1],mm[2][1],mm[1][2],mm[2][2])
opt_R::String = @sprintf(" -R%f/%f/%f/%f+r ", mm[1][1],mm[2][1],mm[1][2],mm[2][2])
o = scan_opt(cmd[1], "-J")
if (o[1] == 'x') size_ = "+scale=" * o[2:end]
elseif (o[1] == 'X') size_ = "+width=" * o[2:end]
Expand Down
4 changes: 2 additions & 2 deletions src/grdimage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function common_shade(d::Dict, cmd::String, arg1, arg2, arg3, arg4, prog)
end

# ---------------------------------------------------------------------------------------------------
function common_get_R_cpt(d::Dict, cmd0::String, cmd::String, opt_R, got_fname, arg1, arg2, arg3, prog::String)
function common_get_R_cpt(d::Dict, cmd0::String, cmd::String, opt_R::String, got_fname::Int, arg1, arg2, arg3, prog::String)
# Used by several proggys
if (convert_syntax[1]) # Here we cannot rist to execute any code. Just parsing. Movie stuff
cmd, = add_opt_cpt(d, cmd, [:C :color :cmap], 'C')
Expand All @@ -146,5 +146,5 @@ end
grdimage!(cmd0::String="", arg1=nothing, arg2=nothing, arg3=nothing; kw...) =
grdimage(cmd0, arg1, arg2, arg3; first=false, kw...)

grdimage(arg1, arg2=nothing, arg3=nothing; kw...) = grdimage("", arg1, arg2, arg3; first=true, kw...)
grdimage(arg1, arg2=nothing, arg3=nothing; kw...) = grdimage("", arg1, arg2, arg3; first=true, kw...)
grdimage!(arg1, arg2=nothing, arg3=nothing; kw...) = grdimage("", arg1, arg2, arg3; first=false, kw...)
6 changes: 3 additions & 3 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,10 @@ function cat_1_arg(arg)
# Add a first column with 1:n to all args that are not GMTdatasets
(isa(arg, Array{<:GMTdataset,1}) || isa(arg, GMTdataset)) && return arg
if (isa(arg, Vector) || typeof(arg) <: AbstractRange)
arg = hcat(1:size(arg,1), arg)
#arg = hcat(collect(eltype(arg), 1:size(arg,1)), arg)
#arg = hcat(collect(1:size(arg,1)), arg)
arg = hcat(collect(eltype(arg), 1:size(arg,1)), arg)
elseif (isa(arg, NTuple))
arg = hcat(1:length(arg), collect(arg))
arg = hcat(collect(eltype(arg), 1:length(arg)), collect(arg))
end
return arg
end
Expand Down
2 changes: 1 addition & 1 deletion src/pscontour.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function contour(cmd0::String="", arg1=nothing; first=true, kwargs...)
arg2 = nothing; arg3 = nothing
cmd, arg1, opt_R, info = read_data(d, cmd0, cmd, arg1, opt_R, false, true)
if (occursin(" -I", cmd) || occursin("+c", opt_W)) # Only try to load cpt if -I was set
cmd, N_used_, arg1, arg2, arg3 = get_cpt_set_R(d, "", cmd, opt_R, (arg1 === nothing), arg1, arg2, arg3, "pscontour")
cmd, N_used_, arg1, arg2, arg3 = get_cpt_set_R(d, "", cmd, opt_R, (arg1 === nothing ? 1 : 0), arg1, arg2, arg3, "pscontour")
end
N_used = (arg1 !== nothing) + (arg2 !== nothing) + (arg3 !== nothing)

Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,9 @@ if (got_it) # Otherwise go straight to end
histogram(I16, zoom=true, Vd=dbg2);
histogram(I16, S=1, Vd=dbg2);
histogram(I16, I=:O);
G = GMT.peaks();
histogram(G, Vd=dbg2);
histogram(G, T=0.3, Vd=dbg2);

println(" PSLEGEND")
# PSLEGEND
Expand Down

0 comments on commit ac8fb5a

Please sign in to comment.