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

source: NEMO/branches/UKMO/dev_r9950_GO8_package/src/ICE/icerst.F90 @ 10326

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

UKMO/dev_r9950_GO8_package: clear SVN keywords.

File size: 11.6 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               SELECT CASE ( jprstlib )
83               CASE DEFAULT
84                  WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
85               END SELECT
86               IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN
87                  WRITE(numout,*) '             kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp
88               ELSE
89                  WRITE(numout,*) '             kt = '                         , kt,' date= ', ndastp
90               ENDIF
91            ENDIF
92            !
93            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kiolib = jprstlib, kdlev = jpl )
94            lrst_ice = .TRUE.
95         ENDIF
96      ENDIF
97      !
98      IF( ln_icectl )   CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
99      !
100   END SUBROUTINE ice_rst_opn
101
102
103   SUBROUTINE ice_rst_write( kt )
104      !!----------------------------------------------------------------------
105      !!                    ***  ice_rst_write  ***
106      !!
107      !! ** purpose  :   write restart file
108      !!----------------------------------------------------------------------
109      INTEGER, INTENT(in) ::   kt     ! number of iteration
110      !!
111      INTEGER ::   jk ,jl   ! dummy loop indices
112      INTEGER ::   iter
113      CHARACTER(len=25) ::   znam
114      CHARACTER(len=2)  ::   zchar, zchar1
115      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
116      !!----------------------------------------------------------------------
117
118      iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
119
120      IF( iter == nitrst ) THEN
121         IF(lwp) WRITE(numout,*)
122         IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file  kt =', kt
123         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'         
124      ENDIF
125
126      ! Write in numriw (if iter == nitrst)
127      ! ------------------
128      !                                                                        ! calendar control
129      CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) )      ! time-step
130      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
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, 'oa_i', oa_i )
137      CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i  )
138      CALL iom_rstput( iter, nitrst, numriw, 't_su', t_su )
139      ! Melt ponds
140      CALL iom_rstput( iter, nitrst, numriw, 'a_ip', a_ip )
141      CALL iom_rstput( iter, nitrst, numriw, 'v_ip', v_ip )
142      ! Snow enthalpy
143      DO jk = 1, nlay_s 
144         WRITE(zchar1,'(I2.2)') jk
145         znam = 'e_s'//'_l'//zchar1
146         z3d(:,:,:) = e_s(:,:,jk,:)
147         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
148      END DO
149      ! Ice enthalpy
150      DO jk = 1, nlay_i 
151         WRITE(zchar1,'(I2.2)') jk
152         znam = 'e_i'//'_l'//zchar1
153         z3d(:,:,:) = e_i(:,:,jk,:)
154         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
155      END DO
156      ! ice velocity
157      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice
158      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice
159      ! fields needed for Met Office (Jules) coupling
160      IF( ln_cpl ) THEN
161         CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice )
162         CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice  )
163      ENDIF
164      !
165
166      ! close restart file
167      ! ------------------
168      IF( iter == nitrst ) THEN
169         CALL iom_close( numriw )
170         lrst_ice = .FALSE.
171      ENDIF
172      !
173   END SUBROUTINE ice_rst_write
174
175
176   SUBROUTINE ice_rst_read
177      !!----------------------------------------------------------------------
178      !!                    ***  ice_rst_read  ***
179      !!
180      !! ** purpose  :   read restart file
181      !!----------------------------------------------------------------------
182      INTEGER           ::   jk, jl
183      LOGICAL           ::   llok
184      INTEGER           ::   id1            ! local integer
185      INTEGER           ::   jlibalt = jprstlib
186      CHARACTER(len=25) ::   znam
187      CHARACTER(len=2)  ::   zchar, zchar1
188      REAL(wp)          ::   zfice, ziter
189      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
190      !!----------------------------------------------------------------------
191
192      IF(lwp) THEN
193         WRITE(numout,*)
194         WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file'
195         WRITE(numout,*) '~~~~~~~~~~~~'
196      ENDIF
197
198      CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib, kdlev = jpl )
199
200      CALL iom_get( numrir, 'nn_fsbc', zfice )
201      CALL iom_get( numrir, 'kt_ice' , ziter )   
202      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
203      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
204
205      ! Control of date
206      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
207         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
208         &                   '   verify the file or rerun with the value 0 for the',        &
209         &                   '   control of time parameter  nrstdt' )
210      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
211         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
212         &                   '   verify the file or rerun with the value 0 for the',         &
213         &                   '   control of time parameter  nrstdt' )
214
215      ! Prognostic variables
216      CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i  )
217      CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s  )
218      CALL iom_get( numrir, jpdom_autoglo, 'sv_i', sv_i )
219      CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i )
220      CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i  )
221      CALL iom_get( numrir, jpdom_autoglo, 't_su', t_su )
222      ! Melt ponds
223      id1 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. )
224      IF( id1 > 0 ) THEN                       ! fields exist (melt ponds)
225         CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip )
226         CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip )
227      ELSE                                     ! start from rest
228         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
229         a_ip(:,:,:) = 0._wp
230         v_ip(:,:,:) = 0._wp
231      ENDIF
232      ! Snow enthalpy
233      DO jk = 1, nlay_s
234         WRITE(zchar1,'(I2.2)') jk
235         znam = 'e_s'//'_l'//zchar1
236         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
237         e_s(:,:,jk,:) = z3d(:,:,:)
238      END DO
239      ! Ice enthalpy
240      DO jk = 1, nlay_i
241         WRITE(zchar1,'(I2.2)') jk
242         znam = 'e_i'//'_l'//zchar1
243         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
244         e_i(:,:,jk,:) = z3d(:,:,:)
245      END DO
246      ! ice velocity
247      CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
248      CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
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.