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/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3 – NEMO

source: branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90 @ 8597

Last change on this file since 8597 was 8597, checked in by clem, 7 years ago

first step to make melt ponds compliant with the new code

File size: 12.3 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      END DO
148
149      DO jl = 1, jpl 
150         WRITE(zchar,'(I2.2)') jl
151         znam = 'a_ip'//'_htc'//zchar
152         z2d(:,:) = a_ip(:,:,jl)
153         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! a_ip
154         znam = 'v_ip'//'_htc'//zchar
155         z2d(:,:) = v_ip(:,:,jl)
156         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! v_ip
157      END DO
158
159      DO jl = 1, jpl 
160         WRITE(zchar,'(I2.2)') jl
161         znam = 'tempt_sl1'//'_htc'//zchar
162         z2d(:,:) = e_s(:,:,1,jl)
163         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! e_s
164         DO jk = 1, nlay_i 
165            WRITE(zchar1,'(I2.2)') jk
166            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
167            z2d(:,:) = e_i(:,:,jk,jl)
168            CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! e_i
169         END DO
170      END DO
171
172      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice
173      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice
174     
175      ! close restart file
176      ! ------------------
177      IF( iter == nitrst ) THEN
178         CALL iom_close( numriw )
179         lrst_ice = .FALSE.
180      ENDIF
181      !
182   END SUBROUTINE ice_rst_write
183
184
185   SUBROUTINE ice_rst_read
186      !!----------------------------------------------------------------------
187      !!                    ***  ice_rst_read  ***
188      !!
189      !! ** purpose  :   read restart file
190      !!----------------------------------------------------------------------
191      INTEGER  ::   jk, jl
192      INTEGER  ::   id1            ! local integer
193      REAL(wp) ::   zfice, ziter
194      REAL(wp), DIMENSION(jpi,jpj) ::   z2d
195      CHARACTER(len=25) ::   znam
196      CHARACTER(len=2)  ::   zchar, zchar1
197      INTEGER           ::   jlibalt = jprstlib
198      LOGICAL           ::   llok
199      !!----------------------------------------------------------------------
200
201      IF(lwp) THEN
202         WRITE(numout,*)
203         WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file'
204         WRITE(numout,*) '~~~~~~~~~~~~'
205      ENDIF
206
207      CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib )
208
209      CALL iom_get( numrir, 'nn_fsbc', zfice )
210      CALL iom_get( numrir, 'kt_ice' , ziter )   
211      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
212      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
213
214      ! Control of date
215      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
216         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
217         &                   '   verify the file or rerun with the value 0 for the',        &
218         &                   '   control of time parameter  nrstdt' )
219      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
220         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
221         &                   '   verify the file or rerun with the value 0 for the',         &
222         &                   '   control of time parameter  nrstdt' )
223
224      ! Prognostic variables
225      DO jl = 1, jpl 
226         WRITE(zchar,'(I2.2)') jl
227         znam = 'v_i'//'_htc'//zchar
228         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
229         v_i(:,:,jl) = z2d(:,:)
230         znam = 'v_s'//'_htc'//zchar
231         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
232         v_s(:,:,jl) = z2d(:,:) 
233         znam = 'sv_i'//'_htc'//zchar
234         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
235         sv_i(:,:,jl) = z2d(:,:)
236         znam = 'oa_i'//'_htc'//zchar
237         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
238         oa_i(:,:,jl) = z2d(:,:)
239         znam = 'a_i'//'_htc'//zchar
240         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
241         a_i(:,:,jl) = z2d(:,:)
242         znam = 't_su'//'_htc'//zchar
243         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
244         t_su(:,:,jl) = z2d(:,:)
245      END DO
246
247      id1 = iom_varid( numrir, 'a_ip_htc01' , ldstop = .FALSE. )
248      IF( id1 > 0 ) THEN                       ! fields exist (melt ponds)
249         DO jl = 1, jpl 
250            WRITE(zchar,'(I2.2)') jl
251            znam = 'a_ip'//'_htc'//zchar
252            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
253            a_ip(:,:,jl) = z2d(:,:)
254            znam = 'v_ip'//'_htc'//zchar
255            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
256            v_ip(:,:,jl) = z2d(:,:)
257         END DO
258      ELSE                                     ! start from rest
259         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it'
260         a_ip(:,:,:) = 0._wp
261         v_ip(:,:,:) = 0._wp
262      ENDIF
263
264      DO jl = 1, jpl 
265         WRITE(zchar,'(I2.2)') jl
266         znam = 'tempt_sl1'//'_htc'//zchar
267         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
268         e_s(:,:,1,jl) = z2d(:,:)
269         DO jk = 1, nlay_i 
270            WRITE(zchar1,'(I2.2)') jk
271            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
272            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
273            e_i(:,:,jk,jl) = z2d(:,:)
274         END DO
275      END DO
276
277      CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
278      CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
279
280   END SUBROUTINE ice_rst_read
281
282#else
283   !!----------------------------------------------------------------------
284   !!   Default option :       Empty module           NO ESIM sea-ice model
285   !!----------------------------------------------------------------------
286#endif
287
288   !!======================================================================
289END MODULE icerst
Note: See TracBrowser for help on using the repository browser.