Minor changes

This commit is contained in:
Giorgio Calderone 2017-08-27 22:25:49 +02:00
parent 5c48219f57
commit 506222b3e5
5 changed files with 80 additions and 127 deletions

View File

@ -1 +0,0 @@
comment: false

View File

@ -1,2 +1,2 @@
julia 0.6 julia 0.6
AbbrvKW 0.3.0 AbbrvKW

View File

@ -1,47 +0,0 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
branches:
only:
- master
- /release-.*/
notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false
install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"Gnuplot\"); Pkg.build(\"Gnuplot\")"
test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"Gnuplot\")"

View File

@ -3,7 +3,7 @@ module Gnuplot
using AbbrvKW using AbbrvKW
include("GnuplotInternals.jl") include("GnuplotInternals.jl")
importall ._priv_ importall .p_
###################################################################### ######################################################################
@ -16,21 +16,21 @@ importall ._priv_
Return the gnuplot command(s) to be executed at the beginning of each Return the gnuplot command(s) to be executed at the beginning of each
session. session.
""" """
getStartup() = _priv_.main.startup getStartup() = p_.main.startup
""" """
# Gnuplot.getSpawnCmd # Gnuplot.getSpawnCmd
Return the command to spawn a gnuplot process. Return the command to spawn a gnuplot process.
""" """
getSpawnCmd() = _priv_.main.gnuplotCmd getSpawnCmd() = p_.main.gnuplotCmd
""" """
# Gnuplot.getVerbose # Gnuplot.getVerbose
Return the verbosity level. Return the verbosity level.
""" """
getVerbose() = _priv_.main.verboseLev getVerbose() = p_.main.verboseLev
#--------------------------------------------------------------------- #---------------------------------------------------------------------
@ -57,17 +57,17 @@ The package options can beretrieved with: `gp.getStartup`,
startup::Union{Void,String}=nothing, startup::Union{Void,String}=nothing,
verbose::Union{Void,Int}=nothing) verbose::Union{Void,Int}=nothing)
if startup != nothing if startup != nothing
_priv_.main.startup = startup p_.main.startup = startup
end end
if cmd != nothing if cmd != nothing
_priv_.main.gnuplotCmd = cmd p_.main.gnuplotCmd = cmd
_priv_.checkGnuplotVersion() p_.checkGnuplotVersion()
end end
if verbose != nothing if verbose != nothing
@assert (0 <= verbose <= 4) @assert (0 <= verbose <= 4)
_priv_.main.verboseLev = verbose p_.main.verboseLev = verbose
end end
return nothing return nothing
@ -85,7 +85,7 @@ end
Return a `Vector{Int}` of available session handles. Return a `Vector{Int}` of available session handles.
""" """
function handles() function handles()
return deepcopy(_priv_.main.handles) return deepcopy(p_.main.handles)
end end
@ -95,8 +95,8 @@ end
Return the handle of the current session. Return the handle of the current session.
""" """
function current() function current()
_priv_.getProcOrStartIt() p_.getProcOrStartIt()
return _priv_.main.handles[_priv_.main.curPos] return p_.main.handles[p_.main.curPos]
end end
@ -114,12 +114,12 @@ Change the current session handle.
- `gp.handles`: return the list of available handles. - `gp.handles`: return the list of available handles.
""" """
function setCurrent(handle) function setCurrent(handle)
i = find(_priv_.main.handles .== handle) i = find(p_.main.handles .== handle)
@assert length(i) == 1 @assert length(i) == 1
i = i[1] i = i[1]
@assert Base.process_running(_priv_.main.procs[i].proc) @assert Base.process_running(p_.main.procs[i].proc)
_priv_.main.curPos = i p_.main.curPos = i
end end
@ -152,31 +152,31 @@ gp.exitAll()
``` ```
""" """
function session() function session()
if length(_priv_.main.handles) > 0 if length(p_.main.handles) > 0
newhandle = max(_priv_.main.handles...) + 1 newhandle = max(p_.main.handles...) + 1
else else
newhandle = 1 newhandle = 1
end end
if _priv_.main.gnuplotCmd == "" if p_.main.gnuplotCmd == ""
_priv_.main.gnuplotCmd = "gnuplot" p_.main.gnuplotCmd = "gnuplot"
_priv_.checkGnuplotVersion() p_.checkGnuplotVersion()
end end
push!(_priv_.main.procs, _priv_.GnuplotProc(_priv_.main.gnuplotCmd)) push!(p_.main.procs, p_.GnuplotProc(p_.main.gnuplotCmd))
push!(_priv_.main.states, _priv_.GnuplotState()) push!(p_.main.states, p_.GnuplotSession())
push!(_priv_.main.handles, newhandle) push!(p_.main.handles, newhandle)
_priv_.main.curPos = length(_priv_.main.handles) p_.main.curPos = length(p_.main.handles)
# Start reading tasks for STDOUT and STDERR # Start reading tasks for STDOUT and STDERR
@async _priv_.readTask(_priv_.main.procs[end].pout, _priv_.main.procs[end].channel, id=newhandle) @async p_.readTask(p_.main.procs[end].pout, p_.main.procs[end].channel, id=newhandle)
@async _priv_.readTask(_priv_.main.procs[end].perr, _priv_.main.procs[end].channel, id=newhandle) @async p_.readTask(p_.main.procs[end].perr, p_.main.procs[end].channel, id=newhandle)
if _priv_.main.startup != "" if p_.main.startup != ""
cmd(_priv_.main.startup) cmd(p_.main.startup)
end end
_priv_.log(1, "New session started with handle $newhandle") p_.log(1, "New session started with handle $newhandle")
return newhandle return newhandle
end end
@ -188,27 +188,27 @@ end
Close current session and quit the corresponding gnuplot process. Close current session and quit the corresponding gnuplot process.
""" """
function exit() function exit()
if _priv_.main.curPos == 0 if p_.main.curPos == 0
return 0 return 0
end end
p = _priv_.main.procs[_priv_.main.curPos] p = p_.main.procs[p_.main.curPos]
close(p.pin) close(p.pin)
close(p.pout) close(p.pout)
close(p.perr) close(p.perr)
wait(p.proc) wait(p.proc)
@assert !Base.process_running(p.proc) @assert !Base.process_running(p.proc)
_priv_.log(1, string("Process exited with status ", p.proc.exitcode)) p_.log(1, string("Process exited with status ", p.proc.exitcode))
deleteat!(_priv_.main.procs , _priv_.main.curPos) deleteat!(p_.main.procs , p_.main.curPos)
deleteat!(_priv_.main.states , _priv_.main.curPos) deleteat!(p_.main.states , p_.main.curPos)
deleteat!(_priv_.main.handles, _priv_.main.curPos) deleteat!(p_.main.handles, p_.main.curPos)
if length(_priv_.main.handles) > 0 if length(p_.main.handles) > 0
setCurrent(max(_priv_.main.handles...)) setCurrent(max(p_.main.handles...))
else else
_priv_.main.curPos = 0 p_.main.curPos = 0
end end
return p.proc.exitcode return p.proc.exitcode
@ -222,7 +222,7 @@ end
Repeatedly call `gp.exit` until all sessions are closed. Repeatedly call `gp.exit` until all sessions are closed.
""" """
function exitAll() function exitAll()
while length(_priv_.main.handles) > 0 while length(p_.main.handles) > 0
exit() exit()
end end
return nothing return nothing
@ -255,22 +255,22 @@ println("Current terminal: ", gp.send("print GPVAL_TERM", capture=true))
`nothing` immediately. `nothing` immediately.
""" """
@AbbrvKW function send(cmd::String; capture::Bool=false) @AbbrvKW function send(cmd::String; capture::Bool=false)
p = _priv_.getProcOrStartIt() p = p_.getProcOrStartIt()
if capture if capture
write(p.pin, "print 'GNUPLOT_JL_SAVE_OUTPUT'\n") write(p.pin, "print 'GNUPLOT_JL_SAVE_OUTPUT'\n")
_priv_.log(4, "-> Start capture", color=_priv_.main.colorIn) p_.log(4, "-> Start capture", color=p_.main.colorIn)
end end
for s in split(cmd, "\n") for s in split(cmd, "\n")
w = write(p.pin, strip(s) * "\n") w = write(p.pin, strip(s) * "\n")
_priv_.log(2, "-> $s" , color=_priv_.main.colorIn) p_.log(2, "-> $s" , color=p_.main.colorIn)
w <= 0 && error("Writing on gnuplot STDIN pipe returned $w") w <= 0 && error("Writing on gnuplot STDIN pipe returned $w")
end end
if capture if capture
write(p.pin, "print 'GNUPLOT_JL_SAVE_OUTPUT_END'\n") write(p.pin, "print 'GNUPLOT_JL_SAVE_OUTPUT_END'\n")
_priv_.log(4, "-> End capture", color=_priv_.main.colorIn) p_.log(4, "-> End capture", color=p_.main.colorIn)
end end
flush(p.pin) flush(p.pin)
@ -302,9 +302,9 @@ data, and plots in the current session.
""" """
function reset() function reset()
send("reset session", capture=true) send("reset session", capture=true)
_priv_.main.states[_priv_.main.curPos] = _priv_.GnuplotState() p_.main.states[p_.main.curPos] = p_.GnuplotSession()
if _priv_.main.startup != "" if p_.main.startup != ""
cmd(_priv_.main.startup) cmd(p_.main.startup)
end end
return nothing return nothing
end end
@ -358,13 +358,13 @@ gp.cmd(title="My title", xlab="X label", xla="Y label")
ylog::Union{Void,Bool}=nothing, ylog::Union{Void,Bool}=nothing,
zlog::Union{Void,Bool}=nothing) zlog::Union{Void,Bool}=nothing)
_priv_.getProcOrStartIt() p_.getProcOrStartIt()
cur = _priv_.main.states[_priv_.main.curPos] cur = p_.main.states[p_.main.curPos]
splot == nothing || (cur.splot = splot) splot == nothing || (cur.splot = splot)
mID = multiID == nothing ? cur.multiID : multiID mID = multiID == nothing ? cur.multiID : multiID
if s != "" if s != ""
push!(cur.cmds, _priv_.MultiCmd(s, mID)) push!(cur.cmds, p_.MultiCmd(s, mID))
if mID == 0 if mID == 0
send(s) send(s)
end end
@ -428,11 +428,11 @@ gp.dump()
function data(data::Vararg{AbstractArray{T,1},N}; function data(data::Vararg{AbstractArray{T,1},N};
name::Union{Void,String}=nothing, name::Union{Void,String}=nothing,
prefix::Union{Void,String}=nothing) where {T<:Number,N} prefix::Union{Void,String}=nothing) where {T<:Number,N}
_priv_.getProcOrStartIt() p_.getProcOrStartIt()
cur = _priv_.main.states[_priv_.main.curPos] cur = p_.main.states[p_.main.curPos]
if name == nothing if name == nothing
name = _priv_.mkBlockName(prefix=prefix) name = p_.mkBlockName(prefix=prefix)
end end
name = "\$$name" name = "\$$name"
@ -501,8 +501,8 @@ gp.dump() # Do the plot
file::Union{Void,String}=nothing, file::Union{Void,String}=nothing,
multiID::Union{Void,Int}=nothing) multiID::Union{Void,Int}=nothing)
_priv_.getProcOrStartIt() p_.getProcOrStartIt()
cur = _priv_.main.states[_priv_.main.curPos] cur = p_.main.states[p_.main.curPos]
mID = multiID == nothing ? cur.multiID : multiID mID = multiID == nothing ? cur.multiID : multiID
src = "" src = ""
@ -511,7 +511,7 @@ gp.dump() # Do the plot
elseif file != nothing elseif file != nothing
src = "'" * file * "'" src = "'" * file * "'"
end end
push!(cur.plot, _priv_.MultiCmd("$src $spec", mID)) push!(cur.plot, p_.MultiCmd("$src $spec", mID))
return nothing return nothing
end end
@ -530,8 +530,8 @@ Initialize a multiplot (through the "set multiplot" Gnuplot command).
## See also: `gp.next`. ## See also: `gp.next`.
""" """
function multi(multiCmd::String="") function multi(multiCmd::String="")
_priv_.getProcOrStartIt() p_.getProcOrStartIt()
cur = _priv_.main.states[_priv_.main.curPos] cur = p_.main.states[p_.main.curPos]
if cur.multiID != 0 if cur.multiID != 0
error("Current multiplot ID is $cur.multiID, while it should be 0") error("Current multiplot ID is $cur.multiID, while it should be 0")
end end
@ -549,8 +549,8 @@ end
Select next slot for multiplot sessions. Select next slot for multiplot sessions.
""" """
function next() function next()
_priv_.getProcOrStartIt() p_.getProcOrStartIt()
cur = _priv_.main.states[_priv_.main.curPos] cur = p_.main.states[p_.main.curPos]
cur.multiID += 1 cur.multiID += 1
return nothing return nothing
end end
@ -587,7 +587,7 @@ commands are returned as `Vector{String}`.
data::Bool=false, data::Bool=false,
file::Union{Void,String}=nothing) file::Union{Void,String}=nothing)
if _priv_.main.curPos == 0 if p_.main.curPos == 0
return "" return ""
end end
@ -596,7 +596,7 @@ commands are returned as `Vector{String}`.
dry = true dry = true
end end
cur = _priv_.main.states[_priv_.main.curPos] cur = p_.main.states[p_.main.curPos]
out = Vector{String}() out = Vector{String}()
all && (push!(out, "reset session")) all && (push!(out, "reset session"))
@ -866,6 +866,7 @@ macro gp_str(s::String)
return Gnuplot.send(s, capture=true) return Gnuplot.send(s, capture=true)
end end
#--------------------------------------------------------------------- #---------------------------------------------------------------------
""" """
# Gnuplot.@gp_cmd # Gnuplot.@gp_cmd

