2 usage () { cat <<END >&2; exit 1 \
4 usage: ./speeds-analyse <train>
5 reads: <train>-*.speeds
6 writes: <train>.speeds.ps
7 writes: <train>.speeds.record
14 case "$1" in -*) usage ;; esac
25 exec 3>$o.stopping.tmp
27 printf >&3 '%d %d %s\n' $1 $(( $2 )) $3
29 . ../layout/ours.redacted.shellvars
33 for f in address length nondetfore nondetrear acceltime deceltime; do
34 # [mm] [mm] [mm] [ms] [ms]
36 if [ "x$v" = x ]; then echo >&2 "missing $train $f"; exit 1; fi
39 for f in $train-*.speeds; do
41 if head -1 $f | grep '^[A-Za-z]' >/dev/null; then
42 this="$this using 2:3"
45 perl -pe 's/^[A-Za-z]\w*//' $f >>$o.all.tmp
50 set terminal postscript
53 set output '$o.ps.tmp'
54 set ylabel "speed [m/s]"
55 set xlabel "nmra speed step 1..126"
56 plot '$o.all.tmp' smooth sbezier notitle $each
59 ed -s $o.ps.tmp <<END >/dev/null
66 sort -rnu $train.speeds.all.tmp |head -1 |awk '{print $1}'
67 case "${PIPESTATUS[*]}" in "0 0 0" | "141 0 0");;
68 *) echo >&2 "? ${PIPESTATUS[*]}"; exit 127;; esac
76 set output '$o.table.tmp'
77 plot '$o.all.tmp' smooth sbezier
80 sort -rn <$o.stopping.tmp >$o.stopping-sorted.tmp
82 perl <$o.stopping-sorted.tmp >$o.record.tmp -ne '
85 $last_stoptime= undef;
87 print "train '$train' is '$address'".
89 "+'$(( $length - $nondetfore - $nondetrear ))'".
93 die unless m/^(\d+)\s+(\d+)(?:\s+([-.0-9]+))?\s*$/;
94 ($step,$stopdist,$stoptime) = ($1,$2,$3);
95 die unless $step < $last_step;
96 if (defined $stoptime) {
97 $stoptime= eval $stoptime; defined $stoptime or die "$@ ?";
99 die unless $last_stoptime;
100 $stoptime= $last_stoptime;
102 printf "train '$train' stops %3d: %4d %5d\n", $step,$stopdist,
106 $last_stoptime= $stoptime;
109 perl <$o.table.tmp >>$o.record.tmp -ne '
116 next if m/^\#/; next unless m/\S/;
117 die unless m/^\s*(\d+)\s+([0-9.]+)\s/;
118 ($step,$speed) = ($1,$2);
119 die "$step $nxt" unless $step==$nxt;
120 if ($speed < $max) { push @decreases, $step; $speed= $max; }
121 $speed[$step]= $speed;
125 die "'$train': decreases at steps @decreases\n"
128 die "'$train': expected 126 steps, found $steps\n"
130 for ($step=1; $step<$nxt; $step++) {
131 printf "train %s step %d=%f\n",
132 "'$train'", $step, $speed[$step]
135 STDOUT->error and die $!;
136 print "end\n" or die $!;
140 rm $o.{all,stopping,stopping-sorted}.tmp
142 for f in ps record; do
143 mv -f $o.$f.tmp $o.$f