New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
icerst.F90 in NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/ICE – NEMO

source: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/ICE/icerst.F90 @ 13334

Last change on this file since 13334 was 13334, checked in by jchanut, 4 years ago

finish bypassing ocean/ice initialization with AGRIF, #2222, #2129

  • Property svn:keywords set to Id
File size: 13.9 KB
Line 
1MODULE 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 iceistate      ! sea-ice: initial state
21   USE icectl         ! sea-ice: control
22   !
23   USE in_out_manager ! I/O manager
24   USE iom            ! I/O manager library
25   USE lib_mpp        ! MPP library
26   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
27
28   USE agrif_oce      ! initial state interpolation
29   USE agrif_ice_interp 
30
31   IMPLICIT NONE
32   PRIVATE
33
34   PUBLIC   ice_rst_opn     ! called by icestp
35   PUBLIC   ice_rst_write   ! called by icestp
36   PUBLIC   ice_rst_read    ! called by ice_init
37
38   !!----------------------------------------------------------------------
39   !! NEMO/ICE 4.0 , NEMO Consortium (2018)
40   !! $Id$
41   !! Software governed by the CeCILL license (see ./LICENSE)
42   !!----------------------------------------------------------------------
43CONTAINS
44
45   SUBROUTINE ice_rst_opn( kt )
46      !!----------------------------------------------------------------------
47      !!                    ***  ice_rst_opn  ***
48      !!
49      !! ** purpose  :   open restart file
50      !!----------------------------------------------------------------------
51      INTEGER, INTENT(in) ::   kt       ! number of iteration
52      !
53      CHARACTER(len=20)   ::   clkt     ! ocean time-step define as a character
54      CHARACTER(len=50)   ::   clname   ! ice output restart file name
55      CHARACTER(len=256)  ::   clpath   ! full path to ice output restart file
56      !!----------------------------------------------------------------------
57      !
58      IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
59
60      IF( ln_rst_list .OR. nn_stock /= -1 ) THEN
61      ! in order to get better performances with NetCDF format, we open and define the ice restart file
62      ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice
63      ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
64      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nn_stock == nn_fsbc    &
65         &                             .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
66         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
67            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
68            IF( nitrst > 99999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
69            ELSE                           ;   WRITE(clkt, '(i8.8)') nitrst
70            ENDIF
71            ! create the file
72            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out)
73            clpath = TRIM(cn_icerst_outdir) 
74            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/'
75            IF(lwp) THEN
76               WRITE(numout,*)
77               WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
78               IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN
79                  WRITE(numout,*) '             kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp
80               ELSE
81                  WRITE(numout,*) '             kt = '                         , kt,' date= ', ndastp
82               ENDIF
83            ENDIF
84            !
85            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl, cdcomp = 'ICE' )
86            lrst_ice = .TRUE.
87         ENDIF
88      ENDIF
89      ENDIF
90      !
91      IF( ln_icectl )   CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
92      !
93   END SUBROUTINE ice_rst_opn
94
95
96   SUBROUTINE ice_rst_write( kt )
97      !!----------------------------------------------------------------------
98      !!                    ***  ice_rst_write  ***
99      !!
100      !! ** purpose  :   write restart file
101      !!----------------------------------------------------------------------
102      INTEGER, INTENT(in) ::   kt     ! number of iteration
103      !!
104      INTEGER ::   jk    ! dummy loop indices
105      INTEGER ::   iter
106      CHARACTER(len=25) ::   znam
107      CHARACTER(len=2)  ::   zchar, zchar1
108      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
109      !!----------------------------------------------------------------------
110
111      iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
112
113      IF( iter == nitrst ) THEN
114         IF(lwp) WRITE(numout,*)
115         IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file  kt =', kt
116         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'         
117      ENDIF
118
119      ! Write in numriw (if iter == nitrst)
120      ! ------------------
121      !                                                                        ! calendar control
122      CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) )      ! time-step
123      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
124      CALL iom_delay_rst( 'WRITE', 'ICE', numriw )   ! save only ice delayed global communication variables
125
126      ! Prognostic variables
127      CALL iom_rstput( iter, nitrst, numriw, 'v_i'  , v_i   )
128      CALL iom_rstput( iter, nitrst, numriw, 'v_s'  , v_s   )
129      CALL iom_rstput( iter, nitrst, numriw, 'sv_i' , sv_i  )
130      CALL iom_rstput( iter, nitrst, numriw, 'a_i'  , a_i   )
131      CALL iom_rstput( iter, nitrst, numriw, 't_su' , t_su  )
132      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice )
133      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice )
134      CALL iom_rstput( iter, nitrst, numriw, 'oa_i' , oa_i  )
135      CALL iom_rstput( iter, nitrst, numriw, 'a_ip' , a_ip  )
136      CALL iom_rstput( iter, nitrst, numriw, 'v_ip' , v_ip  )
137      ! Snow enthalpy
138      DO jk = 1, nlay_s 
139         WRITE(zchar1,'(I2.2)') jk
140         znam = 'e_s'//'_l'//zchar1
141         z3d(:,:,:) = e_s(:,:,jk,:)
142         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
143      END DO
144      ! Ice enthalpy
145      DO jk = 1, nlay_i 
146         WRITE(zchar1,'(I2.2)') jk
147         znam = 'e_i'//'_l'//zchar1
148         z3d(:,:,:) = e_i(:,:,jk,:)
149         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
150      END DO
151      ! fields needed for Met Office (Jules) coupling
152      IF( ln_cpl ) THEN
153         CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice )
154         CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice  )
155      ENDIF
156      !
157
158      ! close restart file
159      ! ------------------
160      IF( iter == nitrst ) THEN
161         CALL iom_close( numriw )
162         lrst_ice = .FALSE.
163      ENDIF
164      !
165   END SUBROUTINE ice_rst_write
166
167
168   SUBROUTINE ice_rst_read( Kbb, Kmm, Kaa )
169      !!----------------------------------------------------------------------
170      !!                    ***  ice_rst_read  ***
171      !!
172      !! ** purpose  :   read restart file
173      !!----------------------------------------------------------------------
174      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa ! ocean time level indices
175      INTEGER           ::   jk
176      LOGICAL           ::   llok
177      INTEGER           ::   id0, id1, id2, id3, id4   ! local integer
178      CHARACTER(len=25) ::   znam
179      CHARACTER(len=2)  ::   zchar, zchar1
180      REAL(wp)          ::   zfice, ziter
181      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
182      !!----------------------------------------------------------------------
183
184      IF(lwp) THEN
185         WRITE(numout,*)
186         WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file'
187         WRITE(numout,*) '~~~~~~~~~~~~'
188      ENDIF
189
190#if defined key_agrif
191      IF( (.NOT.Agrif_Root()).AND.ln_init_chfrpar ) THEN
192         !                 ! -------------------------------- !
193         !                 ! == set ice fields from parent == !
194         !                 ! -------------------------------- !
195         !
196         CALL agrif_istate_ice
197         !
198      ELSE
199#endif
200
201         CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir )
202
203         ! test if v_i exists
204         id0 = iom_varid( numrir, 'v_i' , ldstop = .FALSE. )
205
206         !                    ! ------------------------------ !
207         IF( id0 > 0 ) THEN   ! == case of a normal restart == !
208            !                 ! ------------------------------ !
209         
210            ! Time info
211            CALL iom_get( numrir, 'nn_fsbc', zfice )
212            CALL iom_get( numrir, 'kt_ice' , ziter )   
213            IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
214            IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
215
216            ! Control of date
217            IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
218               &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
219               &                   '   verify the file or rerun with the value 0 for the',        &
220               &                   '   control of time parameter  nrstdt' )
221            IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
222               &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
223               &                   '   verify the file or rerun with the value 0 for the',         &
224               &                   '   control of time parameter  nrstdt' )
225
226            ! --- mandatory fields --- !
227            CALL iom_get( numrir, jpdom_auto, 'v_i'  , v_i   )
228            CALL iom_get( numrir, jpdom_auto, 'v_s'  , v_s   )
229            CALL iom_get( numrir, jpdom_auto, 'sv_i' , sv_i  )
230            CALL iom_get( numrir, jpdom_auto, 'a_i'  , a_i   )
231            CALL iom_get( numrir, jpdom_auto, 't_su' , t_su  )
232            CALL iom_get( numrir, jpdom_auto, 'u_ice', u_ice, cd_type = 'U', psgn = -1._wp )
233            CALL iom_get( numrir, jpdom_auto, 'v_ice', v_ice, cd_type = 'V', psgn = -1._wp )
234            ! Snow enthalpy
235            DO jk = 1, nlay_s
236               WRITE(zchar1,'(I2.2)') jk
237               znam = 'e_s'//'_l'//zchar1
238               CALL iom_get( numrir, jpdom_auto, znam , z3d )
239               e_s(:,:,jk,:) = z3d(:,:,:)
240            END DO
241            ! Ice enthalpy
242            DO jk = 1, nlay_i
243               WRITE(zchar1,'(I2.2)') jk
244               znam = 'e_i'//'_l'//zchar1
245               CALL iom_get( numrir, jpdom_auto, znam , z3d )
246               e_i(:,:,jk,:) = z3d(:,:,:)
247            END DO
248            ! -- optional fields -- !
249            ! ice age
250            id1 = iom_varid( numrir, 'oa_i' , ldstop = .FALSE. )
251            IF( id1 > 0 ) THEN                       ! fields exist
252               CALL iom_get( numrir, jpdom_auto, 'oa_i', oa_i )
253            ELSE                                     ! start from rest
254               IF(lwp) WRITE(numout,*) '   ==>>   previous run without ice age output then set it to zero'
255               oa_i(:,:,:) = 0._wp
256            ENDIF
257            ! melt ponds
258            id2 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. )
259            IF( id2 > 0 ) THEN                       ! fields exist
260               CALL iom_get( numrir, jpdom_auto, 'a_ip' , a_ip )
261               CALL iom_get( numrir, jpdom_auto, 'v_ip' , v_ip )
262            ELSE                                     ! start from rest
263               IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
264               a_ip(:,:,:) = 0._wp
265               v_ip(:,:,:) = 0._wp
266            ENDIF
267            ! fields needed for Met Office (Jules) coupling
268            IF( ln_cpl ) THEN
269               id3 = iom_varid( numrir, 'cnd_ice' , ldstop = .FALSE. )
270               id4 = iom_varid( numrir, 't1_ice'  , ldstop = .FALSE. )
271               IF( id3 > 0 .AND. id4 > 0 ) THEN         ! fields exist
272                  CALL iom_get( numrir, jpdom_auto, 'cnd_ice', cnd_ice )
273                  CALL iom_get( numrir, jpdom_auto, 't1_ice' , t1_ice  )
274               ELSE                                     ! start from rest
275                  IF(lwp) WRITE(numout,*) '   ==>>   previous run without conductivity output then set it to zero'
276                  cnd_ice(:,:,:) = 0._wp
277                  t1_ice (:,:,:) = rt0
278               ENDIF
279            ENDIF
280
281            CALL iom_delay_rst( 'READ', 'ICE', numrir )   ! read only ice delayed global communication variables
282
283            !                 ! ---------------------------------- !
284         ELSE                 ! == case of a simplified restart == !
285            !                 ! ---------------------------------- !
286            CALL ctl_warn('ice_rst_read: you are using a simplified ice restart')
287            !
288            CALL ice_istate_init
289            CALL ice_istate( nit000, Kbb, Kmm, Kaa )
290            !
291            IF( .NOT.ln_iceini .OR. .NOT.ln_iceini_file ) &
292               &   CALL ctl_stop('STOP', 'ice_rst_read: you need ln_ice_ini=T and ln_iceini_file=T')
293            !
294         ENDIF
295#if defined key_agrif
296      ENDIF
297#endif
298
299   END SUBROUTINE ice_rst_read
300
301#else
302   !!----------------------------------------------------------------------
303   !!   Default option :       Empty module           NO SI3 sea-ice model
304   !!----------------------------------------------------------------------
305#endif
306
307   !!======================================================================
308END MODULE icerst
Note: See TracBrowser for help on using the repository browser.