Coverage report: /home/ellis/comp/core/lib/cli/tools/plot.lisp

KindCoveredAll%
expression065 0.0
branch02 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
2
 
3
 ;; gnuplot
4
 
5
 ;;; Code:
6
 (in-package :cli/tools/plot)
7
 
8
 (defvar *gnuplot-process* nil)
9
 
10
 (defun open-gnuplot (&key (gnuplot-binary (find-exe "gnuplot"))
11
                           (terminal "wxt")
12
                           hostname)
13
   (or *gnuplot-process*
14
       (progn
15
         (setf *gnuplot-process* 
16
               (sb-ext:run-program
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)
20
         *gnuplot-process*)))
21
 
22
 (defun close-gnuplot ()
23
   (when *gnuplot-process*
24
     (gnuplot-send "quit~%")
25
     (setf *gnuplot-process* nil)))
26
 
27
 (defmacro with-gnuplot-stream ((stream) &rest body)
28
   `(let ((,stream (sb-ext:process-input
29
                    (open-gnuplot))))
30
      (unwind-protect (progn ,@body) (finish-output ,stream))))
31
 
32
 (defun gnuplot-send (str &rest args)
33
   (with-gnuplot-stream (s)
34
     (apply #'format s str args)))
35
 ;;
36
 (defmacro with-gnuplot-term ((stream num &key multiplot (terminal "wxt") output) &rest body)
37
   (using-gensyms (decl (num output terminal multiplot))
38
     `(let (,@decl)
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~%"))))))
47
 
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))))
52