1!
2! Copyright (C) 1996-2016	The SIESTA group
3!  This file is distributed under the terms of the
4!  GNU General Public License: see COPYING in the top directory
5!  or http://www.gnu.org/copyleft/gpl.txt.
6! See Docs/Contributors.txt for a list of contributors.
7!
8module m_wallclock
9!
10! A simple wall-time-stamper
11! It should be called only from the master node
12!
13
14use m_walltime, only: wall_time
15
16public :: wallclock
17public :: wallclock_shutdown
18
19integer, parameter, private :: dp = selected_real_kind(14,200)
20
21integer, private,  save    :: wt = -1
22logical, private,  save    :: first = .true.
23
24private
25
26CONTAINS
27
28subroutine wallclock(str)
29character(len=*), intent(in) :: str
30!
31real(dp) :: t
32
33if (first) then
34   call io_assign(wt)
35   open(wt,file='CLOCK',form='formatted',status='unknown')
36   first = .false.
37endif
38
39call wall_time(t)
40write(wt,"(a,f18.3)") str, t
41
42end subroutine wallclock
43
44subroutine wallclock_shutdown()
45
46  if ( wt >= 0 ) then
47     call io_close(wt)
48     ! Signal it has to be opened again.
49     first = .true.
50  end if
51
52end subroutine wallclock_shutdown
53
54end module m_wallclock
55
56