fortran_io.f
4.68 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine setup_btio
c---------------------------------------------------------------------
c---------------------------------------------------------------------
include 'header.h'
include 'mpinpb.h'
character*(128) newfilenm
integer m, ierr
if (node.eq.root) record_length = 40/fortran_rec_sz
call mpi_bcast(record_length, 1, MPI_INTEGER,
> root, comm_setup, ierr)
open (unit=99, file=filenm,
$ form='unformatted', access='direct',
$ recl=record_length)
do m = 1, 5
xce_sub(m) = 0.d0
end do
idump_sub = 0
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine output_timestep
c---------------------------------------------------------------------
c---------------------------------------------------------------------
include 'header.h'
include 'mpinpb.h'
integer ix, jio, kio, cio
do cio=1,ncells
do kio=0, cell_size(3,cio)-1
do jio=0, cell_size(2,cio)-1
iseek=(cell_low(1,cio) +
$ PROBLEM_SIZE*((cell_low(2,cio)+jio) +
$ PROBLEM_SIZE*((cell_low(3,cio)+kio) +
$ PROBLEM_SIZE*idump_sub)))
do ix=0,cell_size(1,cio)-1
write(99, rec=iseek+ix+1)
$ u(1,ix, jio,kio,cio),
$ u(2,ix, jio,kio,cio),
$ u(3,ix, jio,kio,cio),
$ u(4,ix, jio,kio,cio),
$ u(5,ix, jio,kio,cio)
enddo
enddo
enddo
enddo
idump_sub = idump_sub + 1
if (rd_interval .gt. 0) then
if (idump_sub .ge. rd_interval) then
call acc_sub_norms(idump+1)
idump_sub = 0
endif
endif
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine acc_sub_norms(idump_cur)
include 'header.h'
include 'mpinpb.h'
integer idump_cur
integer ix, jio, kio, cio, ii, m, ichunk
double precision xce_single(5)
ichunk = idump_cur - idump_sub + 1
do ii=0, idump_sub-1
do cio=1,ncells
do kio=0, cell_size(3,cio)-1
do jio=0, cell_size(2,cio)-1
iseek=(cell_low(1,cio) +
$ PROBLEM_SIZE*((cell_low(2,cio)+jio) +
$ PROBLEM_SIZE*((cell_low(3,cio)+kio) +
$ PROBLEM_SIZE*ii)))
do ix=0,cell_size(1,cio)-1
read(99, rec=iseek+ix+1)
$ u(1,ix, jio,kio,cio),
$ u(2,ix, jio,kio,cio),
$ u(3,ix, jio,kio,cio),
$ u(4,ix, jio,kio,cio),
$ u(5,ix, jio,kio,cio)
enddo
enddo
enddo
enddo
if (node .eq. root) print *, 'Reading data set ', ii+ichunk
call error_norm(xce_single)
do m = 1, 5
xce_sub(m) = xce_sub(m) + xce_single(m)
end do
enddo
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine btio_cleanup
c---------------------------------------------------------------------
c---------------------------------------------------------------------
close(unit=99)
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine accumulate_norms(xce_acc)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
include 'header.h'
include 'mpinpb.h'
double precision xce_acc(5)
integer m
if (rd_interval .gt. 0) goto 20
open (unit=99, file=filenm,
$ form='unformatted', access='direct',
$ recl=record_length)
c clear the last time step
call clear_timestep
c read back the time steps and accumulate norms
call acc_sub_norms(idump)
close(unit=99)
20 continue
do m = 1, 5
xce_acc(m) = xce_sub(m) / dble(idump)
end do
return
end