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 @ 13942

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

Merged with trunk @13787

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