Updated for Julia v0.7
This commit is contained in:
parent
1a82392352
commit
905e3d226d
15
Project.toml
Normal file
15
Project.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
name = "Gnuplot"
|
||||||
|
uuid = "dc211083-a33a-5b79-959f-2ff34033469d"
|
||||||
|
authors = ["Giorgio Calderone <giorgio.calderone@gmail.com>"]
|
||||||
|
version = "0.2.0"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
|
||||||
|
NormalizeStructure = "5369e15c-9fda-11e8-194c-95a38f2a9483"
|
||||||
|
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
||||||
|
|
||||||
|
[extras]
|
||||||
|
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||||
|
|
||||||
|
[targets]
|
||||||
|
test = ["Test"]
|
||||||
1
REQUIRE
1
REQUIRE
@ -1,3 +1,2 @@
|
|||||||
julia 0.6
|
julia 0.6
|
||||||
AbbrvKW 0.3.1
|
|
||||||
ColorTypes 0.6.7
|
ColorTypes 0.6.7
|
||||||
|
|||||||
@ -2,10 +2,10 @@ __precompile__(true)
|
|||||||
|
|
||||||
module Gnuplot
|
module Gnuplot
|
||||||
|
|
||||||
using AbbrvKW
|
using NormalizeStructure
|
||||||
using ColorTypes
|
using ColorTypes
|
||||||
|
using Printf
|
||||||
|
|
||||||
import Base.send
|
|
||||||
import Base.reset
|
import Base.reset
|
||||||
|
|
||||||
|
|
||||||
@ -100,13 +100,13 @@ level.
|
|||||||
"""
|
"""
|
||||||
function logIn(gp::GnuplotProc, s::AbstractString)
|
function logIn(gp::GnuplotProc, s::AbstractString)
|
||||||
(gp.verbosity < 1) && return nothing
|
(gp.verbosity < 1) && return nothing
|
||||||
print_with_color(:yellow , "GNUPLOT ($(gp.id)) -> $s\n")
|
printstyled(color=:yellow , "GNUPLOT ($(gp.id)) -> $s\n")
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
function logData(gp::GnuplotProc, s::AbstractString)
|
function logData(gp::GnuplotProc, s::AbstractString)
|
||||||
(gp.verbosity < 4) && return nothing
|
(gp.verbosity < 4) && return nothing
|
||||||
print_with_color(:light_black, "GNUPLOT ($(gp.id)) -> $s\n")
|
printstyled(color=:light_black, "GNUPLOT ($(gp.id)) -> $s\n")
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -119,19 +119,19 @@ end
|
|||||||
|
|
||||||
function logOut(gp::GnuplotProc, s::AbstractString)
|
function logOut(gp::GnuplotProc, s::AbstractString)
|
||||||
(gp.verbosity < 2) && return nothing
|
(gp.verbosity < 2) && return nothing
|
||||||
print_with_color(:cyan , "GNUPLOT ($(gp.id)) $s\n")
|
printstyled(color=:cyan , "GNUPLOT ($(gp.id)) $s\n")
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
function logErr(gp::GnuplotProc, s::AbstractString)
|
function logErr(gp::GnuplotProc, s::AbstractString)
|
||||||
(gp.verbosity < 3) && return nothing
|
(gp.verbosity < 3) && return nothing
|
||||||
print_with_color(:cyan , "GNUPLOT ($(gp.id)) $s\n")
|
printstyled(color=:cyan , "GNUPLOT ($(gp.id)) $s\n")
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
function logCaptured(gp::GnuplotProc, s::AbstractString)
|
function logCaptured(gp::GnuplotProc, s::AbstractString)
|
||||||
(gp.verbosity < 3) && return nothing
|
(gp.verbosity < 3) && return nothing
|
||||||
print_with_color(:green , "GNUPLOT ($(gp.id)) $s\n")
|
printstyled(color=:green , "GNUPLOT ($(gp.id)) $s\n")
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -186,31 +186,32 @@ end
|
|||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
@AbbrvKW function parseKeywords(;
|
function parseKeywords(; kwargs...)
|
||||||
xrange::Union{Void,NTuple{2, Number}}=nothing,
|
template = (xrange=NTuple{2, Number},
|
||||||
yrange::Union{Void,NTuple{2, Number}}=nothing,
|
yrange=NTuple{2, Number},
|
||||||
zrange::Union{Void,NTuple{2, Number}}=nothing,
|
zrange=NTuple{2, Number},
|
||||||
cbrange::Union{Void,NTuple{2, Number}}=nothing,
|
cbrange=NTuple{2, Number},
|
||||||
title::Union{Void,String}=nothing,
|
title=String,
|
||||||
xlabel::Union{Void,String}=nothing,
|
xlabel=String,
|
||||||
ylabel::Union{Void,String}=nothing,
|
ylabel=String,
|
||||||
zlabel::Union{Void,String}=nothing,
|
zlabel=String,
|
||||||
xlog::Union{Void,Bool}=nothing,
|
xlog=Bool,
|
||||||
ylog::Union{Void,Bool}=nothing,
|
ylog=Bool,
|
||||||
zlog::Union{Void,Bool}=nothing)
|
zlog=Bool)
|
||||||
|
|
||||||
|
kw = NormalizeStructure.normalize(template; kwargs...)
|
||||||
out = Vector{String}()
|
out = Vector{String}()
|
||||||
xrange == nothing || (push!(out, "set xrange [" * join(xrange, ":") * "]"))
|
ismissing(kw.xrange ) || (push!(out, "set xrange [" * join(kw.xrange , ":") * "]"))
|
||||||
yrange == nothing || (push!(out, "set yrange [" * join(yrange, ":") * "]"))
|
ismissing(kw.yrange ) || (push!(out, "set yrange [" * join(kw.yrange , ":") * "]"))
|
||||||
zrange == nothing || (push!(out, "set zrange [" * join(zrange, ":") * "]"))
|
ismissing(kw.zrange ) || (push!(out, "set zrange [" * join(kw.zrange , ":") * "]"))
|
||||||
cbrange == nothing || (push!(out, "set cbrange [" * join(cbrange, ":") * "]"))
|
ismissing(kw.cbrange) || (push!(out, "set cbrange [" * join(kw.cbrange, ":") * "]"))
|
||||||
title == nothing || (push!(out, "set title '" * title * "'"))
|
ismissing(kw.title ) || (push!(out, "set title '" * kw.title * "'"))
|
||||||
xlabel == nothing || (push!(out, "set xlabel '" * xlabel * "'"))
|
ismissing(kw.xlabel ) || (push!(out, "set xlabel '" * kw.xlabel * "'"))
|
||||||
ylabel == nothing || (push!(out, "set ylabel '" * ylabel * "'"))
|
ismissing(kw.ylabel ) || (push!(out, "set ylabel '" * kw.ylabel * "'"))
|
||||||
zlabel == nothing || (push!(out, "set zlabel '" * zlabel * "'"))
|
ismissing(kw.zlabel ) || (push!(out, "set zlabel '" * kw.zlabel * "'"))
|
||||||
xlog == nothing || (push!(out, (xlog ? "" : "un") * "set logscale x"))
|
ismissing(kw.xlog ) || (push!(out, (kw.xlog ? "" : "un") * "set logscale x"))
|
||||||
ylog == nothing || (push!(out, (ylog ? "" : "un") * "set logscale y"))
|
ismissing(kw.ylog ) || (push!(out, (kw.ylog ? "" : "un") * "set logscale y"))
|
||||||
zlog == nothing || (push!(out, (zlog ? "" : "un") * "set logscale z"))
|
ismissing(kw.zlog ) || (push!(out, (kw.zlog ? "" : "un") * "set logscale z"))
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -433,7 +434,7 @@ end
|
|||||||
function addData(gp::GnuplotProc, args...; name="")
|
function addData(gp::GnuplotProc, args...; name="")
|
||||||
name = addData(gp.session, args..., name=name)
|
name = addData(gp.session, args..., name=name)
|
||||||
|
|
||||||
i = find(.!getfield.(gp.session.data, :sent))
|
i = findall(.!getfield.(gp.session.data, :sent))
|
||||||
if length(i) > 0
|
if length(i) > 0
|
||||||
v = getfield.(gp.session.data[i], :str)
|
v = getfield.(gp.session.data[i], :str)
|
||||||
push!(v, " ")
|
push!(v, " ")
|
||||||
@ -521,8 +522,8 @@ Send all necessary commands to gnuplot to actually do the plot.
|
|||||||
Optionally, the commands may be sent to a file or returned as a
|
Optionally, the commands may be sent to a file or returned as a
|
||||||
`Vector{String}`.
|
`Vector{String}`.
|
||||||
"""
|
"""
|
||||||
@AbbrvKW function gpDump(gp::Union{GnuplotSession,GnuplotProc};
|
function gpDump(gp::Union{GnuplotSession,GnuplotProc};
|
||||||
term=("", ""), file="", stream=nothing, asArray=false)
|
term=("", ""), file="", stream=nothing, asArray=false)
|
||||||
|
|
||||||
session = (typeof(gp) == GnuplotProc ? gp.session : gp)
|
session = (typeof(gp) == GnuplotProc ? gp.session : gp)
|
||||||
ret = Vector{String}()
|
ret = Vector{String}()
|
||||||
@ -538,7 +539,7 @@ Optionally, the commands may be sent to a file or returned as a
|
|||||||
if typeof(gp) == GnuplotProc
|
if typeof(gp) == GnuplotProc
|
||||||
dump2Gp = true
|
dump2Gp = true
|
||||||
else
|
else
|
||||||
stream = STDOUT
|
stream = stdout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -702,7 +703,7 @@ function gpDriver(splot, args...)
|
|||||||
stream = arg[2]
|
stream = arg[2]
|
||||||
else
|
else
|
||||||
# A cmd keyword
|
# A cmd keyword
|
||||||
addCmd(gp; arg)
|
addCmd(gp; [arg]...)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# A data set
|
# A data set
|
||||||
@ -731,9 +732,10 @@ blocks).
|
|||||||
"""
|
"""
|
||||||
function CheckGnuplotVersion(cmd::String)
|
function CheckGnuplotVersion(cmd::String)
|
||||||
icmd = `$(cmd) --version`
|
icmd = `$(cmd) --version`
|
||||||
out, procs = open(`$icmd`, "r")
|
|
||||||
s = String(read(out))
|
proc = open(`$icmd`, read=true)
|
||||||
if !success(procs)
|
s = String(read(proc))
|
||||||
|
if !success(proc)
|
||||||
error("An error occurred while running: " * string(icmd))
|
error("An error occurred while running: " * string(icmd))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -749,12 +751,12 @@ function CheckGnuplotVersion(cmd::String)
|
|||||||
|
|
||||||
if ver < v"4.7"
|
if ver < v"4.7"
|
||||||
# Do not raise error in order to pass Travis CI test, since it has v4.6
|
# Do not raise error in order to pass Travis CI test, since it has v4.6
|
||||||
warn("gnuplot ver. >= 4.7 is required, but " * string(ver) * " was found.")
|
@warn "gnuplot ver. >= 4.7 is required, but " * string(ver) * " was found."
|
||||||
end
|
end
|
||||||
if ver < v"4.6"
|
if ver < v"4.6"
|
||||||
error("gnuplot ver. >= 4.7 is required, but " * string(ver) * " was found.")
|
error("gnuplot ver. >= 4.7 is required, but " * string(ver) * " was found.")
|
||||||
end
|
end
|
||||||
info("Running gnuplot version: " * string(ver))
|
@info "Running gnuplot version: " * string(ver)
|
||||||
return ver
|
return ver
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -796,7 +798,7 @@ function GnuplotProc(cmd="gnuplot"; default="")
|
|||||||
pin = Base.Pipe()
|
pin = Base.Pipe()
|
||||||
pout = Base.Pipe()
|
pout = Base.Pipe()
|
||||||
perr = Base.Pipe()
|
perr = Base.Pipe()
|
||||||
proc = spawn(`$cmd`, (pin, pout, perr))
|
proc = run(pipeline(`$cmd`, stdin=pin, stdout=pout, stderr=perr), wait=false)
|
||||||
|
|
||||||
id = newID()
|
id = newID()
|
||||||
out = GnuplotProc(id, pin, pout, perr, proc,
|
out = GnuplotProc(id, pin, pout, perr, proc,
|
||||||
@ -807,9 +809,9 @@ function GnuplotProc(cmd="gnuplot"; default="")
|
|||||||
g_state.obj[id] = out
|
g_state.obj[id] = out
|
||||||
|
|
||||||
# Close unused sides of the pipes
|
# Close unused sides of the pipes
|
||||||
Base.close_pipe_sync(out.pout.in)
|
Base.close(out.pout.in)
|
||||||
Base.close_pipe_sync(out.perr.in)
|
Base.close(out.perr.in)
|
||||||
Base.close_pipe_sync(out.pin.out)
|
Base.close(out.pin.out)
|
||||||
Base.start_reading(out.pout.out)
|
Base.start_reading(out.pout.out)
|
||||||
Base.start_reading(out.perr.out)
|
Base.start_reading(out.perr.out)
|
||||||
|
|
||||||
@ -911,7 +913,7 @@ end
|
|||||||
function getCurrent()
|
function getCurrent()
|
||||||
global g_state
|
global g_state
|
||||||
if !(g_state.id in keys(g_state.obj))
|
if !(g_state.id in keys(g_state.obj))
|
||||||
info("Creating default Gnuplot process...")
|
@info "Creating default Gnuplot process..."
|
||||||
out = GnuplotProc()
|
out = GnuplotProc()
|
||||||
setCurrent(out)
|
setCurrent(out)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
using Base.Test
|
|
||||||
using Gnuplot
|
using Gnuplot
|
||||||
|
|
||||||
function gp_test()
|
function gp_test()
|
||||||
@ -28,10 +27,10 @@ function gp_test()
|
|||||||
|
|
||||||
@gp "plot sin(x)" 2 xr=(-2pi,2pi) "pause 2" "plot cos(4*x)"
|
@gp "plot sin(x)" 2 xr=(-2pi,2pi) "pause 2" "plot cos(4*x)"
|
||||||
|
|
||||||
x = linspace(-2pi, 2pi, 100);
|
x = range(-2pi, stop=2pi, length=100);
|
||||||
y = 1.5 * sin.(0.3 + 0.7x) ;
|
y = 1.5 * sin.(0.3 .+ 0.7x) ;
|
||||||
noise = randn(length(x))./2;
|
noise = randn(length(x))./2;
|
||||||
e = 0.5 * ones(x);
|
e = 0.5 * fill(1, size(x));
|
||||||
|
|
||||||
@gp x y
|
@gp x y
|
||||||
@gp x y "w l"
|
@gp x y "w l"
|
||||||
@ -124,4 +123,5 @@ function gp_test()
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@test gp_test()
|
|
||||||
|
gp_test()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user