forked from KuangLab-Harvard/SAM_SRCv6.11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restart.f90
321 lines (243 loc) · 10.7 KB
/
restart.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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
subroutine write_all()
use vars
implicit none
character *4 rankchar
character *256 filename
integer irank
integer, external :: lenstr
call t_startf ('restart_out')
if(masterproc) then
print*,'Writing restart file ...'
filename = './RESTART/'//trim(case)//'_'//trim(caseid)//'_misc_restart.bin'
open(66,file=trim(filename), status='unknown',form='unformatted', &
! BUFFERED='YES', & ! use for intel compiler
ACTION='WRITE')
end if
if(restart_sep) then
write(rankchar,'(i4)') rank
filename = './RESTART/'//trim(case)//'_'//trim(caseid)//'_'//&
rankchar(5-lenstr(rankchar):4)//'_restart.bin'
open(65,file=trim(filename), status='unknown',form='unformatted', &
! BUFFERED='YES', & ! use for intel compiler
ACTION='WRITE')
write(65) nsubdomains, nsubdomains_x, nsubdomains_y
call write_statement
else
write(rankchar,'(i4)') nsubdomains
filename = './RESTART/'//trim(case)//'_'//trim(caseid)//'_'//&
rankchar(5-lenstr(rankchar):4)//'_restart.bin'
do irank=0,nsubdomains-1
call task_barrier()
if(irank.eq.rank) then
if(masterproc) then
open(65,file=trim(filename), status='unknown',form='unformatted', &
! BUFFERED='YES', & ! use for intel compiler
ACTION='WRITE')
write(65) nsubdomains, nsubdomains_x, nsubdomains_y
else
open(65,file=trim(filename), status='unknown',form='unformatted',&
position='append', &
! BUFFERED='YES', & ! use for intel compiler
ACTION='WRITE')
end if
call write_statement
end if
end do
end if ! restart_sep
call task_barrier()
call t_stopf ('restart_out')
return
end
subroutine read_all()
use vars
use params, only: dompiensemble
implicit none
character *4 rankchar
character *256 filename
integer irank, ii
integer, external :: lenstr
if(masterproc) print*,'Reading restart file ...'
if(nrestart.ne.2) then
filename = './RESTART/'//trim(case)//'_'//trim(caseid)//'_misc_restart.bin'
else
filename = './RESTART/'//trim(case_restart)//'_'//trim(caseid_restart)//'_misc_restart.bin'
end if
open(66,file=trim(filename), status='unknown',form='unformatted', &
! BUFFERED='YES', & ! use for intel compiler
ACTION='READ')
if(restart_sep) then
write(rankchar,'(i4)') rank
if(nrestart.ne.2) then
filename = './RESTART/'//trim(case)//'_'//trim(caseid)//'_'//&
rankchar(5-lenstr(rankchar):4)//'_restart.bin'
else
filename = './RESTART/'//trim(case_restart)//'_'//trim(caseid_restart)//'_'//&
rankchar(5-lenstr(rankchar):4)//'_restart.bin'
end if
open(65,file=trim(filename), status='unknown',form='unformatted', &
! BUFFERED='YES', & ! use for intel compiler
ACTION='READ')
read(65)
call read_statement
else
write(rankchar,'(i4)') nsubdomains
if(nrestart.ne.2) then
filename='./RESTART/'//trim(case)//'_'//trim(caseid)//'_'//&
rankchar(5-lenstr(rankchar):4)//'_restart.bin'
else
filename='./RESTART/'//trim(case_restart)//'_'//trim(caseid_restart)//'_'//&
rankchar(5-lenstr(rankchar):4)//'_restart.bin'
end if
open(65,file=trim(filename), status='unknown',form='unformatted', &
! BUFFERED='YES', & ! use for intel compiler
ACTION='READ')
do irank=0,nsubdomains-1
call task_barrier()
if(irank.eq.rank) then
read (65)
do ii=0,irank-1 ! skip records
read(65)
end do
call read_statement
end if
end do
end if ! restart_sep
call task_barrier()
dtfactor = -1.
! update the boundaries
! (just in case when some parameterization initializes and needs boundary points)
! Kuang Ensemble run: turn off mpi for boundaries and diagnose (Song Qiyu, 2022)
if(dompiensemble) dompi = .false.
call diagnose() ! added by qiyusong
call boundaries(1)
call boundaries(4)
! Kuang Ensemble run: turn on mpi after boundaries and diagnose (Song Qiyu, 2022)
if(dompiensemble) dompi = .true.
return
end
subroutine write_statement()
use vars
use microphysics, only: micro_field, nmicro_fields
use sgs, only: sgs_field, nsgs_fields, sgs_field_diag, nsgs_fields_diag
use tracers
use params
use movies, only: irecc
implicit none
write(65) &
u, v, w, t, p, qv, qcl, qci, qpl, qpi, dudt, dvdt, dwdt, &
tracer, micro_field, sgs_field, sgs_field_diag, z, pres, prespot, presi, prespoti, &
rho, rhow, bet, sstxy, precinst, rank, nx, ny, nz, irecc
close(65)
if(masterproc) then
write(66) version, &
at, bt, ct, dt, dtn, dt3, time, dx, dy, dz, doconstdz,&
day, day0, nstep, na, nb, nc, caseid, case, &
dodamping, doupperbound, docloud, doprecip, doradhomo, dosfchomo,&
dolongwave, doshortwave, dosgs, dosubsidence, dotracers, dosmoke, &
docoriolis, dosurface, dolargescale,doradforcing, dossthomo, &
dosfcforcing, doradsimple, donudging_uv, donudging_tq, &
dowallx, dowally, doperpetual, doseasons, &
docup, docolumn, soil_wetness, dodynamicocean, ocean_type, &
delta_sst, depth_slab_ocean, Szero, deltaS, timesimpleocean, &
pres0, ug, vg, fcor, fcorz, tabs_s, z0, fluxt0, fluxq0, tau0, &
tauls, tautqls, timelargescale, epsv, nudging_uv_z1, nudging_uv_z2, &
donudging_t, donudging_q, doisccp, domodis, domisr, dosimfilesout, &
dosolarconstant, solar_constant, zenith_angle, notracegases, &
doSAMconditionals, dosatupdnconditionals, LES_S, &
nudging_t_z1, nudging_t_z2, nudging_q_z1, nudging_q_z2, &
ocean, land, sfc_flx_fxd, sfc_tau_fxd, &
nrad, nxco2, latitude0, longitude0, dofplane, SLM, &
docoriolisz, doradlon, doradlat, doseawater, salt_factor, &
ntracers, nmicro_fields, nsgs_fields, nsgs_fields_diag
close(66)
end if
if(rank.eq.nsubdomains-1) then
print *,'Restart file was saved. nstep=',nstep
endif
return
end
subroutine read_statement()
use vars
use microphysics, only: micro_field, nmicro_fields
use sgs, only: sgs_field, nsgs_fields, sgs_field_diag, nsgs_fields_diag
use tracers
use params
use movies, only: irecc
implicit none
integer nx1, ny1, nz1, rank1, ntr, nmic, nsgs, nsgsd
character(100) case1,caseid1
character(7) version1
read(65) &
u, v, w, t, p, qv, qcl, qci, qpl, qpi, dudt, dvdt, dwdt, &
tracer, micro_field, sgs_field, sgs_field_diag, z, pres, prespot, presi, prespoti, &
rho, rhow, bet, sstxy, precinst, rank1, nx1, ny1, nz1, irecc
close(65)
read(66) version1, &
at, bt, ct, dt, dtn, dt3, time, dx, dy, dz, doconstdz, &
day, day0, nstep, na, nb, nc, caseid1(1:sizeof(caseid)), case1(1:sizeof(case)), &
dodamping, doupperbound, docloud, doprecip, doradhomo, dosfchomo,&
dolongwave, doshortwave, dosgs, dosubsidence, dotracers, dosmoke, &
docoriolis, dosurface, dolargescale,doradforcing, dossthomo, &
dosfcforcing, doradsimple, donudging_uv, donudging_tq, &
dowallx, dowally, doperpetual, doseasons, &
docup, docolumn, soil_wetness, dodynamicocean, ocean_type,&
delta_sst, depth_slab_ocean, Szero, deltaS, timesimpleocean, &
pres0, ug, vg, fcor, fcorz, tabs_s, z0, fluxt0, fluxq0, tau0, &
tauls, tautqls, timelargescale, epsv, nudging_uv_z1, nudging_uv_z2, &
donudging_t, donudging_q, doisccp, domodis, domisr, dosimfilesout, &
dosolarconstant, solar_constant, zenith_angle, notracegases, &
doSAMconditionals, dosatupdnconditionals, LES_S, &
nudging_t_z1, nudging_t_z2, nudging_q_z1, nudging_q_z2, &
ocean, land, sfc_flx_fxd, sfc_tau_fxd, &
nrad, nxco2, latitude0, longitude0, dofplane, SLM, &
docoriolisz, doradlon, doradlat, doseawater, salt_factor, &
ntr, nmic, nsgs, nsgsd
close(66)
if(version1.ne.version) then
print *,'Wrong restart file!'
print *,'Version of SAM that wrote the restart files:',version1
print *,'Current version of SAM',version
call task_abort()
end if
if(nrestart.ne.3) then
if(rank.ne.rank1) then
print *,'Error: rank of restart data is not the same as rank of the process'
print *,'rank1=',rank1,' rank=',rank
call task_abort()
endif
if(nx.ne.nx1.or.ny.ne.ny1.or.nz.ne.nz1) then
print *,'Error: domain dims (nx,ny,nz) set by grid.f'
print *,' not correspond to ones in the restart file.'
print *,'in executable: nx, ny, nz:',nx,ny,nz
print *,'in restart file: nx, ny, nz:',nx1,ny1,nz1
print *,'Exiting...'
call task_abort()
endif
end if
if(nmic.ne.nmicro_fields) then
print*,'Error: number of micro_field in restart file is not the same as nmicro_fields'
print*,'nmicro_fields=',nmicro_fields,' in file=',nmic
print*,'Exiting...'
call task_abort()
end if
if(nsgs.ne.nsgs_fields.or.nsgsd.ne.nsgs_fields_diag) then
print*,'Error: number of sgs_field in restart file is not the same as nsgs_fields'
print*,'nsgs_fields=',nsgs_fields,' in file=',nsgs
print*,'nsgs_fields_diag=',nsgs_fields_diag,' in file=',nsgsd
print*,'Exiting...'
call task_abort()
end if
if(ntr.ne.ntracers) then
print*,'Error: number of tracers in restart file is not the same as ntracers.'
print*,'ntracers=',ntracers,' ntracers(in file)=',ntr
print*,'Exiting...'
call task_abort()
end if
close(65)
if(rank.eq.nsubdomains-1) then
print *,'Case:',caseid
print *,'Restarting at step:',nstep
print *,'Time(s):',nstep*dt
endif
return
end