Newer
Older
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
MODULE icerst
!!======================================================================
!! *** MODULE icerst ***
!! sea-ice : write/read the ice restart file
!!======================================================================
!! History: 4.0 ! 2018 (many people) SI3 [aka Sea Ice cube]
!!----------------------------------------------------------------------
#if defined key_si3
!!----------------------------------------------------------------------
!! 'key_si3' SI3 sea-ice model
!!----------------------------------------------------------------------
!! ice_rst_opn : open restart file
!! ice_rst_write : write restart file
!! ice_rst_read : read restart file
!!----------------------------------------------------------------------
USE ice ! sea-ice: variables
USE dom_oce ! ocean domain
USE phycst , ONLY : rt0
USE sbc_oce , ONLY : nn_fsbc, ln_cpl
USE sbc_oce , ONLY : nn_components, jp_iam_sas ! SAS ss[st]_m init
USE sbc_oce , ONLY : sst_m, sss_m ! SAS ss[st]_m init
USE oce , ONLY : ts ! SAS ss[st]_m init
USE eosbn2 , ONLY : l_useCT, eos_pt_from_ct ! SAS ss[st]_m init
USE iceistate ! sea-ice: initial state
USE icectl ! sea-ice: control
!
USE in_out_manager ! I/O manager
USE iom ! I/O manager library
USE lib_mpp ! MPP library
USE lib_fortran ! fortran utilities (glob_sum + no signed zero)
IMPLICIT NONE
PRIVATE
PUBLIC ice_rst_opn ! called by icestp
PUBLIC ice_rst_write ! called by icestp
PUBLIC ice_rst_read ! called by ice_init
!!----------------------------------------------------------------------
!! NEMO/ICE 4.0 , NEMO Consortium (2018)
!! $Id: icerst.F90 14239 2020-12-23 08:57:16Z smasson $
!! Software governed by the CeCILL license (see ./LICENSE)
!!----------------------------------------------------------------------
CONTAINS
SUBROUTINE ice_rst_opn( kt )
!!----------------------------------------------------------------------
!! *** ice_rst_opn ***
!!
!! ** purpose : open restart file
!!----------------------------------------------------------------------
INTEGER, INTENT(in) :: kt ! number of iteration
!
CHARACTER(len=20) :: clkt ! ocean time-step define as a character
CHARACTER(len=50) :: clname ! ice output restart file name
CHARACTER(len=256) :: clpath ! full path to ice output restart file
CHARACTER(LEN=52) :: clpname ! ocean output restart file name including prefix for AGRIF
!!----------------------------------------------------------------------
!
IF( kt == nit000 ) lrst_ice = .FALSE. ! default definition
IF( ln_rst_list .OR. nn_stock /= -1 ) THEN
! in order to get better performances with NetCDF format, we open and define the ice restart file
! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice
! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nn_stock == nn_fsbc &
& .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
! beware of the format used to write kt (default is i8.8, that should be large enough...)
IF( nitrst > 99999999 ) THEN ; WRITE(clkt, * ) nitrst
ELSE ; WRITE(clkt, '(i8.8)') nitrst
ENDIF
! create the file
clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out)
clpath = TRIM(cn_icerst_outdir)
IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/'
IF(lwp) THEN
WRITE(numout,*)
WRITE(numout,*) ' open ice restart NetCDF file: ',TRIM(clpath)//clname
IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN
WRITE(numout,*) ' kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp
ELSE
WRITE(numout,*) ' kt = ' , kt,' date= ', ndastp
ENDIF
ENDIF
!
IF(.NOT.lwxios) THEN
CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl, cdcomp = 'ICE' )
ELSE
#if defined key_xios
cw_icerst_cxt = "rstwi_"//TRIM(ADJUSTL(clkt))
IF( TRIM(Agrif_CFixed()) == '0' ) THEN
clpname = clname
ELSE
clpname = TRIM(Agrif_CFixed())//"_"//clname
ENDIF
numriw = iom_xios_setid(TRIM(clpath)//TRIM(clpname))
CALL iom_init( cw_icerst_cxt, kdid = numriw, ld_closedef = .FALSE. )
CALL iom_swap( cxios_context )
#else
CALL ctl_stop( 'Can not use XIOS in rst_opn' )
#endif
ENDIF
lrst_ice = .TRUE.
ENDIF
ENDIF
ENDIF
!
IF( ln_icectl ) CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' ) ! control print
!
END SUBROUTINE ice_rst_opn
SUBROUTINE ice_rst_write( kt )
!!----------------------------------------------------------------------
!! *** ice_rst_write ***
!!
!! ** purpose : write restart file
!!----------------------------------------------------------------------
INTEGER, INTENT(in) :: kt ! number of iteration
!!
INTEGER :: jk ! dummy loop indices
INTEGER :: iter
CHARACTER(len=25) :: znam
CHARACTER(len=2) :: zchar, zchar1
REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace
!!----------------------------------------------------------------------
iter = kt + nn_fsbc - 1 ! ice restarts are written at kt == nitrst - nn_fsbc + 1
IF( iter == nitrst ) THEN
IF(lwp) WRITE(numout,*)
IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file kt =', kt
IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
ENDIF
! Write in numriw (if iter == nitrst)
! ------------------
! ! calendar control
CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) ) ! time-step
CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter , wp ) ) ! date
IF(.NOT.lwxios) CALL iom_delay_rst( 'WRITE', 'ICE', numriw ) ! save only ice delayed global communication variables
! Prognostic variables
CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i )
CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s )
CALL iom_rstput( iter, nitrst, numriw, 'sv_i' , sv_i )
CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i )
CALL iom_rstput( iter, nitrst, numriw, 't_su' , t_su )
CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice )
CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice )
CALL iom_rstput( iter, nitrst, numriw, 'oa_i' , oa_i )
CALL iom_rstput( iter, nitrst, numriw, 'a_ip' , a_ip )
CALL iom_rstput( iter, nitrst, numriw, 'v_ip' , v_ip )
CALL iom_rstput( iter, nitrst, numriw, 'v_il' , v_il )
! Snow enthalpy
DO jk = 1, nlay_s
WRITE(zchar1,'(I2.2)') jk
znam = 'e_s'//'_l'//zchar1
z3d(:,:,:) = e_s(:,:,jk,:)
CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
END DO
! Ice enthalpy
DO jk = 1, nlay_i
WRITE(zchar1,'(I2.2)') jk
znam = 'e_i'//'_l'//zchar1
z3d(:,:,:) = e_i(:,:,jk,:)
CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
END DO
! fields needed for Met Office (Jules) coupling
IF( ln_cpl ) THEN
CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice )
CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice )
ENDIF
!
! close restart file
! ------------------
IF( iter == nitrst ) THEN
IF(.NOT.lwxios) THEN
CALL iom_close( numriw )
ELSE
CALL iom_context_finalize( cw_icerst_cxt )
iom_file(numriw)%nfid = 0
numriw = 0
ENDIF
lrst_ice = .FALSE.
ENDIF
!
END SUBROUTINE ice_rst_write
SUBROUTINE ice_rst_read( Kbb, Kmm, Kaa )
!!----------------------------------------------------------------------
!! *** ice_rst_read ***
!!
!! ** purpose : read restart file
!!----------------------------------------------------------------------
INTEGER, INTENT(in) :: Kbb, Kmm, Kaa ! ocean time level indices
INTEGER :: jk
LOGICAL :: llok
INTEGER :: id0, id1, id2, id3, id4, id5 ! local integer
CHARACTER(len=25) :: znam
CHARACTER(len=2) :: zchar, zchar1
REAL(wp) :: zfice, ziter
CHARACTER(lc) :: clpname
REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace
!!----------------------------------------------------------------------
IF(lwp) THEN
WRITE(numout,*)
WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file'
WRITE(numout,*) '~~~~~~~~~~~~'
ENDIF
lxios_sini = .FALSE.
CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir )
IF( lrxios) THEN
cr_icerst_cxt = 'si3_rst'
IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for SI3'
! IF( TRIM(Agrif_CFixed()) == '0' ) THEN
! clpname = cn_icerst_in
! ELSE
! clpname = TRIM(Agrif_CFixed())//"_"//cn_icerst_in
! ENDIF
CALL iom_init( cr_icerst_cxt, kdid = numrir, ld_closedef = .TRUE. )
ENDIF
! test if v_i exists
id0 = iom_varid( numrir, 'v_i' , ldstop = .FALSE. )
! ! ------------------------------ !
IF( id0 > 0 ) THEN ! == case of a normal restart == !
! ! ------------------------------ !
! Time info
CALL iom_get( numrir, 'nn_fsbc', zfice )
CALL iom_get( numrir, 'kt_ice' , ziter )
IF(lwp) WRITE(numout,*) ' read ice restart file at time step : ', ziter
IF(lwp) WRITE(numout,*) ' in any case we force it to nit000 - 1 : ', nit000 - 1
! Control of date
IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 ) &
& CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart', &
& ' verify the file or rerun with the value 0 for the', &
& ' control of time parameter nrstdt' )
IF( NINT(zfice) /= nn_fsbc .AND. ABS( nrstdt ) == 1 ) &
& CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart', &
& ' verify the file or rerun with the value 0 for the', &
& ' control of time parameter nrstdt' )
! --- mandatory fields --- !
CALL iom_get( numrir, jpdom_auto, 'v_i' , v_i )
CALL iom_get( numrir, jpdom_auto, 'v_s' , v_s )
CALL iom_get( numrir, jpdom_auto, 'sv_i' , sv_i )
CALL iom_get( numrir, jpdom_auto, 'a_i' , a_i )
CALL iom_get( numrir, jpdom_auto, 't_su' , t_su )
CALL iom_get( numrir, jpdom_auto, 'u_ice', u_ice, cd_type = 'U', psgn = -1._wp )
CALL iom_get( numrir, jpdom_auto, 'v_ice', v_ice, cd_type = 'V', psgn = -1._wp )
! Snow enthalpy
DO jk = 1, nlay_s
WRITE(zchar1,'(I2.2)') jk
znam = 'e_s'//'_l'//zchar1
CALL iom_get( numrir, jpdom_auto, znam , z3d )
e_s(:,:,jk,:) = z3d(:,:,:)
END DO
! Ice enthalpy
DO jk = 1, nlay_i
WRITE(zchar1,'(I2.2)') jk
znam = 'e_i'//'_l'//zchar1
CALL iom_get( numrir, jpdom_auto, znam , z3d )
e_i(:,:,jk,:) = z3d(:,:,:)
END DO
! -- optional fields -- !
! ice age
id1 = iom_varid( numrir, 'oa_i' , ldstop = .FALSE. )
IF( id1 > 0 ) THEN ! fields exist
CALL iom_get( numrir, jpdom_auto, 'oa_i', oa_i )
ELSE ! start from rest
IF(lwp) WRITE(numout,*) ' ==>> previous run without ice age output then set it to zero'
oa_i(:,:,:) = 0._wp
ENDIF
! melt ponds
id2 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. )
IF( id2 > 0 ) THEN ! fields exist
CALL iom_get( numrir, jpdom_auto, 'a_ip' , a_ip )
CALL iom_get( numrir, jpdom_auto, 'v_ip' , v_ip )
ELSE ! start from rest
IF(lwp) WRITE(numout,*) ' ==>> previous run without melt ponds output then set it to zero'
a_ip(:,:,:) = 0._wp
v_ip(:,:,:) = 0._wp
ENDIF
! melt pond lids
id3 = iom_varid( numrir, 'v_il' , ldstop = .FALSE. )
IF( id3 > 0 ) THEN
CALL iom_get( numrir, jpdom_auto, 'v_il', v_il)
ELSE
IF(lwp) WRITE(numout,*) ' ==>> previous run without melt ponds lids output then set it to zero'
v_il(:,:,:) = 0._wp
ENDIF
! fields needed for Met Office (Jules) coupling
IF( ln_cpl ) THEN
id4 = iom_varid( numrir, 'cnd_ice' , ldstop = .FALSE. )
id5 = iom_varid( numrir, 't1_ice' , ldstop = .FALSE. )
IF( id4 > 0 .AND. id5 > 0 ) THEN ! fields exist
CALL iom_get( numrir, jpdom_auto, 'cnd_ice', cnd_ice )
CALL iom_get( numrir, jpdom_auto, 't1_ice' , t1_ice )
ELSE ! start from rest
IF(lwp) WRITE(numout,*) ' ==>> previous run without conductivity output then set it to zero'
cnd_ice(:,:,:) = 0._wp
t1_ice (:,:,:) = rt0
ENDIF
ENDIF
IF(.NOT.lrxios) CALL iom_delay_rst( 'READ', 'ICE', numrir ) ! read only ice delayed global communication variables
! ! ---------------------------------- !
ELSE ! == case of a simplified restart == !
! ! ---------------------------------- !
CALL ctl_warn('ice_rst_read: you are attempting to use an unsuitable ice restart')
!
IF( .NOT. ln_iceini .OR. nn_iceini_file == 2 ) THEN
CALL ctl_stop('STOP', 'ice_rst_read: you need ln_ice_ini=T and nn_iceini_file=0 or 1')
ELSE
CALL ctl_warn('ice_rst_read: using ice_istate to set initial conditions instead')
ENDIF
!
IF( nn_components == jp_iam_sas ) THEN ! SAS case: ss[st]_m were not initialized by sbc_ssm_init
!
IF(lwp) WRITE(numout,*) ' SAS: default initialisation of ss[st]_m arrays used in ice_istate'
IF( l_useCT ) THEN ; sst_m(:,:) = eos_pt_from_ct( ts(:,:,1,jp_tem, Kmm), ts(:,:,1,jp_sal, Kmm) )
ELSE ; sst_m(:,:) = ts(:,:,1,jp_tem, Kmm)
ENDIF
sss_m(:,:) = ts(:,:,1,jp_sal, Kmm)
ENDIF
!
CALL ice_istate( nit000, Kbb, Kmm, Kaa )
!
ENDIF
END SUBROUTINE ice_rst_read
#else
!!----------------------------------------------------------------------
!! Default option : Empty module NO SI3 sea-ice model
!!----------------------------------------------------------------------
#endif
!!======================================================================
END MODULE icerst