#!/bin/sh
set -e
#
# calculate the atmospheric pressure (Pa) at the upper face of
# each model layer for a given set of surface pressure fields
#  - requires one full set of a 3-D field to retrieve the
#      vertical levels (in1)
#  - arguements on the card are for CMAM with the model lid 
#      at 0.0575 hPa
#

if [ $# -ne 4 ] ; then
  echo "Error in $0: invalid number of arguments $#"
  exit 1
fi

pfx=$1
inp1=$2
inp2=$3
out=$4

mtype=`uname -s|tr '[A-Z]' '[a-z]'`
case $mtype in
    aix) BINDIR=~ccc101/gcm2nc/cmip5_scripts/bin_aix ;;
  linux) BINDIR=~ccc101/gcm2nc/cmip5_scripts/bin_linux ;;
      *) echo "Unkown kernel type $mtype"
         exit 1 ;;
esac
PATH="${BINDIR}:$PATH"
export PATH

release inp1 inp2
access  inp1 ${pfx}_${inp1}
access  inp2 ${pfx}_${inp2}
echo "           HALF    2 ET15 FACE  -1.    0.0575" | ccc ccmi_pcalc inp1 inp2 ${pfx}_${out}

release inp1 inp2
