#!/bin/csh -f
#
# pextract - extract one parameter from a set of data files 
#
# usage:
#   pextract col pat/file.data-a ...
# 
#  A list of the parameter from that column from each file will appear on
# the standard output. The parameters are numbered as in the file PARMS.
#
# Though the usage indicates that there should be a directory name as
# part of each file name, it is not necessary.
#

if ($#argv <= 1) then
    echo usage: pextract col pat/file.data-a ...
    exit 1
endif

@ col=$1 - 1
shift

if ($col == 0) then
    # ie, the pattern name
    # we strip everything but the directory name from each line.
    foreach i ($*)
    	   if ($i:h != $i) then
    	   	  echo $i:h
        else
    	   	  echo ""
    	   endif
    end
else
    # we strip the pathname off each file name
    # then we print the given column, based on . as a seperator
    # then we strip leading and trailing spaces from each line of output
    echo $* | prep \
    	   | sed 's+.*/++' \
    	   | Awk -F. '{print $'$col'}' \
    	   | sed -e 's/^[ ]*//' -e 's/[ ]*$//'
endif
