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/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE – NEMO

source: NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/ICE/icerst.F90 @ 10372

Last change on this file since 10372 was 10359, checked in by smasson, 5 years ago

dev_r10164_HPC09_ESIWACE_PREP_MERGE: action 4c: introduce a better version of the non-blocking mpp_max, see #2133

  • Property svn:keywords set to Id
File size: 11.7 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 icectl
20   !
21   USE in_out_manager ! I/O manager
22   USE iom            ! I/O manager library
23   USE lib_mpp        ! MPP library
24   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
25
26   IMPLICIT NONE
27   PRIVATE
28
29   PUBLIC   ice_rst_opn     ! called by icestp
30   PUBLIC   ice_rst_write   ! called by icestp
31   PUBLIC   ice_rst_read    ! called by ice_init
32
33   !!----------------------------------------------------------------------
34   !! NEMO/ICE 4.0 , NEMO Consortium (2018)
35   !! $Id$
36   !! Software governed by the CeCILL license (see ./LICENSE)
37   !!----------------------------------------------------------------------
38CONTAINS
39
40   SUBROUTINE ice_rst_opn( kt )
41      !!----------------------------------------------------------------------
42      !!                    ***  ice_rst_opn  ***
43      !!
44      !! ** purpose  :   open restart file
45      !!----------------------------------------------------------------------
46      INTEGER, INTENT(in) ::   kt       ! number of iteration
47      !
48      CHARACTER(len=20)   ::   clkt     ! ocean time-step define as a character
49      CHARACTER(len=50)   ::   clname   ! ice output restart file name
50      CHARACTER(len=256)  ::   clpath   ! full path to ice output restart file
51      !!----------------------------------------------------------------------
52      !
53      IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
54
55      ! in order to get better performances with NetCDF format, we open and define the ice restart file
56      ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice
57      ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
58      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nstock == nn_fsbc    &
59         &                             .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
60         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
61            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
62            IF( nitrst > 99999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
63            ELSE                           ;   WRITE(clkt, '(i8.8)') nitrst
64            ENDIF
65            ! create the file
66            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out)
67            clpath = TRIM(cn_icerst_outdir) 
68            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/'
69            IF(lwp) THEN
70               WRITE(numout,*)
71               SELECT CASE ( jprstlib )
72               CASE DEFAULT
73                  WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
74               END SELECT
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., kiolib = jprstlib, kdlev = jpl )
83            lrst_ice = .TRUE.
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 ::   ji, jk ,jl   ! 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      DO ji = 1, nbdelay
121         CALL iom_rstput( iter, nitrst, numriw, c_delaylist(ji), todelay(ji) )
122      END DO
123
124      ! Prognostic variables
125      CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i  )
126      CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s  )
127      CALL iom_rstput( iter, nitrst, numriw, 'sv_i', sv_i )
128      CALL iom_rstput( iter, nitrst, numriw, 'oa_i', oa_i )
129      CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i  )
130      CALL iom_rstput( iter, nitrst, numriw, 't_su', t_su )
131      ! Melt ponds
132      CALL iom_rstput( iter, nitrst, numriw, 'a_ip', a_ip )
133      CALL iom_rstput( iter, nitrst, numriw, 'v_ip', v_ip )
134      ! Snow enthalpy
135      DO jk = 1, nlay_s 
136         WRITE(zchar1,'(I2.2)') jk
137         znam = 'e_s'//'_l'//zchar1
138         z3d(:,:,:) = e_s(:,:,jk,:)
139         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
140      END DO
141      ! Ice enthalpy
142      DO jk = 1, nlay_i 
143         WRITE(zchar1,'(I2.2)') jk
144         znam = 'e_i'//'_l'//zchar1
145         z3d(:,:,:) = e_i(:,:,jk,:)
146         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
147      END DO
148      ! ice velocity
149      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice
150      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice
151      ! fields needed for Met Office (Jules) coupling
152      IF( ln_cpl ) THEN
153         CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice )
154         CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice  )
155      ENDIF
156      !
157
158      ! close restart file
159      ! ------------------
160      IF( iter == nitrst ) THEN
161         CALL iom_close( numriw )
162         lrst_ice = .FALSE.
163      ENDIF
164      !
165   END SUBROUTINE ice_rst_write
166
167
168   SUBROUTINE ice_rst_read
169      !!----------------------------------------------------------------------
170      !!                    ***  ice_rst_read  ***
171      !!
172      !! ** purpose  :   read restart file
173      !!----------------------------------------------------------------------
174      INTEGER           ::   ji, jk, jl
175      LOGICAL           ::   llok
176      INTEGER           ::   id1            ! local integer
177      INTEGER           ::   jlibalt = jprstlib
178      CHARACTER(len=25) ::   znam
179      CHARACTER(len=2)  ::   zchar, zchar1
180      REAL(wp)          ::   zfice, ziter, zcfl
181      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
182      !!----------------------------------------------------------------------
183
184      IF(lwp) THEN
185         WRITE(numout,*)
186         WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file'
187         WRITE(numout,*) '~~~~~~~~~~~~'
188      ENDIF
189
190      CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib, kdlev = jpl )
191
192      CALL iom_get( numrir, 'nn_fsbc', zfice )
193      CALL iom_get( numrir, 'kt_ice' , ziter )   
194      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
195      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
196
197      ! Control of date
198      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
199         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
200         &                   '   verify the file or rerun with the value 0 for the',        &
201         &                   '   control of time parameter  nrstdt' )
202      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
203         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
204         &                   '   verify the file or rerun with the value 0 for the',         &
205         &                   '   control of time parameter  nrstdt' )
206
207      ! Prognostic variables
208      CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i  )
209      CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s  )
210      CALL iom_get( numrir, jpdom_autoglo, 'sv_i', sv_i )
211      CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i )
212      CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i  )
213      CALL iom_get( numrir, jpdom_autoglo, 't_su', t_su )
214      ! Melt ponds
215      id1 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. )
216      IF( id1 > 0 ) THEN                       ! fields exist (melt ponds)
217         CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip )
218         CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip )
219      ELSE                                     ! start from rest
220         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
221         a_ip(:,:,:) = 0._wp
222         v_ip(:,:,:) = 0._wp
223      ENDIF
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      ! ice velocity
239      CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
240      CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
241
242      ! fields needed for ice_dyn_adv_umx
243      zcfl =            MAXVAL( ABS( u_ice(:,:) ) * rdt_ice * r1_e1u(:,:) )
244      zcfl = MAX( zcfl, MAXVAL( ABS( v_ice(:,:) ) * rdt_ice * r1_e2v(:,:) ) )
245
246      DO ji = 1, nbdelay
247         IF( iom_varid( numrir, c_delaylist(ji), ldstop = .FALSE. ) > 0 )  THEN
248            CALL iom_get( numrir, c_delaylist(ji), todelay(ji) )
249            ndelayid(ji) = 0   ! set to 0 to speficy that the value was read in the restart
250         ENDIF
251      END DO
252
253      ! fields needed for Met Office (Jules) coupling
254      IF( ln_cpl ) THEN
255         CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice )
256         CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice  )
257      ENDIF
258
259   END SUBROUTINE ice_rst_read
260
261#else
262   !!----------------------------------------------------------------------
263   !!   Default option :       Empty module           NO SI3 sea-ice model
264   !!----------------------------------------------------------------------
265#endif
266
267   !!======================================================================
268END MODULE icerst
Note: See TracBrowser for help on using the repository browser.