#! @SHELL@
echo 1..9 # Number of tests to be executed.
#
test -n "$CDO"      || CDO=cdo
#
NTEST=1
#
for grid  in r18x9 ni4 ni96 global_10 t63grid; do
  RSTAT=0

  OPERATOR=ngridpoints
  CDOTEST="$OPERATOR on grid ${grid}"

  CDOCOMMAND="$CDO -s -${OPERATOR} -topo,${grid}"
  echo "$CDOCOMMAND"

  $CDOCOMMAND
  test $? -eq 0 || let RSTAT+=1
  case $grid in
    r18x9)
      if test 162   -eq $($CDOCOMMAND) ; then  echo "ok $NTEST - $CDOTEST"; else echo "not ok $NTEST - $CDOTEST"; fi
      ;;
    ni4)
      if test 250   -eq $($CDOCOMMAND) ; then  echo "ok $NTEST - $CDOTEST"; else echo "not ok $NTEST - $CDOTEST"; fi
      ;;
    ni96)
      if test 94090 -eq $($CDOCOMMAND) ; then  echo "ok $NTEST - $CDOTEST"; else echo "not ok $NTEST - $CDOTEST"; fi
      ;;
    global_10)
      if test 648   -eq $($CDOCOMMAND) ; then  echo "ok $NTEST - $CDOTEST"; else echo "not ok $NTEST - $CDOTEST"; fi
      ;;
    t63grid)
      if test 18432 -eq $($CDOCOMMAND) ; then  echo "ok $NTEST - $CDOTEST"; else echo "not ok $NTEST - $CDOTEST"; fi
      ;;
  esac

  let NTEST+=1
done
# some addional test for operator: ngrids
CDOCOMMAND="$CDO -O -s -ngrids"
$CDOCOMMAND -topo,global_10
test $? -eq 0 || let RSTAT+=1
test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST"
test $RSTAT -eq 0 || echo "not ok $NTEST - $CDOTEST"
let NTEST+=1

if test 1 -eq $($CDOCOMMAND -topo,r1x1) ; then  echo "ok $NTEST - $CDOCOMMAND -topo,r1x1"; else echo "not ok $NTEST - $CDOCOMMAND -topo,r1x1"; fi; let NTEST+=1
if test 1 -eq $($CDOCOMMAND -topo,global_1) ; then  echo "ok $NTEST - $CDOCOMMAND -topo,global_1"; else echo "not ok $NTEST - $CDOCOMMAND -topo,global_1"; fi; let NTEST+=1

# create temporary data
if [ "@ENABLE_NETCDF@" = yes ] ; then
  $CDO -O -f nc -temp,r18x9 temp.small
  $CDO -O -f nc -temp,global_10 temp.global
  $CDO -O -f nc -merge temp.small temp.global temp.2grids
  if test 2 -eq $($CDOCOMMAND temp.2grids) ; then  echo "ok $NTEST - $CDOCOMMAND temp.2grids"; else echo "not ok $NTEST - $CDOCOMMAND temp.2grids"; fi; let NTEST+=1
  else
    test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST # SKIP netCDF not enabled"
  fi

#
exit 0
