diff --git a/src/GMT.jl b/src/GMT.jl index d623f3481..ad22473d2 100644 --- a/src/GMT.jl +++ b/src/GMT.jl @@ -53,7 +53,7 @@ else const GMTdevdate = Date(devdate, dateformat"y.m.d") # 'devdate' comes from reading 'deps.jl' end -const global G_API = [C_NULL] +const G_API = Ref{Ptr{Cvoid}}(C_NULL) const PSname = Ref{String}("") # The PS file (filled in __init__) where, in classic mode, all lands. const global TMPDIR_USR = [tempdir(), "", ""] # Save the tmp dir and user name (also filled in __init__) const global TESTSDIR = joinpath(dirname(pathof(GMT))[1:end-4], "test", "") # To have easy access to test files @@ -78,7 +78,7 @@ const noGrdCopy = Ref{Bool}(false) # If true, grids are sent without transpos const GMTCONF = Ref{Bool}(false) # Flag if gmtset was used and must be 'unused' const FMT = Ref{String}("png") # The default plot format const BOX_STR = Ref{String}("") # Used in plotyy to know -R of first call -const global POSTMAN = [Dict{String,String}()] # To pass messages to functions (start with get_dataset) +const POSTMAN = Ref{Dict{String,String}}(Dict{String,String}()) # To pass messages to functions (start with get_dataset) #const global SACO = [Dict{String,Union{AbstractArray, Vector{AbstractArray}}}()] # When funs (fillsinks) want to return extra data but not via the return mechanism const DEF_FIG_SIZE = "15c/10c" # Default fig size for plot like programs. Approx 16/11 const DEF_FIG_AXES_BAK = " -Baf -BWSen" # Default fig axes for plot like programs @@ -219,13 +219,13 @@ include("gdal/gdal.jl") include("gdal_utils.jl") include("proj_utils.jl") const global MatGDsGd = Union{Matrix{<:AbstractFloat}, GMTdataset, Vector{<:GMTdataset}, Gdal.AbstractDataset} -const global CURRENT_CPT = [GMTcpt()] # To store the current palette +const CURRENT_CPT = Ref{GMTcpt}(GMTcpt()) # To store the current palette include("gmt_main.jl") include("utils_types.jl") include("grd_operations.jl") include("common_options.jl") -const global LEGEND_TYPE = [legend_bag()] # To store Legends info +const LEGEND_TYPE = Ref{legend_bag}(legend_bag()) # To store Legends info include("beziers.jl") include("circfit.jl") include("crop.jl") @@ -380,7 +380,6 @@ include("windbarbs/windbarbs.jl") include("zscale.jl") include("get_enums.jl") - using .Gdal using .Laszip @@ -388,7 +387,7 @@ using .Laszip #using .ImageFeatures @compile_workload begin - G_API[1] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) + G_API[] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) #GMT.parse_B(Dict{Symbol, Any}(:frame => (annot=10, title="Ai Ai"), :grid => (pen=2, x=10, y=20)), "", " -Baf -BWSen"); #GMT.parse_R(Dict{Symbol, Any}(:xlim => (1,2), :ylim => (3,4), :zlim => (5,6)), ""); #GMT.parse_J(Dict{Symbol, Any}(:J => "X", :scale => "1:10"), ""); @@ -462,7 +461,7 @@ end function __init__(test::Bool=false) clear_sessions(3600) # Delete stray sessions dirs older than 1 hour - G_API[1] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) # (0.010179 sec) + G_API[] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) # (0.010179 sec) theme_modern() # Set the MODERN theme and some more gmtlib_setparameter() calls haskey(ENV, "JULIA_GMT_IMGFORMAT") && (FMT[] = ENV["JULIA_GMT_IMGFORMAT"]) f = joinpath(GMTuserdir[1], "theme_jl.txt") diff --git a/src/blendimg.jl b/src/blendimg.jl index 5d877db12..89aff88eb 100644 --- a/src/blendimg.jl +++ b/src/blendimg.jl @@ -342,7 +342,7 @@ function lelandshade(G::GMTgrid; detail=1.0, contrast=2.0, uint16=false, intensi _cpt = iscptmaster ? cmap : nothing if (cmap != "") cpt = cmap - isa(cpt, GMTcpt) && (CURRENT_CPT[1] = cpt) + isa(cpt, GMTcpt) && (CURRENT_CPT[] = cpt) elseif (equalize == 0) cpt = makecpt(G; C=_cpt, Vd=-1, kw...) # The 'nothing' branch will pick G's cpt else diff --git a/src/choropleth_utils.jl b/src/choropleth_utils.jl index 0de29ea0b..a72521851 100644 --- a/src/choropleth_utils.jl +++ b/src/choropleth_utils.jl @@ -32,7 +32,7 @@ function cpt4dcw(codes::Vector{<:AbstractString}, vals::Vector{<:Real}; kwargs.. while(_vals[k] > C.minmax[2] && k > 0) c[k] = false; k -= 1 end _codes, _vals = _codes[c], _vals[c] - P::Ptr{GMT_PALETTE} = palette_init(G_API[1], C) # A pointer to a GMT CPT + P::Ptr{GMT_PALETTE} = palette_init(G_API[], C) # A pointer to a GMT CPT Ccat::GMTcpt = gmt("makecpt -T"*join(_codes, ",")) rgb = [0.0, 0.0, 0.0, 0.0]; @@ -40,7 +40,7 @@ function cpt4dcw(codes::Vector{<:AbstractString}, vals::Vector{<:Real}; kwargs.. inc = (C.minmax[2] - C.minmax[1]) / size(Ccat.cpt, 1) for k = 1:size(Ccat.cpt, 1) - gmt_get_rgb_from_z(G_API[1], P, _vals[k], rgb) + gmt_get_rgb_from_z(G_API[], P, _vals[k], rgb) Ccat.colormap[k, 1], Ccat.colormap[k, 2], Ccat.colormap[k, 3] = rgb[1], rgb[2], rgb[3] _rgb[1], _rgb[2], _rgb[3] = rgb[1], rgb[2], rgb[3] [Ccat.cpt[k, n+1] = copy(_rgb[(n % 3) + 1]) for n = 0:5] # cpt = [rgb rgb] diff --git a/src/common_options.jl b/src/common_options.jl index 097a1904c..8c943d758 100644 --- a/src/common_options.jl +++ b/src/common_options.jl @@ -1004,7 +1004,7 @@ function parse_B(d::Dict, cmd::String, opt_B__::String="", del::Bool=true)::Tupl if (haskey(d, :xlabel)) _val = "-BS"; have_a_none = true # Unless labels are wanted, but elseif (haskey(d, :ylabel)) _val = "-BW"; have_a_none = true # GMT Bug forces using tricks elseif (haskey(d, :title)) _val = ""; have_a_none = true - else POSTMAN[1]["noframe"] = "y"; return cmd, "" + else POSTMAN[]["noframe"] = "y"; return cmd, "" end elseif (_val == "noannot" || _val == "bare") return cmd * " -B0", " -B0" @@ -2226,7 +2226,7 @@ function finish_PS(d::Dict, cmd::String, output::String, K::Bool, O::Bool)::Stri else if ((K && !O) || (!K && !O) || O) cmd *= opt end end - !O && !startswith(cmd, "psxy") && (LEGEND_TYPE[1] = legend_bag()) # Make sure that we always start with an empty one + !O && !startswith(cmd, "psxy") && (LEGEND_TYPE[] = legend_bag()) # Make sure that we always start with an empty one return cmd end @@ -2637,11 +2637,11 @@ function add_opt_cpt(d::Dict, cmd::String, symbs::VMs, opt::Char, N_args::Int=0, if (store && c != "" && tryparse(Float32, c) === nothing) # Because if !== nothing then it's a number and -Cn is not valid try # Wrap in try because not always (e.g. grdcontour -C) this is a makecpt callable r = isa(arg1, GMTgrid) ? makecpt(arg1, C=c) : makecpt_raw("makecpt -Vq " * opt_C) - CURRENT_CPT[1] = (r !== nothing) ? r : GMTcpt() + CURRENT_CPT[] = (r !== nothing) ? r : GMTcpt() catch end - elseif (in_bag && !isempty(CURRENT_CPT[1])) # If we have something in Bag, return it - cmd, arg1, arg2, N_args = helper_add_cpt(cmd, "", N_args, arg1, arg2, CURRENT_CPT[1], false) + elseif (in_bag && !isempty(CURRENT_CPT[])) # If we have something in Bag, return it + cmd, arg1, arg2, N_args = helper_add_cpt(cmd, "", N_args, arg1, arg2, CURRENT_CPT[], false) end end end @@ -2655,8 +2655,8 @@ function add_opt_cpt(d::Dict, cmd::String, symbs::VMs, opt::Char, N_args::Int=0, cpt.bfn[3, :] = [1.0 1.0 1.0] # Some deep bug, in occasions, returns grays on 2nd and on calls end cmd, arg1, arg2, N_args = helper_add_cpt(cmd, opt, N_args, arg1, arg2, cpt, store) - elseif (in_bag && !isempty(CURRENT_CPT[1])) # If everything else has failed and we have one in the Bag, return it - cmd, arg1, arg2, N_args = helper_add_cpt(cmd, opt, N_args, arg1, arg2, CURRENT_CPT[1], false) + elseif (in_bag && !isempty(CURRENT_CPT[])) # If everything else has failed and we have one in the Bag, return it + cmd, arg1, arg2, N_args = helper_add_cpt(cmd, opt, N_args, arg1, arg2, CURRENT_CPT[], false) end if (occursin(" -C", cmd)) @@ -2671,7 +2671,7 @@ end function helper_add_cpt(cmd::String, opt, N_args::Int, arg1, arg2, val::GMTcpt, store::Bool) # Helper function to avoid repeating 3 times the same code in add_opt_cpt (N_args == 0) ? arg1 = val : arg2 = val; N_args += 1 - if (store) global CURRENT_CPT[1] = val end + if (store) global CURRENT_CPT[] = val end ((isa(opt, Char) || (isa(opt, String) && opt != "")) && !contains(cmd, " -"*opt)) && (cmd *= " -" * opt) return cmd, arg1, arg2, N_args end @@ -2743,7 +2743,7 @@ function get_cpt_set_R(d::Dict, cmd0::String, cmd::String, opt_R::String, got_fn if (isa(arg1, GItype) || (cmd0 != "" && cmd0[1] != '@')) val, symb = find_in_dict(d, CPTaliases, false) - if (isempty(CURRENT_CPT[1]) && val === nothing) + if (isempty(CURRENT_CPT[]) && val === nothing) # If no cpt name sent in, then compute (later) a default cpt if (isa(arg1, GMTgrid) && ((val = find_in_dict(d, [:percent :pct])[1])) !== nothing) lh = quantile(any(!isfinite, arg1) ? skipnan(vec(arg1)) : vec(arg1), [(100 - val)/200, (1 - (100 - val)/200)]) @@ -2812,7 +2812,7 @@ function makecpt_raw(cmd::String, arg1=nothing)::GMTcpt _r = gmt_GMTcpt(cmd, arg1) r::GMTcpt = (_r !== nothing) ? _r : GMTcpt() # _r === nothing when we save CPT on disk. (contains(cmd, " -N") && !isempty(r)) && (r.bfn = ones(3,3)) # Cannot remove the bfn like in plain GMT so make it all whites - CURRENT_CPT[1] = r + CURRENT_CPT[] = r return r end @@ -2821,7 +2821,7 @@ function get_colorbar_pos(anchor) hack_modern_session(CTRL.pocket_R[1], CTRL.pocket_J[1] * CTRL.pocket_J[3], " -Baf -Bza", fullremove=true) # Start a modern session justify = anchor == "TC" ? 10 : (anchor == "BC" ? 2 : (anchor == "LM" ? 5 : 7)) p_offset = pointer([0.0, 0.0]) - GMT_ = GMT_Get_Ctrl(G_API[1]) + GMT_ = GMT_Get_Ctrl(G_API[]) ccall((:gmt_auto_offsets_for_colorbar, libgmt), Cvoid, (Cstring, Ptr{Cdouble}, Int32, Ptr{Cvoid}), GMT_, p_offset, justify, pointer([NULL])) gmtend(reset=false) # hack_modern_session() issued the opening gmtbegin() call offset = [unsafe_load(p_offset,1), unsafe_load(p_offset,2)] @@ -4114,7 +4114,7 @@ function dbg_print_cmd(d::Dict, cmd::Vector{String}) CTRL.pocket_call[3] = nothing # This is mostly for testing purposes, but potentially needed elsewhere. CTRL.limits[1:12] = zeros(12) # Some times an automtic CPT has been generated by the Vd'ed cmd but when that happens MUST debug it - #CURRENT_CPT[1] = GMTcpt() # Can't do this because it would f. plot(..., colorbar=true) + #CURRENT_CPT[] = GMTcpt() # Can't do this because it would f. plot(..., colorbar=true) end if (length(d) > 0) dd = deepcopy(d) # Make copy so that we can harmlessly delete those below @@ -4122,7 +4122,7 @@ function dbg_print_cmd(d::Dict, cmd::Vector{String}) prog = isa(cmd, String) ? split(cmd)[1] : split(cmd[1])[1] (length(dd) > 0) && println("Warning: the following options were not consumed in $prog => ", keys(dd)) end - (size(LEGEND_TYPE[1].label, 1) != 0) && (LEGEND_TYPE[1].Vd = Vd) # So that autolegend can also work + (size(LEGEND_TYPE[].label, 1) != 0) && (LEGEND_TYPE[].Vd = Vd) # So that autolegend can also work (Vd == 1) && println("\t", length(cmd) == 1 ? cmd[1] : cmd) (Vd >= 2) && return length(cmd) == 1 ? cmd[1] : cmd end @@ -4168,7 +4168,7 @@ function showfig(d::Dict{Symbol, Any}, fname_ps::String, fname_ext::String, opt_ # OPT_T holds the psconvert -T option, again when not PS # FNAME is for when using the savefig option - global CURRENT_CPT[1] = GMTcpt() # Reset to empty when fig is finalized + global CURRENT_CPT[] = GMTcpt() # Reset to empty when fig is finalized digests_legend_bag(d) # Plot the legend if requested @@ -4237,7 +4237,7 @@ end function desconf(resetdef::Bool=true) # Undo the gmtset() doing and delete eventual gmt.conf files in current dir. !GMTCONF[] && return nothing # No gmtset was used in classic or outside a modern mode block - resetdef && resetdefaults(G_API[1]) # Set the modern mode settings (will clear eventual gmt.conf contents) + resetdef && resetdefaults(G_API[]) # Set the modern mode settings (will clear eventual gmt.conf contents) isfile("gmt.conf") && rm("gmt.conf") # If gmt.conf file is to be kept, save it at ~.gmt/gmt.conf GMTCONF[] = false return nothing @@ -4250,7 +4250,7 @@ function showfig(; kwargs...) d = KW(kwargs) (!haskey(d, :show)) && (d[:show] = true) # The default is to show CTRL.limits .= 0.0; CTRL.proj_linear[1] = true; # Reset these for safety - !isempty(LEGEND_TYPE[1].optsDict) && (d[:legend] = dict2nt(LEGEND_TYPE[1].optsDict)) # Recover opt settings + !isempty(LEGEND_TYPE[].optsDict) && (d[:legend] = dict2nt(LEGEND_TYPE[].optsDict)) # Recover opt settings digests_legend_bag(d) # Plot the legend if requested arg = (isPSclosed[]) ? "" : "psxy -R0/1/0/1 -JX0.001c -T -O" # In Modern the PS is already closed finish_PS_module(d, arg, "", false, true, true) @@ -4267,7 +4267,7 @@ function helper_showfig4modern(show::String="show")::Bool IamModern[] = false call_display = false (isJupyter[] && show != "") && (show = ""; call_display = true) - (isFranklin[] || show == "") ? gmt("end") : (gmt("end " * show); CURRENT_CPT[1] = GMTcpt()) # isFranklin = true for docs + (isFranklin[] || show == "") ? gmt("end") : (gmt("end " * show); CURRENT_CPT[] = GMTcpt()) # isFranklin = true for docs isPSclosed[] = true desconf(false) # FALSE because modern mode calls do a gmt_restart() in the gmt() main function. call_display && showfig() # Fragile. How to assert that modern_fname is not empty? @@ -4571,19 +4571,19 @@ function finish_PS_module_barr_last(d::Dict{Symbol, Any}, cmd::Vector{String}, f if (fname_ext == "" && opt_extra == "") # Return result as an GMTimage P = showfig(d, output, fname_ext, "", K) CTRL.limits .= 0.0 - LEGEND_TYPE[1] = legend_bag() + LEGEND_TYPE[] = legend_bag() gmt_restart() # Returning a PS screws the session elseif ((haskey(d, :show) && d[:show] != 0) || fname != "" || opt_T != "") P = showfig(d, output, fname_ext, opt_T, K, fname) # Return something here for the case we are in Pluto (typeof(P) == Base.Process) && (P = nothing) # Don't want spurious message on REPL when plotting CTRL.IamInPaperMode[2] = true # Means, next time a paper mode is used offset XY only on first call CTRL.limits .= 0.0 - LEGEND_TYPE[1] = legend_bag() + LEGEND_TYPE[] = legend_bag() end elseif ((haskey(d, :show) && d[:show] != 0)) # Let modern mode also call show=true helper_showfig4modern() CTRL.limits .= 0.0 - LEGEND_TYPE[1] = legend_bag() + LEGEND_TYPE[] = legend_bag() end CTRL.XYlabels[1] = ""; CTRL.XYlabels[2] = ""; # Reset these in case they weren't empty show_non_consumed(d, cmd) @@ -4651,7 +4651,7 @@ end function show_non_consumed(d::Dict{Symbol, Any}, cmd) # First delete some that could not have been delete earlier (from legend for example) delete!(d, [[:fmt], [:show], [:leg, :legend, :l], [:box_pos], [:leg_pos], [:P, :portrait], [:this_cpt], [:linefit, :linearfit]]) - !isempty(CURRENT_CPT[1]) && delete!(d, [[:percent], [:clim]]) # To not (wrongly) complain about these + !isempty(CURRENT_CPT[]) && delete!(d, [[:percent], [:clim]]) # To not (wrongly) complain about these if (!haskey(d, :Vd) && length(d) > 0) # Vd, if exists, must be a Vd=0 to signal no warnings. prog = isa(cmd, String) ? split(cmd)[1] : split(cmd[1])[1] println("Warning: the following options were not consumed in $prog => ", keys(d)) @@ -4749,11 +4749,11 @@ function put_in_legend_bag(d::Dict, cmd, arg, O::Bool=false, opt_l::String="") for k = 1:numel(pens) pens[k] *= extra_opt end if ((ind = findfirst(arg.colnames .== "Zcolor")) !== nothing) rgb = [0.0, 0.0, 0.0, 0.0] - P::Ptr{GMT_PALETTE} = palette_init(G_API[1], CURRENT_CPT[1]) # A pointer to a GMT CPT - gmt_get_rgb_from_z(G_API[1], P, arg[gindex[1],ind], rgb) + P::Ptr{GMT_PALETTE} = palette_init(G_API[], CURRENT_CPT[]) # A pointer to a GMT CPT + gmt_get_rgb_from_z(G_API[], P, arg[gindex[1],ind], rgb) cmd_[1] *= " -G" * arg2str(rgb.*255) for k = 1:numel(pens) - gmt_get_rgb_from_z(G_API[1], P, arg[gindex[k+1],ind]+10eps(), rgb) + gmt_get_rgb_from_z(G_API[], P, arg[gindex[k+1],ind]+10eps(), rgb) pens[k] *= @sprintf(" -G%.0f/%.0f/%.0f", rgb[1]*255, rgb[2]*255, rgb[3]*255) end end @@ -4781,19 +4781,19 @@ function put_in_legend_bag(d::Dict, cmd, arg, O::Bool=false, opt_l::String="") for k = 1:nDs lab[k] = string('y',k) end end - (!O) && (LEGEND_TYPE[1] = legend_bag()) # Make sure that we always start with an empty one + (!O) && (LEGEND_TYPE[] = legend_bag()) # Make sure that we always start with an empty one - if (size(LEGEND_TYPE[1].label, 1) == 0) # First time - LEGEND_TYPE[1] = legend_bag(lab, [cmd_[1]], length(cmd_) == 1 ? [""] : [cmd_[2]], opt_l, dd, 0) + if (size(LEGEND_TYPE[].label, 1) == 0) # First time + LEGEND_TYPE[] = legend_bag(lab, [cmd_[1]], length(cmd_) == 1 ? [""] : [cmd_[2]], opt_l, dd, 0) # Forgot about the logic of the above and it errors when first arg is a GMTdataset vec, # so do this till a decent fix gets invented. - (length(lab) > 1) && (LEGEND_TYPE[1] = legend_bag(lab, cmd_, cmd_, opt_l, dd, 0)) + (length(lab) > 1) && (LEGEND_TYPE[] = legend_bag(lab, cmd_, cmd_, opt_l, dd, 0)) else - append!(LEGEND_TYPE[1].cmd, [cmd_[1]]) - append!(LEGEND_TYPE[1].cmd2, (length(cmd_) > 1) ? [cmd_[2]] : [""]) - append!(LEGEND_TYPE[1].label, lab) + append!(LEGEND_TYPE[].cmd, [cmd_[1]]) + append!(LEGEND_TYPE[].cmd2, (length(cmd_) > 1) ? [cmd_[2]] : [""]) + append!(LEGEND_TYPE[].label, lab) # If font, pos, etc are only given at end and no show() is used, they would get lost and not visible by showfig() - isempty(LEGEND_TYPE[1].optsDict) && (LEGEND_TYPE[1].optsDict = dd) + isempty(LEGEND_TYPE[].optsDict) && (LEGEND_TYPE[].optsDict = dd) end return nothing @@ -4802,44 +4802,44 @@ end # -------------------------------------------------------------------------------------------------- function digests_legend_bag(d::Dict{Symbol, Any}, del::Bool=true) # Plot a legend if the leg or legend keywords were used. Legend info is stored in LEGEND_TYPE global variable - (size(LEGEND_TYPE[1].label, 1) == 0) && return nothing + (size(LEGEND_TYPE[].label, 1) == 0) && return nothing dd::Dict{Symbol, Any} = ((val = find_in_dict(d, [:leg :legend :l], false)[1]) !== nothing && isa(val, NamedTuple)) ? nt2dict(val) : Dict{Symbol, Any}() kk, fs = 0, 8 # Font size in points symbW = 0.65 # Symbol width. Default to 0.75 cm (good for lines but bad for symbols) - nl, count_no = length(LEGEND_TYPE[1].label), 0 + nl, count_no = length(LEGEND_TYPE[].label), 0 leg::Vector{String} = Vector{String}(undef, 3nl) - all(contains.(LEGEND_TYPE[1].cmd, "-S")) && (symbW = 0.25) # When all entries are symbols shrink the 'symbW' + all(contains.(LEGEND_TYPE[].cmd, "-S")) && (symbW = 0.25) # When all entries are symbols shrink the 'symbW' - #lab_width = maximum(length.(LEGEND_TYPE[1].label[:])) * fs / 72 * 2.54 * 0.50 + 0.25 # Guess label width in cm + #lab_width = maximum(length.(LEGEND_TYPE[].label[:])) * fs / 72 * 2.54 * 0.50 + 0.25 # Guess label width in cm # Problem is that we may have a lot more chars in label than those effectively printed (PS octal chars etc) n_max_chars = 0 - for k = 1:numel(LEGEND_TYPE[1].label) - s = split(LEGEND_TYPE[1].label[k], "`") # Means that after the '`' comes the this string char counting - n_chars = (length(s) == 2) ? (LEGEND_TYPE[1].label[k] = s[1]; parse(Int,s[2])) : length(LEGEND_TYPE[1].label[k]) + for k = 1:numel(LEGEND_TYPE[].label) + s = split(LEGEND_TYPE[].label[k], "`") # Means that after the '`' comes the this string char counting + n_chars = (length(s) == 2) ? (LEGEND_TYPE[].label[k] = s[1]; parse(Int,s[2])) : length(LEGEND_TYPE[].label[k]) n_max_chars = max(n_chars, n_max_chars) end lab_width = n_max_chars * fs / 72 * 2.54 * 0.50 + 0.25 # Guess label width in cm for k = 1:nl # Loop over number of entries - (LEGEND_TYPE[1].label[k] == " ") && (count_no += 1; continue) # Sometimes we may want to open a leg entry but not plot it - if ((symb = scan_opt(LEGEND_TYPE[1].cmd[k], "-S")) == "") symb = "-" + (LEGEND_TYPE[].label[k] == " ") && (count_no += 1; continue) # Sometimes we may want to open a leg entry but not plot it + if ((symb = scan_opt(LEGEND_TYPE[].cmd[k], "-S")) == "") symb = "-" else symbW_ = symb[2:end]; end - ((fill = scan_opt(LEGEND_TYPE[1].cmd[k], "-G")) == "") && (fill = "-") - pen = scan_opt(LEGEND_TYPE[1].cmd[k], "-W"); + ((fill = scan_opt(LEGEND_TYPE[].cmd[k], "-G")) == "") && (fill = "-") + pen = scan_opt(LEGEND_TYPE[].cmd[k], "-W"); (pen == "" && symb[1] != '-' && fill != "-") ? pen = "-" : (pen == "" ? pen = "0.25p" : pen = pen) if (symb[1] == '-') leg[kk += 1] = @sprintf("S %.3fc %s %.2fc %s %s %.2fc %s", - symbW/2, symb[1], symbW, fill, pen, symbW+0.14, LEGEND_TYPE[1].label[k]) - if ((symb2 = scan_opt(LEGEND_TYPE[1].cmd2[k], "-S")) != "") # A line + a symbol + symbW/2, symb[1], symbW, fill, pen, symbW+0.14, LEGEND_TYPE[].label[k]) + if ((symb2 = scan_opt(LEGEND_TYPE[].cmd2[k], "-S")) != "") # A line + a symbol leg[kk += 1] = "G -1l" # Go back one line before plotting the overlaying symbol xx = split(pen, ',') if (length(xx) == 2) fill = xx[2] - else fill = ((c = scan_opt(LEGEND_TYPE[1].cmd2[k], "-G")) != "") ? c : "black" + else fill = ((c = scan_opt(LEGEND_TYPE[].cmd2[k], "-G")) != "") ? c : "black" end - penS = scan_opt(LEGEND_TYPE[1].cmd2[k], "-W"); + penS = scan_opt(LEGEND_TYPE[].cmd2[k], "-W"); leg[kk += 1] = @sprintf("S - %s %s %s %s - %s", symb2[1], symb2[2:end], fill, penS, "") end elseif (symb[1] == '~' || symb[1] == 'q' || symb[1] == 'f') @@ -4848,9 +4848,9 @@ function digests_legend_bag(d::Dict{Symbol, Any}, del::Bool=true) (ind === nothing) && error("Error: missing colon (:) in decorated string opt.") symb = string(symb[1],"n1", symb[ind[1]:end]) end - leg[kk += 1] = @sprintf("S - %s %s %s %s - %s", symb, symbW, fill, pen, LEGEND_TYPE[1].label[k]) + leg[kk += 1] = @sprintf("S - %s %s %s %s - %s", symb, symbW, fill, pen, LEGEND_TYPE[].label[k]) else - leg[kk += 1] = @sprintf("S - %s %s %s %s - %s", symb[1], symbW_, fill, pen, LEGEND_TYPE[1].label[k]) # Who is this? + leg[kk += 1] = @sprintf("S - %s %s %s %s - %s", symb[1], symbW_, fill, pen, LEGEND_TYPE[].label[k]) # Who is this? end end (count_no > 0) && (resize!(leg, nl-count_no)) @@ -4858,10 +4858,10 @@ function digests_legend_bag(d::Dict{Symbol, Any}, del::Bool=true) fnt = get_legend_font(dd, fs) # Parse the eventual 'font' or 'fontsize' options # Because we accept extended settings either from first or last legend() commands we must seek which - # one may have the desired keyword. First command is stored in 'LEGEND_TYPE[1].optsDict' and last in 'dd' + # one may have the desired keyword. First command is stored in 'LEGEND_TYPE[].optsDict' and last in 'dd' _d::Dict{Symbol,Any} = (haskey(dd, :pos) || haskey(dd, :position)) ? dd : - (haskey(LEGEND_TYPE[1].optsDict, :pos) || haskey(LEGEND_TYPE[1].optsDict, :position)) ? - LEGEND_TYPE[1].optsDict : Dict{Symbol,Any}() + (haskey(LEGEND_TYPE[].optsDict, :pos) || haskey(LEGEND_TYPE[].optsDict, :position)) ? + LEGEND_TYPE[].optsDict : Dict{Symbol,Any}() #_opt_D = (((val = find_in_dict(_d, [:pos :position], false)[1]) !== nothing) && isa(val, StrSymb)) ? string(val)::String : "" _opt_D = hlp_desnany_str(d, [:pos, :position], false) @@ -4876,7 +4876,7 @@ function digests_legend_bag(d::Dict{Symbol, Any}, del::Bool=true) opt_D *= "+j" * opt_D[2] * (opt_D[3] == 'L' ? 'R' : 'L') if (!occursin("+o", opt_D)) # Try to find a -Baxes token and see if 'axes' contains an annotated axis on the same side as the legend - s = split(LEGEND_TYPE[1].cmd[1], " -B") + s = split(LEGEND_TYPE[].cmd[1], " -B") for t in s t[1] == '-' && continue # This one can't be of any interest ss = split(split(t)[1],'+')[1] # If we have an annotated or with ticks guestimate an offset @@ -4898,7 +4898,7 @@ function digests_legend_bag(d::Dict{Symbol, Any}, del::Bool=true) (!occursin("+o", opt_D)) && (opt_D *= "+o" * offset) end - _d = (haskey(dd, :box) && dd[:box] !== nothing) ? dd : haskey(LEGEND_TYPE[1].optsDict, :box) ? LEGEND_TYPE[1].optsDict : Dict{Symbol, Any}() + _d = (haskey(dd, :box) && dd[:box] !== nothing) ? dd : haskey(LEGEND_TYPE[].optsDict, :box) ? LEGEND_TYPE[].optsDict : Dict{Symbol, Any}() opt_F::String = add_opt(_d, "", "", [:box], (clearance="+c", fill=("+g", add_opt_fill), inner="+i", pen=("+p", add_opt_pen), rounded="+r", shade="+s"); del=false) # FORCES RECOMPILE plot if (opt_F == "") opt_F = "+p0.5+gwhite" @@ -4911,8 +4911,8 @@ function digests_legend_bag(d::Dict{Symbol, Any}, del::Bool=true) end end - if (LEGEND_TYPE[1].Vd > 0) d[:Vd] = LEGEND_TYPE[1].Vd; dbg_print_cmd(d, leg[1:kk]) end # Vd=2 wont work - (LEGEND_TYPE[1].Vd > 0) && println("F=",opt_F, " D=",opt_D, " font=",fnt) + if (LEGEND_TYPE[].Vd > 0) d[:Vd] = LEGEND_TYPE[].Vd; dbg_print_cmd(d, leg[1:kk]) end # Vd=2 wont work + (LEGEND_TYPE[].Vd > 0) && println("F=",opt_F, " D=",opt_D, " font=",fnt) gmt_restart() # Some things with the themes may screw #legend!(text_record(leg[1:kk]), F=opt_F, D=opt_D, par=(:FONT_ANNOT_PRIMARY, fnt), Vd=1) @@ -4923,7 +4923,7 @@ function digests_legend_bag(d::Dict{Symbol, Any}, del::Bool=true) prep_and_call_finish_PS_module(Dict{Symbol, Any}(), [proggy * " -J $opt_R -F$(opt_F) -D$(opt_D) --FONT_ANNOT_PRIMARY=$fnt"], "", true, true, true, text_record(leg[1:kk])) - LEGEND_TYPE[1] = legend_bag() # Job done, now empty the bag + LEGEND_TYPE[] = legend_bag() # Job done, now empty the bag return nothing end diff --git a/src/gdal/gdal_tools.jl b/src/gdal/gdal_tools.jl index b7fa12435..409110a61 100644 --- a/src/gdal/gdal_tools.jl +++ b/src/gdal/gdal_tools.jl @@ -144,30 +144,30 @@ function polygonize(data::GItype; gdataset=nothing, kwargs...) cell_area = Float64(val)::Float64 * data.inc[1] * data.inc[2] end s_area = string(cell_area) - isempty(POSTMAN[1]) ? (POSTMAN[1] = Dict("min_polygon_area" => s_area)) : POSTMAN[1]["min_polygon_area"] = s_area - (max_area > 0.0) && (POSTMAN[1]["max_polygon_area"] = string(cell_area2)) - _isgeog && (POSTMAN[1]["polygon_isgeog"] = "1") + isempty(POSTMAN[]) ? (POSTMAN[] = Dict("min_polygon_area" => s_area)) : POSTMAN[]["min_polygon_area"] = s_area + (max_area > 0.0) && (POSTMAN[]["max_polygon_area"] = string(cell_area2)) + _isgeog && (POSTMAN[]["polygon_isgeog"] = "1") end o = helper_run_GDAL_fun(gdalpolygonize, data, "", String[], "", d...) if (gdataset === nothing) # Should be doing this for GDAL objects too but need to learn how to. - POSTMAN[1]["polygonize"] = "y" # To inform gd2gmt() that it should check if last Di is the whole area. - (find_in_dict(d, [:sort])[1] !== nothing) && (POSTMAN[1]["sort_polygons"] = "y") + POSTMAN[]["polygonize"] = "y" # To inform gd2gmt() that it should check if last Di is the whole area. + (find_in_dict(d, [:sort])[1] !== nothing) && (POSTMAN[]["sort_polygons"] = "y") if ((val = find_in_dict(d, [:simplify])[1]) !== nothing) s_val::String = string(val) # If simplify=auto, then use the cell side to estimate the simplification tolerance. s_val[1] == 'a' && (s_val = _isgeog ? string(data.inc[1] * m_per_deg) : string(data.inc[1])) - POSTMAN[1]["simplify"] = s_val + POSTMAN[]["simplify"] = s_val end prj = getproj(data) D = gd2gmt(o); !isempty(D) && (isa(D, Vector) ? (D[1].proj4 = prj) : (D.proj4 = prj)) - delete!(POSTMAN[1], "min_polygon_area") # In case it was set above - delete!(POSTMAN[1], "polygon_isgeog") + delete!(POSTMAN[], "min_polygon_area") # In case it was set above + delete!(POSTMAN[], "polygon_isgeog") return D end - delete!(POSTMAN[1], "min_polygon_area") + delete!(POSTMAN[], "min_polygon_area") o end diff --git a/src/gdal_utils.jl b/src/gdal_utils.jl index e46e69778..a05a1c775 100644 --- a/src/gdal_utils.jl +++ b/src/gdal_utils.jl @@ -257,14 +257,14 @@ function gd2gmt(dataset::Gdal.AbstractDataset) # This method is for OGR formats only (Gdal.GDALGetRasterCount(dataset.ptr) >= 1) && return gd2gmt(dataset; pad=0) - drv = get(POSTMAN[1], "GDALdriver", ""); (drv != "") && delete!(POSTMAN[1], "GDALdriver") + drv = get(POSTMAN[], "GDALdriver", ""); (drv != "") && delete!(POSTMAN[], "GDALdriver") (startswith(drv, "XLS") || drv == "CSV") && return helper_read_XLSCSV(dataset) - min_area = (get(POSTMAN[1], "min_polygon_area", "") != "") ? parse(Float64, POSTMAN[1]["min_polygon_area"]) : 0.0 - max_area = (get(POSTMAN[1], "max_polygon_area", "") != "") ? parse(Float64, POSTMAN[1]["max_polygon_area"]) : 0.0 - p_isgeog = (get(POSTMAN[1], "polygon_isgeog", "") != "") ? true : false + min_area = (get(POSTMAN[], "min_polygon_area", "") != "") ? parse(Float64, POSTMAN[]["min_polygon_area"]) : 0.0 + max_area = (get(POSTMAN[], "max_polygon_area", "") != "") ? parse(Float64, POSTMAN[]["max_polygon_area"]) : 0.0 + p_isgeog = (get(POSTMAN[], "polygon_isgeog", "") != "") ? true : false D, ds, get_area = Vector{GMTdataset{Float64, 2}}(undef, Gdal.ngeom(dataset)), 1, false - (get(POSTMAN[1], "sort_polygons", "") != "") && (polyg_area = zeros(length(D)); get_area = true) + (get(POSTMAN[], "sort_polygons", "") != "") && (polyg_area = zeros(length(D)); get_area = true) proj = "" # Fk local vars inside for for k = 1:Gdal.nlayer(dataset) layer = getlayer(dataset, k-1) @@ -306,15 +306,15 @@ function gd2gmt(dataset::Gdal.AbstractDataset) D[1].colnames = startswith(proj, "+proj=longlat") ? ["lon","lat", ["z$i" for i=1:size(D[1].data,2)-2]...] : ["x","y", ["z$i" for i=1:size(D[1].data,2)-2]...] set_dsBB!(D, false) # Compute and set the global BoundingBox for this dataset - if (get(POSTMAN[1], "polygonize", "") != "") && isapprox(D[1].ds_bbox, D[end].bbox) # Last one is often an error (the whole area) + if (get(POSTMAN[], "polygonize", "") != "") && isapprox(D[1].ds_bbox, D[end].bbox) # Last one is often an error (the whole area) pop!(D) - delete!(POSTMAN[1], "polygonize") + delete!(POSTMAN[], "polygonize") ds -= 1 end - if (get(POSTMAN[1], "sort_polygons", "") != "") # polygonize requested that the polygons go out in growing order + if (get(POSTMAN[], "sort_polygons", "") != "") # polygonize requested that the polygons go out in growing order (polyg_area = deleteat!(polyg_area, ds:length(polyg_area))) if (isempty(polyg_area)) - delete!(POSTMAN[1], "sort_polygons"); delete!(POSTMAN[1], "simplify") + delete!(POSTMAN[], "sort_polygons"); delete!(POSTMAN[], "simplify") return GMTdataset() end @@ -322,7 +322,7 @@ function gd2gmt(dataset::Gdal.AbstractDataset) isapprox(D[1].ds_bbox, D[ind[1]].bbox) && (popat!(ind, 1)) # Some times the almost full area polygon was not cought yet. n_polys = length(ind) if (n_polys == 0) - delete!(POSTMAN[1], "sort_polygons"); delete!(POSTMAN[1], "simplify") + delete!(POSTMAN[], "sort_polygons"); delete!(POSTMAN[], "simplify") return GMTdataset() end @@ -341,11 +341,11 @@ function gd2gmt(dataset::Gdal.AbstractDataset) (maximum(polyg_area) > 100000) && (polyg_area ./= 1e6; att_area_name = "area_km2") # If large, convert to km^2 end for k = 1:n_polys D[k].attrib[att_area_name] = string(polyg_area[ind[k]]) end - delete!(POSTMAN[1], "sort_polygons") + delete!(POSTMAN[], "sort_polygons") end - if ((tol = get(POSTMAN[1], "simplify", "")) != "") # The caller requested a line simplification step + if ((tol = get(POSTMAN[], "simplify", "")) != "") # The caller requested a line simplification step D = gmtsimplify(D, T=tol, f = p_isgeog ? "g" : "c") - delete!(POSTMAN[1], "simplify") # Used, so clean it. + delete!(POSTMAN[], "simplify") # Used, so clean it. end return (length(D) == 1) ? D[1] : D end @@ -354,8 +354,8 @@ end # This function is made apart because XLS and CSVs have geometries and the calling functio, as is, # would not be able to extract the data from the 'dataset' function helper_read_XLSCSV(dataset::Gdal.AbstractDataset)::GDtype - if (get(POSTMAN[1], "meteostat", "") != "") - delete!(POSTMAN[1], "meteostat") + if (get(POSTMAN[], "meteostat", "") != "") + delete!(POSTMAN[], "meteostat") return read_meteostat(dataset) end @@ -514,8 +514,8 @@ function coords_resque(dataset) # and does not assign it a geotransform. In such case we try to fish the coordinates from # info obtained by gdalinfo. # Shit is that here file name is lost (it's = /vsimem/tmp) so we must use a copy save in a global. - info = gdalinfo(POSTMAN[1]["nc_name"]) # We have saved the netcdf name in the POSTMAN dict - delete!(POSTMAN[1], "nc_name") # Clean it + info = gdalinfo(POSTMAN[]["nc_name"]) # We have saved the netcdf name in the POSTMAN dict + delete!(POSTMAN[], "nc_name") # Clean it ind = findfirst("Files: ", info)[end] k = ind + 1 @@ -870,7 +870,7 @@ function gdalread(fname::AbstractString, optsP=String[]; opts=String[], gdataset check = (ind === nothing || ind[1] < 3) ? true : false check && startswith(fname, "/vsi") && (check = false) # Don't check existence of /VSI.../ files (check && !isfile(fname)) && error("Input file '$fname' does not exist.") # Breaks when passing a SUBDATASET - startswith(fname, "NETCDF:") && (POSTMAN[1] = Dict("nc_name" => fname)) # For cases where GDAL fcks and doest have a geotransform + startswith(fname, "NETCDF:") && (POSTMAN[] = Dict("nc_name" => fname)) # For cases where GDAL fcks and doest have a geotransform (isempty(optsP) && !isempty(opts)) && (optsP = opts) # Accept either Positional or KW argument _optsP::Vector{String} = isa(optsP, String) ? string.(split(optsP)) : optsP ressurectGDAL(); @@ -883,8 +883,8 @@ function gdalread(fname::AbstractString, optsP=String[]; opts=String[], gdataset else (ds_t.ptr == C_NULL) && (ds_t = Gdal.read(fname, flags = Gdal.GDAL_OF_VECTOR | Gdal.GDAL_OF_VERBOSE_ERROR, I=false)) optsP = (isempty(optsP)) ? ["-overwrite"] : (isa(optsP, String) ? ["-overwrite " * optsP] : append!(optsP, ["-overwrite"])) - POSTMAN[1]["GDALdriver"] = Gdal.shortname(getdriver(ds_t)) # Used when read XLS files - startswith(fname, "/vsigzip") && contains(fname, ".meteostat") && (POSTMAN[1]["meteostat"] = "y") # Escape route for Meteostat files + POSTMAN[]["GDALdriver"] = Gdal.shortname(getdriver(ds_t)) # Used when read XLS files + startswith(fname, "/vsigzip") && contains(fname, ".meteostat") && (POSTMAN[]["meteostat"] = "y") # Escape route for Meteostat files ds = ogr2ogr(ds_t, optsP; gdataset=true, kw...) (ds.ptr != C_NULL) && Gdal.deletedatasource(ds, "/vsimem/tmp") # WTF I need to do this? end diff --git a/src/get_enums.jl b/src/get_enums.jl index bf22e6ee3..e7419eb3f 100644 --- a/src/get_enums.jl +++ b/src/get_enums.jl @@ -7,91 +7,91 @@ const global GMT_SESSION_RUNMODE = 16 # If set enable GMT's modern runmode. [C const global GMT_SESSION_NOGDALCLOSE = 64 # External API tells GMT to not call GDALDestroyDriverManager() const global GMT_SESSION_BITFLAGS = GMT_SESSION_NOEXIT + GMT_SESSION_EXTERNAL + GMT_SESSION_NOGDALCLOSE + GMT_SESSION_COLMAJOR -G_API[1] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) - -enu = GMT_Get_Enum(G_API[1], "GMT_CHAR"); const global GMT_CHAR = (enu != -99999) ? enu : 0 -enu = GMT_Get_Enum(G_API[1], "GMT_UCHAR"); const global GMT_UCHAR = (enu != -99999) ? enu : 1 -enu = GMT_Get_Enum(G_API[1], "GMT_SHORT"); const global GMT_SHORT = (enu != -99999) ? enu : 2 -enu = GMT_Get_Enum(G_API[1], "GMT_USHORT"); const global GMT_USHORT = (enu != -99999) ? enu : 3 -enu = GMT_Get_Enum(G_API[1], "GMT_INT"); const global GMT_INT = (enu != -99999) ? enu : 4 -enu = GMT_Get_Enum(G_API[1], "GMT_UINT"); const global GMT_UINT = (enu != -99999) ? enu : 5 -enu = GMT_Get_Enum(G_API[1], "GMT_LONG"); const global GMT_LONG = (enu != -99999) ? enu : 6 -enu = GMT_Get_Enum(G_API[1], "GMT_ULONG"); const global GMT_ULONG = (enu != -99999) ? enu : 7 -enu = GMT_Get_Enum(G_API[1], "GMT_FLOAT"); const global GMT_FLOAT = (enu != -99999) ? enu : 8 -enu = GMT_Get_Enum(G_API[1], "GMT_DOUBLE"); const global GMT_DOUBLE = (enu != -99999) ? enu : 9 -enu = GMT_Get_Enum(G_API[1], "GMT_TEXT"); const global GMT_TEXT = (enu != -99999) ? enu : 10 - -enu = GMT_Get_Enum(G_API[1], "GMT_OPT_INFILE"); const global GMT_OPT_INFILE = (enu != -99999) ? enu : 60 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_OUTPUT"); const global GMT_IS_OUTPUT = (enu != -99999) ? enu : 1024 -enu = GMT_Get_Enum(G_API[1], "GMT_VIA_MATRIX"); const global GMT_VIA_MATRIX = (enu != -99999) ? enu : 256 +G_API[] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) + +enu = GMT_Get_Enum(G_API[], "GMT_CHAR"); const global GMT_CHAR = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_UCHAR"); const global GMT_UCHAR = (enu != -99999) ? enu : 1 +enu = GMT_Get_Enum(G_API[], "GMT_SHORT"); const global GMT_SHORT = (enu != -99999) ? enu : 2 +enu = GMT_Get_Enum(G_API[], "GMT_USHORT"); const global GMT_USHORT = (enu != -99999) ? enu : 3 +enu = GMT_Get_Enum(G_API[], "GMT_INT"); const global GMT_INT = (enu != -99999) ? enu : 4 +enu = GMT_Get_Enum(G_API[], "GMT_UINT"); const global GMT_UINT = (enu != -99999) ? enu : 5 +enu = GMT_Get_Enum(G_API[], "GMT_LONG"); const global GMT_LONG = (enu != -99999) ? enu : 6 +enu = GMT_Get_Enum(G_API[], "GMT_ULONG"); const global GMT_ULONG = (enu != -99999) ? enu : 7 +enu = GMT_Get_Enum(G_API[], "GMT_FLOAT"); const global GMT_FLOAT = (enu != -99999) ? enu : 8 +enu = GMT_Get_Enum(G_API[], "GMT_DOUBLE"); const global GMT_DOUBLE = (enu != -99999) ? enu : 9 +enu = GMT_Get_Enum(G_API[], "GMT_TEXT"); const global GMT_TEXT = (enu != -99999) ? enu : 10 + +enu = GMT_Get_Enum(G_API[], "GMT_OPT_INFILE"); const global GMT_OPT_INFILE = (enu != -99999) ? enu : 60 +enu = GMT_Get_Enum(G_API[], "GMT_IS_OUTPUT"); const global GMT_IS_OUTPUT = (enu != -99999) ? enu : 1024 +enu = GMT_Get_Enum(G_API[], "GMT_VIA_MATRIX"); const global GMT_VIA_MATRIX = (enu != -99999) ? enu : 256 # GMT_enum_container -enu = GMT_Get_Enum(G_API[1], "GMT_CONTAINER_AND_DATA"); const global GMT_CONTAINER_AND_DATA = (enu != -99999) ? enu : 0 -enu = GMT_Get_Enum(G_API[1], "GMT_CONTAINER_ONLY"); const global GMT_CONTAINER_ONLY = (enu != -99999) ? enu : 1 -enu = GMT_Get_Enum(G_API[1], "GMT_DATA_ONLY"); const global GMT_DATA_ONLY = (enu != -99999) ? enu : 2 -enu = GMT_Get_Enum(G_API[1], "GMT_WITH_STRINGS"); const global GMT_WITH_STRINGS = (enu != -99999) ? enu : 32 -enu = GMT_Get_Enum(G_API[1], "GMT_NO_STRINGS"); const global GMT_NO_STRINGS = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_CONTAINER_AND_DATA"); const global GMT_CONTAINER_AND_DATA = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_CONTAINER_ONLY"); const global GMT_CONTAINER_ONLY = (enu != -99999) ? enu : 1 +enu = GMT_Get_Enum(G_API[], "GMT_DATA_ONLY"); const global GMT_DATA_ONLY = (enu != -99999) ? enu : 2 +enu = GMT_Get_Enum(G_API[], "GMT_WITH_STRINGS"); const global GMT_WITH_STRINGS = (enu != -99999) ? enu : 32 +enu = GMT_Get_Enum(G_API[], "GMT_NO_STRINGS"); const global GMT_NO_STRINGS = (enu != -99999) ? enu : 0 # GMT_enum_read -enu = GMT_Get_Enum(G_API[1], "GMT_READ_DATA"); const global GMT_READ_DATA = (enu != -99999) ? enu : 1 -enu = GMT_Get_Enum(G_API[1], "GMT_READ_TEXT"); const global GMT_READ_TEXT = (enu != -99999) ? enu : 2 -enu = GMT_Get_Enum(G_API[1], "GMT_READ_MIXED"); const global GMT_READ_MIXED = (enu != -99999) ? enu : 3 +enu = GMT_Get_Enum(G_API[], "GMT_READ_DATA"); const global GMT_READ_DATA = (enu != -99999) ? enu : 1 +enu = GMT_Get_Enum(G_API[], "GMT_READ_TEXT"); const global GMT_READ_TEXT = (enu != -99999) ? enu : 2 +enu = GMT_Get_Enum(G_API[], "GMT_READ_MIXED"); const global GMT_READ_MIXED = (enu != -99999) ? enu : 3 # begin enum GMT_enum_family -enu = GMT_Get_Enum(G_API[1], "GMT_IS_DATASET"); const global GMT_IS_DATASET = (enu != -99999) ? enu : 0 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_GRID"); const global GMT_IS_GRID = (enu != -99999) ? enu : 1 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_IMAGE"); const global GMT_IS_IMAGE = (enu != -99999) ? enu : 2 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_PALETTE"); const global GMT_IS_PALETTE = (enu != -99999) ? enu : 3 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_POSTSCRIPT"); const global GMT_IS_POSTSCRIPT = (enu != -99999) ? enu : 4 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_MATRIX"); const global GMT_IS_MATRIX = (enu != -99999) ? enu : 5 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_VECTOR"); const global GMT_IS_VECTOR = (enu != -99999) ? enu : 6 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_CUBE"); const global GMT_IS_CUBE = (enu != -99999) ? enu : 7 - -enu = GMT_Get_Enum(G_API[1], "GMT_COMMENT_IS_TEXT"); const global GMT_COMMENT_IS_TEXT = (enu != -99999) ? enu : 0 -enu = GMT_Get_Enum(G_API[1], "GMT_IMAGE_ALPHA_LAYER"); const global GMT_IMAGE_ALPHA_LAYER = (enu != -99999) ? enu : 8192 +enu = GMT_Get_Enum(G_API[], "GMT_IS_DATASET"); const global GMT_IS_DATASET = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_IS_GRID"); const global GMT_IS_GRID = (enu != -99999) ? enu : 1 +enu = GMT_Get_Enum(G_API[], "GMT_IS_IMAGE"); const global GMT_IS_IMAGE = (enu != -99999) ? enu : 2 +enu = GMT_Get_Enum(G_API[], "GMT_IS_PALETTE"); const global GMT_IS_PALETTE = (enu != -99999) ? enu : 3 +enu = GMT_Get_Enum(G_API[], "GMT_IS_POSTSCRIPT"); const global GMT_IS_POSTSCRIPT = (enu != -99999) ? enu : 4 +enu = GMT_Get_Enum(G_API[], "GMT_IS_MATRIX"); const global GMT_IS_MATRIX = (enu != -99999) ? enu : 5 +enu = GMT_Get_Enum(G_API[], "GMT_IS_VECTOR"); const global GMT_IS_VECTOR = (enu != -99999) ? enu : 6 +enu = GMT_Get_Enum(G_API[], "GMT_IS_CUBE"); const global GMT_IS_CUBE = (enu != -99999) ? enu : 7 + +enu = GMT_Get_Enum(G_API[], "GMT_COMMENT_IS_TEXT"); const global GMT_COMMENT_IS_TEXT = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_IMAGE_ALPHA_LAYER"); const global GMT_IMAGE_ALPHA_LAYER = (enu != -99999) ? enu : 8192 # begin enum GMT_module_enum -enu = GMT_Get_Enum(G_API[1], "GMT_MODULE_EXIST"); const global GMT_MODULE_EXIST = (enu != -99999) ? enu : -3 -enu = GMT_Get_Enum(G_API[1], "GMT_MODULE_OPT"); const global GMT_MODULE_OPT = (enu != -99999) ? enu : -1 -enu = GMT_Get_Enum(G_API[1], "GMT_MODULE_CMD"); const global GMT_MODULE_CMD = (enu != -99999) ? enu : 0 -enu = GMT_Get_Enum(G_API[1], "GMT_SYNOPSIS"); const global GMT_SYNOPSIS = (enu != -99999) ? enu : 1 +enu = GMT_Get_Enum(G_API[], "GMT_MODULE_EXIST"); const global GMT_MODULE_EXIST = (enu != -99999) ? enu : -3 +enu = GMT_Get_Enum(G_API[], "GMT_MODULE_OPT"); const global GMT_MODULE_OPT = (enu != -99999) ? enu : -1 +enu = GMT_Get_Enum(G_API[], "GMT_MODULE_CMD"); const global GMT_MODULE_CMD = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_SYNOPSIS"); const global GMT_SYNOPSIS = (enu != -99999) ? enu : 1 # begin enum GMT_io_enum -enu = GMT_Get_Enum(G_API[1], "GMT_IN"); const global GMT_IN = (enu != -99999) ? enu : 0 -enu = GMT_Get_Enum(G_API[1], "GMT_OUT"); const global GMT_OUT = (enu != -99999) ? enu : 1 +enu = GMT_Get_Enum(G_API[], "GMT_IN"); const global GMT_IN = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_OUT"); const global GMT_OUT = (enu != -99999) ? enu : 1 -enu = GMT_Get_Enum(G_API[1], "GMT_ALLOC_EXTERNALLY"); const global GMT_ALLOC_EXTERNALLY = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_ALLOC_EXTERNALLY"); const global GMT_ALLOC_EXTERNALLY = (enu != -99999) ? enu : 0 # begin enum GMT_enum_dimindex -enu = GMT_Get_Enum(G_API[1], "GMT_SEG"); const global GMT_SEG = (enu != -99999) ? enu : 1 -enu = GMT_Get_Enum(G_API[1], "GMT_ROW"); const global GMT_ROW = (enu != -99999) ? enu : 2 -enu = GMT_Get_Enum(G_API[1], "GMT_COL"); const global GMT_COL = (enu != -99999) ? enu : 3 +enu = GMT_Get_Enum(G_API[], "GMT_SEG"); const global GMT_SEG = (enu != -99999) ? enu : 1 +enu = GMT_Get_Enum(G_API[], "GMT_ROW"); const global GMT_ROW = (enu != -99999) ? enu : 2 +enu = GMT_Get_Enum(G_API[], "GMT_COL"); const global GMT_COL = (enu != -99999) ? enu : 3 #const global GMT_GRID_ALL = 0 # This one is a #define # begin enum GMT_enum_fmt -enu = GMT_Get_Enum(G_API[1], "GMT_IS_COL_FORMAT"); const global GMT_IS_COL_FORMAT = (enu != -99999) ? enu : 2 +enu = GMT_Get_Enum(G_API[], "GMT_IS_COL_FORMAT"); const global GMT_IS_COL_FORMAT = (enu != -99999) ? enu : 2 # begin enum GMT_enum_geometry -enu = GMT_Get_Enum(G_API[1], "GMT_IS_PLP"); const global GMT_IS_PLP = (enu != -99999) ? enu : 7 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_SURFACE"); const global GMT_IS_SURFACE = (enu != -99999) ? enu : 8 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_VOLUME"); const global GMT_IS_VOLUME = (enu != -99999) ? enu : 9 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_NONE"); const global GMT_IS_NONE = (enu != -99999) ? enu : 16 +enu = GMT_Get_Enum(G_API[], "GMT_IS_PLP"); const global GMT_IS_PLP = (enu != -99999) ? enu : 7 +enu = GMT_Get_Enum(G_API[], "GMT_IS_SURFACE"); const global GMT_IS_SURFACE = (enu != -99999) ? enu : 8 +enu = GMT_Get_Enum(G_API[], "GMT_IS_VOLUME"); const global GMT_IS_VOLUME = (enu != -99999) ? enu : 9 +enu = GMT_Get_Enum(G_API[], "GMT_IS_NONE"); const global GMT_IS_NONE = (enu != -99999) ? enu : 16 # begin enum GMT_enum_color -enu = GMT_Get_Enum(G_API[1], "GMT_RGB"); const global GMT_RGB = (enu != -99999) ? enu : 0 -enu = GMT_Get_Enum(G_API[1], "GMT_CMYK"); const global GMT_CMYK = (enu != -99999) ? enu : 1 -enu = GMT_Get_Enum(G_API[1], "GMT_HSV"); const global GMT_HSV = (enu != -99999) ? enu : 2 +enu = GMT_Get_Enum(G_API[], "GMT_RGB"); const global GMT_RGB = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_CMYK"); const global GMT_CMYK = (enu != -99999) ? enu : 1 +enu = GMT_Get_Enum(G_API[], "GMT_HSV"); const global GMT_HSV = (enu != -99999) ? enu : 2 # GMT_enum_cptflags -enu = GMT_Get_Enum(G_API[1], "GMT_CPT_HINGED"); const global GMT_CPT_HINGED = (enu != -99999) ? enu : 4 +enu = GMT_Get_Enum(G_API[], "GMT_CPT_HINGED"); const global GMT_CPT_HINGED = (enu != -99999) ? enu : 4 # GMT_enum_CPT -enu = GMT_Get_Enum(G_API[1], "GMT_IS_PALETTE_KEY"); const global GMT_IS_PALETTE_KEY = (enu != -99999) ? enu : 1024 -enu = GMT_Get_Enum(G_API[1], "GMT_IS_PALETTE_LABEL"); const global GMT_IS_PALETTE_LABEL = (enu != -99999) ? enu : 2048 +enu = GMT_Get_Enum(G_API[], "GMT_IS_PALETTE_KEY"); const global GMT_IS_PALETTE_KEY = (enu != -99999) ? enu : 1024 +enu = GMT_Get_Enum(G_API[], "GMT_IS_PALETTE_LABEL"); const global GMT_IS_PALETTE_LABEL = (enu != -99999) ? enu : 2048 # GMT_enum_workflowmode -enu = GMT_Get_Enum(G_API[1], "GMT_USE_WORKFLOW"); const global GMT_USE_WORKFLOW = (enu != -99999) ? enu : 0 -enu = GMT_Get_Enum(G_API[1], "GMT_BEGIN_WORKFLOW"); const global GMT_BEGIN_WORKFLOW = (enu != -99999) ? enu : 1 -enu = GMT_Get_Enum(G_API[1], "GMT_END_WORKFLOW"); const global GMT_END_WORKFLOW = (enu != -99999) ? enu : 2 +enu = GMT_Get_Enum(G_API[], "GMT_USE_WORKFLOW"); const global GMT_USE_WORKFLOW = (enu != -99999) ? enu : 0 +enu = GMT_Get_Enum(G_API[], "GMT_BEGIN_WORKFLOW"); const global GMT_BEGIN_WORKFLOW = (enu != -99999) ? enu : 1 +enu = GMT_Get_Enum(G_API[], "GMT_END_WORKFLOW"); const global GMT_END_WORKFLOW = (enu != -99999) ? enu : 2 -GMT_Destroy_Session(G_API[1]); \ No newline at end of file +GMT_Destroy_Session(G_API[]); \ No newline at end of file diff --git a/src/gmt_main.jl b/src/gmt_main.jl index 7c25e53ee..43bfd3713 100644 --- a/src/gmt_main.jl +++ b/src/gmt_main.jl @@ -38,16 +38,16 @@ function gmt(cmd::String, args...) # Here we must account for the fact that we may have started from a CLASSIC session. Then, the session dir does # not exist yet and in consequence when GMT_begin calls gmt_manage_workflow it will wrongly assume we are in CLASSIC # mode and write a gmt.conf in the session dir with classic instead of modern defaults. Solution is to create it now. - API = unsafe_load(convert(Ptr{GMTAPI_CTRL}, G_API[1])) + API = unsafe_load(convert(Ptr{GMTAPI_CTRL}, G_API[])) sess = joinpath(unsafe_string(API.session_dir), "gmt_session." * unsafe_string(API.session_name)) !isdir(sess) && mkdir(sess) - gmtlib_setparameter(G_API[1], "MAP_ORIGIN_X", "0") # Workarround GMT bug. - gmtlib_setparameter(G_API[1], "MAP_ORIGIN_Y", "0") + gmtlib_setparameter(G_API[], "MAP_ORIGIN_X", "0") # Workarround GMT bug. + gmtlib_setparameter(G_API[], "MAP_ORIGIN_Y", "0") IamModern[] = true elseif (g_module == "end") # Last command of a MODERN session (r == "") && (r = "-Vq") # Cannot have a no-args for this case otherwise it prints help - gmtlib_setparameter(G_API[1], "MAP_ORIGIN_X", "20c") - gmtlib_setparameter(G_API[1], "MAP_ORIGIN_Y", "20c") + gmtlib_setparameter(G_API[], "MAP_ORIGIN_X", "20c") + gmtlib_setparameter(G_API[], "MAP_ORIGIN_Y", "20c") elseif (r == "" && n_argin == 0) # Just requesting usage message, add -? to options r = "-?" elseif (n_argin > 1 && (g_module == "psscale" || g_module == "colorbar")) # Happens with nested calls like in grdimage @@ -57,16 +57,16 @@ function gmt(cmd::String, args...) end pad = 2 - if (!isa(G_API[1], Ptr{Nothing}) || G_API[1] == C_NULL) - G_API[1] = GMT_Create_Session("GMT", pad, GMT_SESSION_BITFLAGS) + if (!isa(G_API[], Ptr{Nothing}) || G_API[] == C_NULL) + G_API[] = GMT_Create_Session("GMT", pad, GMT_SESSION_BITFLAGS) theme_modern() # Set the MODERN theme end # 2. In case this was a clean up call or a begin/end from the modern mode - gmt_manage_workflow(G_API[1], 0, NULL) # Force going here to see if we are in middle of a MODERN session + gmt_manage_workflow(G_API[], 0, NULL) # Force going here to see if we are in middle of a MODERN session # Make sure this is a valid module - if ((status = GMT_Call_Module(G_API[1], g_module, GMT_MODULE_EXIST, C_NULL)) != 0) + if ((status = GMT_Call_Module(G_API[], g_module, GMT_MODULE_EXIST, C_NULL)) != 0) error("GMT: No module by that name -- " * g_module * " -- was found.") end @@ -94,7 +94,7 @@ function gmt(cmd::String, args...) (IMG_MEM_LAYOUT[] != "") && (mem_layout::String = IMG_MEM_LAYOUT[]; mem_kw = "API_IMAGE_LAYOUT") (GRD_MEM_LAYOUT[] != "") && (mem_layout = GRD_MEM_LAYOUT[]; mem_kw = "API_GRID_LAYOUT") (IMG_MEM_LAYOUT[] != "" && mem_layout[end] != 'a') && (mem_layout *= "a") - GMT_Set_Default(G_API[1], mem_kw, mem_layout); # Tell module to give us the image/grid with this mem layout + GMT_Set_Default(G_API[], mem_kw, mem_layout); # Tell module to give us the image/grid with this mem layout end # 2++ Add -T to gmtwrite if user did not explicitly give -T. Seek also for MEM layout requests @@ -119,18 +119,18 @@ function gmt(cmd::String, args...) # 2+++ If gmtread -Ti than temporarily set pad to 0 since we don't want padding in image arrays if (occursin("read", g_module) && occursin("-T", r)) - (occursin("-Ti", r) || occursin("-Tg", r)) && GMT_Set_Default(G_API[1], "API_PAD", "0") + (occursin("-Ti", r) || occursin("-Tg", r)) && GMT_Set_Default(G_API[], "API_PAD", "0") end # 3. Convert command line arguments to a linked GMT option list #LL = NULL - LL = GMT_Create_Options(G_API[1], 0, r) # It uses also the fact that GMT parses and check options + LL = GMT_Create_Options(G_API[], 0, r) # It uses also the fact that GMT parses and check options # 4. Preprocess to update GMT option lists and return info array X pLL = Ref([LL], 1) n_itemsP = Ref{UInt32}(0) - XX = GMT_Encode_Options(G_API[1], g_module, n_argin, pLL, n_itemsP) # This call also changes LL + XX = GMT_Encode_Options(G_API[], g_module, n_argin, pLL, n_itemsP) # This call also changes LL n_items = n_itemsP[] if (XX == NULL && n_items > 65000) # Just got usage/synopsis option (if (n_items == UINT_MAX)) in C (n_items > 65000) ? n_items = 0 : error("Failure to encode Julia command options") @@ -145,21 +145,21 @@ function gmt(cmd::String, args...) for k = 1:n_items X[k] = unsafe_load(XX, k) # Cannot use pointer_to_array() because GMT_RESOURCE is not immutable and would BOOM! end - gmt_free_mem(G_API[1], XX) + gmt_free_mem(G_API[], XX) - #println(g_module * " " * unsafe_string(GMT_Create_Cmd(G_API[1], LL))) # Uncomment when need to confirm argins + #println(g_module * " " * unsafe_string(GMT_Create_Cmd(G_API[], LL))) # Uncomment when need to confirm argins # 5. Assign input sources (from Julia to GMT) and output destinations (from GMT to Julia) (g_module == "grdpaste") && (noGrdCopy[] = true) # Signal grid_init() that it should not make a grid copy for k = 1:n_items # Number of GMT containers involved in this module call */ if (X[k].direction == GMT_IN && n_argin == 0) error("GMT: Expects a Matrix for input") end ptr = (X[k].direction == GMT_IN) ? args[X[k].pos+1] : nothing - GMTJL_Set_Object(G_API[1], X[k], ptr, pad) # Set object pointer + GMTJL_Set_Object(G_API[], X[k], ptr, pad) # Set object pointer end (g_module == "grdpaste") && (noGrdCopy[] = false) # 6. Run GMT module; give usage message if errors arise during parsing - status = GMT_Call_Module(G_API[1], g_module, GMT_MODULE_OPT, LL) + status = GMT_Call_Module(G_API[], g_module, GMT_MODULE_OPT, LL) if (status != 0) ((status < 0) || status == GMT_SYNOPSIS || status == Int('?')) && return resetGMT() # If it screwed, reset it to not let this error afect posterious calls. @@ -179,17 +179,17 @@ function gmt(cmd::String, args...) for k = 1:n_items # Get results from GMT into Julia arrays if (X[k].direction == GMT_IN) continue end # Only looking for stuff coming OUT of GMT here - out[X[k].pos+1] = GMTJL_Get_Object(G_API[1], X[k]) # Hook object onto rhs list + out[X[k].pos+1] = GMTJL_Get_Object(G_API[], X[k]) # Hook object onto rhs list end # 2++- If gmtread -Ti than reset the session's pad value that was temporarily changed above (2+++) if (occursin("read", g_module) && (occursin("-Ti", r) || occursin("-Tg", r)) ) - GMT_Set_Default(G_API[1], "API_PAD", string(pad)) + GMT_Set_Default(G_API[], "API_PAD", string(pad)) end # Due to the damn GMT pad I'm forced to a lot of trickery. One involves cheating on memory ownership if (CTRL.gmt_mem_bag[1] != C_NULL) - gmt_free_mem(G_API[1], CTRL.gmt_mem_bag[1]) # Free a GMT owned memory that we pretended was ours + gmt_free_mem(G_API[], CTRL.gmt_mem_bag[1]) # Free a GMT owned memory that we pretended was ours CTRL.gmt_mem_bag[1] = C_NULL end @@ -197,8 +197,8 @@ function gmt(cmd::String, args...) for k = 1:n_items ppp = X[k].object name = String([X[k].name...]) # Because X.name is a NTuple - (GMT_Close_VirtualFile(G_API[1], name) != 0) && error("GMT: Failed to close virtual file") - (GMT_Destroy_Data(G_API[1], Ref([X[k].object], 1)) != 0) && error("Failed to destroy GMT<->Julia interface object") + (GMT_Close_VirtualFile(G_API[], name) != 0) && error("GMT: Failed to close virtual file") + (GMT_Destroy_Data(G_API[], Ref([X[k].object], 1)) != 0) && error("Failed to destroy GMT<->Julia interface object") # Success, now make sure we dont destroy the same pointer more than once for kk = k+1:n_items if (X[kk].object == ppp) X[kk].object = NULL; end @@ -206,9 +206,9 @@ function gmt(cmd::String, args...) end # 9. Destroy linked option list - GMT_Destroy_Options(G_API[1], pLL) + GMT_Destroy_Options(G_API[], pLL) - #if (IamModern[]) gmt_put_history(G_API[1]); end # Needed, otherwise history is not updated + #if (IamModern[]) gmt_put_history(G_API[]); end # Needed, otherwise history is not updated (IamModern[] && g_module != "begin") && gmt_restart() # Needed, otherwise history is not updated IMG_MEM_LAYOUT[] = ""; GRD_MEM_LAYOUT[] = "" # Reset to not afect next readings @@ -240,23 +240,23 @@ gmt_GMTgrid(cmd::String, args...)::GMTgrid{Float32,2} = gmt(cmd, args...)::GMTgr # ----------------------------------------------------------------------------------------------- function gmt_restart(restart::Bool=true) # Destroy the contents of the current API pointer and, by default, recreate a new one. - GMT_Destroy_Session(G_API[1]) + GMT_Destroy_Session(G_API[]) if (restart) - G_API[1] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) + G_API[] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) theme_modern() # Set the MODERN theme and calls extra_sets() else - G_API[1] = C_NULL + G_API[] = C_NULL end return nothing end # ----------------------------------------------------------------------------------------------- function extra_sets() - gmtlib_setparameter(G_API[1], "MAP_DEFAULT_PEN", "0.5p,black") # Change the default 0.25 pen thickness in -W - gmtlib_setparameter(G_API[1], "COLOR_NAN", "255") # Stop those ugly grays - gmtlib_setparameter(G_API[1], "MAP_ORIGIN_X", "20c") # Change the origin offset - gmtlib_setparameter(G_API[1], "MAP_ORIGIN_Y", "20c") - gmtlib_setparameter(G_API[1], "MAP_EMBELLISHMENT_MODE", "auto") + gmtlib_setparameter(G_API[], "MAP_DEFAULT_PEN", "0.5p,black") # Change the default 0.25 pen thickness in -W + gmtlib_setparameter(G_API[], "COLOR_NAN", "255") # Stop those ugly grays + gmtlib_setparameter(G_API[], "MAP_ORIGIN_X", "20c") # Change the origin offset + gmtlib_setparameter(G_API[], "MAP_ORIGIN_Y", "20c") + gmtlib_setparameter(G_API[], "MAP_EMBELLISHMENT_MODE", "auto") end # ----------------------------------------------------------------------------------------------- @@ -620,16 +620,16 @@ function get_dataset(API::Ptr{Nothing}, object::Ptr{Nothing})::GDtype D::GMT_DATASET = unsafe_load(convert(Ptr{GMT_DATASET}, object)) # This is for the particular case of the DCW countries that have a myriad of small segments and no Attributes - if (!isempty(POSTMAN[1])) - min_pts = (get(POSTMAN[1], "minpts", "") != "") ? parse(Int, POSTMAN[1]["minpts"]) - 1 : 0 - (min_pts > 0) && delete!(POSTMAN[1], "minpts") - if ((t = get(POSTMAN[1], "DCWnames", "")) != "") # If DCW country names will turn into attribs + if (!isempty(POSTMAN[])) + min_pts = (get(POSTMAN[], "minpts", "") != "") ? parse(Int, POSTMAN[]["minpts"]) - 1 : 0 + (min_pts > 0) && delete!(POSTMAN[], "minpts") + if ((t = get(POSTMAN[], "DCWnames", "")) != "") # If DCW country names will turn into attribs codelen = parse(Int, t) - delete!(POSTMAN[1], "DCWnames") + delete!(POSTMAN[], "DCWnames") end DCWnames = (t !== "") ? true : false - plusZzero = (get(POSTMAN[1], "plusZzero", "") != "") ? true : false # To eventually add an extra column with 0's - (plusZzero) && delete!(POSTMAN[1], "plusZzero") + plusZzero = (get(POSTMAN[], "plusZzero", "") != "") ? true : false # To eventually add an extra column with 0's + (plusZzero) && delete!(POSTMAN[], "plusZzero") else min_pts, DCWnames, plusZzero = 0, false, false end @@ -1494,7 +1494,7 @@ function resetGMT(dorestart::Bool=true) MULTI_COL[] = false; CONVERT_SYNTAX[] = false; CURRENT_VIEW[] = ""; SHOW_KWARGS[] = false; IMG_MEM_LAYOUT[] = ""; GRD_MEM_LAYOUT[] = ""; CTRL.limits .= 0.0; CTRL.proj_linear[1] = true; CTRLshapes.fname[1] = "";CTRLshapes.first[1] = true; CTRLshapes.points[1] = false; - CURRENT_CPT[1] = GMTcpt(); LEGEND_TYPE[1] = legend_bag(); ressurectGDAL() + CURRENT_CPT[] = GMTcpt(); LEGEND_TYPE[] = legend_bag(); ressurectGDAL() DEF_FIG_AXES[] = DEF_FIG_AXES_BAK; DEF_FIG_AXES3[] = DEF_FIG_AXES3_BAK; CTRL.pocket_J[1], CTRL.pocket_J[2], CTRL.pocket_J[3], CTRL.pocket_J[4] = "", "", "", " "; CTRL.IamInPaperMode[:] = [false, true]; IamInset[1], IamInset[2] = false, false diff --git a/src/gmtbegin.jl b/src/gmtbegin.jl index b58894f48..6c01983e0 100644 --- a/src/gmtbegin.jl +++ b/src/gmtbegin.jl @@ -430,7 +430,7 @@ function hack_modern_session(opt_R, opt_J, opt_B=" -Blrbt"; fullremove=false) opt_J == "" && throw(ArgumentError("The 'proj' option cannot be empty in hack_modern_session()")) gmt("begin") gmt("basemap " * opt_R * opt_J * opt_B) - API = unsafe_load(convert(Ptr{GMTAPI_CTRL}, G_API[1])) + API = unsafe_load(convert(Ptr{GMTAPI_CTRL}, G_API[])) session_dir = unsafe_string(API.gwf_dir) fname = session_dir * filesep * "gmt_0.ps-" rm(fname) # To remove PS headers and such diff --git a/src/gmtset.jl b/src/gmtset.jl index ea48c65d1..eb40b1d68 100644 --- a/src/gmtset.jl +++ b/src/gmtset.jl @@ -33,7 +33,7 @@ function gmtset(; kwargs...) for k = 1:length(d) (key[k] == :Vd) && continue cmd *= " " * string(key[k]) * " " * string(d[key[k]]) - gmtlib_setparameter(G_API[1], string(key[k]), string(d[key[k]])) + gmtlib_setparameter(G_API[], string(key[k]), string(d[key[k]])) delete!(d, key[k]) end GMTCONF[] = true diff --git a/src/grd2cpt.jl b/src/grd2cpt.jl index 14c5cdda6..97ab3d60e 100644 --- a/src/grd2cpt.jl +++ b/src/grd2cpt.jl @@ -85,7 +85,7 @@ function grd2cpt_helper(cmd0::String, arg1; kw...) r = common_grd(d, "grd2cpt " * cmd, arg1, arg2) # r may be a tuple if -E+f was used (isa(r, String)) && (return got_N ? r * " -N" : r) # If it's a String it's beause of a Vd=2 got_N && (r.bfn = ones(3,3)) # Cannot remove the bfn like in plain GMT so make it all whites - CURRENT_CPT[1] = (r !== nothing) ? (isa(r, Tuple) ? r[1] : r) : GMTcpt() + CURRENT_CPT[] = (r !== nothing) ? (isa(r, Tuple) ? r[1] : r) : GMTcpt() isa(r, Tuple) && (r[2].colnames = ["Z", "CDF(Z)"]) CTRL.pocket_d[1] = d # Store d that may be not empty with members to use in other modules return r diff --git a/src/grdimage.jl b/src/grdimage.jl index bcd545945..7269affe0 100644 --- a/src/grdimage.jl +++ b/src/grdimage.jl @@ -139,7 +139,7 @@ function _grdimage(cmd0::String, arg1, arg2, arg3, O::Bool, K::Bool, d::Dict) set_defcpt!(d, cmd0, arg1) # When dealing with a remote grid assign it a default CPT (isa(arg1, GMTgrid) && arg1.cpt != "") && (d[:this_cpt] = arg1.cpt) - (haskey(d, :this_cpt) && isfile(d[:this_cpt])) && (CURRENT_CPT[1] = gmtread(d[:this_cpt])) + (haskey(d, :this_cpt) && isfile(d[:this_cpt])) && (CURRENT_CPT[] = gmtread(d[:this_cpt])) cmd, _, arg1, arg2, arg3 = common_get_R_cpt(d, cmd0, cmd, opt_R, got_fname, arg1, arg2, arg3, "grdimage") cmd, arg1, arg2, arg3, arg4 = common_shade(d, cmd, arg1, arg2, arg3, arg4, "grdimage") diff --git a/src/imshow.jl b/src/imshow.jl index b65bae2c9..947a96dc4 100644 --- a/src/imshow.jl +++ b/src/imshow.jl @@ -199,7 +199,7 @@ function imshow(arg1::GItype; kw...) grdimage("", fun(arg1[:,:,1], arg1); d...) for k = 2:n_levels !isempty(tits) && (d[:title] = rt[k]) - CURRENT_CPT[1] = GMTcpt() # Force creating a new CPT for next layer + CURRENT_CPT[] = GMTcpt() # Force creating a new CPT for next layer grdimage("", fun(arg1[:,:,k], arg1); panel=:next, d...) end subplot(see ? :show : :end) diff --git a/src/makecpt.jl b/src/makecpt.jl index c577f970a..82f0a1806 100644 --- a/src/makecpt.jl +++ b/src/makecpt.jl @@ -84,7 +84,7 @@ function makecpt(cmd0::String, arg1, d::Dict)::Union{String, GMTcpt} @assert (r isa GMTcpt) (got_N && !isempty(r)) && (r.bfn = ones(3,3)) # Cannot remove the bfn like in plain GMT so make it all whites CTRL.pocket_d[1] = d # Store d that may be not empty with members to use in other modules - CURRENT_CPT[1] = r + CURRENT_CPT[] = r return r end diff --git a/src/mapproject.jl b/src/mapproject.jl index e7cdc47eb..c820a2e88 100644 --- a/src/mapproject.jl +++ b/src/mapproject.jl @@ -85,7 +85,7 @@ function mapproject(cmd0::String="", arg1=nothing, arg2=nothing; kwargs...) cmd, args, n, = add_opt(d, cmd, "L", [:L :dist2line], :line, Array{Any,1}([arg1, arg2]), (unit="+u1", cartesian="_+uc", project="_+uC", fractional_pt="_+p")) - contains(cmd, "-L") && gmtlib_setparameter(G_API[1], "GMT_COMPATIBILITY", "4") # GMT<=6.4 bug + contains(cmd, "-L") && gmtlib_setparameter(G_API[], "GMT_COMPATIBILITY", "4") # GMT<=6.4 bug if (n > 0) arg1, arg2 = args[:] diff --git a/src/plot.jl b/src/plot.jl index 9c2c0ceb3..8c377c69a 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -403,7 +403,7 @@ function scatter(D::Vector{<:GMTdataset{Float64,2}}; first=true, kw...) ts = fish_attrib_in_str(s_val) labels = [D[k].attrib[ts] for k = 1:length(D)] end - Dc = mat2ds(gmt_centroid_area(G_API[1], D, Int(isgeog(D)), ca=2), geom=wkbPoint, text=labels) + Dc = mat2ds(gmt_centroid_area(G_API[], D, Int(isgeog(D)), ca=2), geom=wkbPoint, text=labels) (is_in_dict(d, [:marker, :Marker, :shape]) === nothing) && (d[:marker] = "circ") (is_in_dict(d, [:ms :markersize :MarkerSize :size]) === nothing) && (d[:ms] = "12p") _common_plot_xyz("", Dc, "bubble", !first, true, false, d) @@ -1701,7 +1701,7 @@ function ternary(cmd0::String="", arg1=nothing; first::Bool=true, image::Bool=fa if ((val = find_in_dict(d, [:par :conf :params], false)[1]) === nothing) d[:par] = (MAP_GRID_PEN_PRIMARY="thinnest,gray",) end - (G_API[1] == C_NULL) && gmt_restart() # Force having a valid API. We can't afford otherwise here. + (G_API[] == C_NULL) && gmt_restart() # Force having a valid API. We can't afford otherwise here. r = common_plot_xyz("", mat2ds(arg1), "ternary", first, false, d) # With the following trick we leave the -R history in 0/1/0/1 and so we can append with plot, text, etc gmt("psxy -Scp -R0/1/0/1 -JX -O -Vq > " * joinpath(TMPDIR_USR[1], "lixo_" * TMPDIR_USR[2] * TMPDIR_USR[3] * ".ps"), [0. 0.]) diff --git a/src/pscoast.jl b/src/pscoast.jl index 229bf5ec6..de3d6b512 100644 --- a/src/pscoast.jl +++ b/src/pscoast.jl @@ -123,8 +123,8 @@ function coast_parser(first::Bool, clip::String; kwargs...) have_opt_M = contains(cmd, " -M") twoORfour = have_opt_M && contains(cmd, "+z") && contains(cmd, '.') ? "4" : "2" # To use in gmt_main to decide CODE attrib if (cmd != "") # Check for a minimum of points that segments must have - if ((val = hlp_desnany_str(d, [:minpts])) !== "") POSTMAN[1]["minpts"] = val - elseif (get(POSTMAN[1], "minpts", "") != "") delete!(POSTMAN[1], "minpts") + if ((val = hlp_desnany_str(d, [:minpts])) !== "") POSTMAN[]["minpts"] = val + elseif (get(POSTMAN[], "minpts", "") != "") delete!(POSTMAN[], "minpts") end end @@ -132,10 +132,10 @@ function coast_parser(first::Bool, clip::String; kwargs...) toTrack::Union{String, GMTgrid} = "" if (have_opt_M) O = true - POSTMAN[1]["DCWnames"] = twoORfour # When dumping, we want to add the country name as attribute + POSTMAN[]["DCWnames"] = twoORfour # When dumping, we want to add the country name as attribute if ((val = find_in_dict(d, [:Z])[1]) !== nothing) toTrack = (isa(val, GMTgrid) || (isa(val, String) && length(val) > 4)) ? val : "" - toTrack == "" && (POSTMAN[1]["plusZzero"] = "y")# If toTrack the extra column is added by the grdtrack call below + toTrack == "" && (POSTMAN[]["plusZzero"] = "y")# If toTrack the extra column is added by the grdtrack call below end end diff --git a/src/pscontour.jl b/src/pscontour.jl index 26d73c7e8..796a36cb5 100644 --- a/src/pscontour.jl +++ b/src/pscontour.jl @@ -133,7 +133,7 @@ function contour_helper(cmd0::String, arg1, O::Bool, K::Bool, d::Dict{Symbol,Any if (occursin("-I", cmd) && !occursin("-C", cmd)) r = round_wesn([wesn[5], wesn[6], wesn[5], wesn[6]]) wesn[5], wesn[6] = r[1], r[2] - opt_T = (isempty(CURRENT_CPT[1])) ? @sprintf(" -T%.14g/%.14g/11+n", wesn[5], wesn[6]) : "" + opt_T = (isempty(CURRENT_CPT[])) ? @sprintf(" -T%.14g/%.14g/11+n", wesn[5], wesn[6]) : "" if (N_used <= 1) cmd, arg1, arg2, = add_opt_cpt(d, cmd, [:C], 'C', N_used, arg1, arg2, true, true, opt_T, true) else diff --git a/src/pslegend.jl b/src/pslegend.jl index 0ff347bde..b954f0de5 100644 --- a/src/pslegend.jl +++ b/src/pslegend.jl @@ -64,7 +64,7 @@ function legend(cmd0::String="", arg1=nothing; first::Bool=true, kwargs...) # Must also recreate a NT if any of 'fontsize' or 'font' is present in 'd' (because of how digests_legend_bag works) ((val = find_in_dict(d, [:fontsize])[1]) !== nothing) && (d[:leg] = (fontsize=val,)) ((val = find_in_dict(d, [:font])[1]) !== nothing) && (haskey(d, :leg) ? d[:leg] = (fontsize=d[:leg], font=val) : d[:leg] = (font=val,)) - ((val = find_in_dict(d, [:pos :position])[1]) !== nothing) && (LEGEND_TYPE[1].optsDict = Dict(:pos => val)) + ((val = find_in_dict(d, [:pos :position])[1]) !== nothing) && (LEGEND_TYPE[].optsDict = Dict(:pos => val)) digests_legend_bag(d) # It's over now, lets show up (or not) and return return (do_show || figname != "") ? showfig(show=do_show, savefig=figname) : nothing diff --git a/src/psscale.jl b/src/psscale.jl index 0028ffa04..76cf52aed 100644 --- a/src/psscale.jl +++ b/src/psscale.jl @@ -74,8 +74,8 @@ function colorbar_parser(arg1::Union{Nothing, GMTcpt}=nothing; first=true, kwarg cmd *= opt_D cmd, arg1, = add_opt_cpt(d, cmd, CPTaliases, 'C', 0, arg1) if (!isa(arg1, GMTcpt) && !occursin("-C", cmd)) # If given no CPT, try to see if we have a current one stored in global - if (!isempty(CURRENT_CPT[1])) - cmd *= " -C"; arg1 = CURRENT_CPT[1] + if (!isempty(CURRENT_CPT[])) + cmd *= " -C"; arg1 = CURRENT_CPT[] end end diff --git a/src/psxy.jl b/src/psxy.jl index b0ab02628..0c9675928 100644 --- a/src/psxy.jl +++ b/src/psxy.jl @@ -189,7 +189,7 @@ function _common_plot_xyz(cmd0::String, arg1, caller::String, O::Bool, K::Bool, (got_Zvars && (do_Z_fill || opt_G != "") && opt_L == "") && (cmd *= " -L") # GMT requires -L when -Z fill or -G if ((do_Z_fill || do_Z_outline || (got_color_line_grad && !is3D)) && !occursin("-C", cmd)) - if (isempty(CURRENT_CPT[1])) + if (isempty(CURRENT_CPT[])) if (got_color_line_grad) # Use the fact that we have min/max already stored mima::Vector{Float64} = (arg1.ds_bbox[5+2*is3D]::Float64, arg1.ds_bbox[6+2*is3D]::Float64) else @@ -197,7 +197,7 @@ function _common_plot_xyz(cmd0::String, arg1, caller::String, O::Bool, K::Bool, end r = makecpt_raw(@sprintf("makecpt -T%f/%f/65+n -Cturbo -Vq", mima[1]-eps(1e10), mima[2]+eps(1e10))) else - r = CURRENT_CPT[1] + r = CURRENT_CPT[] end (arg1 === nothing) ? arg1 = r : ((arg2 === nothing) ? arg2 = r : (arg3 === nothing ? arg3 = r : arg4 = r)) cmd *= " -C" @@ -253,7 +253,7 @@ function _common_plot_xyz(cmd0::String, arg1, caller::String, O::Bool, K::Bool, finish = (is_ternary && occursin(" -M",_cmd[1])) ? false : true # But this case (-M) is bugged still in 6.2.0 ((r = check_dbg_print_cmd(d, _cmd)) !== nothing) && return r # FORCES RECOMPILE R = prep_and_call_finish_PS_module(d, _cmd, "", K, O, finish, arg1, arg2, arg3, arg4) - LEGEND_TYPE[1].Vd = 0 # Because for nested calls with legends this was still > 0, which screwed later + LEGEND_TYPE[].Vd = 0 # Because for nested calls with legends this was still > 0, which screwed later CTRL.pocket_d[1] = d # Store d that may be not empty with members to use in other modules (opt_B == " -B") && gmt_restart() # For some Fking mysterious reason (see Ex45) return R @@ -381,7 +381,7 @@ function parse_plot_callers(d::Dict{Symbol, Any}, gmt_proggy::String, caller::St (arg1 !== nothing && !isa(arg1, GDtype) && !isa(arg1, Matrix{<:Real}) && !isFV) && (arg1 = tabletypes2ds(arg1, ((val = hlp_desnany_int(d, [:interp])) !== -999) ? interp=val : interp=0)) (caller != "bar") && (arg1 = if_multicols(d, arg1, is3D)) # Repeat because DataFrames or ODE's have skipped first round - (!O) && (LEGEND_TYPE[1] = legend_bag()) # Make sure that we always start with an empty one + (!O) && (LEGEND_TYPE[] = legend_bag()) # Make sure that we always start with an empty one cmd::String = ""; sub_module::String = "" # Will change to "scatter", etc... if called by sub-modules opt_A::String = "" # For the case the caller was in fact "stairs" @@ -432,7 +432,7 @@ function plt_txt_attrib!(D::Vector{<:GMTdataset{T,N}}, d::Dict{Symbol, Any}, _cm fnt = "+f" t = outline .* t end - ct::GMTdataset{Float64,2} = mat2ds(gmt_centroid_area(G_API[1], D, Int(isgeog(D))), geom=wkbPoint) + ct::GMTdataset{Float64,2} = mat2ds(gmt_centroid_area(G_API[], D, Int(isgeog(D))), geom=wkbPoint) ct.text = t # Texts will be plotted at the polygons centroids (CTRL.pocket_call[1] === nothing) ? (CTRL.pocket_call[1] = ct) : (CTRL.pocket_call[2] = ct) end @@ -861,8 +861,8 @@ function helper_psxy_line_barr1(cmd::String, is3D::Bool, arg1, arg2, arg3)::GMTc CPTname = scan_opt(cmd, "-C") cpt::GMTcpt = gmtread(CPTname, cpt=true) end - elseif (!isempty(CURRENT_CPT[1])) - cpt = CURRENT_CPT[1] + elseif (!isempty(CURRENT_CPT[])) + cpt = CURRENT_CPT[] else mima = (size(arg1,2) == 2) ? (1,size(arg1,1)) : (arg1.ds_bbox[5+0*is3D], arg1.ds_bbox[6+0*is3D]) cpt = gmt(@sprintf("makecpt -T%f/%f/65+n -Cturbo -Vq", mima[1]-eps(1e10), mima[2]+eps(1e10))) @@ -1286,7 +1286,7 @@ function make_color_column(d::Dict, cmd::String, opt_i::String, len_cmd::Int, N_ for k = 1:numel(arg1) add2ds!(arg1[k], 1:n_rows; name="Zcolor") end # Will error if the n_rows varies end arg2::GMTcpt = gmt(string("makecpt -T1/$(n_rows+1)/1 -C" * join(bar_fill, ","))) - CURRENT_CPT[1] = arg2 + CURRENT_CPT[] = arg2 (!occursin(" -C", cmd)) && (cmd *= " -C") # Need to inform that there is a cpt to use find_in_dict(d, [:G :fill]) # Deletes the :fill. Not used anymore return cmd, arg1, arg2, 2, true @@ -1339,7 +1339,7 @@ function make_color_column_(d::Dict, cmd::String, len_cmd::Int, N_args::Int, n_p just_C = just_C[1:ind[1]-1] end arg2 = gmt(string("makecpt -T", mi-0.001*abs(mi), '/', ma+0.001*abs(ma), " ", just_C) * (IamModern[] ? " -H" : "")) - CURRENT_CPT[1] = arg2 + CURRENT_CPT[] = arg2 if (occursin(" -C", cmd)) cmd = cmd[1:len_cmd+3] end # Strip the cpt name if (reset_i != "") cmd *= reset_i end # Reset -i, in case it existed @@ -1391,8 +1391,8 @@ function check_caller(d::Dict, cmd::String, opt_S::String, opt_W::String, caller end if (occursin('3', caller)) - (!occursin(" -B", cmd) && !O && (get(POSTMAN[1], "noframe", "") == "")) && (cmd *= DEF_FIG_AXES3[]) # For overlays default is no axes - (get(POSTMAN[1], "noframe", "") != "") && delete!(POSTMAN[1], "noframe") + (!occursin(" -B", cmd) && !O && (get(POSTMAN[], "noframe", "") == "")) && (cmd *= DEF_FIG_AXES3[]) # For overlays default is no axes + (get(POSTMAN[], "noframe", "") != "") && delete!(POSTMAN[], "noframe") end return cmd @@ -1502,7 +1502,7 @@ function sort_visible_faces(FV::GMTfv, azim, elev; del::Bool=true)::Tuple{GMTfv, projs = Float64[] if (!isempty(FV.color_vwall)) - P::Ptr{GMT_PALETTE} = palette_init(G_API[1], gmt("makecpt -T0/1 -C" * FV.color_vwall)); # A pointer to a GMT CPT + P::Ptr{GMT_PALETTE} = palette_init(G_API[], gmt("makecpt -T0/1 -C" * FV.color_vwall)); # A pointer to a GMT CPT rgb = [0.0, 0.0, 0.0, 0.0] end @@ -1540,7 +1540,7 @@ function sort_visible_faces(FV::GMTfv, azim, elev; del::Bool=true)::Tuple{GMTfv, end push!(_projs, this_proj) # But need the normals as stated at the begining of this function if (have_colorwall) - gmt_get_rgb_from_z(G_API[1], P, this_proj, rgb) + gmt_get_rgb_from_z(G_API[], P, this_proj, rgb) FV.color[k][face] = @sprintf("-G#%.2x%.2x%.2x", round(Int, rgb[1]*255), round(Int, rgb[2]*255), round(Int, rgb[3]*255)) end end @@ -1597,7 +1597,7 @@ function sort_visible_triangles(Dv::Vector{<:GMTdataset}; del_hidden=false, zfac end # ---------------------- Now sort by distance to the viewer ---------------------- - Dc::GMTdataset{Float64,2} = mat2ds(gmt_centroid_area(G_API[1], Dv, Int(isgeog(Dv)), ca=2), geom=wkbPoint) + Dc::GMTdataset{Float64,2} = mat2ds(gmt_centroid_area(G_API[], Dv, Int(isgeog(Dv)), ca=2), geom=wkbPoint) dists = [(Dc.data[1,1] * sin_az + Dc.data[1,2] * cos_az, (Dv[1].bbox[5] + Dv[1].bbox[6]) / 2 * sin_el)] for k = 2:size(Dc, 1) push!(dists, (Dc.data[k,1] * sin_az + Dc.data[k,2] * cos_az, (Dv[k].bbox[5] + Dv[k].bbox[6]) / 2 * sin_el)) @@ -1746,17 +1746,17 @@ function replicant_worker(FV::GMTfv, xyz, azim, elev, cval, cpt, scales) end end - P::Ptr{GMT_PALETTE} = palette_init(G_API[1], cpt) # A pointer to a GMT CPT + P::Ptr{GMT_PALETTE} = palette_init(G_API[], cpt) # A pointer to a GMT CPT rgb = [0.0, 0.0, 0.0, 0.0] cor = [0.0, 0.0, 0.0] D2 = Vector{GMTdataset{promote_type(eltype(xyz), eltype(scales), eltype(t)),2}}(undef, size(xyz, 1) * n_faces_tot) # ---------- Now we do the replication for k = 1:size(xyz, 1) # Loop over number of positions. For each of these we have a new body - gmt_get_rgb_from_z(G_API[1], P, cval[k], rgb) + gmt_get_rgb_from_z(G_API[], P, cval[k], rgb) for face = 1:n_faces_tot # Loop over number of faces of the base body cor[1], cor[2], cor[3] = rgb[1], rgb[2], rgb[3] - gmt_illuminate(G_API[1], normals[face], cor) + gmt_illuminate(G_API[], normals[face], cor) txt = @sprintf("-G%.0f/%.0f/%.0f", cor[1]*255, cor[2]*255, cor[3]*255) D2[(k-1)*n_faces_tot+face] = GMTdataset(data=(D1[face].data * scales[k] .+ xyz[k:k,1:3]), header=txt) end diff --git a/src/spatial_funs.jl b/src/spatial_funs.jl index 4e24733bc..be16b7768 100644 --- a/src/spatial_funs.jl +++ b/src/spatial_funs.jl @@ -310,7 +310,7 @@ function getbyattrib(D::Vector{<:GMTdataset}, ind_::Bool; kw...)::Vector{Int} (ind = findfirst(atts .== "_nps")) !== nothing && (nps = parse.(Float64, vals[ind])) (ind = findfirst(atts .== "_aspect")) !== nothing && (ratio = parse(Float64, vals[ind])) ((ind = findfirst(atts .== "_area")) !== nothing || (ind = findfirst(atts .== "_unique")) !== nothing) && - (area = parse.(Float64, vals[ind]); areas = gmt_centroid_area(G_API[1], D, Int(isgeog(D)), ca=1); isgeog(D) && (areas .*= 1e-6)) # areas in km^2 if geographic coords + (area = parse.(Float64, vals[ind]); areas = gmt_centroid_area(G_API[], D, Int(isgeog(D)), ca=1); isgeog(D) && (areas .*= 1e-6)) # areas in km^2 if geographic coords indices::Vector{Int} = Int[] ky = keys(D[1].attrib) diff --git a/src/statplots.jl b/src/statplots.jl index 9ba754e82..5e7057e5d 100644 --- a/src/statplots.jl +++ b/src/statplots.jl @@ -1509,7 +1509,7 @@ function marginalhist(arg1::Union{GDtype, Matrix{<:Real}}; first=true, kwargs... l = CTRL.figsize[1] <= 6 ? 3 : CTRL.figsize[1] <= 20 ? CTRL.figsize[1] / 4 : CTRL.figsize[1] * 0.2 colorbar(pos=(inside=:TL,length=(l,0.25), horizontal=true, offset=(0.2,0.2)), B=(ylabel=:Count, annot=:a), par=("FONT_ANNOT_PRIMARY","7p"), Vd=Vd) end - #gmt("psscale -Bpa -Bpy+lCount -DjTL+w3/0.25+h+o0.2/0.2 -C --FONT_ANNOT_PRIMARY=7p", CURRENT_CPT[1]) + #gmt("psscale -Bpa -Bpy+lCount -DjTL+w3/0.25+h+o0.2/0.2 -C --FONT_ANNOT_PRIMARY=7p", CURRENT_CPT[]) end subplot(endwith) end diff --git a/src/themes.jl b/src/themes.jl index 752ab777d..6c8acf3bc 100644 --- a/src/themes.jl +++ b/src/themes.jl @@ -32,7 +32,7 @@ This function can be called alone, e.g. `theme("dark")` or as an option in the ` function theme(name="modern"; kwargs...) # Provide the support for themes - (!isa(G_API[1], Ptr{Nothing}) || G_API[1] == C_NULL) && (G_API[1] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS)) + (!isa(G_API[], Ptr{Nothing}) || G_API[] == C_NULL) && (G_API[] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS)) d = KW(kwargs) font::String = ((val = find_in_dict(d, [:font])[1]) !== nothing) ? string(val) : "" @@ -59,8 +59,8 @@ function theme(name="modern"; kwargs...) (find_in_dict(d, [:noticks :no_ticks])[1] !== nothing) && helper_theme_noticks() # No ticks (find_in_dict(d, [:inner_ticks :innerticks])[1] !== nothing) && helper_theme_inticks() # Inner ticks if (find_in_dict(d, [:gray_grid :graygrid])[1] !== nothing) - gmtlib_setparameter(G_API[1], "MAP_GRID_PEN_PRIMARY", "auto,gray") - gmtlib_setparameter(G_API[1], "MAP_GRID_PEN_SECONDARY", "auto,gray") + gmtlib_setparameter(G_API[], "MAP_GRID_PEN_PRIMARY", "auto,gray") + gmtlib_setparameter(G_API[], "MAP_GRID_PEN_SECONDARY", "auto,gray") end isOn = true # Means this theme will be reset to the default (modern) in showfig() @@ -96,7 +96,7 @@ function parse_theme_names(name::String) contains(name, "V") && (t1 = "xag -Bya") # Only vertical grid lines end if contains(name, "Graph") # Add a vector to the end of each axis - gmtlib_setparameter(G_API[1], "MAP_FRAME_TYPE", "graph") + gmtlib_setparameter(G_API[], "MAP_FRAME_TYPE", "graph") name *= "XY" # Must be if already there, no problems end t2 = contains(name, "XY") ? "WS" : (contains(name, "YY")) ? "WE" : (contains(name, "XX")) ? "SN" : "WSrt" @@ -104,7 +104,7 @@ function parse_theme_names(name::String) if (name[2] == '0') if (length(name) == 2) t1, t2 = " ", "" # Really no axes no annotations/ticks - else gmtlib_setparameter(G_API[1], "MAP_FRAME_PEN", "0.001,white@100") # No axes, but need this sad trick + else gmtlib_setparameter(G_API[], "MAP_FRAME_PEN", "0.001,white@100") # No axes, but need this sad trick end end @@ -112,8 +112,8 @@ function parse_theme_names(name::String) if (contains(name, "nt") || contains(name, "NT")) helper_theme_noticks() # No ticks elseif (contains(name, "it") || contains(name, "IT")) helper_theme_inticks() # Inside ticks end - gmtlib_setparameter(G_API[1], "MAP_GRID_PEN_PRIMARY", "auto,gray") - gmtlib_setparameter(G_API[1], "MAP_GRID_PEN_SECONDARY", "auto,gray") + gmtlib_setparameter(G_API[], "MAP_GRID_PEN_PRIMARY", "auto,gray") + gmtlib_setparameter(G_API[], "MAP_GRID_PEN_SECONDARY", "auto,gray") return true end return false @@ -122,14 +122,14 @@ end # --------------------------------------------------------------------------------------------------- function helper_theme_inticks() # Inside ticks. Fixed length because GMT has no way to set it auto - gmtlib_setparameter(G_API[1], "MAP_TICK_LENGTH_PRIMARY", "-4p") - gmtlib_setparameter(G_API[1], "MAP_TICK_LENGTH_SECONDARY", "-12p") + gmtlib_setparameter(G_API[], "MAP_TICK_LENGTH_PRIMARY", "-4p") + gmtlib_setparameter(G_API[], "MAP_TICK_LENGTH_SECONDARY", "-12p") end # --------------------------------------------------------------------------------------------------- function helper_theme_noticks() - gmtlib_setparameter(G_API[1], "MAP_TICK_LENGTH_PRIMARY", "0/0") - gmtlib_setparameter(G_API[1], "MAP_TICK_LENGTH_SECONDARY", "0/0") + gmtlib_setparameter(G_API[], "MAP_TICK_LENGTH_PRIMARY", "0/0") + gmtlib_setparameter(G_API[], "MAP_TICK_LENGTH_SECONDARY", "0/0") end # --------------------------------------------------------------------------------------------------- @@ -144,44 +144,44 @@ end function fonts_colors_settings(fonts, colors, bg_color) # This function serves mainly the dark theme but can be used by any other theme that # wants to change font and/or colors. - gmtlib_setparameter(G_API[1], "FONT_ANNOT_PRIMARY", "auto,$(fonts[1]),$(colors[1])") - gmtlib_setparameter(G_API[1], "FONT_ANNOT_SECONDARY", "auto,$(fonts[1]),$(colors[1])") - gmtlib_setparameter(G_API[1], "FONT_HEADING", "auto,$(fonts[2]),$(colors[1])") - gmtlib_setparameter(G_API[1], "FONT_LABEL", "auto,$(fonts[1]),$(colors[1])") - gmtlib_setparameter(G_API[1], "FONT_LOGO", "auto,$(fonts[3]),$(colors[1])") - gmtlib_setparameter(G_API[1], "FONT_TAG", "auto,$(fonts[1]),$(colors[1])") - gmtlib_setparameter(G_API[1], "FONT_TITLE", "auto,$(fonts[2]),$(colors[1])") - gmtlib_setparameter(G_API[1], "MAP_DEFAULT_PEN", "0.25p,$(colors[1])") - gmtlib_setparameter(G_API[1], "MAP_FRAME_PEN", "0.75,$(colors[1])") - gmtlib_setparameter(G_API[1], "MAP_GRID_PEN_PRIMARY", "auto,$(colors[1])") - gmtlib_setparameter(G_API[1], "MAP_GRID_PEN_SECONDARY", "auto,$(colors[2])") - gmtlib_setparameter(G_API[1], "MAP_TICK_PEN_PRIMARY", "auto,$(colors[1])") - gmtlib_setparameter(G_API[1], "MAP_TICK_PEN_SECONDARY", "auto,$(colors[2])") - gmtlib_setparameter(G_API[1], "PS_PAGE_COLOR", "$bg_color") + gmtlib_setparameter(G_API[], "FONT_ANNOT_PRIMARY", "auto,$(fonts[1]),$(colors[1])") + gmtlib_setparameter(G_API[], "FONT_ANNOT_SECONDARY", "auto,$(fonts[1]),$(colors[1])") + gmtlib_setparameter(G_API[], "FONT_HEADING", "auto,$(fonts[2]),$(colors[1])") + gmtlib_setparameter(G_API[], "FONT_LABEL", "auto,$(fonts[1]),$(colors[1])") + gmtlib_setparameter(G_API[], "FONT_LOGO", "auto,$(fonts[3]),$(colors[1])") + gmtlib_setparameter(G_API[], "FONT_TAG", "auto,$(fonts[1]),$(colors[1])") + gmtlib_setparameter(G_API[], "FONT_TITLE", "auto,$(fonts[2]),$(colors[1])") + gmtlib_setparameter(G_API[], "MAP_DEFAULT_PEN", "0.25p,$(colors[1])") + gmtlib_setparameter(G_API[], "MAP_FRAME_PEN", "0.75,$(colors[1])") + gmtlib_setparameter(G_API[], "MAP_GRID_PEN_PRIMARY", "auto,$(colors[1])") + gmtlib_setparameter(G_API[], "MAP_GRID_PEN_SECONDARY", "auto,$(colors[2])") + gmtlib_setparameter(G_API[], "MAP_TICK_PEN_PRIMARY", "auto,$(colors[1])") + gmtlib_setparameter(G_API[], "MAP_TICK_PEN_SECONDARY", "auto,$(colors[2])") + gmtlib_setparameter(G_API[], "PS_PAGE_COLOR", "$bg_color") end # --------------------------------------------------------------------------------------------------- function theme_modern() # Set the MODERN mode settings - swapmode(G_API[1], classic=false) # Set GMT->current.setting.run_mode = GMT_MODERN - resetdefaults(G_API[1]) # Set the modern mode settings (will clear eventual gmt.conf contents) - gmtlib_setparameter(G_API[1], "MAP_FRAME_PEN", "0.75") - gmtlib_setparameter(G_API[1], "FONT_TITLE", "auto,Times-Roman,black") - gmtlib_setparameter(G_API[1], "FONT_HEADING", "auto,Times-Roman,black") - gmtlib_setparameter(G_API[1], "FONT_SUBTITLE", "auto,Times-Roman,black") - #!IamModern[] && swapmode(G_API[1], classic=true) # Reset GMT->current.setting.run_mode = GMT_CLASSIC + swapmode(G_API[], classic=false) # Set GMT->current.setting.run_mode = GMT_MODERN + resetdefaults(G_API[]) # Set the modern mode settings (will clear eventual gmt.conf contents) + gmtlib_setparameter(G_API[], "MAP_FRAME_PEN", "0.75") + gmtlib_setparameter(G_API[], "FONT_TITLE", "auto,Times-Roman,black") + gmtlib_setparameter(G_API[], "FONT_HEADING", "auto,Times-Roman,black") + gmtlib_setparameter(G_API[], "FONT_SUBTITLE", "auto,Times-Roman,black") + #!IamModern[] && swapmode(G_API[], classic=true) # Reset GMT->current.setting.run_mode = GMT_CLASSIC if (IamModern[]) - gmtlib_setparameter(G_API[1], "MAP_ORIGIN_X", "0") # Workarround GMT bug. - gmtlib_setparameter(G_API[1], "MAP_ORIGIN_Y", "0") + gmtlib_setparameter(G_API[], "MAP_ORIGIN_X", "0") # Workarround GMT bug. + gmtlib_setparameter(G_API[], "MAP_ORIGIN_Y", "0") end - gmt_getdefaults(G_API[1]) # Read back eventual gmt.conf file whose contents we wipped out above + gmt_getdefaults(G_API[]) # Read back eventual gmt.conf file whose contents we wipped out above return nothing end # --------------------------------------------------------------------------------------------------- function theme_classic() - swapmode(G_API[1], classic=true) # Set GMT->current.setting.run_mode = GMT_CLASSIC - resetdefaults(G_API[1]) + swapmode(G_API[], classic=true) # Set GMT->current.setting.run_mode = GMT_CLASSIC + resetdefaults(G_API[]) end # --------------------------------------------------------------------------------------------------- diff --git a/src/utils_project.jl b/src/utils_project.jl index 34f6d3570..09f15973b 100644 --- a/src/utils_project.jl +++ b/src/utils_project.jl @@ -144,7 +144,7 @@ function worldrectangular(GI::GItype; proj::StrSymb="+proj=vandg +over", pm=0, l end G = grdcut(G, R=(G.x[pix_x[1]], G.x[pix_x[2]], yb, yt)) - POSTMAN[1]["Grange"] = @sprintf("%.10g %.10g %.10g %.10g", G.range[1], G.range[2], G.range[3], G.range[4]) # To be used by plotgrid! + POSTMAN[]["Grange"] = @sprintf("%.10g %.10g %.10g %.10g", G.range[1], G.range[2], G.range[3], G.range[4]) # To be used by plotgrid! G.remark = "pad=$pad" # Use this as a pocket to use in worldrectgrid() if (is_lee_os) cl = (isempty(coastlines)) ? pscoast(dump=:true, res=res, region=lims_geog) : coastlines @@ -563,7 +563,7 @@ end function plotgrid(Dgrat::Vector{<:GMTdataset}; first=true, kw...) temp::String = "GMTjl_annots_" * TMPDIR_USR[2] * TMPDIR_USR[3] fname = joinpath(TMPDIR_USR[1], temp * ".txt") - ((val = get(POSTMAN[1], "Grange", nothing)) === nothing) && error("Cannot find 'Grange' in POSTMAN. Was 'worldrectgrid' used to create the graticules?") + ((val = get(POSTMAN[], "Grange", nothing)) === nothing) && error("Cannot find 'Grange' in POSTMAN. Was 'worldrectgrid' used to create the graticules?") x0, x1, y0, y1 = parse.(Float64, split(val)) fig_dims = gmt("mapproject -W" * CTRL.pocket_R[1] * CTRL.pocket_J[1]).data::Matrix{Float64} shift = 0.004 * fig_dims[3] diff --git a/src/utils_types.jl b/src/utils_types.jl index b88208040..c322150bd 100644 --- a/src/utils_types.jl +++ b/src/utils_types.jl @@ -1198,10 +1198,10 @@ function line2multiseg(M::Matrix{T}; is3D::Bool=false, color::GMTcpt=GMTcpt(), a if (!isempty(color)) z_col = color_col rgb = [0.0, 0.0, 0.0, 0.0] - P::Ptr{GMT_PALETTE} = palette_init(G_API[1], color); # A pointer to a GMT CPT + P::Ptr{GMT_PALETTE} = palette_init(G_API[], color); # A pointer to a GMT CPT for k = 1:n_ds z = (use_row_number) ? z4color[k] : M[k, z_col] - gmt_get_rgb_from_z(G_API[1], P, z, rgb) + gmt_get_rgb_from_z(G_API[], P, z, rgb) t = @sprintf(",%.0f/%.0f/%.0f", rgb[1]*255, rgb[2]*255, rgb[3]*255) _hdr[k] = (first) ? " -W"*t : _hdr[k] * t end @@ -2045,7 +2045,7 @@ function burn_alpha!(img::GMTimage{<:UInt8, 3}, alpha::AbstractMatrix{UInt8}; bg bg_r, bg_g, bg_b = 255.0, 255.0, 255.0 # Background color if (isa(bg, Symbol) || isa(bg, String)) rgb = [0.0, 0.0, 0.0] - (gmt_getrgb(G_API[1], string(bg), rgb) != 0) && return nothing # A GMT error was printed already + (gmt_getrgb(G_API[], string(bg), rgb) != 0) && return nothing # A GMT error was printed already bg_r, bg_g, bg_b = rgb[1]*255, rgb[2]*255, rgb[3]*255 elseif isa(bg, Tuple) bg_r, bg_g, bg_b = Float64(bg[1]), Float64(bg[2]), Float64(bg[3]) diff --git a/test/test_PSs.jl b/test/test_PSs.jl index a4776bca2..e80007934 100644 --- a/test/test_PSs.jl +++ b/test/test_PSs.jl @@ -61,7 +61,7 @@ coast(R="-10/0/35/45", J="M12c", W=(0.5,"red"), B=:a, N=(type=1,pen=(1,"green")) coast!(R="-10/0/35/45", J="M12c", W=(0.5,"red"), B=:a, N=(type=1,pen=(1,"green")), clip=:stop, rivers="1/0.5p", Vd=dbg2) coast(region=(continent=:AN,), Vd=dbg2); coast(region="-10/36/-7/41+r", proj=:guess); -GMT.GMT_Get_Common(GMT.G_API[1], 'R'); +GMT.GMT_Get_Common(GMT.G_API[], 'R'); @test GMT.parse_dcw("", ((country=:PT, pen=(2,:red), fill=:blue), (country=:ES, pen=(2,:blue)) )) == " -EPT+p2,red+gblue -EES+p2,blue" r = coast(region=:g, proj=(name=:Gnomonic, center=(-120,35), horizon=60), frame=(annot=30, grid=15), res=:crude, area=10000, land=:tan, ocean=:cyan, shore=:thinnest, figsize=10, Vd=dbg2); @test startswith(r, "pscoast -Rg -JF-120/35/60/10 -Bpa30g15 -BWSen -A10000 -Dcrude -Gtan -Scyan -Wthinnest") diff --git a/test/test_common_opts.jl b/test/test_common_opts.jl index c1f90a144..98f5ef319 100644 --- a/test/test_common_opts.jl +++ b/test/test_common_opts.jl @@ -380,7 +380,7 @@ @test GMT.set_aspect_ratio("square", "", true) == "15c/15c" @test GMT.set_aspect_ratio(nothing, "", true, true) == "15c/0" - @test_throws ErrorException("Only integer or floating point types allowed in input. Not this: Char") GMT.dataset_init(GMT.G_API[1], ' ', [0]) + @test_throws ErrorException("Only integer or floating point types allowed in input. Not this: Char") GMT.dataset_init(GMT.G_API[], ' ', [0]) GMT.show_non_consumed(Dict{Symbol,Any}(:lala => 0), "prog"); GMT.dbg_print_cmd(Dict{Symbol,Any}(:lala => 0, :Vd=>2), "prog"); diff --git a/test/test_views.jl b/test/test_views.jl index 19561926b..5a1a28111 100644 --- a/test/test_views.jl +++ b/test/test_views.jl @@ -15,7 +15,7 @@ grdimage(rand(Float32, 128, 128)*255, rand(Float32, 128, 128)*255, rand(Float32, grdimage(data=(Gr,Gg,Gb), J=:X10, I=mat2grid(rand(Float32,128,128)), Vd=dbg2) grdimage(rand(Float32, 128, 128), shade=(default=30,), coast=(W=1,), Vd=dbg2) grdimage(rand(Float32, 128, 128), colorbar=(color=:rainbow, pos=(anchor=:RM,length=8)), Vd=dbg2) -GMT.CURRENT_CPT[1] = GMTcpt() +GMT.CURRENT_CPT[] = GMTcpt() grdimage(rand(Float32, 128, 128), percent=90, Vd=dbg2) grdimage(rand(Float32, 128, 128), clim=[0.1, 0.9], Vd=dbg2) grdimage("@earth_relief_01d_g", percent=98, Vd=dbg2) @@ -85,7 +85,7 @@ imshow(I,Vd=dbg2) imshow(mat2ds([0 0; 10 0; 10 10; 11 10]), Vd=dbg2) imshow(makecpt(1,5, cmap=:polar), Vd=dbg2) imshow(:gray, Vd=dbg2) -GMT.CURRENT_CPT[1] = GMT.GMTcpt() # The fact that I need to do this because prev line did no "show", shows a subtle bug. +GMT.CURRENT_CPT[] = GMT.GMTcpt() # The fact that I need to do this because prev line did no "show", shows a subtle bug. X4 = mat2grid(rand(Float32,32,32,4), title="lixo"); viz(X4, colorbar=true, show=false) GMT.mat2grid("ackley");