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/2012/dev_LOCEAN_UKMO_2012/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: branches/2012/dev_LOCEAN_UKMO_2012/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90 @ 3653

Last change on this file since 3653 was 3653, checked in by cetlod, 11 years ago

commit the changes from LOCEAN & UKMO merge, see ticket #1021

  • Property svn:keywords set to Id
File size: 11.9 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 trdmld_oce      ! ocean active mixed layer tracers trends variables
25   USE domvvl          ! variable volume
26   USE divcur          ! hor. divergence and curl      (div & cur routines)
27
28   IMPLICIT NONE
29   PRIVATE
30
31   PUBLIC   rst_opn    ! routine called by step module
32   PUBLIC   rst_write  ! routine called by step module
33   PUBLIC   rst_read   ! routine called by opa  module
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   ! ice output restart file name
59      !!----------------------------------------------------------------------
60      !
61      IF( kt == nit000 ) THEN   ! default definitions
62         lrst_oce = .FALSE.   
63         nitrst = nitend
64      ENDIF
65      IF( MOD( kt - 1, nstock ) == 0 ) THEN   
66         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
67         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
68         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
69      ENDIF
70      ! to get better performances with NetCDF format:
71      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
72      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
73      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
74         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
75         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
76         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
77         ENDIF
78         ! create the file
79         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
80         IF(lwp) THEN
81            WRITE(numout,*)
82            SELECT CASE ( jprstlib )
83            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart binary file: '//clname
84            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart NetCDF file: '//clname
85            END SELECT
86            IF ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
87            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
88            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
89            ENDIF
90         ENDIF
91         !
92         CALL iom_open( clname, numrow, ldwrt = .TRUE., kiolib = jprstlib )
93         lrst_oce = .TRUE.
94      ENDIF
95      !
96   END SUBROUTINE rst_opn
97
98
99   SUBROUTINE rst_write( kt )
100      !!---------------------------------------------------------------------
101      !!                   ***  ROUTINE rstwrite  ***
102      !!                     
103      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
104      !!
105      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
106      !!              file, save fields which are necessary for restart
107      !!----------------------------------------------------------------------
108      INTEGER, INTENT(in) ::   kt   ! ocean time-step
109      !!----------------------------------------------------------------------
110
111                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       )   ! dynamics time step
112                     CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1) )   ! surface tracer time step
113
114                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub        )     ! before fields
115                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb        )
116                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tsb(:,:,:,jp_tem) )
117                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , tsb(:,:,:,jp_sal) )
118                     CALL iom_rstput( kt, nitrst, numrow, 'rotb'   , rotb      )
119                     CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb     )
120                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb      )
121      IF( lk_vvl )   CALL iom_rstput( kt, nitrst, numrow, 'fse3t_b', fse3t_b(:,:,:) )
122                     !
123                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , un        )     ! now fields
124                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn        )
125                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tsn(:,:,:,jp_tem) )
126                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , tsn(:,:,:,jp_sal) )
127                     CALL iom_rstput( kt, nitrst, numrow, 'rotn'   , rotn      )
128                     CALL iom_rstput( kt, nitrst, numrow, 'hdivn'  , hdivn     )
129                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , sshn      )
130                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop      )
131#if defined key_zdfkpp
132                     CALL iom_rstput( kt, nitrst, numrow, 'rhd'    , rhd       )
133#endif
134      IF( kt == nitrst ) THEN
135         CALL iom_close( numrow )     ! close the restart file (only at last time step)
136         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
137      ENDIF
138      !
139   END SUBROUTINE rst_write
140
141
142   SUBROUTINE rst_read
143      !!----------------------------------------------------------------------
144      !!                   ***  ROUTINE rst_read  ***
145      !!
146      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
147      !!
148      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
149      !!----------------------------------------------------------------------
150      REAL(wp) ::   zrdt, zrdttra1
151      INTEGER  ::   jk, jlibalt = jprstlib
152      LOGICAL  ::   llok
153      !!----------------------------------------------------------------------
154
155      IF(lwp) THEN                                             ! Contol prints
156         WRITE(numout,*)
157         SELECT CASE ( jprstlib )
158         CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
159         CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
160         END SELECT
161         IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
162         WRITE(numout,*) '~~~~~~~~'
163      ENDIF
164
165      IF ( jprstlib == jprstdimg ) THEN
166        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
167        ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90
168        INQUIRE( FILE = TRIM(cn_ocerst_in)//'.nc', EXIST = llok )
169        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
170      ENDIF
171      CALL iom_open( cn_ocerst_in, numror, kiolib = jlibalt )
172
173      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
174      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
175         CALL iom_get( numror, 'rdt', zrdt )
176         IF( zrdt /= rdt )   neuler = 0
177      ENDIF
178      IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 )   THEN
179         CALL iom_get( numror, 'rdttra1', zrdttra1 )
180         IF( zrdttra1 /= rdttra(1) )   neuler = 0
181      ENDIF
182      !
183      IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
184         CALL iom_get( numror, jpdom_autoglo, 'ub'     , ub      )   ! before fields
185         CALL iom_get( numror, jpdom_autoglo, 'vb'     , vb      )
186         CALL iom_get( numror, jpdom_autoglo, 'tb'     , tsb(:,:,:,jp_tem) )
187         CALL iom_get( numror, jpdom_autoglo, 'sb'     , tsb(:,:,:,jp_sal) )
188         CALL iom_get( numror, jpdom_autoglo, 'rotb'   , rotb    )
189         CALL iom_get( numror, jpdom_autoglo, 'hdivb'  , hdivb   )
190         CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb    )
191         IF( lk_vvl )   CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) )
192      ELSE
193         neuler = 0
194      ENDIF
195      !
196      CALL iom_get( numror, jpdom_autoglo, 'un'     , un      )   ! now    fields
197      CALL iom_get( numror, jpdom_autoglo, 'vn'     , vn      )
198      CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,:,jp_tem) )
199      CALL iom_get( numror, jpdom_autoglo, 'sn'     , tsn(:,:,:,jp_sal) )
200      CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn    )
201      IF( iom_varid( numror, 'rotn', ldstop = .FALSE. ) > 0 ) THEN
202         CALL iom_get( numror, jpdom_autoglo, 'rotn'   , rotn    )
203         CALL iom_get( numror, jpdom_autoglo, 'hdivn'  , hdivn   )
204      ELSE
205         CALL div_cur( 0 )                              ! Horizontal divergence & Relative vorticity
206      ENDIF
207      IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN
208         CALL iom_get( numror, jpdom_autoglo, 'rhop'   , rhop    )   ! now    potential density
209      ELSE
210         CALL eos    ( tsn, rhd, rhop )   
211      ENDIF
212#if defined key_zdfkpp
213      IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN
214         CALL iom_get( numror, jpdom_autoglo, 'rhd'    , rhd     )   ! now    in situ density anomaly
215      ELSE
216         CALL eos( tsn, rhd )   ! compute rhd
217      ENDIF
218#endif
219      !
220      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
221         tsb  (:,:,:,:) = tsn  (:,:,:,:)                             ! all before fields set to now values
222         ub   (:,:,:)   = un   (:,:,:)
223         vb   (:,:,:)   = vn   (:,:,:)
224         rotb (:,:,:)   = rotn (:,:,:)
225         hdivb(:,:,:)   = hdivn(:,:,:)
226         sshb (:,:)     = sshn (:,:)
227         IF( lk_vvl ) THEN
228            DO jk = 1, jpk
229               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
230            END DO
231         ENDIF
232      ENDIF
233      !
234   END SUBROUTINE rst_read
235
236   !!=====================================================================
237END MODULE restart
Note: See TracBrowser for help on using the repository browser.