Skip to content

Commit 5f919e2

Browse files
authored
Fix a longstanding issue with subplots containing colorbars. (#1906)
The solution is a workaround because true cause lies in an inaccessible part of the C library.
1 parent 6461bcb commit 5f919e2

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/segy/segy.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Plot a SEGY file as a seismic data image.
55
"""
6-
segy!(cmd0::String; kwargs...) = segy_helper(cmd0; first=false, kwargs...)
6+
segy!(cmd0::String; kwargs...) = segy(cmd0; first=false, kwargs...)
77
function segy(cmd0::String; first=true, kw...)
88
#(cmd0 === "") && error("Missing input segY file name to run this module.")
99
d, K, O = init_module(first==1, kw...) # Also checks if the user wants ONLY the HELP mode
@@ -49,7 +49,7 @@ end
4949
5050
Plot a SEGY file in 3-D as a seismic data image.
5151
"""
52-
segyz!(cmd0::String; kwargs...) = segyz_helper(cmd0; first=false, kwargs...)
52+
segyz!(cmd0::String; kwargs...) = segyz(cmd0; first=false, kwargs...)
5353
function segyz(cmd0::String; first=true, kw...)
5454
d, K, O = init_module(first==1, kw...) # Also checks if the user wants ONLY the HELP mode
5555
segyz_helper(cmd0, O, K, d)

src/subplot.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function subplot(fim::String, stop::Bool, d::Dict{Symbol, Any})
113113
gmt("gmtset MAP_FRAME_TYPE fancy")
114114
catch; resetGMT()
115115
end
116+
remove_map_origin() # Remove MAP_ORIGIN_X and MAP_ORIGIN_Y from the gmt.conf.0.subplot file (see comments in function)
116117
IamSubplot[], IamModern[] = true, true
117118
elseif (do_set)
118119
(!IamSubplot[]) && error("Cannot call subplot(set, ...) before setting dimensions")
@@ -216,4 +217,31 @@ function mura_arg(arg)::Dict
216217
else d = (isa(arg, NamedTuple)) ? nt2dict(arg) : arg
217218
end
218219
d
220+
end
221+
222+
# --------------------------------------------------------------------------
223+
function remove_map_origin()
224+
# Remove MAP_ORIGIN_X and MAP_ORIGIN_Y from the gmt.conf.0.subplot file
225+
# The problem: GMT CLI when it creates the gmt.conf.0.subplot file, does not set MAP_ORIGIN_X and MAP_ORIGIN_Y
226+
# but because we fiddle a lot with themes and make the classic mode behave like modern, we end up setting them
227+
# and that has a drastic effect of burning permanently in the GMT_keyword_updated[] internal variable, AND THERE
228+
# IS NO WAY TO UNSET things inside GMT_keyword_updated[] from externals. When gmt_begin() is called, the
229+
# gmt.conf.0.subplot file is created and the MAP_ORIGIN_X and MAP_ORIGIN_Y are set. But this SCREWS the location
230+
# of the colorbars when we have subplots because they all overlap each other. The only solution found is to remove
231+
# the MAP_ORIGIN_X and MAP_ORIGIN_Y from the gmt.conf.0.subplot file.
232+
# WARNING: If we ever implement the 'figure' case, this function will need to be modified to account for the
233+
# figure number. As it is, the "0" in gmt.conf.0.subplot stands for figure 0.
234+
API = unsafe_load(convert(Ptr{GMTAPI_CTRL}, G_API[]))
235+
session_dir = unsafe_string(API.gwf_dir)
236+
fname = session_dir * filesep * "gmt.conf.0.subplot"
237+
!isfile(fname) && return
238+
lines = readlines(fname)
239+
filtered = filter(l -> !startswith(l, "MAP_ORIGIN_"), lines)
240+
length(filtered) == length(lines) && return nothing # Nothing to remove
241+
open(fname, "w") do io
242+
for l in filtered
243+
println(io, l)
244+
end
245+
end
246+
return nothing
219247
end

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ using InteractiveUtils
133133

134134
println(" SEGY")
135135
segy("", R="-35/6/0/30", J="x0.15i/-0.15i", D=0.35, C=8.0, F=:green, Q=(b=-1.2, x=0.1, y=0.1), S=:c, W=true, Vd=2);
136+
segy!("", D=0.35, C=8.0, F=:green, Q=(b=-1.2, x=0.1, y=0.1), S=:c, W=true, Vd=2);
136137
segyz("", R="-35/6/0/30/0/30", J="x0.15i/-0.15i", Jz="-0.15i", p=(175,5), D=0.35, C=8.0, F=:green, Q=(b=-1.2,), S="c/5", W=true, Vd=2);
138+
segyz!("", Jz="-0.15i", p=(175,5), D=0.35, C=8.0, F=:green, Q=(b=-1.2,), S="c/5", W=true, Vd=2);
137139
segy2grd("", R="-35/6/0/30", I=0.1, Vd=2);
138140

139141
#G = gmt("grdmath -R-15/15/-15/15 -I1 X Y HYPOT DUP 2 MUL PI MUL 8 DIV COS EXCH NEG 10 DIV EXP MUL =");

0 commit comments

Comments
 (0)