1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
;
; module providing gwave support for plot/export using GNU graph
; as the backend.
;
(define-module (app gwave export-gnugraph)
:use-module (gtk gtk)
:use-module (ice-9 optargs)
:use-module (ice-9 format)
:use-module (app gwave cmds)
:use-module (app gwave export)
:use-module (app gwave utils)
:use-module (app gwave gtk-helpers)
:use-module (app gwave gwave-config)
)
(read-set! keywords 'prefix)
(debug-enable 'backtrace)
(debug-enable 'debug)
; Build a sub-dialog for gnu GRAPH plot options
; Returns a list of two items:
; - A GtkWidget for the notebook pannel of the dialog.
; - A procedure, which when called, will return
; a plot options list. The plot options list will be
; passed unchanged to the export procedure.
(define (build-gnugraph-panel)
(let* ((frame (gtk-frame-new "GNU Graph"))
; (hbox (gtk-hbox-new #f 5))
(vbox (gtk-vbox-new #f 5))
(opt-format "ps")
(format-optmenu (build-option-menu
(lambda (f) (set! opt-format f))
(list '("Postscript" . "ps")
'("Portable Network Graphics" . "png")
'("Portable Anymap" . "pnm")
'("Scalable Vector Graphics" . "svg")
'("Fig" . "fig")
'("Gnu Graphics Metafile" . "meta"))))
(landscape-hbox (gtk-hbox-new #f 0))
(opt-landscape #f)
(landscape-rbtns (build-radiobutton-box
landscape-hbox
(lambda (v) (set! opt-landscape v))
(list '("Portrait" . #f)
'("Landscape" . #t))))
(opt-color #f)
(color-rbtns (build-radiobutton-box
(gtk-hbox-new #f 0)
(lambda (v) (set! opt-color v))
(list '("Greyscale" . #f)
'("Color" . #t) )))
)
(gtk-container-border-width frame 10)
(gtk-widget-set-usize frame 200 150)
(gtk-widget-show frame)
(gtk-container-add frame vbox)
(gtk-box-pack-start vbox format-optmenu #f #f 0)
(gtk-widget-show vbox)
(gtk-box-pack-start vbox landscape-rbtns #f #f 0)
(gtk-widget-show landscape-rbtns)
(gtk-box-pack-start vbox color-rbtns #f #f 0)
(gtk-widget-show color-rbtns)
(list frame
(lambda ()
; (format #t "opt-landscape=~s\n" opt-landscape)
(append (list "-T" opt-format)
(if opt-landscape
(list "--rotation" "90")
'())
(if opt-color
(list "-C")
'())
)))
))
; export a wavepanel's data in the format needed by gnu graph's
; "a" input format.
(define (export-wavepanel-to-ggfile f wp)
(let ((p (open f (logior O_WRONLY O_CREAT O_TRUNC) #o0777))
(minx (wtable-start-xval))
(maxx (wtable-end-xval)))
(for-each (lambda (vw)
(export-variables (cons vw '()) p minx maxx)
(display "\n" p))
(wavepanel-visiblewaves wp))
(close-port p)
))
; export-wavepanels-gnugraph -
;
; generate hardcopy or documentary representation of the displayed
; waveforms on one or more wavepanels, using gnu graph as
; the formatting backend.
;
(define (export-wavepanels-gnugraph fname panellist options keeptmp)
(let* ((args (append (list-copy options)
(list "--input-format" "a"
"--width-of-plot" "0.9")))
(shfile (format #f "~a.sh" (filter-metachars fname)))
(tmpbase (filter-metachars fname))
(tmpfilelist (list shfile))
(ngraphs (length panellist))
(idx 0))
(set! args (append args (list "--height-of-plot"
(format #f "~f" (- (/ 0.9 ngraphs) 0.05)))))
(set! args (append args '("--toggle-round-to-next-tick" "X"
"--font-size" "0.03"
"--grid-style" "3")))
(if (wtable-xlogscale?)
(append! args '("-l" "X")))
(for-each (lambda (wp)
; (format #t "\nwavepanel: ~s args: ~s\n" wp args)
(if (> idx 0)
(set! args (append args (list "--reposition" "0"
(format #f "~f" (* idx (/ 0.9 ngraphs)))
"1"))))
(if (wavepanel-ylogscale? wp)
(set! args (append args '("-l" "Y"))))
(let ((fname (format #f "~a.~s" tmpbase idx)))
; (let ((fname (string-append tmpbase (number->string idx))))
(export-wavepanel-to-ggfile fname wp)
(set! args (append args (list fname)))
(set! tmpfilelist (cons fname tmpfilelist))
(if (wavepanel-ylogscale? wp)
(set! args (append args '("-l" "Y"))))
(set! idx (+ 1 idx))
))
panellist)
; finally we have the arglist and tmpfilelist
; (format #t "export-graph shfile=~s args=~s\ntmpfilelist=~s\n"
; shfile args tmpfilelist)
(with-output-to-file shfile
(lambda ()
(display "#!/bin/sh\n")
(format #t "~a ~a\n" gnugraph-pathname (join " " args))
(if (not keeptmp)
(format #t "rm -f ~a\n" (join " " tmpfilelist)))))
; (format #t "running sh -C ~a\n" shfile)
(subprocess-to-file fname "/bin/sh" (list "sh" shfile))
))
(register-plotfilter "GNU Graph"
build-gnugraph-panel export-wavepanels-gnugraph)
|