View File

@ -1,10 +1,10 @@
###################################################################### ######################################################################
# MODULE GnuplotInternals (private functions and definitions) # MODULE GnuplotInternals (private functions and definitions)
###################################################################### ######################################################################
module _priv_ module p_
importall Gnuplot importall Gnuplot
const _pub_ = Gnuplot const P_ = Gnuplot
###################################################################### ######################################################################
# Structure definitions # Structure definitions
@ -59,7 +59,7 @@ end
""" """
Structure containing the state of a single gnuplot session. Structure containing the state of a single gnuplot session.
""" """
mutable struct GnuplotState mutable struct GnuplotSession
blockCnt::Int # data blocks counter blockCnt::Int # data blocks counter
cmds::Vector{MultiCmd} # gnuplot commands cmds::Vector{MultiCmd} # gnuplot commands
data::Vector{String} # data blocks data::Vector{String} # data blocks
@ -68,7 +68,8 @@ mutable struct GnuplotState
lastDataName::String # name of the last data block lastDataName::String # name of the last data block
multiID::Int # current multiplot index (0 if no multiplot) multiID::Int # current multiplot index (0 if no multiplot)
GnuplotState() = new(1, Vector{MultiCmd}(), Vector{String}(), Vector{MultiCmd}(), false, "", 0) GnuplotSession() = new(1, Vector{MultiCmd}(), Vector{String}(),
Vector{MultiCmd}(), false, "", 0)
end end
@ -77,20 +78,19 @@ end
Structure containing the global package state. Structure containing the global package state.
""" """
mutable struct MainState mutable struct MainState
colorOut::Symbol # gnuplot STDOUT is printed with this color colorOut::Symbol # gnuplot STDOUT is printed with this color
colorIn::Symbol # gnuplot STDIN is printed with this color colorIn::Symbol # gnuplot STDIN is printed with this color
verboseLev::Int # verbosity level (0 - 3), default: 3 verboseLev::Int # verbosity level (0 - 3), default: 3
gnuplotCmd::String # command used to start the gnuplot process gnuplotCmd::String # command used to start the gnuplot process
startup::String # commands automatically sent to each new gnuplot process startup::String # commands automatically sent to each new gnuplot process
procs::Vector{GnuplotProc} # array of currently active gnuplot process and pipes procs::Vector{GnuplotProc} # array of currently active gnuplot process and pipes
states::Vector{GnuplotState} # array of gnuplot sessions states::Vector{GnuplotSession} # array of gnuplot sessions
handles::Vector{Int} # handles of gnuplot sessions handles::Vector{Int} # handles of gnuplot sessions
curPos::Int # index in the procs, states and handles array of current session curPos::Int # index in the procs, states and handles array of current session
MainState() = new(:cyan, :yellow, 1, MainState() = new(:cyan, :yellow, 1,
"", "", "", "", Vector{GnuplotProc}(), Vector{GnuplotSession}(),
Vector{GnuplotProc}(), Vector{GnuplotState}(), Vector{Int}(), Vector{Int}(), 0)
0)
end end
@ -200,7 +200,7 @@ Return a unique data block name
""" """
function mkBlockName(;prefix::Union{Void,String}=nothing) function mkBlockName(;prefix::Union{Void,String}=nothing)
if prefix == nothing if prefix == nothing
prefix = string("d", _pub_.current()) prefix = string("d", main.handles[main.curPos])
end end
cur = main.states[main.curPos] cur = main.states[main.curPos]
@ -219,7 +219,7 @@ gnuplot process if none is running.
function getProcOrStartIt() function getProcOrStartIt()
if main.curPos == 0 if main.curPos == 0
log(1, "Starting a new gnuplot process...") log(1, "Starting a new gnuplot process...")
id = _pub_.session() id = P_.session()
end end
p = main.procs[main.curPos] p = main.procs[main.curPos]