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

source: NEMO/branches/UKMO/NEMO_4.0_GO8_package_text_diagnostics/src/ICE/icerst.F90 @ 10948

Last change on this file since 10948 was 10897, checked in by davestorkey, 5 years ago

UKMO/NEMO_4.0_GO8_package branch: Copy over changes from previous version of the branch.

  1. Implement datestamping of restarts.
  2. Local diagnostics, particularly vertically-interpolated MLD diagnostics.
  3. Restrict write-out in tra_bbl_init with IF(lwp).
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 ioipsl, ONLY : ju2ymds    ! for calendar
24   USE lib_mpp        ! MPP library
25   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
26
27   IMPLICIT NONE
28   PRIVATE
29
30   PUBLIC   ice_rst_opn     ! called by icestp
31   PUBLIC   ice_rst_write   ! called by icestp
32   PUBLIC   ice_rst_read    ! called by ice_init
33
34   !!----------------------------------------------------------------------
35   !! NEMO/ICE 4.0 , NEMO Consortium (2018)
36   !! $Id$
37   !! Software governed by the CeCILL license (see ./LICENSE)
38   !!----------------------------------------------------------------------
39CONTAINS
40
41   SUBROUTINE ice_rst_opn( kt )
42      !!----------------------------------------------------------------------
43      !!                    ***  ice_rst_opn  ***
44      !!
45      !! ** purpose  :   open restart file
46      !!----------------------------------------------------------------------
47      INTEGER, INTENT(in) ::   kt       ! number of iteration
48      !
49      INTEGER             ::   iyear, imonth, iday
50      REAL (wp)           ::   zsec
51      REAL (wp)           ::   zfjulday
52      CHARACTER(len=20)   ::   clkt     ! ocean time-step define as a character
53      CHARACTER(len=50)   ::   clname   ! ice output restart file name
54      CHARACTER(len=256)  ::   clpath   ! full path to ice output restart file
55      !!----------------------------------------------------------------------
56      !
57      IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
58
59      ! in order to get better performances with NetCDF format, we open and define the ice restart file
60      ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice
61      ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
62      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nstock == nn_fsbc    &
63         &                             .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
64         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
65            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
66            IF ( ln_rstdate ) THEN
67               zfjulday = fjulday + (2*nn_fsbc+1)*rdt / rday
68               IF( ABS(zfjulday - REAL(NINT(zfjulday),wp)) < 0.1 / rday )   zfjulday = REAL(NINT(zfjulday),wp)   ! avoid truncation error
69               CALL ju2ymds( zfjulday, iyear, imonth, iday, zsec )           
70               WRITE(clkt, '(i4.4,2i2.2)') iyear, imonth, iday
71            ELSE
72               IF( nitrst > 99999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
73               ELSE                           ;   WRITE(clkt, '(i8.8)') nitrst
74               ENDIF
75            ENDIF
76            ! create the file
77            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out)
78            clpath = TRIM(cn_icerst_outdir) 
79            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/'
80            IF(lwp) THEN
81               WRITE(numout,*)
82               WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
83               IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN
84                  WRITE(numout,*) '             kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp
85               ELSE
86                  WRITE(numout,*) '             kt = '                         , kt,' date= ', ndastp
87               ENDIF
88            ENDIF
89            !
90            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl )
91            lrst_ice = .TRUE.
92         ENDIF
93      ENDIF
94      !
95      IF( ln_icectl )   CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
96      !
97   END SUBROUTINE ice_rst_opn
98
99
100   SUBROUTINE ice_rst_write( kt )
101      !!----------------------------------------------------------------------
102      !!                    ***  ice_rst_write  ***
103      !!
104      !! ** purpose  :   write restart file
105      !!----------------------------------------------------------------------
106      INTEGER, INTENT(in) ::   kt     ! number of iteration
107      !!
108      INTEGER ::   jk    ! dummy loop indices
109      INTEGER ::   iter
110      CHARACTER(len=25) ::   znam
111      CHARACTER(len=2)  ::   zchar, zchar1
112      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
113      !!----------------------------------------------------------------------
114
115      iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
116
117      IF( iter == nitrst ) THEN
118         IF(lwp) WRITE(numout,*)
119         IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file  kt =', kt
120         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'         
121      ENDIF
122
123      ! Write in numriw (if iter == nitrst)
124      ! ------------------
125      !                                                                        ! calendar control
126      CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) )      ! time-step
127      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
128      CALL iom_delay_rst( 'WRITE', 'ICE', numriw )   ! save only ice delayed global communication variables
129
130      ! Prognostic variables
131      CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i  )
132      CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s  )
133      CALL iom_rstput( iter, nitrst, numriw, 'sv_i', sv_i )
134      CALL iom_rstput( iter, nitrst, numriw, 'oa_i', oa_i )
135      CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i  )
136      CALL iom_rstput( iter, nitrst, numriw, 't_su', t_su )
137      ! Melt ponds
138      CALL iom_rstput( iter, nitrst, numriw, 'a_ip', a_ip )
139      CALL iom_rstput( iter, nitrst, numriw, 'v_ip', v_ip )
140      ! Snow enthalpy
141      DO jk = 1, nlay_s 
142         WRITE(zchar1,'(I2.2)') jk
143         znam = 'e_s'//'_l'//zchar1
144         z3d(:,:,:) = e_s(:,:,jk,:)
145         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
146      END DO
147      ! Ice enthalpy
148      DO jk = 1, nlay_i 
149         WRITE(zchar1,'(I2.2)') jk
150         znam = 'e_i'//'_l'//zchar1
151         z3d(:,:,:) = e_i(:,:,jk,:)
152         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
153      END DO
154      ! ice velocity
155      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice
156      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice
157      ! fields needed for Met Office (Jules) coupling
158      IF( ln_cpl ) THEN
159         CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice )
160         CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice  )
161      ENDIF
162      !
163
164      ! close restart file
165      ! ------------------
166      IF( iter == nitrst ) THEN
167         CALL iom_close( numriw )
168         lrst_ice = .FALSE.
169      ENDIF
170      !
171   END SUBROUTINE ice_rst_write
172
173
174   SUBROUTINE ice_rst_read
175      !!----------------------------------------------------------------------
176      !!                    ***  ice_rst_read  ***
177      !!
178      !! ** purpose  :   read restart file
179      !!----------------------------------------------------------------------
180      INTEGER           ::   jk
181      LOGICAL           ::   llok
182      INTEGER           ::   id1            ! local integer
183      CHARACTER(len=25) ::   znam
184      CHARACTER(len=2)  ::   zchar, zchar1
185      REAL(wp)          ::   zfice, ziter
186      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
187      !!----------------------------------------------------------------------
188
189      IF(lwp) THEN
190         WRITE(numout,*)
191         WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file'
192         WRITE(numout,*) '~~~~~~~~~~~~'
193      ENDIF
194
195      CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kdlev = jpl )
196
197      CALL iom_get( numrir, 'nn_fsbc', zfice )
198      CALL iom_get( numrir, 'kt_ice' , ziter )   
199      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
200      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
201
202      ! Control of date
203      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
204         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
205         &                   '   verify the file or rerun with the value 0 for the',        &
206         &                   '   control of time parameter  nrstdt' )
207      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
208         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
209         &                   '   verify the file or rerun with the value 0 for the',         &
210         &                   '   control of time parameter  nrstdt' )
211
212      ! Prognostic variables
213      CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i  )
214      CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s  )
215      CALL iom_get( numrir, jpdom_autoglo, 'sv_i', sv_i )
216      CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i )
217      CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i  )
218      CALL iom_get( numrir, jpdom_autoglo, 't_su', t_su )
219      ! Melt ponds
220      id1 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. )
221      IF( id1 > 0 ) THEN                       ! fields exist (melt ponds)
222         CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip )
223         CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip )
224      ELSE                                     ! start from rest
225         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
226         a_ip(:,:,:) = 0._wp
227         v_ip(:,:,:) = 0._wp
228      ENDIF
229      ! Snow enthalpy
230      DO jk = 1, nlay_s
231         WRITE(zchar1,'(I2.2)') jk
232         znam = 'e_s'//'_l'//zchar1
233         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
234         e_s(:,:,jk,:) = z3d(:,:,:)
235      END DO
236      ! Ice enthalpy
237      DO jk = 1, nlay_i
238         WRITE(zchar1,'(I2.2)') jk
239         znam = 'e_i'//'_l'//zchar1
240         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
241         e_i(:,:,jk,:) = z3d(:,:,:)
242      END DO
243      ! ice velocity
244      CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
245      CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
246
247      CALL iom_delay_rst( 'READ', 'ICE', numrir )   ! read only ice delayed global communication variables
248
249      ! fields needed for Met Office (Jules) coupling
250      IF( ln_cpl ) THEN
251         CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice )
252         CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice  )
253      ENDIF
254
255   END SUBROUTINE ice_rst_read
256
257#else
258   !!----------------------------------------------------------------------
259   !!   Default option :       Empty module           NO SI3 sea-ice model
260   !!----------------------------------------------------------------------
261#endif
262
263   !!======================================================================
264END MODULE icerst
Note: See TracBrowser for help on using the repository browser.