#!/bin/csh
#---------------------------------------------------------------------------
# install_helio: Compile and install heliospheric model.
#
# Usage: ./install_helio [resolution]
#     [resolution] is either low or medium
#---------------------------------------------------------------------------

# Usage message
if ($#argv != 1 || ($1 != 'low' && $1 != 'medium')) then
  echo "install_helio: Compile and install heliospheric model."
  echo ""
  echo "Usage: ./install_helio [resolution]"
  echo "    [resolution] is either low or medium"
  exit 1
endif

# Set parameters
set resolution = $1

# Set environment variables
source ./set.sh make

set project_dir = $ENLIL_BIN
set numo = mp3m

# Set default parameters
set procs = 1

# Set auxiliary parameters
if ($resolution == 'low') then
  set n1 = 128
  set n2 = 60
  set n3 = 90
else
  set n1 = 256
  set n2 = 120
  set n3 = 180
endif

set n1x = $n1
@ n1x /= $procs
set grd = $n1'x'$n2'x'$n3
set code = $procs-$numo.$grd

# Make directories
test -d $project_dir || mkdir $project_dir
test -d $project_dir/code.$code || mkdir $project_dir/code.$code

# Write maximum array dimensions and compile the codes
cd $project_dir/code.$code

echo "MODULE COMMAX"                                          > commax.F
echo "IMPLICIT NONE"                                         >> commax.F
echo "PUBLIC"                                                >> commax.F
echo "INTEGER, PARAMETER :: nbb1=1,    nbb2=$n2,  nbb3=$n3"  >> commax.F
echo "INTEGER, PARAMETER :: ncc1=$n1x, ncc2=$n2,  ncc3=$n3"  >> commax.F
echo "INTEGER, PARAMETER :: ngguard=2, maxhel=20, maxsel=20" >> commax.F
echo "INTEGER, PARAMETER :: maxfld=5,  maxfstep=1500"        >> commax.F
echo "INTEGER, PARAMETER :: maxblk=1"                        >> commax.F
echo "END MODULE COMMAX"                                     >> commax.F

cat $ENLIL_DIR/set/set.$numo $ENLIL_DIR/make/make.enlil-pc > Makefile.enlil
make -f Makefile.enlil

cat $ENLIL_DIR/set/set.$numo $ENLIL_DIR/make/make.mas2bc > Makefile.mas2bc
make -f Makefile.mas2bc

/bin/rm *.o *.mod

exit 0
