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/2014_Surge_Modelling/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: branches/UKMO/2014_Surge_Modelling/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90 @ 5750

Last change on this file since 5750 was 5750, checked in by rfurner, 9 years ago

changes to add restart directory names

  • Property svn:keywords set to Id
File size: 14.2 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)
[508]11   !!----------------------------------------------------------------------
[3]12
13   !!----------------------------------------------------------------------
[508]14   !!   rst_opn    : open the ocean restart file
15   !!   rst_write  : write the ocean restart file
16   !!   rst_read   : read the ocean restart file
[3]17   !!----------------------------------------------------------------------
[2528]18   USE oce             ! ocean dynamics and tracers
[3]19   USE dom_oce         ! ocean space and time domain
20   USE phycst          ! physical constants
[508]21   USE in_out_manager  ! I/O manager
22   USE iom             ! I/O module
[544]23   USE eosbn2          ! equation of state            (eos bn2 routine)
[579]24   USE trdmld_oce      ! ocean active mixed layer tracers trends variables
[3680]25   USE divcur          ! hor. divergence and curl      (div & cur routines)
[4206]26   USE sbc_ice, ONLY : lk_lim3
[5746]27! for ln_rstdate....
28   USE ioipsl, ONLY : ju2ymds    ! for calendar
[3]29
30   IMPLICIT NONE
31   PRIVATE
32
[4292]33   PUBLIC   rst_opn         ! routine called by step module
34   PUBLIC   rst_write       ! routine called by step module
35   PUBLIC   rst_read        ! routine called by istate module
36   PUBLIC   rst_read_open   ! routine called in rst_read and (possibly) in dom_vvl_init
[3]37
[508]38   !! * Substitutions
[2528]39#  include "domzgr_substitute.h90"
[508]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
[5750]61      CHARACTER(LEN=50)   ::   clname   ! ocean output restart file name
62      CHARACTER(len=150)  ::   clpath   ! full path to ocean output restart file
[5746]63! Included for ln_rstdate
64      INTEGER             ::   iyear, imonth, iday
65      REAL (wp)           ::   zsec
66
[508]67      !!----------------------------------------------------------------------
68      !
[783]69      IF( kt == nit000 ) THEN   ! default definitions
70         lrst_oce = .FALSE.   
71         nitrst = nitend
[508]72      ENDIF
[783]73      IF( MOD( kt - 1, nstock ) == 0 ) THEN   
74         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
75         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
76         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
77      ENDIF
78      ! to get better performances with NetCDF format:
79      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
80      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
81      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
[5746]82! changes for ln_rstdate....
83!         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
84!         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
85!         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
86           IF ( ln_rstdate ) THEN
87              CALL ju2ymds( fjulday + rdttra(1) / rday, iyear, imonth, iday, zsec )           
88              WRITE(clkt, '(i4.4,2i2.2)') iyear, imonth, iday
89           ELSE
90              ! beware of the format used to write kt (default is i8.8, that should be large enough...)
91              IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
92              ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
93              ENDIF
94! end
[508]95         ENDIF
96         ! create the file
[1229]97         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
[5750]98         clpath = TRIM(cn_ocerst_outdir)
99         IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
100         !
[611]101         IF(lwp) THEN
102            WRITE(numout,*)
[632]103            SELECT CASE ( jprstlib )
[783]104            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart binary file: '//clname
105            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart NetCDF file: '//clname
[632]106            END SELECT
[2528]107            IF ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
[1130]108            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
109            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
[611]110            ENDIF
111         ENDIF
[2528]112         !
[5750]113         CALL iom_open( TRIM(clpath)//TRIM(clname), numrow, ldwrt = .TRUE., kiolib = jprstlib )
[508]114         lrst_oce = .TRUE.
115      ENDIF
116      !
117   END SUBROUTINE rst_opn
118
119
[3]120   SUBROUTINE rst_write( kt )
121      !!---------------------------------------------------------------------
122      !!                   ***  ROUTINE rstwrite  ***
123      !!                     
[632]124      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
[3]125      !!
[508]126      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
[2528]127      !!              file, save fields which are necessary for restart
[3]128      !!----------------------------------------------------------------------
[508]129      INTEGER, INTENT(in) ::   kt   ! ocean time-step
[3]130      !!----------------------------------------------------------------------
[1239]131
[2528]132                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       )   ! dynamics time step
133                     CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1) )   ! surface tracer time step
[3]134
[2528]135                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub        )     ! before fields
136                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb        )
[3294]137                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tsb(:,:,:,jp_tem) )
138                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , tsb(:,:,:,jp_sal) )
[2528]139                     CALL iom_rstput( kt, nitrst, numrow, 'rotb'   , rotb      )
140                     CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb     )
141                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb      )
142                     !
143                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , un        )     ! now fields
144                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn        )
[3294]145                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tsn(:,:,:,jp_tem) )
146                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , tsn(:,:,:,jp_sal) )
[2528]147                     CALL iom_rstput( kt, nitrst, numrow, 'rotn'   , rotn      )
148                     CALL iom_rstput( kt, nitrst, numrow, 'hdivn'  , hdivn     )
149                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , sshn      )
150                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop      )
[1545]151#if defined key_zdfkpp
[2528]152                     CALL iom_rstput( kt, nitrst, numrow, 'rhd'    , rhd       )
[1483]153#endif
[4206]154                  IF( lk_lim3 ) THEN
[4205]155                     CALL iom_rstput( kt, nitrst, numrow, 'iatte'  , iatte     ) !clem modif
156                     CALL iom_rstput( kt, nitrst, numrow, 'oatte'  , oatte     ) !clem modif
[4206]157                  ENDIF
[508]158      IF( kt == nitrst ) THEN
159         CALL iom_close( numrow )     ! close the restart file (only at last time step)
[579]160         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
[3]161      ENDIF
[508]162      !
[3]163   END SUBROUTINE rst_write
164
[4292]165   SUBROUTINE rst_read_open
166      !!----------------------------------------------------------------------
167      !!                   ***  ROUTINE rst_read_open  ***
168      !!
169      !! ** Purpose :   Open read files for restart (format fixed by jprstlib )
170      !!
171      !! ** Method  :   Use a non-zero, positive value of numror to assess whether or not
172      !!                the file has already been opened
173      !!----------------------------------------------------------------------
174      INTEGER  ::   jlibalt = jprstlib
175      LOGICAL  ::   llok
[5750]176      CHARACTER(lc)  ::   clpath   ! full path to ocean output restart file
[4292]177      !!----------------------------------------------------------------------
[3]178
[4292]179      IF( numror .LE. 0 ) THEN
180         IF(lwp) THEN                                             ! Contol prints
181            WRITE(numout,*)
182            SELECT CASE ( jprstlib )
183            CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
184            CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
185            END SELECT
186            IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
187            WRITE(numout,*) '~~~~~~~~'
188         ENDIF
189
[5750]190         clpath = TRIM(cn_ocerst_indir)
191         IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
[4292]192         IF ( jprstlib == jprstdimg ) THEN
193           ! eventually read netcdf file (monobloc)  for restarting on different number of processors
194           ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90
[5750]195           INQUIRE( FILE = TRIM(cn_ocerst_indir)//'/'//TRIM(cn_ocerst_in)//'.nc', EXIST = llok )
[4292]196           IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
197         ENDIF
[5750]198         CALL iom_open( TRIM(clpath)//cn_ocerst_in, numror, kiolib = jlibalt )
[4292]199      ENDIF
200   END SUBROUTINE rst_read_open
201
[3]202   SUBROUTINE rst_read
203      !!----------------------------------------------------------------------
204      !!                   ***  ROUTINE rst_read  ***
205      !!
[632]206      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
[3]207      !!
[1531]208      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
[3]209      !!----------------------------------------------------------------------
[1130]210      REAL(wp) ::   zrdt, zrdttra1
[4292]211      INTEGER  ::   jk
[1473]212      LOGICAL  ::   llok
[3]213      !!----------------------------------------------------------------------
214
[4292]215      CALL rst_read_open           ! open restart for reading (if not already opened)
[3]216
[544]217      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
[746]218      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
[544]219         CALL iom_get( numror, 'rdt', zrdt )
220         IF( zrdt /= rdt )   neuler = 0
221      ENDIF
[746]222      IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 )   THEN
[544]223         CALL iom_get( numror, 'rdttra1', zrdttra1 )
224         IF( zrdttra1 /= rdttra(1) )   neuler = 0
225      ENDIF
[1607]226      !
[3680]227      IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
228         CALL iom_get( numror, jpdom_autoglo, 'ub'     , ub      )   ! before fields
229         CALL iom_get( numror, jpdom_autoglo, 'vb'     , vb      )
230         CALL iom_get( numror, jpdom_autoglo, 'tb'     , tsb(:,:,:,jp_tem) )
231         CALL iom_get( numror, jpdom_autoglo, 'sb'     , tsb(:,:,:,jp_sal) )
232         CALL iom_get( numror, jpdom_autoglo, 'rotb'   , rotb    )
233         CALL iom_get( numror, jpdom_autoglo, 'hdivb'  , hdivb   )
234         CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb    )
235      ELSE
236         neuler = 0
237      ENDIF
238      !
239      CALL iom_get( numror, jpdom_autoglo, 'un'     , un      )   ! now    fields
240      CALL iom_get( numror, jpdom_autoglo, 'vn'     , vn      )
241      CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,:,jp_tem) )
242      CALL iom_get( numror, jpdom_autoglo, 'sn'     , tsn(:,:,:,jp_sal) )
243      CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn    )
244      IF( iom_varid( numror, 'rotn', ldstop = .FALSE. ) > 0 ) THEN
245         CALL iom_get( numror, jpdom_autoglo, 'rotn'   , rotn    )
246         CALL iom_get( numror, jpdom_autoglo, 'hdivn'  , hdivn   )
247      ELSE
248         CALL div_cur( 0 )                              ! Horizontal divergence & Relative vorticity
249      ENDIF
250      IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN
251         CALL iom_get( numror, jpdom_autoglo, 'rhop'   , rhop    )   ! now    potential density
252      ELSE
[4313]253         CALL eos    ( tsn, rhd, rhop, fsdept_n(:,:,:) )   
[3680]254      ENDIF
[1545]255#if defined key_zdfkpp
256      IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN
[3680]257         CALL iom_get( numror, jpdom_autoglo, 'rhd'    , rhd     )   ! now    in situ density anomaly
[1545]258      ELSE
[4313]259         CALL eos( tsn, rhd, fsdept_n(:,:,:) )   ! compute rhd
[1545]260      ENDIF
[1483]261#endif
[2528]262      !
[508]263      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
[3294]264         tsb  (:,:,:,:) = tsn  (:,:,:,:)                             ! all before fields set to now values
265         ub   (:,:,:)   = un   (:,:,:)
266         vb   (:,:,:)   = vn   (:,:,:)
267         rotb (:,:,:)   = rotn (:,:,:)
268         hdivb(:,:,:)   = hdivn(:,:,:)
269         sshb (:,:)     = sshn (:,:)
[3]270      ENDIF
[508]271      !
[4206]272      IF( lk_lim3 ) THEN
273         CALL iom_get( numror, jpdom_autoglo, 'iatte' , iatte ) ! clem modif
274         CALL iom_get( numror, jpdom_autoglo, 'oatte' , oatte ) ! clem modif
275      ENDIF
[4205]276      !
[508]277   END SUBROUTINE rst_read
[473]278
[3]279   !!=====================================================================
280END MODULE restart
Note: See TracBrowser for help on using the repository browser.