#! /bin/csh -f
#	split packed library

if ( $#argv != 1 ) then
  echo "Usage: libsplit filename"
  exit 1
endif

set libpack = $argv[1]

if ( -e LIBLIST ) then
  echo "Splitted files may exist / You must delete these files."
  echo -n "Do you want to remove *.f files (y/n) ? "
  set line = $<
  if ( $line == y ) then
    \rm *.f
  else
    echo "exit from libsplit"
    exit 1
  endif
endif

awk '{ if ($0 ~ /\*------/) nl=nl+1; \
       if (nl<2) print > "HEADER" ; else print > "BODY" }' $libpack

fsplit BODY >! LIBLIST
\rm BODY

echo -n "Do you want to remove original $libpack (y/n) ? "
set line = $<
if ( $line == y ) then
  \rm $libpack
endif
