-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathlogging.f90
More file actions
50 lines (39 loc) · 1.1 KB
/
Copy pathlogging.f90
File metadata and controls
50 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module logging
use, intrinsic :: iso_fortran_env, only: int32, int64, real32, real64, stderr=>error_unit
implicit none
contains
subroutine logger(val, filename)
!! polymorphic logging to text file, appending new values line by line.
!! logs to disk, auto-creating filename if not given
class(*), intent(in) :: val
character(*), intent(in), optional :: filename
character (:), allocatable :: logfn
if(present(filename)) then
logfn = trim(filename)
else
logfn = 'debug.log'
endif
block
integer :: u
open(newunit=u, file=logfn, status='unknown', form='formatted', access='stream', &
position='append')
select type (val)
type is (character(*))
write(u,'(A)') val
type is (real(real32))
write(u,'(F0.7)') val
type is (real(real64))
write(u,'(F0.15)') val
type is (integer(int32))
write(u,'(I0)') val
type is (integer(int64))
write(u,'(I0)') val
type is (logical)
write(u,'(L1)') val
class default
write(stderr, *) 'logging error: could not log unknown type/kind' ! can't use val here
end select
close(u)
end block
end subroutine logger
end module logging