-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathio_restart_derivedtype.F90
More file actions
234 lines (219 loc) · 9.81 KB
/
io_restart_derivedtype.F90
File metadata and controls
234 lines (219 loc) · 9.81 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
module restart_derivedtype_module
interface
subroutine write_all_bin_restarts(ctarr, path_in, pathi_in, partit, mesh, ice, dynamics, tracers)
use MOD_ICE
use MOD_DYN
use MOD_TRACER
use MOD_PARTIT
use MOD_MESH
integer, dimension(3) , intent(in) :: ctarr
character(len=*), intent(in) :: path_in
character(len=*), intent(in) :: pathi_in
type(t_partit), intent(in), target :: partit
type(t_mesh) , intent(in), target :: mesh
type(t_ice) , intent(in), target, optional :: ice
type(t_dyn) , intent(in), target, optional :: dynamics
type(t_tracer), intent(in), target, optional :: tracers
end subroutine write_all_bin_restarts
subroutine read_all_bin_restarts(path_in, partit, mesh, ice, dynamics, tracers)
use MOD_ICE
use MOD_DYN
use MOD_TRACER
use MOD_PARTIT
use MOD_MESH
character(len=*), intent(in) :: path_in
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(inout), target :: mesh
type(t_ice) , intent(inout), target, optional :: ice
type(t_dyn) , intent(inout), target, optional :: dynamics
type(t_tracer), intent(inout), target, optional :: tracers
end subroutine read_all_bin_restarts
end interface
end module restart_derivedtype_module
!
!
!_______________________________________________________________________________
subroutine write_all_bin_restarts(ctarr, path_in, pathi_in, partit, mesh, ice, dynamics, tracers)
use MOD_ICE
use MOD_DYN
use MOD_TRACER
use MOD_PARTIT
use MOD_MESH
use fortran_utils
implicit none
integer, dimension(3) , intent(in) :: ctarr ! //cstep,ctime,cyear//
character(len=*) , intent(in) :: path_in
character(len=*) , intent(in) :: pathi_in
type(t_partit), target, intent(in) :: partit
type(t_mesh) , target, intent(in) :: mesh
type(t_ice) , target, intent(in), optional :: ice
type(t_dyn) , target, intent(in), optional :: dynamics
type(t_tracer), target, intent(in), optional :: tracers
! EO parameters
integer fileunit, fileunit_i
!___________________________________________________________________________
! write info file
if(partit%mype == 0) then
print *, achar(27)//'[1;33m'//' --> writing derived type binary restarts to '//trim(path_in)//achar(27)//'[0m'
! store metadata about the raw restart
fileunit_i = 299
open(newunit = fileunit_i, file = trim(pathi_in))
write(fileunit_i, '(g0)') ctarr(1)
write(fileunit_i, '(g0)') ctarr(2)
write(fileunit_i, '(2(g0))') "! year: ",ctarr(3)
end if
!___________________________________________________________________________
! mesh derived type
fileunit = partit%mype+300
open(newunit = fileunit, &
file = trim(path_in)//'/'//'t_mesh.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'replace', &
form = 'unformatted')
write(fileunit) mesh
close(fileunit)
if(partit%mype == 0) then
write(fileunit_i, '(1(g0))') "! t_mesh"
print *, achar(27)//'[33m'//' > write derived type t_mesh'//achar(27)//'[0m'
end if
!___________________________________________________________________________
! partit derived type
fileunit = partit%mype+300
open(newunit = fileunit, &
file = trim(path_in)//'/'//'t_partit.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'replace', &
form = 'unformatted')
write(fileunit) partit
close(fileunit)
if(partit%mype == 0) then
write(fileunit_i, '(1(g0))') "! t_partit"
print *, achar(27)//'[33m'//' > write derived type t_partit'//achar(27)//'[0m'
end if
!___________________________________________________________________________
! tracer derived type
if (present(tracers)) then
fileunit = partit%mype+300
open(newunit = fileunit, &
file = trim(path_in)//'/'//'t_tracer.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'replace', &
form = 'unformatted')
write(fileunit) tracers
close(fileunit)
if(partit%mype == 0) then
write(fileunit_i, '(1(g0))') "! t_tracer"
print *, achar(27)//'[33m'//' > write derived type t_tracer'//achar(27)//'[0m'
end if
end if
!___________________________________________________________________________
! dynamics derived type
if (present(dynamics)) then
fileunit = partit%mype+300
open(newunit = fileunit, &
file = trim(path_in)//'/'//'t_dynamics.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'replace', &
form = 'unformatted')
write(fileunit) dynamics
close(fileunit)
if(partit%mype == 0) then
write(fileunit_i, '(1(g0))') "! t_dynamics"
print *, achar(27)//'[33m'//' > write derived type t_dynamics'//achar(27)//'[0m'
end if
end if
!___________________________________________________________________________
! ice derived type
if (present(ice)) then
fileunit = partit%mype+300
open(newunit = fileunit, &
file = trim(path_in)//'/'//'t_ice.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'replace', &
form = 'unformatted')
write(fileunit) ice
close(fileunit)
if(partit%mype == 0) then
write(fileunit_i, '(1(g0))') "! t_ice"
print *, achar(27)//'[33m'//' > write derived type t_ice'//achar(27)//'[0m'
end if
end if
!___________________________________________________________________________
if(partit%mype == 0) close(fileunit_i)
end subroutine write_all_bin_restarts
!
!
!_______________________________________________________________________________
! read derived type binary restart files, depending on input (see optional) not
! all derived type binaries are read --> functionalitiy for dwarfs !
subroutine read_all_bin_restarts(path_in, partit, mesh, ice, dynamics, tracers)
use MOD_ICE
use MOD_DYN
use MOD_TRACER
use MOD_PARTIT
use MOD_MESH
use fortran_utils
implicit none
! do optional here for the usage with dwarfs, since there only specific derived
! types will be needed
character(len=*), intent(in) :: path_in
type(t_partit), intent(inout), target :: partit
type(t_mesh) , intent(inout), target :: mesh
type(t_ice) , intent(inout), target, optional :: ice
type(t_dyn) , intent(inout), target, optional :: dynamics
type(t_tracer), intent(inout), target, optional :: tracers
integer fileunit
!___________________________________________________________________________
if (partit%mype==0) print *, achar(27)//'[1;33m'//' --> read restarts from derived type binary'//achar(27)//'[0m'
!___________________________________________________________________________
! mesh derived type
fileunit = partit%mype+300
open( newunit = fileunit, &
file = trim(path_in)//'/'//'t_mesh.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'old', &
form = 'unformatted')
read(fileunit) mesh
close(fileunit)
if (partit%mype==0) print *, achar(27)//'[33m'//' > read derived type t_mesh'//achar(27)//'[0m'
!___________________________________________________________________________
! partit derived type
fileunit = partit%mype+300
open(newunit = fileunit, &
file = trim(path_in)//'/'//'t_partit.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'old', &
form = 'unformatted')
read(fileunit) partit
close(fileunit)
if (partit%mype==0) print *, achar(27)//'[33m'//' > read derived type t_partit'//achar(27)//'[0m'
!___________________________________________________________________________
! tracer derived type
if (present(tracers)) then
fileunit = partit%mype+300
open(newunit = fileunit, &
file = trim(path_in)//'/'//'t_tracer.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'old', &
form = 'unformatted')
read(fileunit) tracers
close(fileunit)
if (partit%mype==0) print *, achar(27)//'[33m'//' > read derived type t_tracer'//achar(27)//'[0m'
end if
!___________________________________________________________________________
! dynamics derived type
if (present(dynamics)) then
fileunit = partit%mype+300
open(newunit = fileunit, &
file = trim(path_in)//'/'//'t_dynamics.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'old', &
form = 'unformatted')
read(fileunit) dynamics
close(fileunit)
if (partit%mype==0) print *, achar(27)//'[33m'//' > read derived type t_dynamics'//achar(27)//'[0m'
end if
!___________________________________________________________________________
! ice derived type
if (present(ice)) then
fileunit = partit%mype+300
open(newunit = fileunit, &
file = trim(path_in)//'/'//'t_ice.'//mpirank_to_txt(partit%MPI_COMM_FESOM), &
status = 'old', &
form = 'unformatted')
read(fileunit) ice
close(fileunit)
if (partit%mype==0) print *, achar(27)//'[33m'//' > read derived type t_ice'//achar(27)//'[0m'
end if
end subroutine read_all_bin_restarts