#!/bin/bash usage () { cat <&2; exit 1 \ usage: ./speeds-analyse reads: -*.speeds 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 . $train.manual 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.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; warn "warning: '$train': expected 126 steps, found $steps\n" unless $steps==126; print "train '$train' is '$address'". " '$nondetfore'". "+'$(( $length - $nondetfore - $nondetrear ))'". "+'$nondetrear'\n" or die $!; sub calcwait ($$) { my ($step,$wholetime) = @_; return 0 if $step<0 || $step>=$steps; return $wholetime * 1000.0 * ($speed[$step+1] - $speed[$step]) / $max; } for ($step=0; $step<$nxt; $step++) { printf "train %s step %d=%d %d/%d\n", "'$train'", $step, $speed[$step]*1e6, calcwait($step-1,'$acceltime'), calcwait($step,'$deceltime') or die $!; } STDOUT->error and die $!; print "end\n" or die $!; } ' rm $o.all.tmp for f in ps record; do mv -f $o.$f.tmp $o.$f done