Renamed gpexec

This commit is contained in:
Giorgio Calderone 2020-04-01 16:18:50 +02:00
parent 6c3b83c3b1
commit 2c4b8dda1e
2 changed files with 41 additions and 41 deletions

View File

@ -7,7 +7,7 @@ import Base.write
export session_names, dataset_names, palette_names, linetypes, palette, export session_names, dataset_names, palette_names, linetypes, palette,
terminal, terminals, test_terminal, terminal, terminals, test_terminal,
stats, @gp, @gsp, save, stats, @gp, @gsp, save, gpexec,
boxxyerror, contourlines, hist boxxyerror, contourlines, hist
# ╭───────────────────────────────────────────────────────────────────╮ # ╭───────────────────────────────────────────────────────────────────╮
@ -134,7 +134,7 @@ tostring(::Missing) = "?"
tostring(c::ColorTypes.RGB) = string(Int(c.r*255)) * " " * string(Int(c.g*255)) * " " * string(Int(c.b*255)) tostring(c::ColorTypes.RGB) = string(Int(c.r*255)) * " " * string(Int(c.g*255)) * " " * string(Int(c.b*255))
""" """
Gnuplot.arrays2datablock(arrays...) arrays2datablock(arrays...)
Convert one (or more) arrays into an `Vector{String}`, ready to be ingested as an *inline datablock*. Convert one (or more) arrays into an `Vector{String}`, ready to be ingested as an *inline datablock*.
@ -352,7 +352,7 @@ function GPSession(sid::Symbol)
sessions[sid] = out sessions[sid] = out
for l in options.init for l in options.init
writeread(out, l) gpexec(out, l)
end end
# Set window title (if not already set) # Set window title (if not already set)
@ -386,9 +386,9 @@ function gp_write_table(args...; kw...)
sid = Symbol("j", Base.Libc.getpid()) sid = Symbol("j", Base.Libc.getpid())
gp = getsession(sid) gp = getsession(sid)
reset(gp) reset(gp)
exec(sid, "set term unknown") gpexec(sid, "set term unknown")
driver(sid, "set table '$tmpfile'", args...; kw...) driver(sid, "set table '$tmpfile'", args...; kw...)
exec(sid, "unset table") gpexec(sid, "unset table")
quit(sid) quit(sid)
out = readlines(tmpfile) out = readlines(tmpfile)
rm(tmpfile) rm(tmpfile)
@ -589,7 +589,7 @@ function reset(gp::Session)
gp.datas = OrderedDict{String, DataSet}() gp.datas = OrderedDict{String, DataSet}()
gp.plots = [SinglePlot()] gp.plots = [SinglePlot()]
gp.curmid = 1 gp.curmid = 1
exec(gp, "reset session") gpexec(gp, "reset session")
return nothing return nothing
end end
@ -659,7 +659,7 @@ end
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
function add_cmd(gp::Session, v::String) function add_cmd(gp::Session, v::String)
(v != "") && (push!(gp.plots[gp.curmid].cmds, v)) (v != "") && (push!(gp.plots[gp.curmid].cmds, v))
(length(gp.plots) == 1) && (exec(gp, v)) # execute now to check against errors (length(gp.plots) == 1) && (gpexec(gp, v)) # execute now to check against errors
return nothing return nothing
end end
@ -709,7 +709,7 @@ end
# -------------------------------------------------------------------- # --------------------------------------------------------------------
function stats(gp::Session, name::String) function stats(gp::Session, name::String)
@info sid=gp.sid name=name source=gp.datas[name].gpsource @info sid=gp.sid name=name source=gp.datas[name].gpsource
println(exec(gp, "stats " * gp.datas[name].gpsource)) println(gpexec(gp, "stats " * gp.datas[name].gpsource))
end end
stats(gp::Session) = for (name, d) in gp.datas stats(gp::Session) = for (name, d) in gp.datas
stats(gp, name) stats(gp, name)
@ -717,12 +717,12 @@ end
# ╭───────────────────────────────────────────────────────────────────╮ # ╭───────────────────────────────────────────────────────────────────╮
# │ exec(), execall(), dump() and driver() │ # │ gpexec(), execall(), dump() and driver() │
# ╰───────────────────────────────────────────────────────────────────╯ # ╰───────────────────────────────────────────────────────────────────╯
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
exec(gp::DrySession, command::String) = "" gpexec(gp::DrySession, command::String) = ""
function exec(gp::GPSession, command::String) function gpexec(gp::GPSession, command::String)
answer = Vector{String}() answer = Vector{String}()
push!(answer, writeread(gp, command)...) push!(answer, writeread(gp, command)...)
@ -745,29 +745,29 @@ end
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
execall(gp::DrySession; term::AbstractString="", output::AbstractString="") = nothing execall(gp::DrySession; term::AbstractString="", output::AbstractString="") = nothing
function execall(gp::GPSession; term::AbstractString="", output::AbstractString="") function execall(gp::GPSession; term::AbstractString="", output::AbstractString="")
exec(gp, "reset") gpexec(gp, "reset")
if term != "" if term != ""
former_term = writeread(gp, "print GPVAL_TERM")[1] former_term = writeread(gp, "print GPVAL_TERM")[1]
former_opts = writeread(gp, "print GPVAL_TERMOPTIONS")[1] former_opts = writeread(gp, "print GPVAL_TERMOPTIONS")[1]
exec(gp, "set term $term") gpexec(gp, "set term $term")
end end
(output != "") && exec(gp, "set output '$output'") (output != "") && gpexec(gp, "set output '$output'")
for i in 1:length(gp.plots) for i in 1:length(gp.plots)
d = gp.plots[i] d = gp.plots[i]
for j in 1:length(d.cmds) for j in 1:length(d.cmds)
exec(gp, d.cmds[j]) gpexec(gp, d.cmds[j])
end end
if length(d.elems) > 0 if length(d.elems) > 0
s = (d.flag3d ? "splot " : "plot ") * " \\\n " * s = (d.flag3d ? "splot " : "plot ") * " \\\n " *
join(d.elems, ", \\\n ") join(d.elems, ", \\\n ")
exec(gp, s) gpexec(gp, s)
end end
end end
(length(gp.plots) > 1) && exec(gp, "unset multiplot") (length(gp.plots) > 1) && gpexec(gp, "unset multiplot")
(output != "") && exec(gp, "set output") (output != "") && gpexec(gp, "set output")
if term != "" if term != ""
exec(gp, "set term $former_term $former_opts") gpexec(gp, "set term $former_term $former_opts")
end end
return nothing return nothing
end end
@ -1057,8 +1057,8 @@ end
# -------------------------------------------------------------------- # --------------------------------------------------------------------
""" """
Gnuplot.exec(sid::Symbol, command::String) gpexec(sid::Symbol, command::String)
Gnuplot.exec(command::String) gpexec(command::String)
Execute the gnuplot command `command` on the underlying gnuplot process of the `sid` session, and return the results as a `Vector{String}`. If a gnuplot error arises it is propagated as an `ErrorException`. Execute the gnuplot command `command` on the underlying gnuplot process of the `sid` session, and return the results as a `Vector{String}`. If a gnuplot error arises it is propagated as an `ErrorException`.
@ -1066,12 +1066,12 @@ The the `sid` argument is not provided, the default session is considered.
## Examples: ## Examples:
```julia-repl ```julia-repl
Gnuplot.exec("print GPVAL_TERM") gpexec("print GPVAL_TERM")
Gnuplot.exec("plot sin(x)") gpexec("plot sin(x)")
``` ```
""" """
exec(sid::Symbol, s::String) = exec(getsession(sid), s) gpexec(sid::Symbol, s::String) = gpexec(getsession(sid), s)
exec(s::String) = exec(getsession(), s) gpexec(s::String) = gpexec(getsession(), s)
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
@ -1200,16 +1200,16 @@ function splash(outputfile="")
# terminals). # terminals).
terms = terminals() terms = terminals()
if "wxt" in terms if "wxt" in terms
exec(gp, "set term wxt noenhanced size 600,300") gpexec(gp, "set term wxt noenhanced size 600,300")
elseif "qt" in terms elseif "qt" in terms
exec(gp, "set term qt noenhanced size 600,300") gpexec(gp, "set term qt noenhanced size 600,300")
elseif "aqua" in terms elseif "aqua" in terms
exec(gp, "set term aqua noenhanced size 600,300") gpexec(gp, "set term aqua noenhanced size 600,300")
else else
@warn "None of the `wxt`, `qt` and `aqua` terminals are available. Output may look strange.." @warn "None of the `wxt`, `qt` and `aqua` terminals are available. Output may look strange.."
end end
else else
exec(gp, "set term unknown") gpexec(gp, "set term unknown")
end end
@gp :- :splash "set margin 0" "set border 0" "unset tics" :- @gp :- :splash "set margin 0" "set border 0" "unset tics" :-
@gp :- :splash xr=[-0.3,1.7] yr=[-0.3,1.1] :- @gp :- :splash xr=[-0.3,1.7] yr=[-0.3,1.1] :-
@ -1321,7 +1321,7 @@ end
Return a `Vector{String}` with the names of all the available gnuplot terminals. Return a `Vector{String}` with the names of all the available gnuplot terminals.
""" """
terminals() = string.(split(strip(exec("print GPVAL_TERMINALS")), " ")) terminals() = string.(split(strip(gpexec("print GPVAL_TERMINALS")), " "))
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -1331,7 +1331,7 @@ terminals() = string.(split(strip(exec("print GPVAL_TERMINALS")), " "))
Return a `String` with the current gnuplot terminal (and its options) of the process associated to session `sid`, or to the default session (if `sid` is not provided). Return a `String` with the current gnuplot terminal (and its options) of the process associated to session `sid`, or to the default session (if `sid` is not provided).
""" """
terminal(sid::Symbol=options.default) = exec(getsession(sid), "print GPVAL_TERM") * " " * exec(getsession(sid), "print GPVAL_TERMOPTIONS") terminal(sid::Symbol=options.default) = gpexec(getsession(sid), "print GPVAL_TERM") * " " * gpexec(getsession(sid), "print GPVAL_TERMOPTIONS")
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -1352,13 +1352,13 @@ function test_terminal(term=nothing; linetypes=nothing, palette=nothing)
quit(:test_term) quit(:test_term)
quit(:test_palette) quit(:test_palette)
if !isnothing(term) if !isnothing(term)
exec(:test_term , "set term $term") gpexec(:test_term , "set term $term")
exec(:test_palette , "set term $term") gpexec(:test_palette , "set term $term")
end end
s = (isnothing(linetypes) ? "" : Gnuplot.linetypes(linetypes)) s = (isnothing(linetypes) ? "" : linetypes(linetypes))
exec(:test_term , "$s; test") gpexec(:test_term , "$s; test")
s = (isnothing(palette) ? "" : Gnuplot.palette(palette)) s = (isnothing(palette) ? "" : palette(palette))
exec(:test_palette , "$s; test palette") gpexec(:test_palette , "$s; test palette")
end end

View File

@ -166,9 +166,9 @@ if Gnuplot.options.dry
b = 0.3 b = 0.3
c = 0.7 c = 0.7
else else
a = Meta.parse(Gnuplot.exec("print a")) a = Meta.parse(gpexec("print a"))
b = Meta.parse(Gnuplot.exec("print b")) b = Meta.parse(gpexec("print b"))
c = Meta.parse(Gnuplot.exec("print c")) c = Meta.parse(gpexec("print c"))
end end
@gp :dry "f(x) = a * sin(b + c*x); a = 1; b = 1; c = 1;" :- @gp :dry "f(x) = a * sin(b + c*x); a = 1; b = 1; c = 1;" :-
@ -183,7 +183,7 @@ name = "\$MyDataSet1"
@gp :- :dry @gp :- :dry
save("test.gp") # write on file test.gp save("test.gp") # write on file test.gp
Gnuplot.quitall() Gnuplot.quitall()
Gnuplot.exec("load 'test.gp'") # load file test.gp gpexec("load 'test.gp'") # load file test.gp
#----------------------------------------------------------------- #-----------------------------------------------------------------
@gp(""" @gp("""