exec now tests for errors in Gnuplot process
This commit is contained in:
parent
51b4771ef3
commit
f8d2e4c0be
@ -495,7 +495,7 @@ newdataset(gp::DrySession, args...; name="") = newdataset(gp, data2string(args..
|
|||||||
function newcmd(gp::DrySession, v::String; mid::Int=0)
|
function newcmd(gp::DrySession, v::String; mid::Int=0)
|
||||||
setmulti(gp, mid)
|
setmulti(gp, mid)
|
||||||
(v != "") && (push!(gp.plots[gp.curmid].cmds, v))
|
(v != "") && (push!(gp.plots[gp.curmid].cmds, v))
|
||||||
(length(gp.plots) == 1) && (println(gp, v))
|
(length(gp.plots) == 1) && (exec(gp, v)) # execute now to check against errors
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -537,8 +537,8 @@ end
|
|||||||
# ╰───────────────────────────────────────────────────────────────────╯
|
# ╰───────────────────────────────────────────────────────────────────╯
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
dump(gp::DrySession; kw...) = dump(gp, gp; kw...)
|
dump(gp::DrySession; kw...) = dump(gp, gp; kw...)
|
||||||
function dump(gp::DrySession, stream; term::AbstractString="", output::AbstractString="")
|
function dump(gp::DrySession, stream; all=false, term::AbstractString="", output::AbstractString="")
|
||||||
println(stream, "reset")
|
all && println(stream, "reset session")
|
||||||
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]
|
||||||
@ -546,8 +546,7 @@ function dump(gp::DrySession, stream; term::AbstractString="", output::AbstractS
|
|||||||
end
|
end
|
||||||
(output != "") && println(stream, "set output '$output'")
|
(output != "") && println(stream, "set output '$output'")
|
||||||
|
|
||||||
if !(typeof(stream) <: DrySession)
|
if all # Dump datasets
|
||||||
# Dump datasets
|
|
||||||
for i in 1:length(gp.datas)
|
for i in 1:length(gp.datas)
|
||||||
d = gp.datas[i]
|
d = gp.datas[i]
|
||||||
println(stream, d.name * " << EOD")
|
println(stream, d.name * " << EOD")
|
||||||
@ -948,20 +947,28 @@ exec("print GPVAL_TERM")
|
|||||||
exec("plot sin(x)")
|
exec("plot sin(x)")
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function exec(sid::Symbol, s::Vector{String})
|
function exec(gp::DrySession, command::String)
|
||||||
global options
|
|
||||||
gp = getsession(sid)
|
|
||||||
answer = Vector{String}()
|
answer = Vector{String}()
|
||||||
for v in s
|
push!(answer, writeread(gp, command)...)
|
||||||
push!(answer, writeread(gp, v)...)
|
|
||||||
|
errno = writeread(gp, "print GPVAL_ERRNO")[1]
|
||||||
|
if errno != "0"
|
||||||
|
printstyled(color=:red, "GNUPLOT ERROR $(gp.sid) -> ERRNO=$errno\n")
|
||||||
|
errmsg = writeread(gp, "print GPVAL_ERRMSG")
|
||||||
|
write(gp.pin, "reset error\n")
|
||||||
|
for line in errmsg
|
||||||
|
printstyled(color=:red, "GNUPLOT ERROR $(gp.sid) -> $line\n")
|
||||||
end
|
end
|
||||||
|
error("Gnuplot process raised an error")
|
||||||
|
end
|
||||||
|
|
||||||
return join(answer, "\n")
|
return join(answer, "\n")
|
||||||
end
|
end
|
||||||
function exec(s::String)
|
function exec(s::String)
|
||||||
global options
|
global options
|
||||||
exec(options.default, [s])
|
exec(getsession(), s)
|
||||||
end
|
end
|
||||||
exec(sid::Symbol, s::String) = exec(sid, [s])
|
exec(sid::Symbol, s::String) = exec(getsession(sid), s)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
@ -992,12 +999,12 @@ To save the data and command from a specific session pass the ID as first argume
|
|||||||
|
|
||||||
In all cases the `term` keyword allows to specify a gnuplot terminal, and the `output` keyword allows to specify an output file.
|
In all cases the `term` keyword allows to specify a gnuplot terminal, and the `output` keyword allows to specify an output file.
|
||||||
"""
|
"""
|
||||||
save( ; kw...) = dump(getsession() ; kw...)
|
save( ; kw...) = dump(getsession() ; all=true, kw...)
|
||||||
save(sid::Symbol ; kw...) = dump(getsession(sid) ; kw...)
|
save(sid::Symbol ; kw...) = dump(getsession(sid) ; all=true, kw...)
|
||||||
save( stream::IO ; kw...) = dump(getsession() , stream; kw...)
|
save( stream::IO ; kw...) = dump(getsession() , stream; all=true, kw...)
|
||||||
save(sid::Symbol, stream::IO ; kw...) = dump(getsession(sid), stream; kw...)
|
save(sid::Symbol, stream::IO ; kw...) = dump(getsession(sid), stream; all=true, kw...)
|
||||||
save( file::AbstractString; kw...) = open(file, "w") do stream; dump(getsession() , stream; kw...); end
|
save( file::AbstractString; kw...) = open(file, "w") do stream; dump(getsession() , stream; all=true, kw...); end
|
||||||
save(sid::Symbol, file::AbstractString; kw...) = open(file, "w") do stream; dump(getsession(sid), stream; kw...); end
|
save(sid::Symbol, file::AbstractString; kw...) = open(file, "w") do stream; dump(getsession(sid), stream; all=true, kw...); end
|
||||||
|
|
||||||
|
|
||||||
# ╭───────────────────────────────────────────────────────────────────╮
|
# ╭───────────────────────────────────────────────────────────────────╮
|
||||||
|
|||||||
@ -115,7 +115,7 @@ name = "\$MyDataSet1"
|
|||||||
@gp x y name "plot $name w l" "pl $name u 1:(2*\$2) w l"
|
@gp x y name "plot $name w l" "pl $name u 1:(2*\$2) w l"
|
||||||
|
|
||||||
@gsp randn(Float64, 30, 50)
|
@gsp randn(Float64, 30, 50)
|
||||||
@gp randn(Float64, 30, 50) "w image"
|
@gp 1:30 1:50 randn(Float64, 30, 50) "w image"
|
||||||
@gsp x y y
|
@gsp x y y
|
||||||
|
|
||||||
@gp("set key horizontal", "set grid",
|
@gp("set key horizontal", "set grid",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user