#! @SHELL@
echo 1..4 # Number of tests to be executed.
#
test -n "$CDO"      || CDO=cdo
test -n "$DATAPATH" || DATAPATH=./data
#
CDOOUT=cout$$
CDOERR=cerr$$
#
NTEST=1
#
for OPERATOR in sinfon infon; do
  for FILE in testfile01 testfile02; do
    RSTAT=0
    IFILE=$DATAPATH/netcdf_${FILE}.nc
    OFILE=netcdf_${FILE}_${OPERATOR}
    RFILE=$DATAPATH/${OFILE}_ref

    CDOTEST="$OPERATOR $FILE"
    CDOCOMMAND="$CDO $OPERATOR $IFILE"

    if [ "@ENABLE_NETCDF@" = yes ] ; then
      echo "Running test: $NTEST"
      echo "$CDOCOMMAND"

      $CDOCOMMAND > $OFILE
      test $? -eq 0 || let RSTAT+=1

      diff $OFILE $RFILE > $CDOOUT 2> $CDOERR
      test $? -eq 0 || let RSTAT+=1

      test -s $CDOERR && let RSTAT+=1
      cat $CDOOUT $CDOERR

      test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST"
      test $RSTAT -eq 0 || echo "not ok $NTEST - $CDOTEST"
    else
      test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST # SKIP netCDF not enabled"
    fi

    let NTEST+=1
    rm -f $OFILE
  done
done
#
rm -f $CDOOUT $CDOERR
#
exit 0
