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 | !!---------------------------------------------------------------------- |
---|
58 | ! |
---|
59 | IF( kt == nit000 ) lrst_ice = .FALSE. ! default definition |
---|
60 | |
---|
61 | IF( ln_rst_list .OR. nn_stock /= -1 ) THEN |
---|
62 | ! in order to get better performances with NetCDF format, we open and define the ice restart file |
---|
63 | ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice |
---|
64 | ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1 |
---|
65 | IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nn_stock == nn_fsbc & |
---|
66 | & .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN |
---|
67 | IF( nitrst <= nitend .AND. nitrst > 0 ) THEN |
---|
68 | ! beware of the format used to write kt (default is i8.8, that should be large enough...) |
---|
69 | IF( nitrst > 99999999 ) THEN ; WRITE(clkt, * ) nitrst |
---|
70 | ELSE ; WRITE(clkt, '(i8.8)') nitrst |
---|
71 | ENDIF |
---|
72 | ! create the file |
---|
73 | clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out) |
---|
74 | clpath = TRIM(cn_icerst_outdir) |
---|
75 | IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/' |
---|
76 | IF(lwp) THEN |
---|
77 | WRITE(numout,*) |
---|
78 | WRITE(numout,*) ' open ice restart NetCDF file: ',TRIM(clpath)//clname |
---|
79 | IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN |
---|
80 | WRITE(numout,*) ' kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp |
---|
81 | ELSE |
---|
82 | WRITE(numout,*) ' kt = ' , kt,' date= ', ndastp |
---|
83 | ENDIF |
---|
84 | ENDIF |
---|
85 | ! |
---|
86 | CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl, cdcomp = 'ICE' ) |
---|
87 | lrst_ice = .TRUE. |
---|
88 | ENDIF |
---|
89 | ENDIF |
---|
90 | ENDIF |
---|
91 | ! |
---|
92 | IF( ln_icectl ) CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' ) ! control print |
---|
93 | ! |
---|
94 | END SUBROUTINE ice_rst_opn |
---|
95 | |
---|
96 | |
---|
97 | SUBROUTINE ice_rst_write( kt ) |
---|
98 | !!---------------------------------------------------------------------- |
---|
99 | !! *** ice_rst_write *** |
---|
100 | !! |
---|
101 | !! ** purpose : write restart file |
---|
102 | !!---------------------------------------------------------------------- |
---|
103 | INTEGER, INTENT(in) :: kt ! number of iteration |
---|
104 | !! |
---|
105 | INTEGER :: jk ! dummy loop indices |
---|
106 | INTEGER :: iter |
---|
107 | CHARACTER(len=25) :: znam |
---|
108 | CHARACTER(len=2) :: zchar, zchar1 |
---|
109 | REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace |
---|
110 | !!---------------------------------------------------------------------- |
---|
111 | |
---|
112 | iter = kt + nn_fsbc - 1 ! ice restarts are written at kt == nitrst - nn_fsbc + 1 |
---|
113 | |
---|
114 | IF( iter == nitrst ) THEN |
---|
115 | IF(lwp) WRITE(numout,*) |
---|
116 | IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file kt =', kt |
---|
117 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~' |
---|
118 | ENDIF |
---|
119 | |
---|
120 | ! Write in numriw (if iter == nitrst) |
---|
121 | ! ------------------ |
---|
122 | ! ! calendar control |
---|
123 | CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) ) ! time-step |
---|
124 | CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter , wp ) ) ! date |
---|
125 | CALL iom_delay_rst( 'WRITE', 'ICE', numriw ) ! save only ice delayed global communication variables |
---|
126 | |
---|
127 | ! Prognostic variables |
---|
128 | CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i ) |
---|
129 | CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s ) |
---|
130 | CALL iom_rstput( iter, nitrst, numriw, 'sv_i' , sv_i ) |
---|
131 | CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i ) |
---|
132 | CALL iom_rstput( iter, nitrst, numriw, 't_su' , t_su ) |
---|
133 | CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) |
---|
134 | CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) |
---|
135 | CALL iom_rstput( iter, nitrst, numriw, 'oa_i' , oa_i ) |
---|
136 | CALL iom_rstput( iter, nitrst, numriw, 'a_ip' , a_ip ) |
---|
137 | CALL iom_rstput( iter, nitrst, numriw, 'v_ip' , v_ip ) |
---|
138 | CALL iom_rstput( iter, nitrst, numriw, 'v_il' , v_il ) |
---|
139 | ! Snow enthalpy |
---|
140 | DO jk = 1, nlay_s |
---|
141 | WRITE(zchar1,'(I2.2)') jk |
---|
142 | znam = 'e_s'//'_l'//zchar1 |
---|
143 | z3d(:,:,:) = e_s(:,:,jk,:) |
---|
144 | CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) |
---|
145 | END DO |
---|
146 | ! Ice enthalpy |
---|
147 | DO jk = 1, nlay_i |
---|
148 | WRITE(zchar1,'(I2.2)') jk |
---|
149 | znam = 'e_i'//'_l'//zchar1 |
---|
150 | z3d(:,:,:) = e_i(:,:,jk,:) |
---|
151 | CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) |
---|
152 | END DO |
---|
153 | ! fields needed for Met Office (Jules) coupling |
---|
154 | IF( ln_cpl ) THEN |
---|
155 | CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice ) |
---|
156 | CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice ) |
---|
157 | ENDIF |
---|
158 | ! |
---|
159 | |
---|
160 | ! close restart file |
---|
161 | ! ------------------ |
---|
162 | IF( iter == nitrst ) THEN |
---|
163 | CALL iom_close( numriw ) |
---|
164 | lrst_ice = .FALSE. |
---|
165 | ENDIF |
---|
166 | ! |
---|
167 | END SUBROUTINE ice_rst_write |
---|
168 | |
---|
169 | |
---|
170 | SUBROUTINE ice_rst_read( Kbb, Kmm, Kaa ) |
---|
171 | !!---------------------------------------------------------------------- |
---|
172 | !! *** ice_rst_read *** |
---|
173 | !! |
---|
174 | !! ** purpose : read restart file |
---|
175 | !!---------------------------------------------------------------------- |
---|
176 | INTEGER, INTENT(in) :: Kbb, Kmm, Kaa ! ocean time level indices |
---|
177 | INTEGER :: jk |
---|
178 | LOGICAL :: llok |
---|
179 | INTEGER :: id0, id1, id2, id3, id4, id5 ! local integer |
---|
180 | CHARACTER(len=25) :: znam |
---|
181 | CHARACTER(len=2) :: zchar, zchar1 |
---|
182 | REAL(wp) :: zfice, ziter |
---|
183 | REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace |
---|
184 | !!---------------------------------------------------------------------- |
---|
185 | |
---|
186 | IF(lwp) THEN |
---|
187 | WRITE(numout,*) |
---|
188 | WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file' |
---|
189 | WRITE(numout,*) '~~~~~~~~~~~~' |
---|
190 | ENDIF |
---|
191 | |
---|
192 | CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir ) |
---|
193 | |
---|
194 | ! test if v_i exists |
---|
195 | id0 = iom_varid( numrir, 'v_i' , ldstop = .FALSE. ) |
---|
196 | |
---|
197 | ! ! ------------------------------ ! |
---|
198 | IF( id0 > 0 ) THEN ! == case of a normal restart == ! |
---|
199 | ! ! ------------------------------ ! |
---|
200 | |
---|
201 | ! Time info |
---|
202 | CALL iom_get( numrir, 'nn_fsbc', zfice ) |
---|
203 | CALL iom_get( numrir, 'kt_ice' , ziter ) |
---|
204 | IF(lwp) WRITE(numout,*) ' read ice restart file at time step : ', ziter |
---|
205 | IF(lwp) WRITE(numout,*) ' in any case we force it to nit000 - 1 : ', nit000 - 1 |
---|
206 | |
---|
207 | ! Control of date |
---|
208 | IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 ) & |
---|
209 | & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart', & |
---|
210 | & ' verify the file or rerun with the value 0 for the', & |
---|
211 | & ' control of time parameter nrstdt' ) |
---|
212 | IF( NINT(zfice) /= nn_fsbc .AND. ABS( nrstdt ) == 1 ) & |
---|
213 | & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart', & |
---|
214 | & ' verify the file or rerun with the value 0 for the', & |
---|
215 | & ' control of time parameter nrstdt' ) |
---|
216 | |
---|
217 | ! --- mandatory fields --- ! |
---|
218 | CALL iom_get( numrir, jpdom_auto, 'v_i' , v_i ) |
---|
219 | CALL iom_get( numrir, jpdom_auto, 'v_s' , v_s ) |
---|
220 | CALL iom_get( numrir, jpdom_auto, 'sv_i' , sv_i ) |
---|
221 | CALL iom_get( numrir, jpdom_auto, 'a_i' , a_i ) |
---|
222 | CALL iom_get( numrir, jpdom_auto, 't_su' , t_su ) |
---|
223 | CALL iom_get( numrir, jpdom_auto, 'u_ice', u_ice, cd_type = 'U', psgn = -1._wp ) |
---|
224 | CALL iom_get( numrir, jpdom_auto, 'v_ice', v_ice, cd_type = 'V', psgn = -1._wp ) |
---|
225 | ! Snow enthalpy |
---|
226 | DO jk = 1, nlay_s |
---|
227 | WRITE(zchar1,'(I2.2)') jk |
---|
228 | znam = 'e_s'//'_l'//zchar1 |
---|
229 | CALL iom_get( numrir, jpdom_auto, znam , z3d ) |
---|
230 | e_s(:,:,jk,:) = z3d(:,:,:) |
---|
231 | END DO |
---|
232 | ! Ice enthalpy |
---|
233 | DO jk = 1, nlay_i |
---|
234 | WRITE(zchar1,'(I2.2)') jk |
---|
235 | znam = 'e_i'//'_l'//zchar1 |
---|
236 | CALL iom_get( numrir, jpdom_auto, znam , z3d ) |
---|
237 | e_i(:,:,jk,:) = z3d(:,:,:) |
---|
238 | END DO |
---|
239 | ! -- optional fields -- ! |
---|
240 | ! ice age |
---|
241 | id1 = iom_varid( numrir, 'oa_i' , ldstop = .FALSE. ) |
---|
242 | IF( id1 > 0 ) THEN ! fields exist |
---|
243 | CALL iom_get( numrir, jpdom_auto, 'oa_i', oa_i ) |
---|
244 | ELSE ! start from rest |
---|
245 | IF(lwp) WRITE(numout,*) ' ==>> previous run without ice age output then set it to zero' |
---|
246 | oa_i(:,:,:) = 0._wp |
---|
247 | ENDIF |
---|
248 | ! melt ponds |
---|
249 | id2 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. ) |
---|
250 | IF( id2 > 0 ) THEN ! fields exist |
---|
251 | CALL iom_get( numrir, jpdom_auto, 'a_ip' , a_ip ) |
---|
252 | CALL iom_get( numrir, jpdom_auto, 'v_ip' , v_ip ) |
---|
253 | ELSE ! start from rest |
---|
254 | IF(lwp) WRITE(numout,*) ' ==>> previous run without melt ponds output then set it to zero' |
---|
255 | a_ip(:,:,:) = 0._wp |
---|
256 | v_ip(:,:,:) = 0._wp |
---|
257 | ENDIF |
---|
258 | ! melt pond lids |
---|
259 | id3 = iom_varid( numrir, 'v_il' , ldstop = .FALSE. ) |
---|
260 | IF( id3 > 0 ) THEN |
---|
261 | CALL iom_get( numrir, jpdom_auto, 'v_il', v_il) |
---|
262 | ELSE |
---|
263 | IF(lwp) WRITE(numout,*) ' ==>> previous run without melt ponds lids output then set it to zero' |
---|
264 | v_il(:,:,:) = 0._wp |
---|
265 | ENDIF |
---|
266 | ! fields needed for Met Office (Jules) coupling |
---|
267 | IF( ln_cpl ) THEN |
---|
268 | id4 = iom_varid( numrir, 'cnd_ice' , ldstop = .FALSE. ) |
---|
269 | id5 = iom_varid( numrir, 't1_ice' , ldstop = .FALSE. ) |
---|
270 | IF( id4 > 0 .AND. id5 > 0 ) THEN ! fields exist |
---|
271 | CALL iom_get( numrir, jpdom_auto, 'cnd_ice', cnd_ice ) |
---|
272 | CALL iom_get( numrir, jpdom_auto, 't1_ice' , t1_ice ) |
---|
273 | ELSE ! start from rest |
---|
274 | IF(lwp) WRITE(numout,*) ' ==>> previous run without conductivity output then set it to zero' |
---|
275 | cnd_ice(:,:,:) = 0._wp |
---|
276 | t1_ice (:,:,:) = rt0 |
---|
277 | ENDIF |
---|
278 | ENDIF |
---|
279 | |
---|
280 | CALL iom_delay_rst( 'READ', 'ICE', numrir ) ! read only ice delayed global communication variables |
---|
281 | |
---|
282 | ! ! ---------------------------------- ! |
---|
283 | ELSE ! == case of a simplified restart == ! |
---|
284 | ! ! ---------------------------------- ! |
---|
285 | CALL ctl_warn('ice_rst_read: you are attempting to use an unsuitable ice restart') |
---|
286 | ! |
---|
287 | IF( .NOT. ln_iceini .OR. nn_iceini_file == 2 ) THEN |
---|
288 | CALL ctl_stop('STOP', 'ice_rst_read: you need ln_ice_ini=T and nn_iceini_file=0 or 1') |
---|
289 | ELSE |
---|
290 | CALL ctl_warn('ice_rst_read: using ice_istate to set initial conditions instead') |
---|
291 | ENDIF |
---|
292 | ! |
---|
293 | IF( nn_components == jp_iam_sas ) THEN ! SAS case: ss[st]_m were not initialized by sbc_ssm_init |
---|
294 | ! |
---|
295 | IF(lwp) WRITE(numout,*) ' SAS: default initialisation of ss[st]_m arrays used in ice_istate' |
---|
296 | IF( l_useCT ) THEN ; sst_m(:,:) = eos_pt_from_ct( ts(:,:,1,jp_tem, Kmm), ts(:,:,1,jp_sal, Kmm) ) |
---|
297 | ELSE ; sst_m(:,:) = ts(:,:,1,jp_tem, Kmm) |
---|
298 | ENDIF |
---|
299 | sss_m(:,:) = ts(:,:,1,jp_sal, Kmm) |
---|
300 | ENDIF |
---|
301 | ! |
---|
302 | CALL ice_istate( nit000, Kbb, Kmm, Kaa ) |
---|
303 | ! |
---|
304 | ENDIF |
---|
305 | |
---|
306 | END SUBROUTINE ice_rst_read |
---|
307 | |
---|
308 | #else |
---|
309 | !!---------------------------------------------------------------------- |
---|
310 | !! Default option : Empty module NO SI3 sea-ice model |
---|
311 | !!---------------------------------------------------------------------- |
---|
312 | #endif |
---|
313 | |
---|
314 | !!====================================================================== |
---|
315 | END MODULE icerst |
---|