#
+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
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 \
--- /dev/null
+#!/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