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.
restart.F90 in branches/UKMO/dev_merge_2017_CICE_interface/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: branches/UKMO/dev_merge_2017_CICE_interface/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90 @ 9499

Last change on this file since 9499 was 9499, checked in by davestorkey, 6 years ago

branches/UKMO/dev_merge_2017_CICE_interface : clear SVN keywords.

File size: 15.7 KB
RevLine 
[3]1MODULE restart
2   !!======================================================================
3   !!                     ***  MODULE  restart  ***
4   !! Ocean restart :  write the ocean restart file
[508]5   !!======================================================================
[2528]6   !! History :  OPA  !  1999-11  (M. Imbard)  Original code
7   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form
8   !!            2.0  !  2006-07  (S. Masson)  use IOM for restart
9   !!            3.3  !  2010-04  (M. Leclair, G. Madec)  modified LF-RA
10   !!            - -  !  2010-10  (C. Ethe, G. Madec) TRC-TRA merge (T-S in 4D)
[5836]11   !!            3.7  !  2014-01  (G. Madec) suppression of curl and hdiv from the restart
12   !!             -   !  2014-12  (G. Madec) remove KPP scheme
[508]13   !!----------------------------------------------------------------------
[3]14
15   !!----------------------------------------------------------------------
[508]16   !!   rst_opn    : open the ocean restart file
17   !!   rst_write  : write the ocean restart file
18   !!   rst_read   : read the ocean restart file
[3]19   !!----------------------------------------------------------------------
[2528]20   USE oce             ! ocean dynamics and tracers
[3]21   USE dom_oce         ! ocean space and time domain
[5836]22   USE sbc_ice         ! only lk_lim3
[3]23   USE phycst          ! physical constants
[5836]24   USE eosbn2          ! equation of state            (eos bn2 routine)
25   USE trdmxl_oce      ! ocean active mixed layer tracers trends variables
26   !
[508]27   USE in_out_manager  ! I/O manager
28   USE iom             ! I/O module
[6140]29   USE diurnal_bulk
[9367]30
[3]31   IMPLICIT NONE
32   PRIVATE
33
[4292]34   PUBLIC   rst_opn         ! routine called by step module
35   PUBLIC   rst_write       ! routine called by step module
36   PUBLIC   rst_read        ! routine called by istate module
37   PUBLIC   rst_read_open   ! routine called in rst_read and (possibly) in dom_vvl_init
[3]38
[508]39   !! * Substitutions
40#  include "vectopt_loop_substitute.h90"
[3]41   !!----------------------------------------------------------------------
[2528]42   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
[888]43   !! $Id$
[2528]44   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
[359]45   !!----------------------------------------------------------------------
[3]46CONTAINS
47
[508]48   SUBROUTINE rst_opn( kt )
49      !!---------------------------------------------------------------------
50      !!                   ***  ROUTINE rst_opn  ***
51      !!                     
52      !! ** Purpose : + initialization (should be read in the namelist) of nitrst
53      !!              + open the restart when we are one time step before nitrst
54      !!                   - restart header is defined when kt = nitrst-1
55      !!                   - restart data  are written when kt = nitrst
56      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
57      !!----------------------------------------------------------------------
58      INTEGER, INTENT(in) ::   kt     ! ocean time-step
59      !!
60      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
[5341]61      CHARACTER(LEN=50)   ::   clname   ! ocean output restart file name
62      CHARACTER(lc)       ::   clpath   ! full path to ocean output restart file
[9367]63      CHARACTER(LEN=52)   ::   clpname   ! ocean output restart file name including prefix for AGRIF
[508]64      !!----------------------------------------------------------------------
65      !
[783]66      IF( kt == nit000 ) THEN   ! default definitions
67         lrst_oce = .FALSE.   
[5341]68         IF( ln_rst_list ) THEN
69            nrst_lst = 1
70            nitrst = nstocklist( nrst_lst )
71         ELSE
72            nitrst = nitend
73         ENDIF
[508]74      ENDIF
[5341]75
76      ! frequency-based restart dumping (nn_stock)
77      IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN   
[783]78         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
79         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
80         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
81      ENDIF
82      ! to get better performances with NetCDF format:
83      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
84      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
85      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
[5341]86         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN 
87            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
88            IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
89            ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
[611]90            ENDIF
[5341]91            ! create the file
92            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
93            clpath = TRIM(cn_ocerst_outdir)
94            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
95            IF(lwp) THEN
96               WRITE(numout,*)
[9367]97               IF(.NOT.lwxios) THEN
98                  SELECT CASE ( jprstlib )
99                  CASE DEFAULT         ;   WRITE(numout,*)                            &
100                      '             open ocean restart NetCDF file: ',TRIM(clpath)//TRIM(clname)
101                  END SELECT
102                  IF ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
103                  IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
104                  ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
105                  ENDIF
[5341]106               ENDIF
107            ENDIF
108            !
[9367]109            IF(.NOT.lwxios) THEN
110               CALL iom_open( TRIM(clpath)//TRIM(clname), numrow, ldwrt = .TRUE., kiolib = jprstlib )
111            ELSE
112               cwxios_context = "rstw_"//TRIM(ADJUSTL(clkt))
113               IF( TRIM(Agrif_CFixed()) == '0' ) THEN
114                  clpname = clname
115               ELSE
116                  clpname = TRIM(Agrif_CFixed())//"_"//clname   
117               ENDIF
118               CALL iom_init( cwxios_context, TRIM(clpath)//TRIM(clpname))
119               CALL xios_update_calendar(nitrst)
120               CALL iom_swap(      cxios_context          )
121            ENDIF
[5341]122            lrst_oce = .TRUE.
[611]123         ENDIF
[508]124      ENDIF
125      !
126   END SUBROUTINE rst_opn
127
128
[3]129   SUBROUTINE rst_write( kt )
130      !!---------------------------------------------------------------------
131      !!                   ***  ROUTINE rstwrite  ***
132      !!                     
[632]133      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
[3]134      !!
[508]135      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
[2528]136      !!              file, save fields which are necessary for restart
[3]137      !!----------------------------------------------------------------------
[508]138      INTEGER, INTENT(in) ::   kt   ! ocean time-step
[3]139      !!----------------------------------------------------------------------
[9367]140                     IF(lwxios) CALL iom_swap(      cwxios_context          )
141                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       , ldxios = lwxios)   ! dynamics time step
[1239]142
[6140]143      IF ( .NOT. ln_diurnal_only ) THEN
[9367]144                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub, ldxios = lwxios        )     ! before fields
145                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb, ldxios = lwxios        )
146                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tsb(:,:,:,jp_tem), ldxios = lwxios )
147                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , tsb(:,:,:,jp_sal), ldxios = lwxios )
148                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb, ldxios = lwxios      )
[4990]149                     !
[9367]150                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , un, ldxios = lwxios        )     ! now fields
151                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn, ldxios = lwxios        )
152                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tsn(:,:,:,jp_tem), ldxios = lwxios )
153                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , tsn(:,:,:,jp_sal), ldxios = lwxios )
154                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , sshn, ldxios = lwxios      )
155                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop, ldxios = lwxios      )
[6140]156                  ! extra variable needed for the ice sheet coupling
157                  IF ( ln_iscpl ) THEN
[9367]158                     CALL iom_rstput( kt, nitrst, numrow, 'tmask'  , tmask, ldxios = lwxios ) ! need to extrapolate T/S
159                     CALL iom_rstput( kt, nitrst, numrow, 'umask'  , umask, ldxios = lwxios ) ! need to correct barotropic velocity
160                     CALL iom_rstput( kt, nitrst, numrow, 'vmask'  , vmask, ldxios = lwxios ) ! need to correct barotropic velocity
161                     CALL iom_rstput( kt, nitrst, numrow, 'smask'  , ssmask, ldxios = lwxios) ! need to correct barotropic velocity
162                     CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t_n(:,:,:), ldxios = lwxios )   ! need to compute temperature correction
163                     CALL iom_rstput( kt, nitrst, numrow, 'e3u_n', e3u_n(:,:,:), ldxios = lwxios )   ! need to compute bt conservation
164                     CALL iom_rstput( kt, nitrst, numrow, 'e3v_n', e3v_n(:,:,:), ldxios = lwxios )   ! need to compute bt conservation
165                     CALL iom_rstput( kt, nitrst, numrow, 'gdepw_n', gdepw_n(:,:,:), ldxios = lwxios ) ! need to compute extrapolation if vvl
[6140]166                  END IF
167      ENDIF
168     
[9367]169      IF (ln_diurnal) CALL iom_rstput( kt, nitrst, numrow, 'Dsst', x_dsst, ldxios = lwxios ) 
170      IF(lwxios) CALL iom_swap(      cxios_context          )
[508]171      IF( kt == nitrst ) THEN
[9367]172         IF(.NOT.lwxios) THEN
173            CALL iom_close( numrow )     ! close the restart file (only at last time step)
174         ELSE
175            CALL iom_context_finalize(      cwxios_context          )
176         ENDIF
[4990]177!!gm         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
178!!gm  not sure what to do here   ===>>>  ask to Sebastian
179         lrst_oce = .FALSE.
[5341]180            IF( ln_rst_list ) THEN
181               nrst_lst = MIN(nrst_lst + 1, SIZE(nstocklist,1))
182               nitrst = nstocklist( nrst_lst )
183            ENDIF
[3]184      ENDIF
[508]185      !
[3]186   END SUBROUTINE rst_write
187
[4990]188
[4292]189   SUBROUTINE rst_read_open
190      !!----------------------------------------------------------------------
191      !!                   ***  ROUTINE rst_read_open  ***
192      !!
193      !! ** Purpose :   Open read files for restart (format fixed by jprstlib )
194      !!
195      !! ** Method  :   Use a non-zero, positive value of numror to assess whether or not
196      !!                the file has already been opened
197      !!----------------------------------------------------------------------
[5341]198      INTEGER        ::   jlibalt = jprstlib
199      LOGICAL        ::   llok
200      CHARACTER(lc)  ::   clpath   ! full path to ocean output restart file
[4292]201      !!----------------------------------------------------------------------
[4990]202      !
203      IF( numror <= 0 ) THEN
[4292]204         IF(lwp) THEN                                             ! Contol prints
205            WRITE(numout,*)
206            SELECT CASE ( jprstlib )
207            CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
208            END SELECT
209            IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
210            WRITE(numout,*) '~~~~~~~~'
211         ENDIF
[9367]212         lxios_sini = .FALSE.
[5341]213         clpath = TRIM(cn_ocerst_indir)
214         IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
215         CALL iom_open( TRIM(clpath)//cn_ocerst_in, numror, kiolib = jlibalt )
[9367]216! are we using XIOS to read the data? Part above will have to modified once XIOS
217! can handle checking if variable is in the restart file (there will be no need to open
218! restart)
219         IF(.NOT.lxios_set) lrxios = lrxios.AND.lxios_sini
220         IF( lrxios) THEN
221             crxios_context = 'nemo_rst'
222             IF( .NOT.lxios_set ) THEN
223                 IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS'
224                 CALL iom_init( crxios_context )
225                 lxios_set = .TRUE.
226             ENDIF
227         ENDIF
228         IF( TRIM(Agrif_CFixed()) /= '0' .AND. lrxios) THEN
229             CALL iom_init( crxios_context )
230             IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for AGRIF'
231             lxios_set = .TRUE.
232         ENDIF
[4292]233      ENDIF
[9367]234
[4292]235   END SUBROUTINE rst_read_open
236
[5836]237
[3]238   SUBROUTINE rst_read
239      !!----------------------------------------------------------------------
240      !!                   ***  ROUTINE rst_read  ***
241      !!
[632]242      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
[3]243      !!
[1531]244      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
[3]245      !!----------------------------------------------------------------------
[6140]246      REAL(wp) ::   zrdt
[4292]247      INTEGER  ::   jk
[9367]248      REAL(wp), DIMENSION(jpi, jpj, jpk) :: w3d
[3]249      !!----------------------------------------------------------------------
250
[4292]251      CALL rst_read_open           ! open restart for reading (if not already opened)
[3]252
[544]253      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
[746]254      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
[9367]255         CALL iom_get( numror, 'rdt', zrdt, ldxios = lrxios )
[544]256         IF( zrdt /= rdt )   neuler = 0
257      ENDIF
[6140]258
259      ! Diurnal DSST
[9367]260      IF( ln_diurnal ) CALL iom_get( numror, jpdom_autoglo, 'Dsst' , x_dsst, ldxios = lrxios ) 
[6140]261      IF ( ln_diurnal_only ) THEN
262         IF(lwp) WRITE( numout, * ) &
263         &   "rst_read:- ln_diurnal_only set, setting rhop=rau0" 
264         rhop = rau0
[9367]265         CALL iom_get( numror, jpdom_autoglo, 'tn'     , w3d, ldxios = lrxios ) 
266         tsn(:,:,1,jp_tem) = w3d(:,:,1)
[6140]267         RETURN
268      ENDIF 
269     
[3680]270      IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
[9367]271         CALL iom_get( numror, jpdom_autoglo, 'ub'     , ub, ldxios = lrxios                )   ! before fields
272         CALL iom_get( numror, jpdom_autoglo, 'vb'     , vb, ldxios = lrxios                )
273         CALL iom_get( numror, jpdom_autoglo, 'tb'     , tsb(:,:,:,jp_tem), ldxios = lrxios )
274         CALL iom_get( numror, jpdom_autoglo, 'sb'     , tsb(:,:,:,jp_sal), ldxios = lrxios )
275         CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb, ldxios = lrxios              )
[3680]276      ELSE
277         neuler = 0
278      ENDIF
279      !
[9367]280      CALL iom_get( numror, jpdom_autoglo, 'un'     , un, ldxios = lrxios )   ! now    fields
281      CALL iom_get( numror, jpdom_autoglo, 'vn'     , vn, ldxios = lrxios )
282      CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,:,jp_tem), ldxios = lrxios )
283      CALL iom_get( numror, jpdom_autoglo, 'sn'     , tsn(:,:,:,jp_sal), ldxios = lrxios )
284      CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn, ldxios = lrxios )
[3680]285      IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN
[9367]286         CALL iom_get( numror, jpdom_autoglo, 'rhop'   , rhop, ldxios = lrxios )   ! now    potential density
[3680]287      ELSE
[6140]288         CALL eos( tsn, rhd, rhop, gdept_n(:,:,:) )   
[3680]289      ENDIF
[2528]290      !
[508]291      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
[3294]292         tsb  (:,:,:,:) = tsn  (:,:,:,:)                             ! all before fields set to now values
293         ub   (:,:,:)   = un   (:,:,:)
294         vb   (:,:,:)   = vn   (:,:,:)
295         sshb (:,:)     = sshn (:,:)
[5836]296         !
[6140]297         IF( .NOT.ln_linssh ) THEN
[4689]298            DO jk = 1, jpk
[6140]299               e3t_b(:,:,jk) = e3t_n(:,:,jk)
[4689]300            END DO
301         ENDIF
[5836]302         !
[3]303      ENDIF
[508]304      !
305   END SUBROUTINE rst_read
[473]306
[3]307   !!=====================================================================
308END MODULE restart
Note: See TracBrowser for help on using the repository browser.