1 | MODULE icerst |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE icerst *** |
---|
4 | !! sea-ice : write/read the ice restart file |
---|
5 | !!====================================================================== |
---|
6 | !! History: 4.0 ! 2018 (many people) SI3 [aka Sea Ice cube] |
---|
7 | !!---------------------------------------------------------------------- |
---|
8 | #if defined key_si3 |
---|
9 | !!---------------------------------------------------------------------- |
---|
10 | !! 'key_si3' SI3 sea-ice model |
---|
11 | !!---------------------------------------------------------------------- |
---|
12 | !! ice_rst_opn : open restart file |
---|
13 | !! ice_rst_write : write restart file |
---|
14 | !! ice_rst_read : read restart file |
---|
15 | !!---------------------------------------------------------------------- |
---|
16 | USE ice ! sea-ice: variables |
---|
17 | USE dom_oce ! ocean domain |
---|
18 | USE phycst , ONLY : rt0 |
---|
19 | USE sbc_oce , ONLY : nn_fsbc, ln_cpl |
---|
20 | USE sbc_oce , ONLY : nn_components, jp_iam_sas ! SAS ss[st]_m init |
---|
21 | USE sbc_oce , ONLY : sst_m, sss_m ! SAS ss[st]_m init |
---|
22 | USE oce , ONLY : ts ! SAS ss[st]_m init |
---|
23 | USE eosbn2 , ONLY : l_useCT, eos_pt_from_ct ! SAS ss[st]_m init |
---|
24 | USE iceistate ! sea-ice: initial state |
---|
25 | USE icectl ! sea-ice: control |
---|
26 | ! |
---|
27 | USE in_out_manager ! I/O manager |
---|
28 | USE iom ! I/O manager library |
---|
29 | USE lib_mpp ! MPP library |
---|
30 | USE lib_fortran ! fortran utilities (glob_sum + no signed zero) |
---|
31 | |
---|
32 | IMPLICIT NONE |
---|
33 | PRIVATE |
---|
34 | |
---|
35 | PUBLIC ice_rst_opn ! called by icestp |
---|
36 | PUBLIC ice_rst_write ! called by icestp |
---|
37 | PUBLIC ice_rst_read ! called by ice_init |
---|
38 | |
---|
39 | !!---------------------------------------------------------------------- |
---|
40 | !! NEMO/ICE 4.0 , NEMO Consortium (2018) |
---|
41 | !! $Id$ |
---|
42 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
43 | !!---------------------------------------------------------------------- |
---|
44 | CONTAINS |
---|
45 | |
---|
46 | SUBROUTINE ice_rst_opn( kt ) |
---|
47 | !!---------------------------------------------------------------------- |
---|
48 | !! *** ice_rst_opn *** |
---|
49 | !! |
---|
50 | !! ** purpose : open restart file |
---|
51 | !!---------------------------------------------------------------------- |
---|
52 | INTEGER, INTENT(in) :: kt ! number of iteration |
---|
53 | ! |
---|
54 | CHARACTER(len=20) :: clkt ! ocean time-step define as a character |
---|
55 | CHARACTER(len=50) :: clname ! ice output restart file name |
---|
56 | CHARACTER(len=256) :: clpath ! full path to ice output restart file |
---|
57 | CHARACTER(LEN=52) :: clpname ! ocean output restart file name including prefix for AGRIF |
---|
58 | !!---------------------------------------------------------------------- |
---|
59 | ! |
---|
60 | IF( kt == nit000 ) lrst_ice = .FALSE. ! default definition |
---|
61 | |
---|
62 | IF( ln_rst_list .OR. nn_stock /= -1 ) THEN |
---|
63 | ! in order to get better performances with NetCDF format, we open and define the ice restart file |
---|
64 | ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice |
---|
65 | ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1 |
---|
66 | IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nn_stock == nn_fsbc & |
---|
67 | & .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN |
---|
68 | IF( nitrst <= nitend .AND. nitrst > 0 ) THEN |
---|
69 | ! beware of the format used to write kt (default is i8.8, that should be large enough...) |
---|
70 | IF( nitrst > 99999999 ) THEN ; WRITE(clkt, * ) nitrst |
---|
71 | ELSE ; WRITE(clkt, '(i8.8)') nitrst |
---|
72 | ENDIF |
---|
73 | ! create the file |
---|
74 | clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out) |
---|
75 | clpath = TRIM(cn_icerst_outdir) |
---|
76 | IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/' |
---|
77 | IF(lwp) THEN |
---|
78 | WRITE(numout,*) |
---|
79 | WRITE(numout,*) ' open ice restart NetCDF file: ',TRIM(clpath)//clname |
---|
80 | IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN |
---|
81 | WRITE(numout,*) ' kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp |
---|
82 | ELSE |
---|
83 | WRITE(numout,*) ' kt = ' , kt,' date= ', ndastp |
---|
84 | ENDIF |
---|
85 | ENDIF |
---|
86 | ! |
---|
87 | IF(.NOT.lwxios) THEN |
---|
88 | CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl, cdcomp = 'ICE' ) |
---|
89 | ELSE |
---|
90 | #if defined key_iomput |
---|
91 | cw_icerst_cxt = "rstwi_"//TRIM(ADJUSTL(clkt)) |
---|
92 | IF( TRIM(Agrif_CFixed()) == '0' ) THEN |
---|
93 | clpname = clname |
---|
94 | ELSE |
---|
95 | clpname = TRIM(Agrif_CFixed())//"_"//clname |
---|
96 | ENDIF |
---|
97 | numriw = iom_xios_setid(TRIM(clpath)//TRIM(clpname)) |
---|
98 | CALL iom_init( cw_icerst_cxt, kdid = numriw, ld_closedef = .FALSE. ) |
---|
99 | CALL iom_swap( cxios_context ) |
---|
100 | #else |
---|
101 | clinfo = 'Can not use XIOS in rst_opn' |
---|
102 | CALL ctl_stop(TRIM(clinfo)) |
---|
103 | #endif |
---|
104 | ENDIF |
---|
105 | lrst_ice = .TRUE. |
---|
106 | ENDIF |
---|
107 | ENDIF |
---|
108 | ENDIF |
---|
109 | ! |
---|
110 | IF( ln_icectl ) CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' ) ! control print |
---|
111 | ! |
---|
112 | END SUBROUTINE ice_rst_opn |
---|
113 | |
---|
114 | |
---|
115 | SUBROUTINE ice_rst_write( kt ) |
---|
116 | !!---------------------------------------------------------------------- |
---|
117 | !! *** ice_rst_write *** |
---|
118 | !! |
---|
119 | !! ** purpose : write restart file |
---|
120 | !!---------------------------------------------------------------------- |
---|
121 | INTEGER, INTENT(in) :: kt ! number of iteration |
---|
122 | !! |
---|
123 | INTEGER :: jk ! dummy loop indices |
---|
124 | INTEGER :: iter |
---|
125 | CHARACTER(len=25) :: znam |
---|
126 | CHARACTER(len=2) :: zchar, zchar1 |
---|
127 | REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace |
---|
128 | !!---------------------------------------------------------------------- |
---|
129 | |
---|
130 | iter = kt + nn_fsbc - 1 ! ice restarts are written at kt == nitrst - nn_fsbc + 1 |
---|
131 | |
---|
132 | IF( iter == nitrst ) THEN |
---|
133 | IF(lwp) WRITE(numout,*) |
---|
134 | IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file kt =', kt |
---|
135 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~' |
---|
136 | ENDIF |
---|
137 | |
---|
138 | ! Write in numriw (if iter == nitrst) |
---|
139 | ! ------------------ |
---|
140 | ! ! calendar control |
---|
141 | CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) ) ! time-step |
---|
142 | CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter , wp ) ) ! date |
---|
143 | |
---|
144 | IF(.NOT.lwxios) CALL iom_delay_rst( 'WRITE', 'ICE', numriw ) ! save only ice delayed global communication variables |
---|
145 | |
---|
146 | ! Prognostic variables |
---|
147 | CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i ) |
---|
148 | CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s ) |
---|
149 | CALL iom_rstput( iter, nitrst, numriw, 'sv_i' , sv_i ) |
---|
150 | CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i ) |
---|
151 | CALL iom_rstput( iter, nitrst, numriw, 't_su' , t_su ) |
---|
152 | CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) |
---|
153 | CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) |
---|
154 | CALL iom_rstput( iter, nitrst, numriw, 'oa_i' , oa_i ) |
---|
155 | CALL iom_rstput( iter, nitrst, numriw, 'a_ip' , a_ip ) |
---|
156 | CALL iom_rstput( iter, nitrst, numriw, 'v_ip' , v_ip ) |
---|
157 | CALL iom_rstput( iter, nitrst, numriw, 'v_il' , v_il ) |
---|
158 | ! Snow enthalpy |
---|
159 | DO jk = 1, nlay_s |
---|
160 | WRITE(zchar1,'(I2.2)') jk |
---|
161 | znam = 'e_s'//'_l'//zchar1 |
---|
162 | z3d(:,:,:) = e_s(:,:,jk,:) |
---|
163 | CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) |
---|
164 | END DO |
---|
165 | ! Ice enthalpy |
---|
166 | DO jk = 1, nlay_i |
---|
167 | WRITE(zchar1,'(I2.2)') jk |
---|
168 | znam = 'e_i'//'_l'//zchar1 |
---|
169 | z3d(:,:,:) = e_i(:,:,jk,:) |
---|
170 | CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) |
---|
171 | END DO |
---|
172 | ! fields needed for Met Office (Jules) coupling |
---|
173 | IF( ln_cpl ) THEN |
---|
174 | CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice ) |
---|
175 | CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice ) |
---|
176 | ENDIF |
---|
177 | ! |
---|
178 | |
---|
179 | ! close restart file |
---|
180 | ! ------------------ |
---|
181 | IF( iter == nitrst ) THEN |
---|
182 | IF(.NOT.lwxios) THEN |
---|
183 | CALL iom_close( numriw ) |
---|
184 | ELSE |
---|
185 | CALL iom_context_finalize( cw_icerst_cxt ) |
---|
186 | iom_file(numriw)%nfid = 0 |
---|
187 | numriw = 0 |
---|
188 | ENDIF |
---|
189 | lrst_ice = .FALSE. |
---|
190 | ENDIF |
---|
191 | ! |
---|
192 | END SUBROUTINE ice_rst_write |
---|
193 | |
---|
194 | |
---|
195 | SUBROUTINE ice_rst_read( Kbb, Kmm, Kaa ) |
---|
196 | !!---------------------------------------------------------------------- |
---|
197 | !! *** ice_rst_read *** |
---|
198 | !! |
---|
199 | !! ** purpose : read restart file |
---|
200 | !!---------------------------------------------------------------------- |
---|
201 | INTEGER, INTENT(in) :: Kbb, Kmm, Kaa ! ocean time level indices |
---|
202 | INTEGER :: jk |
---|
203 | LOGICAL :: llok |
---|
204 | INTEGER :: id0, id1, id2, id3, id4, id5 ! local integer |
---|
205 | CHARACTER(len=25) :: znam |
---|
206 | CHARACTER(len=2) :: zchar, zchar1 |
---|
207 | REAL(wp) :: zfice, ziter |
---|
208 | CHARACTER(lc) :: clpname |
---|
209 | REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace |
---|
210 | !!---------------------------------------------------------------------- |
---|
211 | |
---|
212 | IF(lwp) THEN |
---|
213 | WRITE(numout,*) |
---|
214 | WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file' |
---|
215 | WRITE(numout,*) '~~~~~~~~~~~~' |
---|
216 | ENDIF |
---|
217 | |
---|
218 | lxios_sini = .FALSE. |
---|
219 | CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir ) |
---|
220 | |
---|
221 | IF( lrxios) THEN |
---|
222 | cr_icerst_cxt = 'si3_rst' |
---|
223 | IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for SI3' |
---|
224 | ! IF( TRIM(Agrif_CFixed()) == '0' ) THEN |
---|
225 | ! clpname = cn_icerst_in |
---|
226 | ! ELSE |
---|
227 | ! clpname = TRIM(Agrif_CFixed())//"_"//cn_icerst_in |
---|
228 | ! ENDIF |
---|
229 | CALL iom_init( cr_icerst_cxt, kdid = numrir, ld_closedef = .TRUE. ) |
---|
230 | ENDIF |
---|
231 | |
---|
232 | ! test if v_i exists |
---|
233 | id0 = iom_varid( numrir, 'v_i' , ldstop = .FALSE. ) |
---|
234 | |
---|
235 | ! ! ------------------------------ ! |
---|
236 | IF( id0 > 0 ) THEN ! == case of a normal restart == ! |
---|
237 | ! ! ------------------------------ ! |
---|
238 | ! Time info |
---|
239 | CALL iom_get( numrir, 'nn_fsbc', zfice ) |
---|
240 | CALL iom_get( numrir, 'kt_ice' , ziter ) |
---|
241 | IF(lwp) WRITE(numout,*) ' read ice restart file at time step : ', ziter |
---|
242 | IF(lwp) WRITE(numout,*) ' in any case we force it to nit000 - 1 : ', nit000 - 1 |
---|
243 | |
---|
244 | ! Control of date |
---|
245 | IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 ) & |
---|
246 | & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart', & |
---|
247 | & ' verify the file or rerun with the value 0 for the', & |
---|
248 | & ' control of time parameter nrstdt' ) |
---|
249 | IF( NINT(zfice) /= nn_fsbc .AND. ABS( nrstdt ) == 1 ) & |
---|
250 | & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart', & |
---|
251 | & ' verify the file or rerun with the value 0 for the', & |
---|
252 | & ' control of time parameter nrstdt' ) |
---|
253 | |
---|
254 | ! --- mandatory fields --- ! |
---|
255 | CALL iom_get( numrir, jpdom_auto, 'v_i' , v_i ) |
---|
256 | CALL iom_get( numrir, jpdom_auto, 'v_s' , v_s ) |
---|
257 | CALL iom_get( numrir, jpdom_auto, 'sv_i' , sv_i ) |
---|
258 | CALL iom_get( numrir, jpdom_auto, 'a_i' , a_i ) |
---|
259 | CALL iom_get( numrir, jpdom_auto, 't_su' , t_su ) |
---|
260 | CALL iom_get( numrir, jpdom_auto, 'u_ice', u_ice, cd_type = 'U', psgn = -1._wp ) |
---|
261 | CALL iom_get( numrir, jpdom_auto, 'v_ice', v_ice, cd_type = 'V', psgn = -1._wp ) |
---|
262 | ! Snow enthalpy |
---|
263 | DO jk = 1, nlay_s |
---|
264 | WRITE(zchar1,'(I2.2)') jk |
---|
265 | znam = 'e_s'//'_l'//zchar1 |
---|
266 | CALL iom_get( numrir, jpdom_auto, znam , z3d ) |
---|
267 | e_s(:,:,jk,:) = z3d(:,:,:) |
---|
268 | END DO |
---|
269 | ! Ice enthalpy |
---|
270 | DO jk = 1, nlay_i |
---|
271 | WRITE(zchar1,'(I2.2)') jk |
---|
272 | znam = 'e_i'//'_l'//zchar1 |
---|
273 | CALL iom_get( numrir, jpdom_auto, znam , z3d ) |
---|
274 | e_i(:,:,jk,:) = z3d(:,:,:) |
---|
275 | END DO |
---|
276 | ! -- optional fields -- ! |
---|
277 | ! ice age |
---|
278 | id1 = iom_varid( numrir, 'oa_i' , ldstop = .FALSE. ) |
---|
279 | IF( id1 > 0 ) THEN ! fields exist |
---|
280 | CALL iom_get( numrir, jpdom_auto, 'oa_i', oa_i ) |
---|
281 | ELSE ! start from rest |
---|
282 | IF(lwp) WRITE(numout,*) ' ==>> previous run without ice age output then set it to zero' |
---|
283 | oa_i(:,:,:) = 0._wp |
---|
284 | ENDIF |
---|
285 | ! melt ponds |
---|
286 | id2 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. ) |
---|
287 | IF( id2 > 0 ) THEN ! fields exist |
---|
288 | CALL iom_get( numrir, jpdom_auto, 'a_ip' , a_ip ) |
---|
289 | CALL iom_get( numrir, jpdom_auto, 'v_ip' , v_ip ) |
---|
290 | ELSE ! start from rest |
---|
291 | IF(lwp) WRITE(numout,*) ' ==>> previous run without melt ponds output then set it to zero' |
---|
292 | a_ip(:,:,:) = 0._wp |
---|
293 | v_ip(:,:,:) = 0._wp |
---|
294 | ENDIF |
---|
295 | ! melt pond lids |
---|
296 | id3 = iom_varid( numrir, 'v_il' , ldstop = .FALSE. ) |
---|
297 | IF( id3 > 0 ) THEN |
---|
298 | CALL iom_get( numrir, jpdom_auto, 'v_il', v_il) |
---|
299 | ELSE |
---|
300 | IF(lwp) WRITE(numout,*) ' ==>> previous run without melt ponds lids output then set it to zero' |
---|
301 | v_il(:,:,:) = 0._wp |
---|
302 | ENDIF |
---|
303 | ! fields needed for Met Office (Jules) coupling |
---|
304 | IF( ln_cpl ) THEN |
---|
305 | id4 = iom_varid( numrir, 'cnd_ice' , ldstop = .FALSE. ) |
---|
306 | id5 = iom_varid( numrir, 't1_ice' , ldstop = .FALSE. ) |
---|
307 | IF( id4 > 0 .AND. id5 > 0 ) THEN ! fields exist |
---|
308 | CALL iom_get( numrir, jpdom_auto, 'cnd_ice', cnd_ice ) |
---|
309 | CALL iom_get( numrir, jpdom_auto, 't1_ice' , t1_ice ) |
---|
310 | ELSE ! start from rest |
---|
311 | IF(lwp) WRITE(numout,*) ' ==>> previous run without conductivity output then set it to zero' |
---|
312 | cnd_ice(:,:,:) = 0._wp |
---|
313 | t1_ice (:,:,:) = rt0 |
---|
314 | ENDIF |
---|
315 | ENDIF |
---|
316 | |
---|
317 | IF(.NOT.lrxios) CALL iom_delay_rst( 'READ', 'ICE', numrir ) ! read only ice delayed global communication variables |
---|
318 | ! ! ---------------------------------- ! |
---|
319 | ELSE ! == case of a simplified restart == ! |
---|
320 | ! ! ---------------------------------- ! |
---|
321 | CALL ctl_warn('ice_rst_read: you are attempting to use an unsuitable ice restart') |
---|
322 | ! |
---|
323 | IF( .NOT. ln_iceini .OR. nn_iceini_file == 2 ) THEN |
---|
324 | CALL ctl_stop('STOP', 'ice_rst_read: you need ln_ice_ini=T and nn_iceini_file=0 or 1') |
---|
325 | ELSE |
---|
326 | CALL ctl_warn('ice_rst_read: using ice_istate to set initial conditions instead') |
---|
327 | ENDIF |
---|
328 | ! |
---|
329 | IF( nn_components == jp_iam_sas ) THEN ! SAS case: ss[st]_m were not initialized by sbc_ssm_init |
---|
330 | ! |
---|
331 | IF(lwp) WRITE(numout,*) ' SAS: default initialisation of ss[st]_m arrays used in ice_istate' |
---|
332 | IF( l_useCT ) THEN ; sst_m(:,:) = eos_pt_from_ct( ts(:,:,1,jp_tem, Kmm), ts(:,:,1,jp_sal, Kmm) ) |
---|
333 | ELSE ; sst_m(:,:) = ts(:,:,1,jp_tem, Kmm) |
---|
334 | ENDIF |
---|
335 | sss_m(:,:) = ts(:,:,1,jp_sal, Kmm) |
---|
336 | ENDIF |
---|
337 | ! |
---|
338 | CALL ice_istate( nit000, Kbb, Kmm, Kaa ) |
---|
339 | ! |
---|
340 | ENDIF |
---|
341 | |
---|
342 | END SUBROUTINE ice_rst_read |
---|
343 | |
---|
344 | #else |
---|
345 | !!---------------------------------------------------------------------- |
---|
346 | !! Default option : Empty module NO SI3 sea-ice model |
---|
347 | !!---------------------------------------------------------------------- |
---|
348 | #endif |
---|
349 | |
---|
350 | !!====================================================================== |
---|
351 | END MODULE icerst |
---|