#!/bin/sh
#
#****s* fm/test_pp_abel.sh
#
# NAME
#    test_pp_abel.sh - Test the ropp_pp abel and inverse routines.
#
# SYNOPSIS
#   test_pp_abel.sh
#
# DESCRIPTION
#   Tests the ROPP PP Abel and inverse routines:
#   (1) refrac --> (2) bangle --> (3) refrac --> (4) bangle.
#   Fortran program ropp_test_abel.f90 compares (1) & (3), and (2) & (4).
#   Uses standard ropp_pp input data file ../data/ropp_pp_test.nc.
#
# NOTES
#   1) If $ROPP_VERBOSE is set, the log files wil be 'cat'ed.
#
# REFERENCES
#   See the ROPP User Guide (SAF/ROM/METO/UG/ROPP/003)
#
#****

#-------------------------------------------------------------------------------
# 0. Loop over tests
#-------------------------------------------------------------------------------

for i_test in 1 ; do  # physical options

#-------------------------------------------------------------------------------
# 1. Define variables
#-------------------------------------------------------------------------------

  EXEC=./ropp_test_abel

  case $i_test in

    1)  # default options
      CMD="$EXEC"
      TEST="t_pp_abel_"${i_test}
      COMMENT="PP Abel/Inv; default opts"
      ;;

  esac

  LOGFILE=${TEST}.log

  echo " "
  echo "Running $TEST ($COMMENT) ..."

  echo "*** Results log of $TEST ($COMMENT) ***" > $LOGFILE

  if [ "$(echo $(basename $(dirname $PWD)) |cut -c1-7)"/"$(basename $PWD)" != "ropp_pp/tests" ] ; then
    echo "*** Not in ropp_pp*/tests subdirectory - test NOT PERFORMED"  >> $LOGFILE
    exit 1
  fi


#-------------------------------------------------------------------------------
# 2. Run the ropp_pp executable
#-------------------------------------------------------------------------------

  if [ -f $EXEC ]; then

    echo "$CMD"  >> $LOGFILE
          $CMD  >> $LOGFILE

  else

    echo "*** $EXEC not found - test FAILED"  >> $LOGFILE

  fi

  if [ -n ${ROPP_VERBOSE:-''} ] ; then

    cat $LOGFILE

  else

    if [ -f $EXEC ]; then

      echo "****************************"
      echo "**********"  `tail -1 ./compare.txt |cut -d"|" -f5 | sed -es/' '//g`  "**********"
      echo "****************************"

    else

      echo "*** $EXEC not found - test FAILED"

    fi

  fi


#-------------------------------------------------------------------------------
# 3. Finish
#-------------------------------------------------------------------------------

  echo "... examine $LOGFILE for details"
  echo " "


done  # loop over options

exit 0
