Added :splot as possible input to gpDriver
This commit is contained in:
parent
f1ed19c2ea
commit
106f8470ba
@ -4,6 +4,10 @@ module Gnuplot
|
|||||||
|
|
||||||
using AbbrvKW
|
using AbbrvKW
|
||||||
|
|
||||||
|
import Base.send
|
||||||
|
import Base.reset
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# Exported symbols
|
# Exported symbols
|
||||||
######################################################################
|
######################################################################
|
||||||
@ -203,24 +207,24 @@ end
|
|||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
"""
|
"""
|
||||||
# gpSend
|
# send
|
||||||
|
|
||||||
Send a string to gnuplot's STDIN.
|
Send a string to gnuplot's STDIN.
|
||||||
|
|
||||||
The commands sent through `gpSend` are not stored in the current
|
The commands sent through `send` are not stored in the current
|
||||||
session (use `addCmd` to save commands in the current session).
|
session (use `addCmd` to save commands in the current session).
|
||||||
|
|
||||||
## Example:
|
## Example:
|
||||||
```
|
```
|
||||||
gp = GnuplotProc()
|
gp = GnuplotProc()
|
||||||
gpSend(gp, "plot sin(x)")
|
send(gp, "plot sin(x)")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Arguments:
|
## Arguments:
|
||||||
- `gp`: a GnuplotProc or GnuplotSession object;
|
- `gp`: a GnuplotProc or GnuplotSession object;
|
||||||
- `str::String`: command to be sent.
|
- `str::String`: command to be sent.
|
||||||
"""
|
"""
|
||||||
function gpSend(gp::GnuplotProc, str::AbstractString, capture=false)
|
function send(gp::GnuplotProc, str::AbstractString, capture=false)
|
||||||
(capture) && (write(gp.pin, "print 'GNUPLOT_CAPTURE_BEGIN'\n"))
|
(capture) && (write(gp.pin, "print 'GNUPLOT_CAPTURE_BEGIN'\n"))
|
||||||
w = write(gp.pin, strip(str) * "\n")
|
w = write(gp.pin, strip(str) * "\n")
|
||||||
logIn(gp, str)
|
logIn(gp, str)
|
||||||
@ -242,11 +246,11 @@ end
|
|||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
"""
|
"""
|
||||||
# gpReset
|
# reset
|
||||||
|
|
||||||
Delete all commands, data, and plots in the gnuplot session.
|
Delete all commands, data, and plots in the gnuplot session.
|
||||||
"""
|
"""
|
||||||
function gpReset(gp::GnuplotSession)
|
function reset(gp::GnuplotSession)
|
||||||
gp.blockCnt = 0
|
gp.blockCnt = 0
|
||||||
gp.data = Vector{inputData}()
|
gp.data = Vector{inputData}()
|
||||||
gp.plot = [inputPlot()]
|
gp.plot = [inputPlot()]
|
||||||
@ -256,15 +260,15 @@ function gpReset(gp::GnuplotSession)
|
|||||||
end
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# gpReset
|
# reset
|
||||||
|
|
||||||
Send a 'reset session' command to gnuplot and delete all commands,
|
Send a 'reset session' command to gnuplot and delete all commands,
|
||||||
data, and plots in the associated session.
|
data, and plots in the associated session.
|
||||||
"""
|
"""
|
||||||
function gpReset(gp::GnuplotProc)
|
function reset(gp::GnuplotProc)
|
||||||
gpReset(gp.session)
|
reset(gp.session)
|
||||||
gpSend(gp, "reset session")
|
send(gp, "reset session")
|
||||||
gpSend(gp, gp.session.defCmd)
|
send(gp, gp.session.defCmd)
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -393,7 +397,9 @@ setMultiID(gp::GnuplotProc, id::Int) = setMultiID(gp.session, id)
|
|||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
function setSplot(gp::GnuplotSession, splot::Bool)
|
function setSplot(gp::GnuplotSession, splot::Bool)
|
||||||
|
if splot
|
||||||
gp.plot[gp.multiID].splot = splot
|
gp.plot[gp.multiID].splot = splot
|
||||||
|
end
|
||||||
end
|
end
|
||||||
setSplot(gp::GnuplotProc, splot::Bool) = setSplot(gp.session, splot)
|
setSplot(gp::GnuplotProc, splot::Bool) = setSplot(gp.session, splot)
|
||||||
|
|
||||||
@ -420,7 +426,7 @@ end
|
|||||||
|
|
||||||
function addCmd(gp::GnuplotProc, s::String; id::Int=0)
|
function addCmd(gp::GnuplotProc, s::String; id::Int=0)
|
||||||
addCmd(gp.session, s, id=id)
|
addCmd(gp.session, s, id=id)
|
||||||
(length(gp.session.plot) == 1) && (gpSend(gp, s))
|
(length(gp.session.plot) == 1) && (send(gp, s))
|
||||||
end
|
end
|
||||||
|
|
||||||
function addCmd(gp::GnuplotProc; id::Int=0, args...)
|
function addCmd(gp::GnuplotProc; id::Int=0, args...)
|
||||||
@ -489,7 +495,7 @@ Optionally, the commands may be sent to a file or returned as a
|
|||||||
(file != "") && (println(sfile , s))
|
(file != "") && (println(sfile , s))
|
||||||
(stream != nothing) && (println(stream, s))
|
(stream != nothing) && (println(stream, s))
|
||||||
(asArray) && (push!(ret, s))
|
(asArray) && (push!(ret, s))
|
||||||
(dump2Gp) && (gpSend(gp, s))
|
(dump2Gp) && (send(gp, s))
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -593,13 +599,15 @@ function gpDriver(args...)
|
|||||||
elseif typeof(arg) == Symbol
|
elseif typeof(arg) == Symbol
|
||||||
if arg == :.
|
if arg == :.
|
||||||
addDump = true
|
addDump = true
|
||||||
|
elseif arg == :splot
|
||||||
|
setSplot(gp, true)
|
||||||
else
|
else
|
||||||
dataName = string(arg)
|
dataName = string(arg)
|
||||||
endOfData()
|
endOfData()
|
||||||
end
|
end
|
||||||
elseif isa(arg, Int)
|
elseif isa(arg, Int)
|
||||||
if arg == 0
|
if arg == 0
|
||||||
gpReset(gp)
|
reset(gp)
|
||||||
else
|
else
|
||||||
endOfData("")
|
endOfData("")
|
||||||
setMultiID(gp, arg)
|
setMultiID(gp, arg)
|
||||||
@ -811,7 +819,7 @@ println("Current gnuplot terminal is: ", GnuplotGet("GPVAL_TERM"))
|
|||||||
"""
|
"""
|
||||||
function GnuplotGet(gp::GnuplotProc, var::String)
|
function GnuplotGet(gp::GnuplotProc, var::String)
|
||||||
out = Vector{String}()
|
out = Vector{String}()
|
||||||
answer = gpSend(gp, "print $var", true)
|
answer = send(gp, "print $var", true)
|
||||||
for line in answer
|
for line in answer
|
||||||
if length(search(line, "undefined variable:")) > 0
|
if length(search(line, "undefined variable:")) > 0
|
||||||
error(line)
|
error(line)
|
||||||
@ -1077,7 +1085,7 @@ splot '\$grid' matrix with lines notitle
|
|||||||
"""
|
"""
|
||||||
macro gp_str(s::String)
|
macro gp_str(s::String)
|
||||||
for v in split(s, "\n")
|
for v in split(s, "\n")
|
||||||
gpSend(getCurrent(), string(v))
|
send(getCurrent(), string(v))
|
||||||
end
|
end
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
@ -1095,13 +1103,12 @@ functions.
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
```
|
```
|
||||||
@gp (1:10).^3 "w l notit lw 4"
|
@gp (1:10).^3 "w l notit lw 4" file="test.gp"
|
||||||
gpDump(gp, file="test.gp")
|
|
||||||
gp`test.gp`
|
gp`test.gp`
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
macro gp_cmd(file::String)
|
macro gp_cmd(file::String)
|
||||||
return gpSend(getCurrent(), "load '$file'")
|
return send(getCurrent(), "load '$file'")
|
||||||
end
|
end
|
||||||
|
|
||||||
end #module
|
end #module
|
||||||
|
|||||||
@ -2,7 +2,7 @@ using Base.Test
|
|||||||
using Gnuplot
|
using Gnuplot
|
||||||
|
|
||||||
function gp_test()
|
function gp_test()
|
||||||
x = collect(1.:100)
|
x = collect(1.:100);
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
#-----------------------------------------------------------------
|
||||||
gp1 = GnuplotProc()
|
gp1 = GnuplotProc()
|
||||||
@ -38,6 +38,7 @@ function gp_test()
|
|||||||
@gp x y :aa "plot \$aa w l" "pl \$aa u 1:(2*\$2) w l"
|
@gp x y :aa "plot \$aa w l" "pl \$aa u 1:(2*\$2) w l"
|
||||||
|
|
||||||
@gp randn(Float64, 30, 50)
|
@gp randn(Float64, 30, 50)
|
||||||
|
@gp :splot x y y
|
||||||
|
|
||||||
@gp("set key horizontal", "set grid",
|
@gp("set key horizontal", "set grid",
|
||||||
xrange=(-7,7), ylabel="Y label",
|
xrange=(-7,7), ylabel="Y label",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user