chiark / gitweb /
can analyse speeds into table, only not with accel
authorian <ian>
Sat, 2 Feb 2008 00:52:24 +0000 (00:52 +0000)
committerian <ian>
Sat, 2 Feb 2008 00:52:24 +0000 (00:52 +0000)
hostside/.cvsignore
hostside/Makefile
hostside/analyse-speeds [new file with mode: 0755]

index 1962df45c328568298fe2bcb459c00b6120cff7d..db748bad9564151cdf1a2ec14ddbdd935dfa2d9a 100644 (file)
@@ -3,8 +3,12 @@ hostside-old
 hostside
 safety
 t
+t.*
 layoutinfo.h
 *.d
+*.tmp
+*.speeds.ps
+*.speeds.record
 proto-expanded
 auproto-*
 gui-plan-bot
index 48e6c5b0dbab2075a1243cac2105a4e8a5462b59..7bd5193532399ae3730481ae79d16ba456662b07 100644 (file)
@@ -1,8 +1,11 @@
 #
 
+TRAINS=                santafe shinkansen
+
 AUTOINCS=      auproto-pic.h layoutinfo.h selectors.h retransmit-table.h \
                errorcodes.h stastate.h record-y.h record-l.h
-TARGETS=       hostside-old gui-plan-bot realtime
+TARGETS=       hostside-old gui-plan-bot realtime \
+               $(addsuffix .speeds.ps, $(TRAINS))
 
 include ../common.make
 include ../cprogs.make
@@ -59,6 +62,11 @@ selectors.h retransmit-table.h errorcodes.h stastate.h: %: %.gen
 safety:                safety.o utils.o trackloc.o ../layout/ours.layout-data.o
                $(LINK)
 
+%.speeds.ps:   %.speeds.record
+
+%.speeds.record: ./speeds-analyse
+               ./$^ $*
+
 hostside:      hostside.o serialio.o client.o obc.o commands.o utils.o \
                 nmra.o encode.o retransmit.o output.o auproto-pic.o \
                 parseutils.o \
diff --git a/hostside/analyse-speeds b/hostside/analyse-speeds
new file mode 100755 (executable)
index 0000000..541ce44
--- /dev/null
@@ -0,0 +1,81 @@
+#!/bin/bash
+usage () { cat <<END >&2; exit 1 \
+
+usage: ./speeds-analyse <train>
+  reads: <train>-*.speeds
+  writes: <train>.speeds.ps
+  writes: <train>.speeds.record
+END
+}
+
+set -e
+
+test $# = 1 || usage
+case "$1" in -*) usage ;; esac
+
+train=$1; shift
+
+o=$train.speeds
+
+>$o.all.tmp
+
+for f in $train-*.speeds; do
+       this="'$f'"
+       if head -1 $f | grep '^[A-Za-z]' >/dev/null; then
+               this="$this using 2:3"
+       fi
+       each="$each, $this"
+       perl -pe 's/^[A-Za-z]\w*//' $f >>$o.all.tmp
+done
+
+gnuplot <<END
+set pointsize 0.3
+set terminal postscript
+set key top left
+set xrange [0:127]
+set output '$o.ps.tmp'
+#set ylabel "speed [m/s]"
+#set xlabel "nmra speed step 1..126"
+plot '$o.all.tmp' smooth sbezier notitle  $each
+END
+
+ed -s $o.ps.tmp <<END >/dev/null
+/^%%Title/
+s/\.tmp$//
+w
+END
+
+max=`
+    sort -rnu $train.speeds.all.tmp |head -1 |awk '{print $1}'
+    case "${PIPESTATUS[*]}" in "0 0 0" | "141 0 0");;
+       *) echo >&2 "? ${PIPESTATUS[*]}"; exit 127;; esac
+`
+
+gnuplot <<END
+set terminal table
+set samples $max
+set xrange [1:$max]
+unset autoscale x
+set output '$o.table.tmp'
+plot '$o.all.tmp' smooth sbezier
+END
+
+perl <$o.table.tmp >$o.record.tmp -ne '
+       BEGIN { $nxt= 1; }
+       next if m/^\#/; next unless m/\S/;
+       die unless m/^\s*(\d+)\s+([0-9.]+)\s/;
+       $step= $1;
+       $speed= int($2*1e6+0.5);
+       die "$step $nxt" unless $step==$nxt;
+       print "train '$train' step $step=$speed ?/?\n" or die $!;
+       $nxt++;
+       END { warn "warning: '$train': expected 126 steps, found ".
+               ($nxt-1)."\n"
+               unless $nxt==127; }
+'
+
+rm $o.all.tmp
+
+for f in ps record; do
+       mv -f $o.$f.tmp $o.$f
+done