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 @ 8518

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

changes in style - part6 - commits of the day

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