File: plot

package info (click to toggle)
ocaml-batteries 3.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,104 kB
  • sloc: ml: 44,518; sh: 146; makefile: 96; ansic: 30; lisp: 15
file content (45 lines) | stat: -rwxr-xr-x 1,381 bytes parent folder | download | duplicates (7)
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
#!/bin/bash

[ $# -eq 0 ] || {
    echo 'unexpected command line arguments'
    echo 'usage: $0'
    echo 'Expects a stream on the standard input and draws'
    echo 'gnuplot graphs when it recognizes some gnuplot data'
    exit 1
}

trap cleanup EXIT SIGINT
cleanup() {
    rm -f "$tmp"
}
tmp="$(mktemp)"

while read line; do
    case "$line" in
        '#'*)
            # reading blocks of line starting with a line
            # starting with a sharp and ending with an empty line
            # this line has format #title size\tname1\tname2 etc.
            names=$(echo "$line" | cut -d '	' -f 2-)
            title=$(echo "$line" | sed 's/^#\([^ ]*\) .*$/\1/')
            > "$tmp" # emptying the file
            while read line && [ "$line" != "" ]; do
                echo "$line" >> "$tmp"
            done
            gnuplot -p <(
                echo set key left top
                echo set logscale x
                echo set title "'$title'"
                echo -n 'plot '
                counter=1
                for name in $names; do
                    counter=$((counter+1))
                    if [ $counter -ne 2 ]; then
                        echo -e -n ', \\\n     '
                    fi
                    echo -n \'"$tmp"\' using 1:$counter title \'"$name"\' with linespoints
                done
                echo
            )
    esac
done