#!/bin/csh -f
#
# mopac - interface the MOPAC program (renamed to "rmopac") with Insight II
#
# the sole parameter is a MOPAC-format-molecule file, whose name MUST end
# with ".dat"
#
# Glenn J. Olander,        Biosym Technologies,  4/27/89, MOPAC Version 4.00
# Clifford Randall Cannon, Biosym Technologies, 11/29/90, MOPAC Version 5.00
#
# (See file ABOUT-mopac for what I learned while bringing MOPAC Version 5.00
#  into Insight II, and some tips on introducing a new version yourself--CRC.)


nohup
onintr end

set a = $1

if ($a == "") then
  echo Usage: mopac file
  goto end
endif
	
if !(-e $a:r.dat) then
  echo mopac: $a:r.dat not found.
  goto end
endif

# remove any leftover files or links from a previous MOPAC run
# (single quotes prevent any aliasing of "rm" command)
'rm' -f $a:r.out $a:r.arc $a:r.gpt
'rm' -f SHUTDOWN FOR005 FOR006 FOR009 FOR010 FOR012 FOR013 FOR016

# link Fortran 77 "unit numbers" to our input and output files (the
# part before the dot is determined by the given input file name).
# this is STILL NECESSARY because the command-line filenames go
# into a variable that can hold at most seven characters
ln -s $a:r.dat FOR005
ln -s $a:r.out FOR006
ln -s $a:r.res FOR009
ln -s $a:r.den FOR010
ln -s $a:r.arc FOR012
ln -s $a:r.gpt FOR013
ln -s $a:r.syb FOR016

# run MOPAC ("rmopac"), at low priority, specifying input and output file
# names on the command line
/bin/nice -19           \
  $INSIGHT_MOPAC/rmopac \
  < FOR005		\
  > FOR006		\
    FOR012		\
    FOR016		\
    FOR010		\
    FOR009		\
    FOR013

# remove Fortran "unit number" links, and the SHUTDOWN file (if any)
# (single quotes prevent any aliasing of "rm" command)
'rm' -f SHUTDOWN FOR005 FOR006 FOR009 FOR010 FOR012 FOR013 FOR016

# jump here to quit after errors
end:
