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_r10984_HPC-13_IRRMANN_DYN_optimization/src/ICE – NEMO

source: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_DYN_optimization/src/ICE/icerst.F90 @ 11390

Last change on this file since 11390 was 11390, checked in by girrmann, 5 years ago

dev_r10984_HPC-13 : merge DYN with BDY @11389, see #2308

  • Property svn:keywords set to Id
File size: 11.5 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      IF( ln_rst_list .OR. nn_stock /= -1 ) THEN
56      ! in order to get better performances with NetCDF format, we open and define the ice restart file
57      ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice
58      ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
59      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nn_stock == nn_fsbc    &
60         &                             .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
61         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
62            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
63            IF( nitrst > 99999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
64            ELSE                           ;   WRITE(clkt, '(i8.8)') nitrst
65            ENDIF
66            ! create the file
67            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out)
68            clpath = TRIM(cn_icerst_outdir) 
69            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/'
70            IF(lwp) THEN
71               WRITE(numout,*)
72               WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
73               IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN
74                  WRITE(numout,*) '             kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp
75               ELSE
76                  WRITE(numout,*) '             kt = '                         , kt,' date= ', ndastp
77               ENDIF
78            ENDIF
79            !
80            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl )
81            lrst_ice = .TRUE.
82         ENDIF
83      ENDIF
84      ENDIF
85      !
86      IF( ln_icectl )   CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
87      !
88   END SUBROUTINE ice_rst_opn
89
90
91   SUBROUTINE ice_rst_write( kt )
92      !!----------------------------------------------------------------------
93      !!                    ***  ice_rst_write  ***
94      !!
95      !! ** purpose  :   write restart file
96      !!----------------------------------------------------------------------
97      INTEGER, INTENT(in) ::   kt     ! number of iteration
98      !!
99      INTEGER ::   jk    ! dummy loop indices
100      INTEGER ::   iter
101      CHARACTER(len=25) ::   znam
102      CHARACTER(len=2)  ::   zchar, zchar1
103      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
104      !!----------------------------------------------------------------------
105
106      iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
107
108      IF( iter == nitrst ) THEN
109         IF(lwp) WRITE(numout,*)
110         IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file  kt =', kt
111         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'         
112      ENDIF
113
114      ! Write in numriw (if iter == nitrst)
115      ! ------------------
116      !                                                                        ! calendar control
117      CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) )      ! time-step
118      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
119      CALL iom_delay_rst( 'WRITE', 'ICE', numriw )   ! save only ice delayed global communication variables
120
121      ! Prognostic variables
122      CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i  )
123      CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s  )
124      CALL iom_rstput( iter, nitrst, numriw, 'sv_i', sv_i )
125      CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i  )
126      CALL iom_rstput( iter, nitrst, numriw, 't_su', t_su )
127      ! ice age
128      CALL iom_rstput( iter, nitrst, numriw, 'oa_i', oa_i )
129      ! Melt ponds
130      CALL iom_rstput( iter, nitrst, numriw, 'a_ip', a_ip )
131      CALL iom_rstput( iter, nitrst, numriw, 'v_ip', v_ip )
132      ! Snow enthalpy
133      DO jk = 1, nlay_s 
134         WRITE(zchar1,'(I2.2)') jk
135         znam = 'e_s'//'_l'//zchar1
136         z3d(:,:,:) = e_s(:,:,jk,:)
137         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
138      END DO
139      ! Ice enthalpy
140      DO jk = 1, nlay_i 
141         WRITE(zchar1,'(I2.2)') jk
142         znam = 'e_i'//'_l'//zchar1
143         z3d(:,:,:) = e_i(:,:,jk,:)
144         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
145      END DO
146      ! ice velocity
147      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice )
148      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice )
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           ::   id1, id2            ! 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      CALL iom_get( numrir, 'nn_fsbc', zfice )
190      CALL iom_get( numrir, 'kt_ice' , ziter )   
191      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
192      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
193
194      ! Control of date
195      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
196         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
197         &                   '   verify the file or rerun with the value 0 for the',        &
198         &                   '   control of time parameter  nrstdt' )
199      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
200         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
201         &                   '   verify the file or rerun with the value 0 for the',         &
202         &                   '   control of time parameter  nrstdt' )
203
204      ! Prognostic variables
205      CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i  )
206      CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s  )
207      CALL iom_get( numrir, jpdom_autoglo, 'sv_i', sv_i )
208      CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i  )
209      CALL iom_get( numrir, jpdom_autoglo, 't_su', t_su )
210      ! ice age
211      id1 = iom_varid( numrir, 'oa_i' , ldstop = .FALSE. )
212      IF( id1 > 0 ) THEN                       ! fields exist
213         CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i )
214      ELSE                                     ! start from rest
215         IF(lwp) WRITE(numout,*) '   ==>>   previous run without ice age output then set it to zero'
216         oa_i(:,:,:) = 0._wp
217      ENDIF
218      ! Melt ponds
219      id2 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. )
220      IF( id2 > 0 ) THEN                       ! fields exist
221         CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip )
222         CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip )
223      ELSE                                     ! start from rest
224         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
225         a_ip(:,:,:) = 0._wp
226         v_ip(:,:,:) = 0._wp
227      ENDIF
228      ! Snow enthalpy
229      DO jk = 1, nlay_s
230         WRITE(zchar1,'(I2.2)') jk
231         znam = 'e_s'//'_l'//zchar1
232         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
233         e_s(:,:,jk,:) = z3d(:,:,:)
234      END DO
235      ! Ice enthalpy
236      DO jk = 1, nlay_i
237         WRITE(zchar1,'(I2.2)') jk
238         znam = 'e_i'//'_l'//zchar1
239         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
240         e_i(:,:,jk,:) = z3d(:,:,:)
241      END DO
242      ! ice velocity
243      CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
244      CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
245
246      CALL iom_delay_rst( 'READ', 'ICE', numrir )   ! read only ice delayed global communication variables
247
248      ! fields needed for Met Office (Jules) coupling
249      IF( ln_cpl ) THEN
250         CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice )
251         CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice  )
252      ENDIF
253
254   END SUBROUTINE ice_rst_read
255
256#else
257   !!----------------------------------------------------------------------
258   !!   Default option :       Empty module           NO SI3 sea-ice model
259   !!----------------------------------------------------------------------
260#endif
261
262   !!======================================================================
263END MODULE icerst
Note: See TracBrowser for help on using the repository browser.