1 | MODULE icerst |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE icerst *** |
---|
4 | !! sea-ice : write/read the ice restart file |
---|
5 | !!====================================================================== |
---|
6 | !! History: 3.0 ! 2005-04 (M. Vancoppenolle) Original code |
---|
7 | !! - ! 2008-03 (C. Ethe) restart files in using IOM interface |
---|
8 | !! 3.4 ! 2011-02 (G. Madec) dynamical allocation |
---|
9 | !! 4.0 ! 2017-11 (M. Andrejczuk) Extend IOM interface to write 3D ice fields |
---|
10 | !!---------------------------------------------------------------------- |
---|
11 | #if defined key_lim3 |
---|
12 | !!---------------------------------------------------------------------- |
---|
13 | !! 'key_lim3' ESIM sea-ice model |
---|
14 | !!---------------------------------------------------------------------- |
---|
15 | !! ice_rst_opn : open restart file |
---|
16 | !! ice_rst_write : write restart file |
---|
17 | !! ice_rst_read : read restart file |
---|
18 | !!---------------------------------------------------------------------- |
---|
19 | USE ice ! sea-ice variables |
---|
20 | USE dom_oce ! ocean domain |
---|
21 | USE sbc_oce , ONLY : nn_fsbc, ln_cpl |
---|
22 | USE icectl |
---|
23 | ! |
---|
24 | USE in_out_manager ! I/O manager |
---|
25 | USE iom ! I/O manager library |
---|
26 | USE ioipsl, ONLY : ju2ymds ! for calendar |
---|
27 | USE lib_mpp ! MPP library |
---|
28 | USE lib_fortran ! fortran utilities (glob_sum + no signed zero) |
---|
29 | |
---|
30 | IMPLICIT NONE |
---|
31 | PRIVATE |
---|
32 | |
---|
33 | PUBLIC ice_rst_opn ! called by icestp |
---|
34 | PUBLIC ice_rst_write ! called by icestp |
---|
35 | PUBLIC ice_rst_read ! called by ice_init |
---|
36 | |
---|
37 | !!---------------------------------------------------------------------- |
---|
38 | !! NEMO/ICE 4.0 , NEMO Consortium (2017) |
---|
39 | !! $Id$ |
---|
40 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
41 | !!---------------------------------------------------------------------- |
---|
42 | CONTAINS |
---|
43 | |
---|
44 | SUBROUTINE ice_rst_opn( kt ) |
---|
45 | !!---------------------------------------------------------------------- |
---|
46 | !! *** ice_rst_opn *** |
---|
47 | !! |
---|
48 | !! ** purpose : open restart file |
---|
49 | !!---------------------------------------------------------------------- |
---|
50 | INTEGER, INTENT(in) :: kt ! number of iteration |
---|
51 | ! |
---|
52 | INTEGER :: iyear, imonth, iday |
---|
53 | REAL (wp) :: zsec |
---|
54 | REAL (wp) :: zfjulday |
---|
55 | CHARACTER(len=20) :: clkt ! ocean time-step define as a character |
---|
56 | CHARACTER(len=50) :: clname ! ice output restart file name |
---|
57 | CHARACTER(len=256) :: clpath ! full path to ice output restart file |
---|
58 | !!---------------------------------------------------------------------- |
---|
59 | ! |
---|
60 | IF( kt == nit000 ) lrst_ice = .FALSE. ! default definition |
---|
61 | |
---|
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. nstock == 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 ( ln_rstdate ) THEN |
---|
70 | zfjulday = fjulday + (2*nn_fsbc+1)*rdt / rday |
---|
71 | IF( ABS(zfjulday - REAL(NINT(zfjulday),wp)) < 0.1 / rday ) zfjulday = REAL(NINT(zfjulday),wp) ! avoid truncation error |
---|
72 | CALL ju2ymds( zfjulday, iyear, imonth, iday, zsec ) |
---|
73 | WRITE(clkt, '(i4.4,2i2.2)') iyear, imonth, iday |
---|
74 | ELSE |
---|
75 | IF( nitrst > 99999999 ) THEN ; WRITE(clkt, * ) nitrst |
---|
76 | ELSE ; WRITE(clkt, '(i8.8)') nitrst |
---|
77 | ENDIF |
---|
78 | ENDIF |
---|
79 | ! create the file |
---|
80 | clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out) |
---|
81 | clpath = TRIM(cn_icerst_outdir) |
---|
82 | IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/' |
---|
83 | IF(lwp) THEN |
---|
84 | WRITE(numout,*) |
---|
85 | SELECT CASE ( jprstlib ) |
---|
86 | CASE DEFAULT |
---|
87 | WRITE(numout,*) ' open ice restart NetCDF file: ',TRIM(clpath)//clname |
---|
88 | END SELECT |
---|
89 | IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN |
---|
90 | WRITE(numout,*) ' kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp |
---|
91 | ELSE |
---|
92 | WRITE(numout,*) ' kt = ' , kt,' date= ', ndastp |
---|
93 | ENDIF |
---|
94 | ENDIF |
---|
95 | ! |
---|
96 | CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kiolib = jprstlib, kdlev = jpl ) |
---|
97 | lrst_ice = .TRUE. |
---|
98 | ENDIF |
---|
99 | ENDIF |
---|
100 | ! |
---|
101 | IF( ln_icectl ) CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' ) ! control print |
---|
102 | ! |
---|
103 | END SUBROUTINE ice_rst_opn |
---|
104 | |
---|
105 | |
---|
106 | SUBROUTINE ice_rst_write( kt ) |
---|
107 | !!---------------------------------------------------------------------- |
---|
108 | !! *** ice_rst_write *** |
---|
109 | !! |
---|
110 | !! ** purpose : write restart file |
---|
111 | !!---------------------------------------------------------------------- |
---|
112 | INTEGER, INTENT(in) :: kt ! number of iteration |
---|
113 | !! |
---|
114 | INTEGER :: jk ,jl ! dummy loop indices |
---|
115 | INTEGER :: iter |
---|
116 | CHARACTER(len=25) :: znam |
---|
117 | CHARACTER(len=2) :: zchar, zchar1 |
---|
118 | REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace |
---|
119 | !!---------------------------------------------------------------------- |
---|
120 | |
---|
121 | iter = kt + nn_fsbc - 1 ! ice restarts are written at kt == nitrst - nn_fsbc + 1 |
---|
122 | |
---|
123 | IF( iter == nitrst ) THEN |
---|
124 | IF(lwp) WRITE(numout,*) |
---|
125 | IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file kt =', kt |
---|
126 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~' |
---|
127 | ENDIF |
---|
128 | |
---|
129 | ! Write in numriw (if iter == nitrst) |
---|
130 | ! ------------------ |
---|
131 | ! ! calendar control |
---|
132 | CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) ) ! time-step |
---|
133 | CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter , wp ) ) ! date |
---|
134 | |
---|
135 | ! Prognostic variables |
---|
136 | CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i ) |
---|
137 | CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s ) |
---|
138 | CALL iom_rstput( iter, nitrst, numriw, 'sv_i', sv_i ) |
---|
139 | CALL iom_rstput( iter, nitrst, numriw, 'oa_i', oa_i ) |
---|
140 | CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i ) |
---|
141 | CALL iom_rstput( iter, nitrst, numriw, 't_su', t_su ) |
---|
142 | ! Melt ponds |
---|
143 | CALL iom_rstput( iter, nitrst, numriw, 'a_ip', a_ip ) |
---|
144 | CALL iom_rstput( iter, nitrst, numriw, 'v_ip', v_ip ) |
---|
145 | ! Snow enthalpy |
---|
146 | DO jk = 1, nlay_s |
---|
147 | WRITE(zchar1,'(I2.2)') jk |
---|
148 | znam = 'e_s'//'_l'//zchar1 |
---|
149 | z3d(:,:,:) = e_s(:,:,jk,:) |
---|
150 | CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) |
---|
151 | END DO |
---|
152 | ! Ice enthalpy |
---|
153 | DO jk = 1, nlay_i |
---|
154 | WRITE(zchar1,'(I2.2)') jk |
---|
155 | znam = 'e_i'//'_l'//zchar1 |
---|
156 | z3d(:,:,:) = e_i(:,:,jk,:) |
---|
157 | CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) |
---|
158 | END DO |
---|
159 | ! ice velocity |
---|
160 | CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice |
---|
161 | CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice |
---|
162 | ! fields needed for Met Office (Jules) coupling |
---|
163 | IF( ln_cpl ) THEN |
---|
164 | CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice ) |
---|
165 | CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice ) |
---|
166 | ENDIF |
---|
167 | ! |
---|
168 | |
---|
169 | ! close restart file |
---|
170 | ! ------------------ |
---|
171 | IF( iter == nitrst ) THEN |
---|
172 | CALL iom_close( numriw ) |
---|
173 | lrst_ice = .FALSE. |
---|
174 | ENDIF |
---|
175 | ! |
---|
176 | END SUBROUTINE ice_rst_write |
---|
177 | |
---|
178 | |
---|
179 | SUBROUTINE ice_rst_read |
---|
180 | !!---------------------------------------------------------------------- |
---|
181 | !! *** ice_rst_read *** |
---|
182 | !! |
---|
183 | !! ** purpose : read restart file |
---|
184 | !!---------------------------------------------------------------------- |
---|
185 | INTEGER :: jk, jl |
---|
186 | LOGICAL :: llok |
---|
187 | INTEGER :: id1 ! local integer |
---|
188 | INTEGER :: jlibalt = jprstlib |
---|
189 | CHARACTER(len=25) :: znam |
---|
190 | CHARACTER(len=2) :: zchar, zchar1 |
---|
191 | REAL(wp) :: zfice, ziter |
---|
192 | REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace |
---|
193 | !!---------------------------------------------------------------------- |
---|
194 | |
---|
195 | IF(lwp) THEN |
---|
196 | WRITE(numout,*) |
---|
197 | WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file' |
---|
198 | WRITE(numout,*) '~~~~~~~~~~~~' |
---|
199 | ENDIF |
---|
200 | |
---|
201 | CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib, kdlev = jpl ) |
---|
202 | |
---|
203 | CALL iom_get( numrir, 'nn_fsbc', zfice ) |
---|
204 | CALL iom_get( numrir, 'kt_ice' , ziter ) |
---|
205 | IF(lwp) WRITE(numout,*) ' read ice restart file at time step : ', ziter |
---|
206 | IF(lwp) WRITE(numout,*) ' in any case we force it to nit000 - 1 : ', nit000 - 1 |
---|
207 | |
---|
208 | ! Control of date |
---|
209 | IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 ) & |
---|
210 | & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart', & |
---|
211 | & ' verify the file or rerun with the value 0 for the', & |
---|
212 | & ' control of time parameter nrstdt' ) |
---|
213 | IF( NINT(zfice) /= nn_fsbc .AND. ABS( nrstdt ) == 1 ) & |
---|
214 | & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart', & |
---|
215 | & ' verify the file or rerun with the value 0 for the', & |
---|
216 | & ' control of time parameter nrstdt' ) |
---|
217 | |
---|
218 | ! Prognostic variables |
---|
219 | CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i ) |
---|
220 | CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s ) |
---|
221 | CALL iom_get( numrir, jpdom_autoglo, 'sv_i', sv_i ) |
---|
222 | CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i ) |
---|
223 | CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i ) |
---|
224 | CALL iom_get( numrir, jpdom_autoglo, 't_su', t_su ) |
---|
225 | ! Melt ponds |
---|
226 | id1 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. ) |
---|
227 | IF( id1 > 0 ) THEN ! fields exist (melt ponds) |
---|
228 | CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip ) |
---|
229 | CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip ) |
---|
230 | ELSE ! start from rest |
---|
231 | IF(lwp) WRITE(numout,*) ' ==>> previous run without melt ponds output then set it to zero' |
---|
232 | a_ip(:,:,:) = 0._wp |
---|
233 | v_ip(:,:,:) = 0._wp |
---|
234 | ENDIF |
---|
235 | ! Snow enthalpy |
---|
236 | DO jk = 1, nlay_s |
---|
237 | WRITE(zchar1,'(I2.2)') jk |
---|
238 | znam = 'e_s'//'_l'//zchar1 |
---|
239 | CALL iom_get( numrir, jpdom_autoglo, znam , z3d ) |
---|
240 | e_s(:,:,jk,:) = z3d(:,:,:) |
---|
241 | END DO |
---|
242 | ! Ice enthalpy |
---|
243 | DO jk = 1, nlay_i |
---|
244 | WRITE(zchar1,'(I2.2)') jk |
---|
245 | znam = 'e_i'//'_l'//zchar1 |
---|
246 | CALL iom_get( numrir, jpdom_autoglo, znam , z3d ) |
---|
247 | e_i(:,:,jk,:) = z3d(:,:,:) |
---|
248 | END DO |
---|
249 | ! ice velocity |
---|
250 | CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice ) |
---|
251 | CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice ) |
---|
252 | ! fields needed for Met Office (Jules) coupling |
---|
253 | IF( ln_cpl ) THEN |
---|
254 | CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice ) |
---|
255 | CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice ) |
---|
256 | ENDIF |
---|
257 | |
---|
258 | END SUBROUTINE ice_rst_read |
---|
259 | |
---|
260 | #else |
---|
261 | !!---------------------------------------------------------------------- |
---|
262 | !! Default option : Empty module NO ESIM sea-ice model |
---|
263 | !!---------------------------------------------------------------------- |
---|
264 | #endif |
---|
265 | |
---|
266 | !!====================================================================== |
---|
267 | END MODULE icerst |
---|