subroutine NECICodeEnd(tCPMD, tVASP)
!= End the NECI code. This contains all the termination
!= procedures for the code (as opposed to the system in general): e.g. for
!= the memory handling scheme, the timing routines, any parallel routines etc.
!= In:
!= tCPMD: True if doing a CPMD-based calculation.
!= tVASP: True if doing a VASP-based calculation.
! Utility modules
use MemoryManager, only: LeaveMemoryManager
use timing_neci, only: end_timing, print_timing_report
use SystemData, only: tMolpro, tMolproMimic, called_as_lib, arr, brr, g1, &
tagArr, tagBrr, tagG1
use DeterminantData, only: FDet, tagFDet
#ifdef USE_MPI
use Parallel_neci, only: MPIEnd
USE MolproPlugin
#endif
implicit none
logical, intent(in) :: tCPMD, tVASP
INTEGER :: rank, ierr
! CALL N_MEMORY_CHECK
! Cleanup any memory that hasn't been deallocated elsewhere, and isn't
! immediately obvious where to deallocate it...
if (.not. tCPMD .and. .not. called_as_lib) call LeaveMemoryManager()
call end_timing()
call print_timing_report()
#ifdef USE_MPI
! Tell Molpro plugin server that we have finished
CALL MolproPluginTerm(0)
! CPMD and VASP have their own MPI initialisation and termination routines.
call MPIEnd(molpro_plugin .or. (tMolpro .and. (.not. tMolproMimic)) .or. tCPMD .or. tVASP .or. called_as_lib)
#endif
end subroutine NECICodeEnd