#! /bin/sh

#    MAR 04/09 - F.Majaess

#id  fmtselname - Prepares formatted input lines to "select" program.

#    AUTHORS - S.Kharin,F.Majaess

#hd  PURPOSE - "fmtselname" scripts is used to prepare formatted 
#hd            input lines to "select" program from a list of 
#hd            up to 86 specified field names.

#pr  PARAMETERS:
#pr
#pr    POSITIONAL
#pr
#pr      fieldnames = list of up to 86 blank separated field names;
#pr                   (1 to 4 characters each). 
#pr
#ex  EXAMPLE:
#ex
#ex    fmtselname ST SIC TEMP SALT GC 
#ex
#ex    The above will result in returning 2 formatted lines with
#ex    properly positioned, right justified field names:
#ex
#ex      ST  SIC TEMP SALT
#ex                GC
#ex 
#ex    where the first 4 parameters complement the first input
#ex    line to "select" program, and the second is passed on as is.
#ex

#  Provided 1 to 86 field names are specified, prepare the formatted
#  input lines to be used with "select" program.

if [ $# -ge 1 -a $# -le 86 ] ; then
 echo $* | tr 'a-z' 'A-Z' | sed -e 's/  */ /g' | $AWK -F ' ' '{
   printf ("%5s%5s%5s%5s\n", \
    $1,$2,$3,$4)
   printf ("          %5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s\n", \
    $5, $6, $7, $8, $9,$10,$11,$12,$13,$14,$15,$16,$17,$18)
   printf ("          %5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s\n", \
    $19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32)
   printf ("          %5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s\n", \
    $33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46)
   printf ("          %5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s\n", \
    $47,$48,$49,$50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$60)
   printf ("          %5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s\n", \
    $61,$62,$63,$64,$65,$66,$67,$68,$69,$70,$71,$72,$73,$74)
   printf ("          %5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s%5s\n", \
    $75,$76,$77,$78,$79,$80,$81,$82,$83,$84,$85,$86)}' | sed -e '/^ *$/d'
else
  echo "ERROR in fmtselname: too many arguments $#. Must be in the range 1...86."
  exit 1
fi
