#!/bin/csh
#----shell script for solving community problem #1 using APPS -- GG 08/04/03
#
#
#1 = /tmp/input.tag   (the file APPS creates containing the iterate 
#                      to be evaluated)
#2 = /tmp/output.tag  (the file APPS expects to be returned contatining the
#                      function value; if constraints are violated, no file
#                      will be returned)
#3 = tag              (the unique identifier created by APPS for each 
#                      different evaluation; used in file names)
#################################################################

set HERE = (/home/tgkolda/community/interface)

####create the names of the files unique to this iterate's function evalulation
set out = A1-$3.out   #output file
set hed = A1-$3.hed   #head file
set wel = A1-$3.wel   #well file 
set mfn = A1-$3.mfn   #mfn file 

###STEP 1: Write the .mfn file
/bin/touch $HERE/$mfn

echo " LIST  26 $out" >> $HERE/$mfn     #output file here
echo " BAS    1 A1.bas" >> $HERE/$mfn
echo " BCF   11 A1.bcf" >> $HERE/$mfn 
echo " OC    10 A1.oc" >> $HERE/$mfn 
echo "DATA  30 $hed" >> $HERE/$mfn      #heads file goes here
echo " PCG   12 A1.pcg" >> $HERE/$mfn 
echo "WEL   13 $wel" >> $HERE/$mfn      #well file goes here
echo " RCH   20 A1.rch" >> $HERE/$mfn

####STEP 2: Calculate the function value by calling Katie's code
set input = input.$3
set output = output.$3
/bin/cp $1 $HERE/$input
/bin/touch $HERE/$output

cd $HERE
./evalCON6 $input $mfn $wel $hed $output >& /dev/null

####STEP 3: Clean up and pass the result back to APPS
/bin/rm -f $HERE/$input
/bin/rm -f $HERE/$mfn
/bin/rm -f $HERE/$wel
/bin/rm -f $HERE/$hed
/bin/rm -f $HERE/$out

if(! -z $HERE/$output)then
  /bin/cp $HERE/$output $2 
endif

/bin/rm -f $HERE/$output
