2 usage () { cat <<END >&2; exit 1 \
4 usage: ./speeds-analyse <train>
5 reads: <train>-*.speeds
7 writes: <train>.speeds.ps
8 writes: <train>.speeds.record
15 case "$1" in -*) usage ;; esac
26 exec 3>$o.stopping.tmp
28 printf >&3 '%d %d %s\n' $1 $(( $2 )) $3
30 . ../layout/ours.redacted.shellvars
34 for f in address length nondetfore nondetrear acceltime deceltime; do
35 # [mm] [mm] [mm] [ms] [ms]
37 if [ "x$v" = x ]; then echo >&2 "missing $train $f"; exit 1; fi
40 for f in $train-*.speeds; do
42 if head -1 $f | grep '^[A-Za-z]' >/dev/null; then
43 this="$this using 2:3"
46 perl -pe 's/^[A-Za-z]\w*//' $f >>$o.all.tmp
51 set terminal postscript
54 set output '$o.ps.tmp'
55 set ylabel "speed [m/s]"
56 set xlabel "nmra speed step 1..126"
57 plot '$o.all.tmp' smooth sbezier notitle $each
60 ed -s $o.ps.tmp <<END >/dev/null
67 sort -rnu $train.speeds.all.tmp |head -1 |awk '{print $1}'
68 case "${PIPESTATUS[*]}" in "0 0 0" | "141 0 0");;
69 *) echo >&2 "? ${PIPESTATUS[*]}"; exit 127;; esac
77 set output '$o.table.tmp'
78 plot '$o.all.tmp' smooth sbezier
81 sort -rn <$o.stopping.tmp >$o.stopping-sorted.tmp
83 perl <$o.stopping-sorted.tmp >$o.record.tmp -ne '
86 $last_stoptime= undef;
88 print "train '$train' is '$address'".
90 "+'$(( $length - $nondetfore - $nondetrear ))'".
94 die unless m/^(\d+)\s+(\d+)(?:\s+([-.0-9]+))?\s*$/;
95 ($step,$stopdist,$stoptime) = ($1,$2,$3);
96 die unless $step < $last_step;
97 if (defined $stoptime) {
98 $stoptime= eval $stoptime; defined $stoptime or die "$@ ?";
100 die unless $last_stoptime;
101 $stoptime= $last_stoptime;
103 printf "train '$train' stops %3d: %4d %5d\n", $step,$stopdist,
107 $last_stoptime= $stoptime;
110 perl <$o.table.tmp >>$o.record.tmp -ne '
117 next if m/^\#/; next unless m/\S/;
118 die unless m/^\s*(\d+)\s+([0-9.]+)\s/;
119 ($step,$speed) = ($1,$2);
120 die "$step $nxt" unless $step==$nxt;
121 if ($speed < $max) { push @decreases, $step; $speed= $max; }
122 $speed[$step]= $speed;
126 warn "warning: '$train': decreases at steps @decreases\n"
129 die "'$train': expected 126 steps, found $steps\n"
131 for ($step=1; $step<$nxt; $step++) {
132 printf "train %s step %d=%f\n",
133 "'$train'", $step, $speed[$step]
136 STDOUT->error and die $!;
137 print "end\n" or die $!;
141 rm $o.{all,stopping,stopping-sorted}.tmp
143 for f in ps record; do
144 mv -f $o.$f.tmp $o.$f