-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobserver.f90
102 lines (77 loc) · 2.33 KB
/
observer.f90
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
module observer
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Module: observer
!
! This module is used to "observe" the state vector of a
! system of equations by writing that state in some format to a file
! for later viewing or plotting by the user.
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
private
public :: observer_init, observer_write, observer_finalize
! file descriptor for output file
integer, parameter :: fd = 10
character(20), parameter :: filename = "data.txt"
contains
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Name: observer_init
!
! Description: Initializes the observer module by, e.g., opening
! files for later writing. This routine must be called before the
! first call to observer_write().
!
! Input: none
!
! Output: none
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine observer_init()
implicit none
!
! Code...
!
open(fd, file = filename, status = "new")
end subroutine observer_init
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Name: observer_write
!
! Description: Formats and writes the contents of the state vector s
! to a file.
!
! Input: s -- the state vector
!
! Output: none
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine observer_write(s)
implicit none
real, dimension(:), intent(in) :: s
!
! Code...
!
write(fd,*) 'state:', s
end subroutine observer_write
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Name: observer_finalize
!
! Description: Finalizes the observer module by, e.g., closing any
! files that were opened by the module. This routine must be called
! only once after all calls to observer_write() have been made.
!
! Input: none
!
! Output: none
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine observer_finalize()
implicit none
!
! Code...
!
close(fd)
end subroutine observer_finalize
end module observer