1      subroutine tce_tidy(rtdb)
2c
3c $Id$
4c
5c     Terminate TCE modulem.
6c
7      implicit none
8#include "mafdecls.fh"
9#include "tcgmsg.fh"
10#include "global.fh"
11#include "bas.fh"
12#include "geom.fh"
13#include "rtdb.fh"
14#include "sym.fh"
15#include "util.fh"
16#include "msgids.fh"
17#include "stdio.fh"
18#include "tce.fh"
19#include "tce_main.fh"
20#include "errquit.fh"
21#include "dra.fh"
22c
23      integer rtdb             ! RTDB handle
24      integer i
25      logical nodezero
26c
27      nodezero = (ga_nodeid().eq.0)
28      if (nodezero.and.util_print('time',print_debug)) then
29        write(LuOut,9000) 'createfile   ', cpusecs(1), cpusecs(51)
30        write(LuOut,9000) 'deletefile   ', cpusecs(2), cpusecs(52)
31        write(LuOut,9000) 'put_block    ', cpusecs(3), cpusecs(53)
32        write(LuOut,9000) 'add_block    ', cpusecs(4), cpusecs(54)
33        write(LuOut,9000) 'get_block    ', cpusecs(5), cpusecs(55)
34        write(LuOut,9000) 'reconcilefile', cpusecs(6), cpusecs(56)
35        write(LuOut,9000) 'tce_sort     ', cpusecs(7), cpusecs(57)
36      endif
37      do i=ipol,1,-1
38        if (.not.ma_pop_stack(l_irs(i))) call errquit
39     1    ('tce_tidy: MA problem',1,MA_ERR)
40        if (.not.ma_pop_stack(l_occ(i))) call errquit
41     1    ('tce_tidy: MA problem',2,MA_ERR)
42        if (.not.ma_pop_stack(l_evl(i))) call errquit
43     1    ('tce_tidy: MA problem',3,MA_ERR)
44      enddo
45      if (.not.geom_destroy(geom))
46     1  call errquit('tce_tidy: geom_destroy failed',0,GEOM_ERR)
47      if (.not.bas_destroy(ao_bas_han))
48     1  call errquit('tce_tidy: bas_destroy failed',0,BASIS_ERR)
49      if (ioalg.eq.5) then
50        if (dra_terminate().ne.0)
51     1  call errquit('tce_tidy: dra termination failed',0,DISK_ERR)
52      endif
53      call fock_2e_tidy(rtdb)
54      call int_terminate()
55      call schwarz_tidy()
56 9000 format(1x,'cpu & wall time in seconds for ',A,2f20.1)
57      return
58      end
59