#!/bin/csh -f
#
# mpextract - extract multiple parameters from a set of data files 
#
# usage:
#   mpextract col1 col2 file.data-a ...
# 
# col1 and col2 specify a range of columns from col1 to col2
# inclusive. 
#   A list of the parameter from those columns from each file will appear on
# the standard output. The parameters are numbered as in the file PARMS.
# The first two parameters, pattern/prefetch? may not be extracted 
# correctly.
#
# WARNING: pipe through 'dm x1' or equivalent to strip leading zeroes
# from each column, if desired. Remember scanf bug.

if ($#argv <= 2) then
    echo usage: mpextract col1 col2 file.data-a ...
    exit 1
endif

# Define column range
@ col1=$1
@ col2=$2
shift;shift

if ($col1 > $col2) then
    echo usage: mpextract col1 col2 file.data-a ...
    echo "col1 ($col1) must not be greater than col2 ($col2)"
    exit 2
endif

# Adjust for PARMS file wierdness
@ col1=$col1 - 1
@ col2=$col2 - 1

# Make a list of columns
set cols=('$'$col1)
@ col=$col1 + 1
while ($col <= $col2)
    set cols=($cols',$'$col)
    @ col=$col + 1
end

# we strip leading and trailing spaces from each line of output
echo $* | prep | Awk -F. '{print '$cols'}' | sed -e 's/^[ ]*//' -e 's/[ ]*$//'

