#!/bin/sh
#
#
#  File:    MesoDynRun (shell script)
#
#  Version: 1.0, November 1995.
#
#
#  Revision:
#
#    Version   Date          Author
#    -----------------------------------------
#    1.0     November 1995       Peter Altevogt 
#                                  (Heidelberg Scientific & Technical Center
#                                   IBM Deutschland Informationssysteme GmbH)
#                                Olaf Evers 
#                                  (BASF)
#
# This shell script has been developed as part of the CAESAR project
# work package "Chemical Engineering".
#
# The CAESAR project (Clusters of Computationally Intensive Applications
# for Engineering, Design and Simulation on Scalable Parallel Architectures)
# is a collaboration between British Aerospace, DASA, Odense and BASF.
#
# The project is managed by the British Aerospace and is funded by the CEC
# under the ESPRIT initiative (Project Ref: 8328).
#
#
# Intended Usage:
#   To execute the parallel simulation program MesoDyn
#

case $# in
  1)  ;;
  2)  ;;
  *)  echo 'Usage: MesoDynRun <parameter_file> <control_file>' 1>&2; exit 1
esac

PARAMETER_FILE=$1
CONTROL_FILE=$2

if test -r $PARAMETER_FILE
then
  echo "Reading number of processors from parameter file"
else
  echo "Can not open parameter file "$PARAMETER_FILE
  exit 1
fi

NPROC=`awk '/processors/{printf("%d",$2*$3*$4)}' $PARAMETER_FILE`
echo 'Requested for parallel simulation run '$NPROC' processor(s)'

TOPO=`awk '/topology_file/ {printf $2}' $PARAMETER_FILE`
/bin/rm -f ./host.list

if test $TOPO=
then
  echo "Using parallel environment to allocate processors (default)"
else
  if test -r $TOPO
  then
    echo "Reading hosts from topology file"
    cat $TOPO |awk '{print $4}' > ./host.list
  else
    echo "Topology file specified not found"
    exit 1
  fi
fi



#   
# File:        Runscript_irix
# Version:     0.0
# Author:      Olaf Evers (BASF AG)
#
# Revisions:	
#
# Notes:
#         
#       
# Purpose:
#   
#              Part of run script MesoDynRun for SG Power Challenge
#              using SGI MPI 
#                                                               

if test -f /usr/bin/mpirun
then
  /usr/bin/mpirun -np $NPROC $MESODYN_HOME/bin/MesoDyn $PARAMETER_FILE $CONTROL_FILE 
else
  echo "ERROR    Could not find native SGI mpirun "
  echo "         Please contact your system administrator!!"
fi
