Skip to content

Commit 6a4bb1a

Browse files
authored
Convert many global variables involving vectors to use Ref instead. (#1841)
Following a Claude analysis.
1 parent 79d24b0 commit 6a4bb1a

44 files changed

Lines changed: 316 additions & 316 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/GMT.jl

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,38 @@ else
5454
end
5555

5656
const global G_API = [C_NULL]
57-
const global PSname = [""] # The PS file (filled in __init__) where, in classic mode, all lands.
57+
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
60-
const global IMG_MEM_LAYOUT = [""] # "TCP" For Images.jl. The default is "TRBa"
61-
const global GRD_MEM_LAYOUT = [""] # "BRP" is the default for GMT PS images.
62-
const global CURRENT_VIEW = [""] # To store the current viewpoint (-p)
63-
const global MULTI_COL = Vector{Bool}(undef, 1);MULTI_COL[1] = false # To allow plottig multiple columns at once.
64-
const global IamModern = Vector{Bool}(undef, 1);IamModern[1] = false # To know if we are in modern mode
65-
const global FirstModern = Vector{Bool}(undef, 1);FirstModern[1] = false # To know
66-
const global DidOneGmtCmd = [Bool(0)] # To know when first gmt() call. Used in first modern mode cmd to not restart what is still fresh
67-
const global IamModernBySubplot = Vector{Bool}(undef, 1); IamModernBySubplot[1] = false # To know if set in subpot
68-
const global IamSubplot = Vector{Bool}(undef, 1);IamSubplot[1] = false # To know if we are in subplot mode
60+
const IMG_MEM_LAYOUT = Ref{String}("") # "TCP" For Images.jl. The default is "TRBa"
61+
const GRD_MEM_LAYOUT = Ref{String}("") # "BRP" is the default for GMT PS images.
62+
const CURRENT_VIEW = Ref{String}("") # To store the current viewpoint (-p)
63+
const MULTI_COL = Ref{Bool}(false) # To allow plottig multiple columns at once.
64+
const IamModern = Ref{Bool}(false) # To know if we are in modern mode
65+
const FirstModern = Ref{Bool}(false) # To know
66+
const DidOneGmtCmd = Ref{Bool}(false) # To know when first gmt() call. Used in first modern mode cmd to not restart what is still fresh
67+
const IamModernBySubplot = Ref{Bool}(false) # To know if set in subpot
68+
const IamSubplot = Ref{Bool}(false) # To know if we are in subplot mode
6969
const global IamInset = [false, false] # To know if we are in Inset mode
70-
const global usedConfPar = Vector{Bool}(undef, 1);usedConfPar[1] = false # Hacky solution for the session's memory trouble
71-
const global ThemeIsOn = Vector{Bool}(undef, 1);ThemeIsOn[1] = false # To know if we have an active plot theme
72-
const global CONVERT_SYNTAX = Vector{Bool}(undef, 1);CONVERT_SYNTAX[1] = false # To only convert to hard core GMT syntax (like Vd=2)
73-
const global SHOW_KWARGS = Vector{Bool}(undef, 1);SHOW_KWARGS[1] = false # To just print the kwargs of a option call)
74-
const global isFranklin = Vector{Bool}(undef, 1);isFranklin[1] = false # Only set/unset by the Docs building scripts.
75-
const global isJupyter = [Bool(0)] # Jupyter and Modern need special treatment (Quarto).
76-
const global isPSclosed = [Bool(0)] # Modern mode will close the PS at the end. We need to know that
77-
const global noGrdCopy = Vector{Bool}(undef, 1);noGrdCopy[1] = false # If true, grids are sent without transpose/copy
78-
const global GMTCONF = Vector{Bool}(undef, 1);GMTCONF[1] = false # Flag if gmtset was used and must be 'unused'
79-
const global FMT = ["png"] # The default plot format
80-
const global BOX_STR = [""] # Used in plotyy to know -R of first call
70+
const usedConfPar = Ref{Bool}(false) # Hacky solution for the session's memory trouble
71+
const ThemeIsOn = Ref{Bool}(false) # To know if we have an active plot theme
72+
const CONVERT_SYNTAX = Ref{Bool}(false) # To only convert to hard core GMT syntax (like Vd=2)
73+
const SHOW_KWARGS = Ref{Bool}(false) # To just print the kwargs of a option call)
74+
const isFranklin = Ref{Bool}(false) # Only set/unset by the Docs building scripts.
75+
const isJupyter = Ref{Bool}(false) # Jupyter and Modern need special treatment (Quarto).
76+
const isPSclosed = Ref{Bool}(false) # Modern mode will close the PS at the end. We need to know that
77+
const noGrdCopy = Ref{Bool}(false) # If true, grids are sent without transpose/copy
78+
const GMTCONF = Ref{Bool}(false) # Flag if gmtset was used and must be 'unused'
79+
const FMT = Ref{String}("png") # The default plot format
80+
const BOX_STR = Ref{String}("") # Used in plotyy to know -R of first call
8181
const global POSTMAN = [Dict{String,String}()] # To pass messages to functions (start with get_dataset)
82-
const global SACO = [Dict{String,Union{AbstractArray, Vector{AbstractArray}}}()] # When funs (fillsinks) want to return extra data but not via the return mechanism
82+
#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
8585
const DEF_FIG_AXES3_BAK = " -Baf -Bza" # "" but for 3D views
86-
const global DEF_FIG_AXES = [DEF_FIG_AXES_BAK] # This one may be be changed by theme()
87-
const global DEF_FIG_AXES3 = [DEF_FIG_AXES3_BAK] # ""
88-
const global FIG_MARGIN = [1] # Figure margin in points after convertion by 'psconvert'. Accessible 'margin' common option
86+
const DEF_FIG_AXES = Ref{String}(DEF_FIG_AXES_BAK) # This one may be be changed by theme()
87+
const DEF_FIG_AXES3 = Ref{String}(DEF_FIG_AXES3_BAK) # ""
88+
const FIG_MARGIN = Ref{Int}(1) # Figure margin in points after convertion by 'psconvert'. Accessible 'margin' common option
8989
const global CTRL = CTRLstruct(zeros(13), zeros(6), [true], [false],
9090
[:arrows, :bubblechart, :basemap, :band, :clip, :coast, :colorbar, :grdcontour, :hband, :hlines, :inset, :logo, :lines, :grdvector, :plot, :plot3, :quiver, :scatter, :scatter3, :stairs, :text, :vlines, :vband], fill(nothing, 6), ["","",""], ["","", "", " "], ["",""], ["",""], [false,true], [C_NULL], [Dict()])
9191
const global CTRLshapes = CTRLstruct2([true], [true], [""]) # Used in sub-module Drawing
@@ -464,14 +464,14 @@ function __init__(test::Bool=false)
464464
clear_sessions(3600) # Delete stray sessions dirs older than 1 hour
465465
G_API[1] = GMT_Create_Session("GMT", 2, GMT_SESSION_BITFLAGS) # (0.010179 sec)
466466
theme_modern() # Set the MODERN theme and some more gmtlib_setparameter() calls
467-
haskey(ENV, "JULIA_GMT_IMGFORMAT") && (FMT[1] = ENV["JULIA_GMT_IMGFORMAT"])
467+
haskey(ENV, "JULIA_GMT_IMGFORMAT") && (FMT[] = ENV["JULIA_GMT_IMGFORMAT"])
468468
f = joinpath(GMTuserdir[1], "theme_jl.txt")
469-
(isfile(f)) && (theme(readline(f)); ThemeIsOn[1] = false) # False because we don't want it reset in showfig()
469+
(isfile(f)) && (theme(readline(f)); ThemeIsOn[] = false) # False because we don't want it reset in showfig()
470470
user = (Sys.isunix() || Sys.isapple()) ? Libc.getpwuid(Libc.getuid(), true).username : Sys.iswindows() ? ENV["USERNAME"] : ""
471471
TMPDIR_USR[2] = replace(user, " " => "_")
472472
haskey(ENV, "JULIA_GMT_MULTIFILE") && (TMPDIR_USR[3] = string("_", getpid()))
473-
PSname[1] = TMPDIR_USR[1] * "/" * "GMTjl_" * TMPDIR_USR[2] * TMPDIR_USR[3] * ".ps"
474-
DidOneGmtCmd[1] = false
473+
PSname[] = TMPDIR_USR[1] * "/" * "GMTjl_" * TMPDIR_USR[2] * TMPDIR_USR[3] * ".ps"
474+
DidOneGmtCmd[] = false
475475
end
476476

477477
"""

0 commit comments

Comments
 (0)