#!/bin/bash usage () { cat <&2; exit 1 \ usage: ./speeds-analyse reads: -*.speeds reads: .manual writes: .speeds.ps writes: .speeds.record END } set -e test $# = 1 || usage case "$1" in -*) usage ;; esac train=$1; shift o=$train.speeds >$o.all.tmp acceltime=100000 deceltime=30000 exec 3>$o.stopping.tmp stops-from () { printf >&3 '%d %d %s\n' $1 $(( $2 )) $3 } . ../layout/ours.redacted.shellvars . $train.manual exec 3>&- for f in address length nondetfore nondetrear acceltime deceltime; do # [mm] [mm] [mm] [ms] [ms] eval "v=\$$f" if [ "x$v" = x ]; then echo >&2 "missing $train $f"; exit 1; fi done 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 </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 <$o.stopping-sorted.tmp perl <$o.stopping-sorted.tmp >$o.record.tmp -ne ' BEGIN { $last_step= 127; $last_stoptime= undef; print "train '$train' is '$address'". " '$nondetfore'". "+'$(( $length - $nondetfore - $nondetrear ))'". "+'$nondetrear'\n" or die $!; } die unless m/^(\d+)\s+(\d+)(?:\s+([-.0-9]+))?\s*$/; ($step,$stopdist,$stoptime) = ($1,$2,$3); die unless $step < $last_step; if (defined $stoptime) { $stoptime= eval $stoptime; defined $stoptime or die "$@ ?"; } else { die unless $last_stoptime; $stoptime= $last_stoptime; } printf "train '$train' stops %3d: %4d %5d\n", $step,$stopdist, $stoptime*1000 or die $!; $last_step= $step; $last_stoptime= $stoptime; ' perl <$o.table.tmp >>$o.record.tmp -ne ' BEGIN { use IO::Handle; $nxt= 1; $max= 0; $speed[0]= 0; } next if m/^\#/; next unless m/\S/; die unless m/^\s*(\d+)\s+([0-9.]+)\s/; ($step,$speed) = ($1,$2); die "$step $nxt" unless $step==$nxt; if ($speed < $max) { push @decreases, $step; $speed= $max; } $speed[$step]= $speed; $max= $speed; $nxt++; END { warn "warning: '$train': decreases at steps @decreases\n" if @decreases; $steps= $nxt-1; die "'$train': expected 126 steps, found $steps\n" unless $steps==126; for ($step=1; $step<$nxt; $step++) { printf "train %s step %d=%f\n", "'$train'", $step, $speed[$step] or die $!; } STDOUT->error and die $!; print "end\n" or die $!; } ' rm $o.{all,stopping,stopping-sorted}.tmp for f in ps record; do mv -f $o.$f.tmp $o.$f done