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/UKMO/NEMO_4.0.1_fix_cpl/src/ICE – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.1_fix_cpl/src/ICE/icerst.F90 @ 12402

Last change on this file since 12402 was 12402, checked in by dancopsey, 4 years ago

Add melt pond lid code.

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