Automatic commit. Wed Sep 19 12:00:12 WST 2012
[matches/honours.git] / research / TCS / poll.sh
1 #!/bin/bash
2
3 #!/bin/bash
4
5 # Script to plot .dat files
6
7 x=1
8 toplot="2"
9 ylabel="Counts"
10 style="lp lw 2"
11 dir="/home/sam/Documents/University/honours/research/TCS"
12
13 title=$(grep "# Title: " $1 | sed 's/# Title: //g')
14 comment=$(grep "# Comment:" $1 | sed 's/# Comment: *//1' | head --bytes=100)
15 labels=$(grep -A 1 "# Data:" $1 | tail --lines=1 | sed 's/#//1')
16
17
18 stream=$1
19 if [ "$2" != "" ]; then
20         stream="< tail --lines=$2 $1"
21 fi
22
23 if [ "$title" == "" ]; then
24         title=$comment
25 else
26         title="$title\n$comment"
27 fi
28 filename=$(echo $1 | sed -e "s:$dir::g")
29 title="$filename\n$title"
30
31 xlabel=$(echo $labels | tr " " "\n" | head --lines=$x | tail --lines=1)
32 command="set title \"$title\""
33 command="$command; set xlabel \"$xlabel\""
34 command="$command; set ylabel \"$ylabel\""
35 command="$command; set key outside right"
36 plot="plot "
37 for y in $toplot; do
38         lab=$(echo $labels | tr " " "\n" | head --lines=$y | tail --lines=1)
39         if [ "$lab" == "" ]; then
40                 lab=$y
41         fi
42         plot="$plot \"$stream\" u $x:$y w $style t \"$lab\","
43 done
44         
45 plot=$(echo $plot | sed -e "s/,//$(echo $toplot | wc -w)")
46 command="$command; $plot; pause 0.5; reread"
47
48 echo "$command" | tr ";" "\n" > plot.template
49
50 gnuplot plot.template 2>&1 >> /dev/null
51
52 rm -f plot.template
53
54 exit 0
55
56 movie=false
57
58 dt=0.5
59
60 if $movie; then
61         output_style="set term png size \"640, 480\"; set output sprintf(\"%d.png\", i)"
62 else
63         output_style=""
64 fi
65
66 sed -e "s:\$file:$1:g" plot.template > plot
67 gnuplot --persist -e "set term x11; t = 0; dt = $dt; load \"plot\"" 2>&1 >> /dev/null
68
69 if $movie; then
70         #frame_rate=$(python -c "print str(min(int(float($steps) / float($tMax)), 40))")
71         frame_rate=20
72         ffmpeg -r $frame_rate -b 1024k -i %d.png animate.mp4
73         mplayer animate.mp4
74 fi

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