Coverage report: /home/ellis/comp/core/lib/cli/tools/plot.lisp
Kind | Covered | All | % |
expression | 0 | 65 | 0.0 |
branch | 0 | 2 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; plot.lisp --- Plotting CLI Tools
6
(in-package :cli/tools/plot)
8
(defvar *gnuplot-process* nil)
10
(defun open-gnuplot (&key (gnuplot-binary (find-exe "gnuplot"))
15
(setf *gnuplot-process*
17
(if hostname "/usr/bin/ssh" gnuplot-binary) (when hostname (list hostname)) :input :stream :wait nil :output t))
18
(when hostname (gnuplot-send "export DISPLAY=:0~%~A~%" gnuplot-binary))
19
(gnuplot-send "~%set datafile fortran~%set term ~a~%" terminal)
22
(defun close-gnuplot ()
23
(when *gnuplot-process*
24
(gnuplot-send "quit~%")
25
(setf *gnuplot-process* nil)))
27
(defmacro with-gnuplot-stream ((stream) &rest body)
28
`(let ((,stream (sb-ext:process-input
30
(unwind-protect (progn ,@body) (finish-output ,stream))))
32
(defun gnuplot-send (str &rest args)
33
(with-gnuplot-stream (s)
34
(apply #'format s str args)))
36
(defmacro with-gnuplot-term ((stream num &key multiplot (terminal "wxt") output) &rest body)
37
(using-gensyms (decl (num output terminal multiplot))
39
(with-gnuplot-stream (,stream)
40
(format ,stream "set term push~%set term ~a ~a~%" ,terminal ,num)
41
(when ,output (format ,stream "set output '~a'~%" (etypecase ,output (pathname (pathname-name ,output)) (string ,output))))
42
(when ,multiplot (format ,stream "set multiplot~%"))
43
(unwind-protect (progn ,@body)
44
(when ,multiplot (format ,stream "unset multiplot~%"))
45
(when ,output (format ,stream "set output~%"))
46
(format ,stream "set term pop~%"))))))
48
(define-cli-tool :dot (args &key (output t) input)
49
(let ((proc (sb-ext:run-program *dot* args :output output :input input)))
50
(unless (eq 0 (sb-ext:process-exit-code proc))
51
(dot-error "DOT (graphviz) command failed: ~A ~A" *dot* args))))