#! /bin/sh

cd ../
ETAROOT=`pwd`
cd ../
HOME=`pwd`
MAKEDIR='$(SRC)/prep/initbc'
MAKELIB1='$(SRC)/prep/util'
MAKELIB2='$(SRC)/prep/initbc'
#################################
##
## Primary grid dimensions
##
## Note:  LM must be 
## 38, 45, 50, or 60 (when running Eta coordinates)
## 25, 30, 38, or 45 (when running sigma coordinates)
##
## Note:  JM MUST be odd!
#
IM=$1
JM=$2
LM=$3
LSM=$4
########################
#
# Note: PT can only be set to 25 or 50 hPa to work properly with
#	the radiation files included in this package.  
#
PT=$5
####################
#
# This is used to link files for use by various programs.  Most machines
# name the linked files as "fort.#", while HP's use "ftn#", where # is the
# unit number.
#
HVAL="fort."
#
##########################

rm $ETAROOT/exe/initbc.exe
rm $ETAROOT/lib/*

cd $ETAROOT/install

cat Makefile.in | sed s:etaroot:$ETAROOT: | sed s:makedir:$MAKEDIR: \
| sed s:makelib1:$MAKELIB1: | sed s:makelib2:$MAKELIB2: > Makefile
cp parmeta.in $HOME/eta/src/include

cd $ETAROOT/src/include

cat parmeta.in  | sed s:imin:$IM: | sed s:jmin:$JM: | \
sed s:lmin:$LM: | sed s:lsmin:$LSM:  > parmeta

cd $ETAROOT/namelist

cat ETAIN.in | sed s:home:$HOME: | sed s:etaroot:$ETAROOT: \
| sed s:imin:$IM: | sed s:jmin:$JM: | sed s:lmin:$LM: \
| sed s:ptin:${PT}00: > ETAIN
cp -f ETAIN $ETAROOT/bin/.

cd $ETAROOT/bin

cp -f ./deta_files/deta_${LM}_wew deta

cat new_prep.sh.in | sed s:headin:$HVAL: > new_prep.sh

cd $HOME/eta/install

make
#######
echo "Compile interp_coupling.f"
sleep 2
cd $ETAROOT/src/prep/initbc
head -8 interp_coupling.f
echo "Are those parameters correct?"
sleep 2
fc=`head -n1 ../../configure/make.inc | awk '{print $3}'`
$fc interp_coupling.f -o interp_coupling.x
