#!/bin/csh -fe
#
# dirtoseq
#    Script to run dirtoseq.exe which converts a direct access
#    file to a sequential access file.
#    Can be invoked from UNIX prompt with:
#
#    dirtoseq name.arc   or
#    dirtoseq name.tor
#
# Product: discover
#
# Molecular Simulations Inc 1997
#-----------------------------------------------------------------------------
#
# Setup environment variables
#
setenv BIOSYM  /usr/global/msi/cerius2_4.2MS/cdiscover
setenv BIOSYM_LIBRARY  /usr/global/msi/cerius2_4.2MS/cdiscover/res
source /usr/global/msi/cerius2_4.2MS/install/lic_setup
#
# Check arguments
#
if ($#argv > 0) then
    set input = $argv[1]
else
    echo "Usage: dirtoseq input-file [output-file]"
    exit 1
endif
#
#
if ( ! -r $input ) then
    if ( -r $input.arc ) then
	set input = $input.arc
    else if ( -r $input.tor ) then
	set input = $input.tor
    else
	echo "Cannot find file named $input [or $input.arc or $input.tor]"
	exit 1
    endif
endif
#
if ($#argv > 1) then
    set output = $argv[2]
else
    set output = ${input}s
endif
#
#
if ( -e $output ) then
    echo "Output-file $output already exists\!"
    echo "Delete $output (Y/N)? "
    set delete = $<
    if ( $delete == 'Y' || $delete == 'y' ) then
       /bin/rm -f $output
    else
       exit 1
    endif
else
    echo "putting sequential file in $output"
endif
#
/bin/rm -f $output
#
# Make links
#
ln -s $input    fort.15  #Direct access file
ln -s $output   fort.16  #Sequential access file
#
# execute conversion program
#
$BIOSYM/exec/dirtoseqe
#
# clean up
#
/bin/rm -f fort.15
/bin/rm -f fort.16
