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 branches/UKMO/dev_r8183_ICEMODEL_svn_removed/NEMOGCM/NEMO/LIM_SRC_3 – NEMO

source: branches/UKMO/dev_r8183_ICEMODEL_svn_removed/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90 @ 8781

Last change on this file since 8781 was 8781, checked in by clem, 6 years ago

make Jules coupling restartable by adding cnd_ice and t1_ice into restart file

File size: 12.8 KB
Line 
1MODULE icerst
2   !!======================================================================
3   !!                     ***  MODULE  icerst  ***
4   !!   sea-ice :  write/read the ice restart file
5   !!======================================================================
6   !! History:   3.0  ! 2005-04 (M. Vancoppenolle) Original code
7   !!             -   ! 2008-03 (C. Ethe) restart files in using IOM interface
8   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
9   !!----------------------------------------------------------------------
10#if defined key_lim3
11   !!----------------------------------------------------------------------
12   !!   'key_lim3'                                       ESIM sea-ice model
13   !!----------------------------------------------------------------------
14   !!   ice_rst_opn   : open  restart file
15   !!   ice_rst_write : write restart file
16   !!   ice_rst_read  : read  restart file
17   !!----------------------------------------------------------------------
18   USE ice            ! sea-ice variables
19   USE dom_oce        ! ocean domain
20   USE sbc_oce , ONLY : nn_fsbc
21   USE icectl
22   !
23   USE in_out_manager ! I/O manager
24   USE iom            ! I/O manager library
25   USE lib_mpp        ! MPP library
26   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
27
28   IMPLICIT NONE
29   PRIVATE
30
31   PUBLIC   ice_rst_opn     ! called by icestp
32   PUBLIC   ice_rst_write   ! called by icestp
33   PUBLIC   ice_rst_read    ! called by ice_init
34
35   !!----------------------------------------------------------------------
36   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
37   !! $Id: icerst.F90 8411 2017-08-07 16:09:12Z clem $
38   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
39   !!----------------------------------------------------------------------
40CONTAINS
41
42   SUBROUTINE ice_rst_opn( kt )
43      !!----------------------------------------------------------------------
44      !!                    ***  ice_rst_opn  ***
45      !!
46      !! ** purpose  :   open restart file
47      !!----------------------------------------------------------------------
48      INTEGER, INTENT(in) ::   kt       ! number of iteration
49      !
50      CHARACTER(len=20)   ::   clkt     ! ocean time-step define as a character
51      CHARACTER(len=50)   ::   clname   ! ice output restart file name
52      CHARACTER(len=256)  ::   clpath   ! full path to ice output restart file
53      !!----------------------------------------------------------------------
54      !
55      IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
56
57      ! in order to get better performances with NetCDF format, we open and define the ice restart file
58      ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice
59      ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
60      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nstock == nn_fsbc    &
61         &                             .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
62         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
63            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
64            IF( nitrst > 99999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
65            ELSE                           ;   WRITE(clkt, '(i8.8)') nitrst
66            ENDIF
67            ! create the file
68            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out)
69            clpath = TRIM(cn_icerst_outdir) 
70            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/'
71            IF(lwp) THEN
72               WRITE(numout,*)
73               SELECT CASE ( jprstlib )
74               CASE DEFAULT
75                  WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
76               END SELECT
77               IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN
78                  WRITE(numout,*) '             kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp
79               ELSE
80                  WRITE(numout,*) '             kt = '                         , kt,' date= ', ndastp
81               ENDIF
82            ENDIF
83            !
84            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kiolib = jprstlib )
85            lrst_ice = .TRUE.
86         ENDIF
87      ENDIF
88      !
89      IF( ln_icectl )   CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
90   END SUBROUTINE ice_rst_opn
91
92
93   SUBROUTINE ice_rst_write( kt )
94      !!----------------------------------------------------------------------
95      !!                    ***  ice_rst_write  ***
96      !!
97      !! ** purpose  :   write restart file
98      !!----------------------------------------------------------------------
99      INTEGER, INTENT(in) ::   kt     ! number of iteration
100      !!
101      INTEGER ::   jk ,jl   ! dummy loop indices
102      INTEGER ::   iter
103      CHARACTER(len=25) ::   znam
104      CHARACTER(len=2)  ::   zchar, zchar1
105      REAL(wp), DIMENSION(jpi,jpj) :: z2d
106      !!----------------------------------------------------------------------
107
108      iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
109
110      IF( iter == nitrst ) THEN
111         IF(lwp) WRITE(numout,*)
112         IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file  kt =', kt
113         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'         
114      ENDIF
115
116      ! Write in numriw (if iter == nitrst)
117      ! ------------------
118      !                                                                        ! calendar control
119      CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) )      ! time-step
120      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
121
122!!gm   It is possible and easy to define a 3D domain size (jpi,jpj,jpl) or use a SIZE( tab, DIM=3) in iom_rtput )
123!!gm         ===>>> just a simple   iom_rstput( iter, nitrst, numriw, 'v_i', v_i )  etc...
124!!gm   "just" ask Sebatien
125
126      ! Prognostic variables
127      DO jl = 1, jpl 
128         WRITE(zchar,'(I2.2)') jl
129         znam = 'v_i'//'_htc'//zchar
130         z2d(:,:) = v_i(:,:,jl)
131         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! v_i
132         znam = 'v_s'//'_htc'//zchar
133         z2d(:,:) = v_s(:,:,jl)
134         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! v_s
135         znam = 'sv_i'//'_htc'//zchar
136         z2d(:,:) = sv_i(:,:,jl)
137         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! sv_i
138         znam = 'oa_i'//'_htc'//zchar
139         z2d(:,:) = oa_i(:,:,jl)
140         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! oa_i
141         znam = 'a_i'//'_htc'//zchar
142         z2d(:,:) = a_i(:,:,jl)
143         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! a_i
144         znam = 't_su'//'_htc'//zchar
145         z2d(:,:) = t_su(:,:,jl)
146         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! t_su
147         znam = 'cnd_ice'//'_htc'//zchar
148         z2d(:,:) = cnd_ice(:,:,jl)
149         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! cnd_ice
150         znam = 't1_ice'//'_htc'//zchar
151         z2d(:,:) = t1_ice(:,:,jl)
152         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! t1_ice
153      END DO
154
155      DO jl = 1, jpl 
156         WRITE(zchar,'(I2.2)') jl
157         znam = 'a_ip'//'_htc'//zchar
158         z2d(:,:) = a_ip(:,:,jl)
159         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! a_ip
160         znam = 'v_ip'//'_htc'//zchar
161         z2d(:,:) = v_ip(:,:,jl)
162         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! v_ip
163      END DO
164
165      DO jl = 1, jpl 
166         WRITE(zchar,'(I2.2)') jl
167         znam = 'tempt_sl1'//'_htc'//zchar
168         z2d(:,:) = e_s(:,:,1,jl)
169         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! e_s
170         DO jk = 1, nlay_i 
171            WRITE(zchar1,'(I2.2)') jk
172            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
173            z2d(:,:) = e_i(:,:,jk,jl)
174            CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! e_i
175         END DO
176      END DO
177
178      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice
179      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice
180     
181      ! close restart file
182      ! ------------------
183      IF( iter == nitrst ) THEN
184         CALL iom_close( numriw )
185         lrst_ice = .FALSE.
186      ENDIF
187      !
188   END SUBROUTINE ice_rst_write
189
190
191   SUBROUTINE ice_rst_read
192      !!----------------------------------------------------------------------
193      !!                    ***  ice_rst_read  ***
194      !!
195      !! ** purpose  :   read restart file
196      !!----------------------------------------------------------------------
197      INTEGER  ::   jk, jl
198      INTEGER  ::   id1            ! local integer
199      REAL(wp) ::   zfice, ziter
200      REAL(wp), DIMENSION(jpi,jpj) ::   z2d
201      CHARACTER(len=25) ::   znam
202      CHARACTER(len=2)  ::   zchar, zchar1
203      INTEGER           ::   jlibalt = jprstlib
204      LOGICAL           ::   llok
205      !!----------------------------------------------------------------------
206
207      IF(lwp) THEN
208         WRITE(numout,*)
209         WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file'
210         WRITE(numout,*) '~~~~~~~~~~~~'
211      ENDIF
212
213      CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib )
214
215      CALL iom_get( numrir, 'nn_fsbc', zfice )
216      CALL iom_get( numrir, 'kt_ice' , ziter )   
217      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
218      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
219
220      ! Control of date
221      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
222         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
223         &                   '   verify the file or rerun with the value 0 for the',        &
224         &                   '   control of time parameter  nrstdt' )
225      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
226         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
227         &                   '   verify the file or rerun with the value 0 for the',         &
228         &                   '   control of time parameter  nrstdt' )
229
230      ! Prognostic variables
231      DO jl = 1, jpl 
232         WRITE(zchar,'(I2.2)') jl
233         znam = 'v_i'//'_htc'//zchar
234         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
235         v_i(:,:,jl) = z2d(:,:)
236         znam = 'v_s'//'_htc'//zchar
237         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
238         v_s(:,:,jl) = z2d(:,:) 
239         znam = 'sv_i'//'_htc'//zchar
240         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
241         sv_i(:,:,jl) = z2d(:,:)
242         znam = 'oa_i'//'_htc'//zchar
243         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
244         oa_i(:,:,jl) = z2d(:,:)
245         znam = 'a_i'//'_htc'//zchar
246         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
247         a_i(:,:,jl) = z2d(:,:)
248         znam = 't_su'//'_htc'//zchar
249         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
250         t_su(:,:,jl) = z2d(:,:)
251         znam = 'cnd_ice'//'_htc'//zchar
252         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
253         cnd_ice(:,:,jl) = z2d(:,:)
254         znam = 't1_ice'//'_htc'//zchar
255         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
256         t1_ice(:,:,jl) = z2d(:,:)
257      END DO
258
259      id1 = iom_varid( numrir, 'a_ip_htc01' , ldstop = .FALSE. )
260      IF( id1 > 0 ) THEN                       ! fields exist (melt ponds)
261         DO jl = 1, jpl 
262            WRITE(zchar,'(I2.2)') jl
263            znam = 'a_ip'//'_htc'//zchar
264            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
265            a_ip(:,:,jl) = z2d(:,:)
266            znam = 'v_ip'//'_htc'//zchar
267            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
268            v_ip(:,:,jl) = z2d(:,:)
269         END DO
270      ELSE                                     ! start from rest
271         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it'
272         a_ip(:,:,:) = 0._wp
273         v_ip(:,:,:) = 0._wp
274      ENDIF
275
276      DO jl = 1, jpl 
277         WRITE(zchar,'(I2.2)') jl
278         znam = 'tempt_sl1'//'_htc'//zchar
279         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
280         e_s(:,:,1,jl) = z2d(:,:)
281         DO jk = 1, nlay_i 
282            WRITE(zchar1,'(I2.2)') jk
283            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
284            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
285            e_i(:,:,jk,jl) = z2d(:,:)
286         END DO
287      END DO
288
289      CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
290      CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
291
292   END SUBROUTINE ice_rst_read
293
294#else
295   !!----------------------------------------------------------------------
296   !!   Default option :       Empty module           NO ESIM sea-ice model
297   !!----------------------------------------------------------------------
298#endif
299
300   !!======================================================================
301END MODULE icerst
Note: See TracBrowser for help on using the repository browser.