#!/bin/csh -fe
#
# seqtodir
#   Script to run seqtodir.exe which converts a sequential access
#   file to a direct access file.
#   Can be invoked from UNIX prompt with:
#   seqtodir name.arc   or
#   seqtodir name.tor
#
# Environment: 
#    Will only run on current platform using discover in Cerius2 release area
# 
# Product: discover
#
# Molecular Simulations Inc 1997
#-----------------------------------------------------------------------------
#
# Setup environment variables
#
setenv BIOSYM  %MSIInstallRoot%/cdiscover
setenv BIOSYM_LIBRARY  %MSIInstallRoot%/cdiscover/res
source %MSIInstallRoot%/install/lic_setup
#
# Check argument list
#
if ($#argv > 0) then
    set input = $argv[1]
else
    echo "Usage: seqtodir input-file [output-file]"
    exit 1
endif
#
#
if ( -r $input ) then
    set output = ${input}d
else
    if ( -r $input.arcs ) then
	set output = $input.arc
	set input = $input.arcs
    else if ( -r $input.tors ) then
	set output = $input.tor
	set input = $input.tors
    else
	echo "Cannot find file named $input [or $input.arcs or $input.tors]"
	exit 1
    endif
endif
#
if ($#argv > 1) then
    set output = $argv[2]
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 direct-access file in $output"
endif
#
/bin/rm -f $output
#
ln -s $output    fort.15  #Direct access file
ln -s $input     fort.16  #Sequential access file
#
# Execute conversion program
#
$BIOSYM/exec/seqtodire
#
# clean up
#
/bin/rm -f fort.15
/bin/rm -f fort.16
