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.4_GO8_package/src/ICE – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.4_GO8_package/src/ICE/icerst.F90 @ 14451

Last change on this file since 14451 was 14078, checked in by cguiavarch, 4 years ago

UKMO/NEMO_4.0.4_GO8_package: copy over changes from NEMO_4.0.3_GO8_package branch @13647.

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