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"]
|
||||
@ -2,10 +2,10 @@ __precompile__(true)
|
||||
|
||||
module Gnuplot
|
||||
|
||||
using AbbrvKW
|
||||
using NormalizeStructure
|
||||
using ColorTypes
|
||||
using Printf
|
||||
|
||||
import Base.send
|
||||
import Base.reset
|
||||
|
||||
|
||||
@ -100,13 +100,13 @@ level.
|
||||
"""
|
||||
function logIn(gp::GnuplotProc, s::AbstractString)
|
||||
(gp.verbosity < 1) && return nothing
|
||||
print_with_color(:yellow , "GNUPLOT ($(gp.id)) -> $s\n")
|
||||
printstyled(color=:yellow , "GNUPLOT ($(gp.id)) -> $s\n")
|
||||
return nothing
|
||||
end
|
||||
|
||||
function logData(gp::GnuplotProc, s::AbstractString)
|
||||
(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
|
||||
end
|
||||
|
||||
@ -119,19 +119,19 @@ end
|
||||
|
||||
function logOut(gp::GnuplotProc, s::AbstractString)
|
||||
(gp.verbosity < 2) && return nothing
|
||||
print_with_color(:cyan , "GNUPLOT ($(gp.id)) $s\n")
|
||||
printstyled(color=:cyan , "GNUPLOT ($(gp.id)) $s\n")
|
||||
return nothing
|
||||
end
|
||||
|
||||
function logErr(gp::GnuplotProc, s::AbstractString)
|
||||
(gp.verbosity < 3) && return nothing
|
||||
print_with_color(:cyan , "GNUPLOT ($(gp.id)) $s\n")
|
||||
printstyled(color=:cyan , "GNUPLOT ($(gp.id)) $s\n")
|
||||
return nothing
|
||||
end
|
||||
|
||||
function logCaptured(gp::GnuplotProc, s::AbstractString)
|
||||
(gp.verbosity < 3) && return nothing
|
||||
print_with_color(:green , "GNUPLOT ($(gp.id)) $s\n")
|
||||
printstyled(color=:green , "GNUPLOT ($(gp.id)) $s\n")
|
||||
return nothing
|
||||
end
|
||||
|
||||
@ -186,31 +186,32 @@ end
|
||||
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
@AbbrvKW function parseKeywords(;
|
||||
xrange::Union{Void,NTuple{2, Number}}=nothing,
|
||||
yrange::Union{Void,NTuple{2, Number}}=nothing,
|
||||
zrange::Union{Void,NTuple{2, Number}}=nothing,
|
||||
cbrange::Union{Void,NTuple{2, Number}}=nothing,
|
||||
title::Union{Void,String}=nothing,
|
||||
xlabel::Union{Void,String}=nothing,
|
||||
ylabel::Union{Void,String}=nothing,
|
||||
zlabel::Union{Void,String}=nothing,
|
||||
xlog::Union{Void,Bool}=nothing,
|
||||
ylog::Union{Void,Bool}=nothing,
|
||||
zlog::Union{Void,Bool}=nothing)
|
||||
function parseKeywords(; kwargs...)
|
||||
template = (xrange=NTuple{2, Number},
|
||||
yrange=NTuple{2, Number},
|
||||
zrange=NTuple{2, Number},
|
||||
cbrange=NTuple{2, Number},
|
||||
title=String,
|
||||
xlabel=String,
|
||||
ylabel=String,
|
||||
zlabel=String,
|
||||
xlog=Bool,
|
||||
ylog=Bool,
|
||||
zlog=Bool)
|
||||
|
||||
kw = NormalizeStructure.normalize(template; kwargs...)
|
||||
out = Vector{String}()
|
||||
xrange == nothing || (push!(out, "set xrange [" * join(xrange, ":") * "]"))
|
||||
yrange == nothing || (push!(out, "set yrange [" * join(yrange, ":") * "]"))
|
||||
zrange == nothing || (push!(out, "set zrange [" * join(zrange, ":") * "]"))
|
||||
cbrange == nothing || (push!(out, "set cbrange [" * join(cbrange, ":") * "]"))
|
||||
title == nothing || (push!(out, "set title '" * title * "'"))
|
||||
xlabel == nothing || (push!(out, "set xlabel '" * xlabel * "'"))
|
||||
ylabel == nothing || (push!(out, "set ylabel '" * ylabel * "'"))
|
||||
zlabel == nothing || (push!(out, "set zlabel '" * zlabel * "'"))
|
||||
xlog == nothing || (push!(out, (xlog ? "" : "un") * "set logscale x"))
|
||||
ylog == nothing || (push!(out, (ylog ? "" : "un") * "set logscale y"))
|
||||
zlog == nothing || (push!(out, (zlog ? "" : "un") * "set logscale z"))
|
||||
ismissing(kw.xrange ) || (push!(out, "set xrange [" * join(kw.xrange , ":") * "]"))
|
||||
ismissing(kw.yrange ) || (push!(out, "set yrange [" * join(kw.yrange , ":") * "]"))
|
||||
ismissing(kw.zrange ) || (push!(out, "set zrange [" * join(kw.zrange , ":") * "]"))
|
||||
ismissing(kw.cbrange) || (push!(out, "set cbrange [" * join(kw.cbrange, ":") * "]"))
|
||||
ismissing(kw.title ) || (push!(out, "set title '" * kw.title * "'"))
|
||||
ismissing(kw.xlabel ) || (push!(out, "set xlabel '" * kw.xlabel * "'"))
|
||||
ismissing(kw.ylabel ) || (push!(out, "set ylabel '" * kw.ylabel * "'"))
|
||||
ismissing(kw.zlabel ) || (push!(out, "set zlabel '" * kw.zlabel * "'"))
|
||||
ismissing(kw.xlog ) || (push!(out, (kw.xlog ? "" : "un") * "set logscale x"))
|
||||
ismissing(kw.ylog ) || (push!(out, (kw.ylog ? "" : "un") * "set logscale y"))
|
||||
ismissing(kw.zlog ) || (push!(out, (kw.zlog ? "" : "un") * "set logscale z"))
|
||||
return out
|
||||
end
|
||||
|
||||
@ -433,7 +434,7 @@ end
|
||||
function addData(gp::GnuplotProc, args...; 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
|
||||
v = getfield.(gp.session.data[i], :str)
|
||||
push!(v, " ")
|
||||
@ -521,7 +522,7 @@ Send all necessary commands to gnuplot to actually do the plot.
|
||||
Optionally, the commands may be sent to a file or returned as a
|
||||
`Vector{String}`.
|
||||
"""
|
||||
@AbbrvKW function gpDump(gp::Union{GnuplotSession,GnuplotProc};
|
||||
function gpDump(gp::Union{GnuplotSession,GnuplotProc};
|
||||
term=("", ""), file="", stream=nothing, asArray=false)
|
||||
|
||||
session = (typeof(gp) == GnuplotProc ? gp.session : gp)
|
||||
@ -538,7 +539,7 @@ Optionally, the commands may be sent to a file or returned as a
|
||||
if typeof(gp) == GnuplotProc
|
||||
dump2Gp = true
|
||||
else
|
||||
stream = STDOUT
|
||||
stream = stdout
|
||||
end
|
||||
end
|
||||
|
||||
@ -702,7 +703,7 @@ function gpDriver(splot, args...)
|
||||
stream = arg[2]
|
||||
else
|
||||
# A cmd keyword
|
||||
addCmd(gp; arg)
|
||||
addCmd(gp; [arg]...)
|
||||
end
|
||||
else
|
||||
# A data set
|
||||
@ -731,9 +732,10 @@ blocks).
|
||||
"""
|
||||
function CheckGnuplotVersion(cmd::String)
|
||||
icmd = `$(cmd) --version`
|
||||
out, procs = open(`$icmd`, "r")
|
||||
s = String(read(out))
|
||||
if !success(procs)
|
||||
|
||||
proc = open(`$icmd`, read=true)
|
||||
s = String(read(proc))
|
||||
if !success(proc)
|
||||
error("An error occurred while running: " * string(icmd))
|
||||
end
|
||||
|
||||
@ -749,12 +751,12 @@ function CheckGnuplotVersion(cmd::String)
|
||||
|
||||
if ver < v"4.7"
|
||||
# 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
|
||||
if ver < v"4.6"
|
||||
error("gnuplot ver. >= 4.7 is required, but " * string(ver) * " was found.")
|
||||
end
|
||||
info("Running gnuplot version: " * string(ver))
|
||||
@info "Running gnuplot version: " * string(ver)
|
||||
return ver
|
||||
end
|
||||
|
||||
@ -796,7 +798,7 @@ function GnuplotProc(cmd="gnuplot"; default="")
|
||||
pin = Base.Pipe()
|
||||
pout = 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()
|
||||
out = GnuplotProc(id, pin, pout, perr, proc,
|
||||
@ -807,9 +809,9 @@ function GnuplotProc(cmd="gnuplot"; default="")
|
||||
g_state.obj[id] = out
|
||||
|
||||
# Close unused sides of the pipes
|
||||
Base.close_pipe_sync(out.pout.in)
|
||||
Base.close_pipe_sync(out.perr.in)
|
||||
Base.close_pipe_sync(out.pin.out)
|
||||
Base.close(out.pout.in)
|
||||
Base.close(out.perr.in)
|
||||
Base.close(out.pin.out)
|
||||
Base.start_reading(out.pout.out)
|
||||
Base.start_reading(out.perr.out)
|
||||
|
||||
@ -911,7 +913,7 @@ end
|
||||
function getCurrent()
|
||||
global g_state
|
||||
if !(g_state.id in keys(g_state.obj))
|
||||
info("Creating default Gnuplot process...")
|
||||
@info "Creating default Gnuplot process..."
|
||||
out = GnuplotProc()
|
||||
setCurrent(out)
|
||||
end
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using Base.Test
|
||||
using Gnuplot
|
||||
|
||||
function gp_test()
|
||||
@ -28,10 +27,10 @@ function gp_test()
|
||||
|
||||
@gp "plot sin(x)" 2 xr=(-2pi,2pi) "pause 2" "plot cos(4*x)"
|
||||
|
||||
x = linspace(-2pi, 2pi, 100);
|
||||
y = 1.5 * sin.(0.3 + 0.7x) ;
|
||||
x = range(-2pi, stop=2pi, length=100);
|
||||
y = 1.5 * sin.(0.3 .+ 0.7x) ;
|
||||
noise = randn(length(x))./2;
|
||||
e = 0.5 * ones(x);
|
||||
e = 0.5 * fill(1, size(x));
|
||||
|
||||
@gp x y
|
||||
@gp x y "w l"
|
||||
@ -124,4 +123,5 @@ function gp_test()
|
||||
return true
|
||||
end
|
||||
|
||||
@test gp_test()
|
||||
|
||||
gp_test()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user