#! /bin/sh
#
# Rcsid[] = "$Id: appendvec,v 6.1 1998/03/06 00:32:42 vivek Exp $";
#
# This script can be used to join multiple vec files together
# to make one vec file with increasing time. The input to this
# script is a file containing the concatenated multiple vec files.
# The output is a single file containing all vectors.  The times
# for the vectors in the second and suqsequent input vec files are
# offset based on the time of the last vector of the previous input
# vec file. New vector files are always started at a "machine cycle"
# time boundry (4000 in the script below).  The input vec files
# cannot contain "headers", and must start with a 0 time vector.
#
# This script can be run with the following:
#
#   (for i in ac1 bv1 bv10 bv2
#    do
#       cat $1.vec
#    done) | appendvec >all.vec
#

trap "rm -f $$.awk" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

cat >$$.awk <<-'EOF'
    BEGIN {time=0; firsttime=1; inc=0}
    NF == 0 {continue;}
    $1 == 0 {
        if(firsttime == 1) {inc = 0; firsttime = 0;}
        else inc = time + (4000 - (time % 4000))
    }
    {
        time = $1+inc
        printf "%11d %s\n", time, $2
    }
EOF

awk -f $$.awk
