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/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/ICE – NEMO

source: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/ICE/icerst.F90 @ 11401

Last change on this file since 11401 was 11401, checked in by clem, 5 years ago

add new functionality for initialization. Now you can use a simplified restart for starting a simulation (as for the initialization)

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