Skip to content

Commit e7e4bc2

Browse files
authored
More global vector variables to Ref. (#1842)
Blame Claude.
1 parent 6a4bb1a commit e7e4bc2

29 files changed

Lines changed: 278 additions & 279 deletions

src/GMT.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ else
5353
const GMTdevdate = Date(devdate, dateformat"y.m.d") # 'devdate' comes from reading 'deps.jl'
5454
end
5555

56-
const global G_API = [C_NULL]
56+
const G_API = Ref{Ptr{Cvoid}}(C_NULL)
5757
const PSname = Ref{String}("") # The PS file (filled in __init__) where, in classic mode, all lands.
5858
const global TMPDIR_USR = [tempdir(), "", ""] # Save the tmp dir and user name (also filled in __init__)
5959
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
7878
const GMTCONF = Ref{Bool}(false) # Flag if gmtset was used and must be 'unused'
7979
const FMT = Ref{String}("png") # The default plot format
8080
const BOX_STR = Ref{String}("") # Used in plotyy to know -R of first call
81-
const global POSTMAN = [Dict{String,String}()] # To pass messages to functions (start with get_dataset)
81+
const POSTMAN = Ref{Dict{String,String}}(Dict{String,String}()) # To pass messages to functions (start with get_dataset)
8282
#const global SACO = [Dict{String,Union{AbstractArray, Vector{AbstractArray}}}()] # When funs (fillsinks) want to return extra data but not via the return mechanism
8383
const DEF_FIG_SIZE = "15c/10c" # Default fig size for plot like programs. Approx 16/11
8484
const DEF_FIG_AXES_BAK = " -Baf -BWSen" # Default fig axes for plot like programs
@@ -219,13 +219,13 @@ include("gdal/gdal.jl")
219219
include("gdal_utils.jl")
220220
include("proj_utils.jl")
221221
const global MatGDsGd = Union{Matrix{<:AbstractFloat}, GMTdataset, Vector{<:GMTdataset}, Gdal.AbstractDataset}
222-
const global CURRENT_CPT = [GMTcpt()] # To store the current palette
222+
const CURRENT_CPT = Ref{GMTcpt}(GMTcpt()) # To store the current palette
223223

224224
include("gmt_main.jl")
225225
include("utils_types.jl")
226226
include("grd_operations.jl")
227227
include("common_options.jl")
228-
const global LEGEND_TYPE = [legend_bag()] # To store Legends info
228+
const LEGEND_TYPE = Ref{legend_bag}(legend_bag()) # To store Legends info
229229
include("beziers.jl")
230230
include("circfit.jl")
231231
include("crop.jl")
@@ -380,15 +380,14 @@ include("windbarbs/windbarbs.jl")
380380
include("zscale.jl")
381381
include("get_enums.jl")
382382

383-
384383
using .Gdal
385384
using .Laszip
386385

387386
#include("ImageFeatures/ImageFeatures.jl")
388387
#using .ImageFeatures
389388

390389
@compile_workload begin
391-
G_API[1] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS)
390+
G_API[] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS)
392391
#GMT.parse_B(Dict{Symbol, Any}(:frame => (annot=10, title="Ai Ai"), :grid => (pen=2, x=10, y=20)), "", " -Baf -BWSen");
393392
#GMT.parse_R(Dict{Symbol, Any}(:xlim => (1,2), :ylim => (3,4), :zlim => (5,6)), "");
394393
#GMT.parse_J(Dict{Symbol, Any}(:J => "X", :scale => "1:10"), "");
@@ -462,7 +461,7 @@ end
462461

463462
function __init__(test::Bool=false)
464463
clear_sessions(3600) # Delete stray sessions dirs older than 1 hour
465-
G_API[1] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) # (0.010179 sec)
464+
G_API[] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) # (0.010179 sec)
466465
theme_modern() # Set the MODERN theme and some more gmtlib_setparameter() calls
467466
haskey(ENV, "JULIA_GMT_IMGFORMAT") && (FMT[] = ENV["JULIA_GMT_IMGFORMAT"])
468467
f = joinpath(GMTuserdir[1], "theme_jl.txt")

src/blendimg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ function lelandshade(G::GMTgrid; detail=1.0, contrast=2.0, uint16=false, intensi
342342
_cpt = iscptmaster ? cmap : nothing
343343
if (cmap != "")
344344
cpt = cmap
345-
isa(cpt, GMTcpt) && (CURRENT_CPT[1] = cpt)
345+
isa(cpt, GMTcpt) && (CURRENT_CPT[] = cpt)
346346
elseif (equalize == 0)
347347
cpt = makecpt(G; C=_cpt, Vd=-1, kw...) # The 'nothing' branch will pick G's cpt
348348
else

src/choropleth_utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ function cpt4dcw(codes::Vector{<:AbstractString}, vals::Vector{<:Real}; kwargs..
3232
while(_vals[k] > C.minmax[2] && k > 0) c[k] = false; k -= 1 end
3333
_codes, _vals = _codes[c], _vals[c]
3434

35-
P::Ptr{GMT_PALETTE} = palette_init(G_API[1], C) # A pointer to a GMT CPT
35+
P::Ptr{GMT_PALETTE} = palette_init(G_API[], C) # A pointer to a GMT CPT
3636

3737
Ccat::GMTcpt = gmt("makecpt -T"*join(_codes, ","))
3838
rgb = [0.0, 0.0, 0.0, 0.0];
3939
_rgb = [0.0, 0.0, 0.0, 0.0];
4040

4141
inc = (C.minmax[2] - C.minmax[1]) / size(Ccat.cpt, 1)
4242
for k = 1:size(Ccat.cpt, 1)
43-
gmt_get_rgb_from_z(G_API[1], P, _vals[k], rgb)
43+
gmt_get_rgb_from_z(G_API[], P, _vals[k], rgb)
4444
Ccat.colormap[k, 1], Ccat.colormap[k, 2], Ccat.colormap[k, 3] = rgb[1], rgb[2], rgb[3]
4545
_rgb[1], _rgb[2], _rgb[3] = rgb[1], rgb[2], rgb[3]
4646
[Ccat.cpt[k, n+1] = copy(_rgb[(n % 3) + 1]) for n = 0:5] # cpt = [rgb rgb]

0 commit comments

Comments
 (0)