#!/bin/csh -f

set SQM = ../../../bin/sqm
set SPDIFF = ../../dacdif
set GODIFF = "../../dacdif -a 0.01"

# check if slko files for DFTB are installed
../../check_slko_files.x
if( $status > 0) then
  # no slko files - do not run DFTB tests
  set SPTESTS = (h2s.mndod.sp h2s.pm6.sp)
  set GOTESTS = (h2s.mndod.go)
else
  # slko files present - run DFTB tests
  set SPTESTS = (h2s.mndod.sp h2s.pm6.sp h2s.dftb.sp)
  set GOTESTS = (h2s.mndod.go h2s.dftb.go)
endif


# single point tests
foreach i ($SPTESTS)
    set input = $i.in
    set output = $i.out
    $SQM -O -i $input -o $output || goto error
    $SPDIFF $output.save $output
end

# geometry optimization tests
# do not check the electronic energy and
# core repulsion energy, they are too sensitive!
# the same holds for the geometry. The optimizer
# may for example rotate methyl groups!
foreach i ($GOTESTS)
    set input = $i.in
    set output = $i.out
    $SQM -O -i $input -o $output || goto error
    grep -v 'Electronic energy' $output > tmp
    grep -v '^  QMMM' tmp > tmp2
    grep -v 'Core-core repulsion' tmp2 > tmp
    grep -v 'DIPOLE' tmp > $output
    rm tmp tmp2
    $GODIFF $output.save $output
end

exit(0)

error:
echo "  ${0}:  Program error"
exit(1)
