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/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90 @ 7158

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

debug branch

  • Property svn:keywords set to Id
File size: 13.6 KB
Line 
1MODULE restart
2   !!======================================================================
3   !!                     ***  MODULE  restart  ***
4   !! Ocean restart :  write the ocean restart file
5   !!======================================================================
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)
11   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   rst_opn    : open the ocean restart file
15   !!   rst_write  : write the ocean restart file
16   !!   rst_read   : read the ocean restart file
17   !!----------------------------------------------------------------------
18   USE oce             ! ocean dynamics and tracers
19   USE dom_oce         ! ocean space and time domain
20   USE phycst          ! physical constants
21   USE in_out_manager  ! I/O manager
22   USE iom             ! I/O module
23   USE eosbn2          ! equation of state            (eos bn2 routine)
24   USE trdmxl_oce      ! ocean active mixed layer tracers trends variables
25   USE divcur          ! hor. divergence and curl      (div & cur routines)
26
27   IMPLICIT NONE
28   PRIVATE
29
30   PUBLIC   rst_opn         ! routine called by step module
31   PUBLIC   rst_write       ! routine called by step module
32   PUBLIC   rst_read        ! routine called by istate module
33   PUBLIC   rst_read_open   ! routine called in rst_read and (possibly) in dom_vvl_init
34
35   !! * Substitutions
36#  include "domzgr_substitute.h90"
37#  include "vectopt_loop_substitute.h90"
38   !!----------------------------------------------------------------------
39   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
40   !! $Id$
41   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
42   !!----------------------------------------------------------------------
43CONTAINS
44
45   SUBROUTINE rst_opn( kt )
46      !!---------------------------------------------------------------------
47      !!                   ***  ROUTINE rst_opn  ***
48      !!                     
49      !! ** Purpose : + initialization (should be read in the namelist) of nitrst
50      !!              + open the restart when we are one time step before nitrst
51      !!                   - restart header is defined when kt = nitrst-1
52      !!                   - restart data  are written when kt = nitrst
53      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
54      !!----------------------------------------------------------------------
55      INTEGER, INTENT(in) ::   kt     ! ocean time-step
56      !!
57      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
58      CHARACTER(LEN=50)   ::   clname   ! ocean output restart file name
59      CHARACTER(lc)       ::   clpath   ! full path to ocean output restart file
60      !!----------------------------------------------------------------------
61      !
62      IF( kt == nit000 ) THEN   ! default definitions
63         lrst_oce = .FALSE.   
64         IF( ln_rst_list ) THEN
65            nrst_lst = 1
66            nitrst = nstocklist( nrst_lst )
67         ELSE
68            nitrst = nitend
69         ENDIF
70      ENDIF
71
72      ! frequency-based restart dumping (nn_stock)
73      IF( .NOT. ln_rst_list .AND. 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
82         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN 
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            ENDIF
87            ! create the file
88            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
89            clpath = TRIM(cn_ocerst_outdir)
90            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
91            IF(lwp) THEN
92               WRITE(numout,*)
93               SELECT CASE ( jprstlib )
94               CASE ( jprstdimg )   ;   WRITE(numout,*)                            &
95                   '             open ocean restart binary file: ',TRIM(clpath)//clname
96               CASE DEFAULT         ;   WRITE(numout,*)                            &
97                   '             open ocean restart NetCDF file: ',TRIM(clpath)//clname
98               END SELECT
99               IF ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
100               IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
101               ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
102               ENDIF
103            ENDIF
104            !
105            CALL iom_open( TRIM(clpath)//TRIM(clname), numrow, ldwrt = .TRUE., kiolib = jprstlib )
106            lrst_oce = .TRUE.
107         ENDIF
108      ENDIF
109      !
110   END SUBROUTINE rst_opn
111
112
113   SUBROUTINE rst_write( kt )
114      !!---------------------------------------------------------------------
115      !!                   ***  ROUTINE rstwrite  ***
116      !!                     
117      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
118      !!
119      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
120      !!              file, save fields which are necessary for restart
121      !!----------------------------------------------------------------------
122      INTEGER, INTENT(in) ::   kt   ! ocean time-step
123      !!----------------------------------------------------------------------
124
125                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       )     ! dynamics and tracer time step
126
127                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub        )     ! before fields
128                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb        )
129                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tsb(:,:,:,jp_tem) )
130                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , tsb(:,:,:,jp_sal) )
131                     CALL iom_rstput( kt, nitrst, numrow, 'rotb'   , rotb      )
132                     CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb     )
133                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb      )
134                     !
135                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , un        )     ! now fields
136                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn        )
137                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tsn(:,:,:,jp_tem) )
138                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , tsn(:,:,:,jp_sal) )
139                     CALL iom_rstput( kt, nitrst, numrow, 'rotn'   , rotn      )
140                     CALL iom_rstput( kt, nitrst, numrow, 'hdivn'  , hdivn     )
141                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , sshn      )
142                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop      )
143#if defined key_zdfkpp
144                     CALL iom_rstput( kt, nitrst, numrow, 'rhd'    , rhd       )
145#endif
146      IF( kt == nitrst ) THEN
147         CALL iom_close( numrow )     ! close the restart file (only at last time step)
148!!gm         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
149!!gm  not sure what to do here   ===>>>  ask to Sebastian
150         lrst_oce = .FALSE.
151            IF( ln_rst_list ) THEN
152               nrst_lst = MIN(nrst_lst + 1, SIZE(nstocklist,1))
153               nitrst = nstocklist( nrst_lst )
154            ENDIF
155            lrst_oce = .FALSE.
156      ENDIF
157      !
158   END SUBROUTINE rst_write
159
160
161   SUBROUTINE rst_read_open
162      !!----------------------------------------------------------------------
163      !!                   ***  ROUTINE rst_read_open  ***
164      !!
165      !! ** Purpose :   Open read files for restart (format fixed by jprstlib )
166      !!
167      !! ** Method  :   Use a non-zero, positive value of numror to assess whether or not
168      !!                the file has already been opened
169      !!----------------------------------------------------------------------
170      INTEGER        ::   jlibalt = jprstlib
171      LOGICAL        ::   llok
172      CHARACTER(lc)  ::   clpath   ! full path to ocean output restart file
173      !!----------------------------------------------------------------------
174      !
175      IF( numror <= 0 ) THEN
176         IF(lwp) THEN                                             ! Contol prints
177            WRITE(numout,*)
178            SELECT CASE ( jprstlib )
179            CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
180            CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
181            END SELECT
182            IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
183            WRITE(numout,*) '~~~~~~~~'
184         ENDIF
185
186         clpath = TRIM(cn_ocerst_indir)
187         IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
188         IF ( jprstlib == jprstdimg ) THEN
189           ! eventually read netcdf file (monobloc)  for restarting on different number of processors
190           ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90
191           INQUIRE( FILE = TRIM(cn_ocerst_indir)//'/'//TRIM(cn_ocerst_in)//'.nc', EXIST = llok )
192           IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
193         ENDIF
194         CALL iom_open( TRIM(clpath)//cn_ocerst_in, numror, kiolib = jlibalt )
195      ENDIF
196   END SUBROUTINE rst_read_open
197
198   SUBROUTINE rst_read
199      !!----------------------------------------------------------------------
200      !!                   ***  ROUTINE rst_read  ***
201      !!
202      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
203      !!
204      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
205      !!----------------------------------------------------------------------
206      REAL(wp) ::   zrdt
207      INTEGER  ::   jk
208      LOGICAL  ::   llok
209      !!----------------------------------------------------------------------
210
211      CALL rst_read_open           ! open restart for reading (if not already opened)
212
213      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
214      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
215         CALL iom_get( numror, 'rdt', zrdt )
216         IF( zrdt /= rdt )   neuler = 0
217      ENDIF
218      !
219      IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
220         CALL iom_get( numror, jpdom_autoglo, 'ub'     , ub      )   ! before fields
221         CALL iom_get( numror, jpdom_autoglo, 'vb'     , vb      )
222         CALL iom_get( numror, jpdom_autoglo, 'tb'     , tsb(:,:,:,jp_tem) )
223         CALL iom_get( numror, jpdom_autoglo, 'sb'     , tsb(:,:,:,jp_sal) )
224         CALL iom_get( numror, jpdom_autoglo, 'rotb'   , rotb    )
225         CALL iom_get( numror, jpdom_autoglo, 'hdivb'  , hdivb   )
226         CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb    )
227      ELSE
228         neuler = 0
229      ENDIF
230      !
231      CALL iom_get( numror, jpdom_autoglo, 'un'     , un      )   ! now    fields
232      CALL iom_get( numror, jpdom_autoglo, 'vn'     , vn      )
233      CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,:,jp_tem) )
234      CALL iom_get( numror, jpdom_autoglo, 'sn'     , tsn(:,:,:,jp_sal) )
235      CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn    )
236      IF( iom_varid( numror, 'rotn', ldstop = .FALSE. ) > 0 ) THEN
237         CALL iom_get( numror, jpdom_autoglo, 'rotn'   , rotn    )
238         CALL iom_get( numror, jpdom_autoglo, 'hdivn'  , hdivn   )
239      ELSE
240         CALL div_cur( 0 )                              ! Horizontal divergence & Relative vorticity
241      ENDIF
242      IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN
243         CALL iom_get( numror, jpdom_autoglo, 'rhop'   , rhop    )   ! now    potential density
244      ELSE
245         CALL eos    ( tsn, rhd, rhop, fsdept_n(:,:,:) )   
246      ENDIF
247#if defined key_zdfkpp
248      IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN
249         CALL iom_get( numror, jpdom_autoglo, 'rhd'    , rhd     )   ! now    in situ density anomaly
250      ELSE
251         CALL eos( tsn, rhd, fsdept_n(:,:,:) )   ! compute rhd
252      ENDIF
253#endif
254      !
255      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
256         tsb  (:,:,:,:) = tsn  (:,:,:,:)                             ! all before fields set to now values
257         ub   (:,:,:)   = un   (:,:,:)
258         vb   (:,:,:)   = vn   (:,:,:)
259         rotb (:,:,:)   = rotn (:,:,:)
260         hdivb(:,:,:)   = hdivn(:,:,:)
261         sshb (:,:)     = sshn (:,:)
262
263         IF( lk_vvl ) THEN
264            DO jk = 1, jpk
265               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
266            END DO
267         ENDIF
268
269      ENDIF
270      !
271   END SUBROUTINE rst_read
272
273   !!=====================================================================
274END MODULE restart
Note: See TracBrowser for help on using the repository browser.