1 | MODULE restart |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE restart *** |
---|
4 | !! Ocean restart : write the ocean restart file |
---|
5 | !!====================================================================== |
---|
6 | !! History : OPA ! 1999-11 (M. Imbard) Original code |
---|
7 | !! NEMO 1.0 ! 2002-08 (G. Madec) F90: Free form |
---|
8 | !! 2.0 ! 2006-07 (S. Masson) use IOM for restart |
---|
9 | !! 3.3 ! 2010-04 (M. Leclair, G. Madec) modified LF-RA |
---|
10 | !! - - ! 2010-10 (C. Ethe, G. Madec) TRC-TRA merge (T-S in 4D) |
---|
11 | !! 3.7 ! 2014-01 (G. Madec) suppression of curl and hdiv from the restart |
---|
12 | !! - ! 2014-12 (G. Madec) remove KPP scheme |
---|
13 | !!---------------------------------------------------------------------- |
---|
14 | |
---|
15 | !!---------------------------------------------------------------------- |
---|
16 | !! rst_opn : open the ocean restart file |
---|
17 | !! rst_write : write the ocean restart file |
---|
18 | !! rst_read : read the ocean restart file |
---|
19 | !!---------------------------------------------------------------------- |
---|
20 | USE oce ! ocean dynamics and tracers |
---|
21 | USE dom_oce ! ocean space and time domain |
---|
22 | USE sbc_ice ! only lk_lim3 |
---|
23 | USE phycst ! physical constants |
---|
24 | USE eosbn2 ! equation of state (eos bn2 routine) |
---|
25 | USE trdmxl_oce ! ocean active mixed layer tracers trends variables |
---|
26 | ! |
---|
27 | USE in_out_manager ! I/O manager |
---|
28 | USE iom ! I/O module |
---|
29 | USE diurnal_bulk |
---|
30 | |
---|
31 | IMPLICIT NONE |
---|
32 | PRIVATE |
---|
33 | |
---|
34 | PUBLIC rst_opn ! routine called by step module |
---|
35 | PUBLIC rst_write ! routine called by step module |
---|
36 | PUBLIC rst_read ! routine called by istate module |
---|
37 | PUBLIC rst_read_open ! routine called in rst_read and (possibly) in dom_vvl_init |
---|
38 | |
---|
39 | !! * Substitutions |
---|
40 | # include "vectopt_loop_substitute.h90" |
---|
41 | !!---------------------------------------------------------------------- |
---|
42 | !! NEMO/OPA 3.3 , NEMO Consortium (2010) |
---|
43 | !! $Id$ |
---|
44 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
45 | !!---------------------------------------------------------------------- |
---|
46 | CONTAINS |
---|
47 | |
---|
48 | SUBROUTINE rst_opn( kt ) |
---|
49 | !!--------------------------------------------------------------------- |
---|
50 | !! *** ROUTINE rst_opn *** |
---|
51 | !! |
---|
52 | !! ** Purpose : + initialization (should be read in the namelist) of nitrst |
---|
53 | !! + open the restart when we are one time step before nitrst |
---|
54 | !! - restart header is defined when kt = nitrst-1 |
---|
55 | !! - restart data are written when kt = nitrst |
---|
56 | !! + define lrst_oce to .TRUE. when we need to define or write the restart |
---|
57 | !!---------------------------------------------------------------------- |
---|
58 | INTEGER, INTENT(in) :: kt ! ocean time-step |
---|
59 | !! |
---|
60 | CHARACTER(LEN=20) :: clkt ! ocean time-step deine as a character |
---|
61 | CHARACTER(LEN=50) :: clname ! ocean output restart file name |
---|
62 | CHARACTER(lc) :: clpath ! full path to ocean output restart file |
---|
63 | CHARACTER(LEN=52) :: clpname ! ocean output restart file name including prefix for AGRIF |
---|
64 | !!---------------------------------------------------------------------- |
---|
65 | ! |
---|
66 | IF( kt == nit000 ) THEN ! default definitions |
---|
67 | lrst_oce = .FALSE. |
---|
68 | IF( ln_rst_list ) THEN |
---|
69 | nrst_lst = 1 |
---|
70 | nitrst = nstocklist( nrst_lst ) |
---|
71 | ELSE |
---|
72 | nitrst = nitend |
---|
73 | ENDIF |
---|
74 | ENDIF |
---|
75 | |
---|
76 | ! frequency-based restart dumping (nn_stock) |
---|
77 | IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN |
---|
78 | ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment |
---|
79 | nitrst = kt + nstock - 1 ! define the next value of nitrst for restart writing |
---|
80 | IF( nitrst > nitend ) nitrst = nitend ! make sure we write a restart at the end of the run |
---|
81 | ENDIF |
---|
82 | ! to get better performances with NetCDF format: |
---|
83 | ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1) |
---|
84 | ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1 |
---|
85 | IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN |
---|
86 | IF( nitrst <= nitend .AND. nitrst > 0 ) THEN |
---|
87 | ! beware of the format used to write kt (default is i8.8, that should be large enough...) |
---|
88 | IF( nitrst > 999999999 ) THEN ; WRITE(clkt, * ) nitrst |
---|
89 | ELSE ; WRITE(clkt, '(i8.8)') nitrst |
---|
90 | ENDIF |
---|
91 | ! create the file |
---|
92 | clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out) |
---|
93 | clpath = TRIM(cn_ocerst_outdir) |
---|
94 | IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/' |
---|
95 | IF(lwp) THEN |
---|
96 | WRITE(numout,*) |
---|
97 | IF(.NOT.lwxios) THEN |
---|
98 | SELECT CASE ( jprstlib ) |
---|
99 | CASE DEFAULT ; WRITE(numout,*) & |
---|
100 | ' open ocean restart NetCDF file: ',TRIM(clpath)//TRIM(clname) |
---|
101 | END SELECT |
---|
102 | IF ( snc4set%luse ) WRITE(numout,*) ' opened for NetCDF4 chunking and compression' |
---|
103 | IF( kt == nitrst - 1 ) THEN ; WRITE(numout,*) ' kt = nitrst - 1 = ', kt |
---|
104 | ELSE ; WRITE(numout,*) ' kt = ' , kt |
---|
105 | ENDIF |
---|
106 | ENDIF |
---|
107 | ENDIF |
---|
108 | ! |
---|
109 | IF(.NOT.lwxios) THEN |
---|
110 | CALL iom_open( TRIM(clpath)//TRIM(clname), numrow, ldwrt = .TRUE., kiolib = jprstlib ) |
---|
111 | ELSE |
---|
112 | cwxios_context = "rstw_"//TRIM(ADJUSTL(clkt)) |
---|
113 | IF( TRIM(Agrif_CFixed()) == '0' ) THEN |
---|
114 | clpname = clname |
---|
115 | ELSE |
---|
116 | clpname = TRIM(Agrif_CFixed())//"_"//clname |
---|
117 | ENDIF |
---|
118 | CALL iom_init( cwxios_context, TRIM(clpath)//TRIM(clpname)) |
---|
119 | CALL xios_update_calendar(nitrst) |
---|
120 | CALL iom_swap( cxios_context ) |
---|
121 | ENDIF |
---|
122 | lrst_oce = .TRUE. |
---|
123 | ENDIF |
---|
124 | ENDIF |
---|
125 | ! |
---|
126 | END SUBROUTINE rst_opn |
---|
127 | |
---|
128 | |
---|
129 | SUBROUTINE rst_write( kt ) |
---|
130 | !!--------------------------------------------------------------------- |
---|
131 | !! *** ROUTINE rstwrite *** |
---|
132 | !! |
---|
133 | !! ** Purpose : Write restart fields in the format corresponding to jprstlib |
---|
134 | !! |
---|
135 | !! ** Method : Write in numrow when kt == nitrst in NetCDF |
---|
136 | !! file, save fields which are necessary for restart |
---|
137 | !!---------------------------------------------------------------------- |
---|
138 | INTEGER, INTENT(in) :: kt ! ocean time-step |
---|
139 | !!---------------------------------------------------------------------- |
---|
140 | IF(lwxios) CALL iom_swap( cwxios_context ) |
---|
141 | CALL iom_rstput( kt, nitrst, numrow, 'rdt' , rdt , ldxios = lwxios) ! dynamics time step |
---|
142 | |
---|
143 | IF ( .NOT. ln_diurnal_only ) THEN |
---|
144 | CALL iom_rstput( kt, nitrst, numrow, 'ub' , ub, ldxios = lwxios ) ! before fields |
---|
145 | CALL iom_rstput( kt, nitrst, numrow, 'vb' , vb, ldxios = lwxios ) |
---|
146 | CALL iom_rstput( kt, nitrst, numrow, 'tb' , tsb(:,:,:,jp_tem), ldxios = lwxios ) |
---|
147 | CALL iom_rstput( kt, nitrst, numrow, 'sb' , tsb(:,:,:,jp_sal), ldxios = lwxios ) |
---|
148 | CALL iom_rstput( kt, nitrst, numrow, 'sshb' , sshb, ldxios = lwxios ) |
---|
149 | ! |
---|
150 | CALL iom_rstput( kt, nitrst, numrow, 'un' , un, ldxios = lwxios ) ! now fields |
---|
151 | CALL iom_rstput( kt, nitrst, numrow, 'vn' , vn, ldxios = lwxios ) |
---|
152 | CALL iom_rstput( kt, nitrst, numrow, 'tn' , tsn(:,:,:,jp_tem), ldxios = lwxios ) |
---|
153 | CALL iom_rstput( kt, nitrst, numrow, 'sn' , tsn(:,:,:,jp_sal), ldxios = lwxios ) |
---|
154 | CALL iom_rstput( kt, nitrst, numrow, 'sshn' , sshn, ldxios = lwxios ) |
---|
155 | CALL iom_rstput( kt, nitrst, numrow, 'rhop' , rhop, ldxios = lwxios ) |
---|
156 | ! extra variable needed for the ice sheet coupling |
---|
157 | IF ( ln_iscpl ) THEN |
---|
158 | CALL iom_rstput( kt, nitrst, numrow, 'tmask' , tmask, ldxios = lwxios ) ! need to extrapolate T/S |
---|
159 | CALL iom_rstput( kt, nitrst, numrow, 'umask' , umask, ldxios = lwxios ) ! need to correct barotropic velocity |
---|
160 | CALL iom_rstput( kt, nitrst, numrow, 'vmask' , vmask, ldxios = lwxios ) ! need to correct barotropic velocity |
---|
161 | CALL iom_rstput( kt, nitrst, numrow, 'smask' , ssmask, ldxios = lwxios) ! need to correct barotropic velocity |
---|
162 | CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t_n(:,:,:), ldxios = lwxios ) ! need to compute temperature correction |
---|
163 | CALL iom_rstput( kt, nitrst, numrow, 'e3u_n', e3u_n(:,:,:), ldxios = lwxios ) ! need to compute bt conservation |
---|
164 | CALL iom_rstput( kt, nitrst, numrow, 'e3v_n', e3v_n(:,:,:), ldxios = lwxios ) ! need to compute bt conservation |
---|
165 | CALL iom_rstput( kt, nitrst, numrow, 'gdepw_n', gdepw_n(:,:,:), ldxios = lwxios ) ! need to compute extrapolation if vvl |
---|
166 | END IF |
---|
167 | ENDIF |
---|
168 | |
---|
169 | IF (ln_diurnal) CALL iom_rstput( kt, nitrst, numrow, 'Dsst', x_dsst, ldxios = lwxios ) |
---|
170 | IF(lwxios) CALL iom_swap( cxios_context ) |
---|
171 | IF( kt == nitrst ) THEN |
---|
172 | IF(.NOT.lwxios) THEN |
---|
173 | CALL iom_close( numrow ) ! close the restart file (only at last time step) |
---|
174 | ELSE |
---|
175 | CALL iom_context_finalize( cwxios_context ) |
---|
176 | ENDIF |
---|
177 | !!gm IF( .NOT. lk_trdmld ) lrst_oce = .FALSE. |
---|
178 | !!gm not sure what to do here ===>>> ask to Sebastian |
---|
179 | lrst_oce = .FALSE. |
---|
180 | IF( ln_rst_list ) THEN |
---|
181 | nrst_lst = MIN(nrst_lst + 1, SIZE(nstocklist,1)) |
---|
182 | nitrst = nstocklist( nrst_lst ) |
---|
183 | ENDIF |
---|
184 | ENDIF |
---|
185 | ! |
---|
186 | END SUBROUTINE rst_write |
---|
187 | |
---|
188 | |
---|
189 | SUBROUTINE rst_read_open |
---|
190 | !!---------------------------------------------------------------------- |
---|
191 | !! *** ROUTINE rst_read_open *** |
---|
192 | !! |
---|
193 | !! ** Purpose : Open read files for restart (format fixed by jprstlib ) |
---|
194 | !! |
---|
195 | !! ** Method : Use a non-zero, positive value of numror to assess whether or not |
---|
196 | !! the file has already been opened |
---|
197 | !!---------------------------------------------------------------------- |
---|
198 | INTEGER :: jlibalt = jprstlib |
---|
199 | LOGICAL :: llok |
---|
200 | CHARACTER(lc) :: clpath ! full path to ocean output restart file |
---|
201 | !!---------------------------------------------------------------------- |
---|
202 | ! |
---|
203 | IF( numror <= 0 ) THEN |
---|
204 | IF(lwp) THEN ! Contol prints |
---|
205 | WRITE(numout,*) |
---|
206 | SELECT CASE ( jprstlib ) |
---|
207 | CASE ( jpnf90 ) ; WRITE(numout,*) 'rst_read : read oce NetCDF restart file' |
---|
208 | END SELECT |
---|
209 | IF ( snc4set%luse ) WRITE(numout,*) 'rst_read : configured with NetCDF4 support' |
---|
210 | WRITE(numout,*) '~~~~~~~~' |
---|
211 | ENDIF |
---|
212 | lxios_sini = .FALSE. |
---|
213 | clpath = TRIM(cn_ocerst_indir) |
---|
214 | IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/' |
---|
215 | CALL iom_open( TRIM(clpath)//cn_ocerst_in, numror, kiolib = jlibalt ) |
---|
216 | ! are we using XIOS to read the data? Part above will have to modified once XIOS |
---|
217 | ! can handle checking if variable is in the restart file (there will be no need to open |
---|
218 | ! restart) |
---|
219 | IF(.NOT.lxios_set) lrxios = lrxios.AND.lxios_sini |
---|
220 | IF( lrxios) THEN |
---|
221 | crxios_context = 'nemo_rst' |
---|
222 | IF( .NOT.lxios_set ) THEN |
---|
223 | IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS' |
---|
224 | CALL iom_init( crxios_context ) |
---|
225 | lxios_set = .TRUE. |
---|
226 | ENDIF |
---|
227 | ENDIF |
---|
228 | IF( TRIM(Agrif_CFixed()) /= '0' .AND. lrxios) THEN |
---|
229 | CALL iom_init( crxios_context ) |
---|
230 | IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for AGRIF' |
---|
231 | lxios_set = .TRUE. |
---|
232 | ENDIF |
---|
233 | ENDIF |
---|
234 | |
---|
235 | END SUBROUTINE rst_read_open |
---|
236 | |
---|
237 | |
---|
238 | SUBROUTINE rst_read |
---|
239 | !!---------------------------------------------------------------------- |
---|
240 | !! *** ROUTINE rst_read *** |
---|
241 | !! |
---|
242 | !! ** Purpose : Read files for restart (format fixed by jprstlib ) |
---|
243 | !! |
---|
244 | !! ** Method : Read in restart.nc file fields which are necessary for restart |
---|
245 | !!---------------------------------------------------------------------- |
---|
246 | REAL(wp) :: zrdt |
---|
247 | INTEGER :: jk |
---|
248 | REAL(wp), DIMENSION(jpi, jpj, jpk) :: w3d |
---|
249 | !!---------------------------------------------------------------------- |
---|
250 | |
---|
251 | CALL rst_read_open ! open restart for reading (if not already opened) |
---|
252 | |
---|
253 | ! Check dynamics and tracer time-step consistency and force Euler restart if changed |
---|
254 | IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 ) THEN |
---|
255 | CALL iom_get( numror, 'rdt', zrdt, ldxios = lrxios ) |
---|
256 | IF( zrdt /= rdt ) neuler = 0 |
---|
257 | ENDIF |
---|
258 | |
---|
259 | ! Diurnal DSST |
---|
260 | IF( ln_diurnal ) CALL iom_get( numror, jpdom_autoglo, 'Dsst' , x_dsst, ldxios = lrxios ) |
---|
261 | IF ( ln_diurnal_only ) THEN |
---|
262 | IF(lwp) WRITE( numout, * ) & |
---|
263 | & "rst_read:- ln_diurnal_only set, setting rhop=rau0" |
---|
264 | rhop = rau0 |
---|
265 | CALL iom_get( numror, jpdom_autoglo, 'tn' , w3d, ldxios = lrxios ) |
---|
266 | tsn(:,:,1,jp_tem) = w3d(:,:,1) |
---|
267 | RETURN |
---|
268 | ENDIF |
---|
269 | |
---|
270 | IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN |
---|
271 | CALL iom_get( numror, jpdom_autoglo, 'ub' , ub, ldxios = lrxios ) ! before fields |
---|
272 | CALL iom_get( numror, jpdom_autoglo, 'vb' , vb, ldxios = lrxios ) |
---|
273 | CALL iom_get( numror, jpdom_autoglo, 'tb' , tsb(:,:,:,jp_tem), ldxios = lrxios ) |
---|
274 | CALL iom_get( numror, jpdom_autoglo, 'sb' , tsb(:,:,:,jp_sal), ldxios = lrxios ) |
---|
275 | CALL iom_get( numror, jpdom_autoglo, 'sshb' , sshb, ldxios = lrxios ) |
---|
276 | ELSE |
---|
277 | neuler = 0 |
---|
278 | ENDIF |
---|
279 | ! |
---|
280 | CALL iom_get( numror, jpdom_autoglo, 'un' , un, ldxios = lrxios ) ! now fields |
---|
281 | CALL iom_get( numror, jpdom_autoglo, 'vn' , vn, ldxios = lrxios ) |
---|
282 | CALL iom_get( numror, jpdom_autoglo, 'tn' , tsn(:,:,:,jp_tem), ldxios = lrxios ) |
---|
283 | CALL iom_get( numror, jpdom_autoglo, 'sn' , tsn(:,:,:,jp_sal), ldxios = lrxios ) |
---|
284 | CALL iom_get( numror, jpdom_autoglo, 'sshn' , sshn, ldxios = lrxios ) |
---|
285 | IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN |
---|
286 | CALL iom_get( numror, jpdom_autoglo, 'rhop' , rhop, ldxios = lrxios ) ! now potential density |
---|
287 | ELSE |
---|
288 | CALL eos( tsn, rhd, rhop, gdept_n(:,:,:) ) |
---|
289 | ENDIF |
---|
290 | ! |
---|
291 | IF( neuler == 0 ) THEN ! Euler restart (neuler=0) |
---|
292 | tsb (:,:,:,:) = tsn (:,:,:,:) ! all before fields set to now values |
---|
293 | ub (:,:,:) = un (:,:,:) |
---|
294 | vb (:,:,:) = vn (:,:,:) |
---|
295 | sshb (:,:) = sshn (:,:) |
---|
296 | ! |
---|
297 | IF( .NOT.ln_linssh ) THEN |
---|
298 | DO jk = 1, jpk |
---|
299 | e3t_b(:,:,jk) = e3t_n(:,:,jk) |
---|
300 | END DO |
---|
301 | ENDIF |
---|
302 | ! |
---|
303 | ENDIF |
---|
304 | ! |
---|
305 | END SUBROUTINE rst_read |
---|
306 | |
---|
307 | !!===================================================================== |
---|
308 | END MODULE restart |
---|