Automatic commit. Tue Sep 4 12:00:09 WST 2012
[matches/honours.git] / research / TCS / plot.sh
1 #!/bin/bash
2
3 # Script to plot .dat files
4
5 x=1
6 toplot="3 5"
7 ylabel="Counts"
8 style="l"
9 dir="/home/sam/Documents/University/honours/research/TCS"
10
11 title=$(grep "# Title = " $1 | sed 's/# Title = //g')
12 comment=$(grep "# Comment = " $1 | sed 's/# Comment = *//1' | head --bytes=100)
13 labels=$(grep -A 1 "# Data:" $1 | tail --lines=1 | sed 's/#//1')
14
15 if [ "$title" == "" ]; then
16         title=$comment
17 else
18         title="$title\n$comment"
19 fi
20 filename=$(echo $1 | sed -e "s:$dir::g")
21 title="$filename\n$title"
22
23 xlabel=$(echo $labels | tr " " "\n" | head --lines=$x | tail --lines=1)
24 if [ $2 != "" ]; then
25         if [ $2 == $1 ]; then
26                 exit 1
27         fi
28         command="set term png size 1024,800; set output \"$2\""
29 else
30         command=""
31 fi
32
33 command="$command; set title \"$title\""
34 command="$command; set xlabel \"$xlabel\""
35 command="$command; set ylabel \"$ylabel\""
36 command="$command; set key outside right"
37 plot="plot "
38 for y in $toplot; do
39         lab=$(echo $labels | tr " " "\n" | head --lines=$y | tail --lines=1)
40         if [ "$lab" == "" ]; then
41                 lab=$y
42         fi
43         plot="$plot \"$1\" u $x:$y w $style t \"$lab\","
44 done
45         
46 plot=$(echo $plot | sed -e "s/,//$(echo $toplot | wc -w)")
47 command="$command; $plot; exit"
48
49 gnuplot="/usr/bin/gnuplot"
50 $gnuplot --persist -e "$command"
51
52
53
54

UCC git Repository :: git.ucc.asn.au