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_r11842_SI3-10_EAP/src/ICE – NEMO

source: NEMO/branches/2019/dev_r11842_SI3-10_EAP/src/ICE/icerst.F90 @ 13662

Last change on this file since 13662 was 13662, checked in by clem, 3 years ago

update to almost r4.0.4

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