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/dev_001_SBC/NEMO/OPA_SRC – NEMO

source: branches/dev_001_SBC/NEMO/OPA_SRC/restart.F90 @ 811

Last change on this file since 811 was 811, checked in by ctlod, 16 years ago

dev_001_SBC: merge with the trunk last changesets: #780, 782, 783, 784, 785, 788, 789, 793, 794

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.6 KB
Line 
1MODULE restart
2   !!======================================================================
3   !!                     ***  MODULE  restart  ***
4   !! Ocean restart :  write the ocean restart file
5   !!======================================================================
6   !! History :        !  99-11  (M. Imbard)  Original code
7   !!             8.5  !  02-08  (G. Madec)  F90: Free form
8   !!             9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
9   !!             9.0  !  06-07  (S. Masson)  use IOM for restart
10   !!----------------------------------------------------------------------
11
12   !!----------------------------------------------------------------------
13   !!   rst_opn    : open the ocean restart file
14   !!   rst_write  : write the ocean restart file
15   !!   rst_read   : read the ocean restart file
16   !!----------------------------------------------------------------------
17   USE dom_oce         ! ocean space and time domain
18   USE oce             ! ocean dynamics and tracers
19   USE phycst          ! physical constants
20   USE daymod          ! calendar
21   USE cpl_oce, ONLY : lk_cpl              !
22   USE in_out_manager  ! I/O manager
23   USE iom             ! I/O module
24   USE ini1d           ! re-initialization of u-v mask for the 1D configuration
25   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
26   USE eosbn2          ! equation of state            (eos bn2 routine)
27   USE trdmld_oce      ! ocean active mixed layer tracers trends variables
28
29   IMPLICIT NONE
30   PRIVATE
31
32   PUBLIC   rst_opn    ! routine called by step module
33   PUBLIC   rst_write  ! routine called by step module
34   PUBLIC   rst_read   ! routine called by opa  module
35
36   LOGICAL, PUBLIC ::   lrst_oce                  !: logical to control the oce restart write
37   INTEGER, PUBLIC ::   numror, numrow            !: logical unit for cean restart (read and write)
38
39   !! * Substitutions
40#  include "vectopt_loop_substitute.h90"
41   !!----------------------------------------------------------------------
42   !!  OPA 9.0 , LOCEAN-IPSL (2006)
43   !! $Id$
44   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
45   !!----------------------------------------------------------------------
46
47CONTAINS
48
49   SUBROUTINE rst_opn( kt )
50      !!---------------------------------------------------------------------
51      !!                   ***  ROUTINE rst_opn  ***
52      !!                     
53      !! ** Purpose : + initialization (should be read in the namelist) of nitrst
54      !!              + open the restart when we are one time step before nitrst
55      !!                   - restart header is defined when kt = nitrst-1
56      !!                   - restart data  are written when kt = nitrst
57      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
58      !!----------------------------------------------------------------------
59      INTEGER, INTENT(in) ::   kt     ! ocean time-step
60      !!
61      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
62      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
63      !!----------------------------------------------------------------------
64      !
65      IF( kt == nit000 ) THEN   ! default definitions
66         lrst_oce = .FALSE.   
67         nitrst = nitend
68      ENDIF
69      IF( MOD( kt - 1, nstock ) == 0 ) THEN   
70         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
71         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
72         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
73      ENDIF
74
75      ! to get better performances with NetCDF format:
76      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
77      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
78      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
79         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
80         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
81         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
82         ENDIF
83         ! create the file
84         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_restart"
85         IF(lwp) THEN
86            WRITE(numout,*)
87            SELECT CASE ( jprstlib )
88            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart binary file: '//clname
89            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart NetCDF file: '//clname
90            END SELECT
91            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt,' date= ', ndastp
92            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt,' date= ', ndastp
93            ENDIF
94         ENDIF
95
96         CALL iom_open( clname, numrow, ldwrt = .TRUE., kiolib = jprstlib )
97         lrst_oce = .TRUE.
98      ENDIF
99      !
100   END SUBROUTINE rst_opn
101
102
103   SUBROUTINE rst_write( kt )
104      !!---------------------------------------------------------------------
105      !!                   ***  ROUTINE rstwrite  ***
106      !!                     
107      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
108      !!
109      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
110      !!      file, save fields which are necessary for restart
111      !!----------------------------------------------------------------------
112      INTEGER, INTENT(in) ::   kt   ! ocean time-step
113      !!----------------------------------------------------------------------
114
115      IF( kt == nitrst ) THEN
116         IF(lwp) WRITE(numout,*)
117         IF(lwp) WRITE(numout,*) 'rst_write : write oce restart file  kt =', kt
118         IF(lwp) WRITE(numout,*) '~~~~~~~'         
119      ENDIF
120
121      ! calendar control
122      CALL iom_rstput( kt, nitrst, numrow, 'kt'     , REAL( kt    , wp) )   ! time-step
123      CALL iom_rstput( kt, nitrst, numrow, 'ndastp' , REAL( ndastp, wp) )   ! date
124      CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj            )   ! number of elapsed days since
125      !                                                                     ! the begining of the run [s]
126      CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt               )   ! dynamics time step
127      CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1)         )   ! surface tracer time step
128
129      ! prognostic variables
130      CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub      )   
131      CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb      )
132      CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tb      )
133      CALL iom_rstput( kt, nitrst, numrow, 'sb'     , sb      )
134      CALL iom_rstput( kt, nitrst, numrow, 'rotb'   , rotb    )
135      CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb   )
136      CALL iom_rstput( kt, nitrst, numrow, 'un'     , un      )
137      CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn      )
138      IF( lk_vvl ) CALL iom_rstput( kt, nitrst, numrow, 'wn'     , wn      )
139      CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tn      )
140      CALL iom_rstput( kt, nitrst, numrow, 'sn'     , sn      )
141      CALL iom_rstput( kt, nitrst, numrow, 'rotn'   , rotn    )
142      CALL iom_rstput( kt, nitrst, numrow, 'hdivn'  , hdivn   )
143
144      IF( nn_dynhpg_rst == 1 .OR. lk_vvl ) THEN
145         CALL iom_rstput( kt, nitrst, numrow, 'rhd' , rhd  )
146         CALL iom_rstput( kt, nitrst, numrow, 'rhop', rhop )
147         IF( ln_zps ) THEN
148            CALL iom_rstput( kt, nitrst, numrow, 'gtu' , gtu )
149            CALL iom_rstput( kt, nitrst, numrow, 'gsu' , gsu )
150            CALL iom_rstput( kt, nitrst, numrow, 'gru' , gru )
151            CALL iom_rstput( kt, nitrst, numrow, 'gtv' , gtv )
152            CALL iom_rstput( kt, nitrst, numrow, 'gsv' , gsv )
153            CALL iom_rstput( kt, nitrst, numrow, 'grv' , grv )
154         ENDIF
155      ENDIF
156
157      IF( kt == nitrst ) THEN
158         CALL iom_close( numrow )     ! close the restart file (only at last time step)
159         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
160      ENDIF
161      !
162   END SUBROUTINE rst_write
163
164
165   SUBROUTINE rst_read
166      !!----------------------------------------------------------------------
167      !!                   ***  ROUTINE rst_read  ***
168      !!
169      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
170      !!
171      !! ** Method  :   Read the previous fields on the NetCDF/binary file
172      !!      the first record indicates previous characterics
173      !!      after control with the present run, we read :
174      !!      - prognostic variables on the second record
175      !!      - elliptic solver arrays
176      !!      - barotropic stream function arrays ("key_dynspg_rl" defined)
177      !!        or free surface arrays
178      !!      - tke arrays (lk_zdftke=T)
179      !!      for this last three records,  the previous characteristics
180      !!      could be different with those used in the present run.
181      !!
182      !!   According to namelist parameter nrstdt,
183      !!       nrstdt = 0  no control on the date (nit000 is  arbitrary).
184      !!       nrstdt = 1  we verify that nit000 is equal to the last
185      !!                   time step of previous run + 1.
186      !!       In both those options, the  exact duration of the experiment
187      !!       since the beginning (cumulated duration of all previous restart runs)
188      !!       is not stored in the restart and is assumed to be (nit000-1)*rdt.
189      !!       This is valid is the time step has remained constant.
190      !!
191      !!       nrstdt = 2  the duration of the experiment in days (adatrj)
192      !!                    has been stored in the restart file.
193      !!----------------------------------------------------------------------
194      REAL(wp) ::   zcoef, zkt, zrdt, zrdttra1, zndastp
195#if defined key_ice_lim
196      INTEGER  ::   ji, jj
197#endif
198      !!----------------------------------------------------------------------
199
200      IF(lwp) THEN                                             ! Contol prints
201         WRITE(numout,*)
202         SELECT CASE ( jprstlib )
203         CASE ( jpnf90 )
204            WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
205         CASE ( jprstdimg )
206            WRITE(numout,*) 'rst_read : read oce binary restart file'
207         END SELECT
208         WRITE(numout,*) '~~~~~~~~'
209
210         WRITE(numout,*) ' *** Info on the present job : '
211         WRITE(numout,*) '   time-step           : ', nit000
212         WRITE(numout,*) '   date ndastp         : ', ndastp
213         WRITE(numout,*)
214         WRITE(numout,*) ' *** restart option'
215         SELECT CASE ( nrstdt )
216         CASE ( 0 ) 
217            WRITE(numout,*) ' nrstdt = 0 no control of nit000'
218         CASE ( 1 ) 
219            WRITE(numout,*) ' nrstdt = 1 we control the date of nit000'
220         CASE ( 2 )
221            WRITE(numout,*) ' nrstdt = 2 the date adatrj is read in restart file'
222         CASE DEFAULT
223            WRITE(numout,*) '  ===>>>> nrstdt not equal 0, 1 or 2 : no control of the date'
224            WRITE(numout,*) '  =======                  ========='
225         END SELECT
226         WRITE(numout,*)
227      ENDIF
228
229      CALL iom_open( 'restart', numror, kiolib = jprstlib )
230
231      ! Calendar informations
232      CALL iom_get( numror, 'kt'     , zkt      )   ! time-step
233      CALL iom_get( numror, 'ndastp' , zndastp  )   ! date
234      IF(lwp) THEN
235         WRITE(numout,*)
236         WRITE(numout,*) ' *** Info on the restart file read : '
237         WRITE(numout,*) '   time-step           : ', NINT( zkt )
238         WRITE(numout,*) '   date ndastp         : ', NINT( zndastp )
239         WRITE(numout,*)
240      ENDIF
241      ! Control of date
242      IF( nit000 - NINT( zkt )  /= 1 .AND. nrstdt /= 0 ) &
243           & CALL ctl_stop( ' ===>>>> : problem with nit000 for the restart', &
244           & ' verify the restart file or rerun with nrstdt = 0 (namelist)' )
245      ! re-initialisation of  adatrj0
246      adatrj0 = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
247      IF ( nrstdt == 2 ) THEN
248         ! by default ndatsp has been set to ndate0 in dom_nam
249         ! ndate0 has been read in the namelist (standard OPA 8)
250         ! here when nrstdt=2 we keep the  final date of previous run
251         ndastp = NINT( zndastp )
252         CALL iom_get( numror, 'adatrj', adatrj )   ! number of elapsed days since the begining of last run
253      ENDIF
254      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
255      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
256         CALL iom_get( numror, 'rdt', zrdt )
257         IF( zrdt /= rdt )   neuler = 0
258      ENDIF
259      IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 )   THEN
260         CALL iom_get( numror, 'rdttra1', zrdttra1 )
261         IF( zrdttra1 /= rdttra(1) )   neuler = 0
262      ENDIF
263      !
264      !                                                       ! Read prognostic variables
265      CALL iom_get( numror, jpdom_autoglo, 'ub'   , ub    )        ! before i-component velocity
266      CALL iom_get( numror, jpdom_autoglo, 'vb'   , vb    )        ! before j-component velocity
267      CALL iom_get( numror, jpdom_autoglo, 'tb'   , tb    )        ! before temperature
268      CALL iom_get( numror, jpdom_autoglo, 'sb'   , sb    )        ! before salinity
269      CALL iom_get( numror, jpdom_autoglo, 'rotb' , rotb  )        ! before curl
270      CALL iom_get( numror, jpdom_autoglo, 'hdivb', hdivb )        ! before horizontal divergence
271      CALL iom_get( numror, jpdom_autoglo, 'un'   , un    )        ! now    i-component velocity
272      CALL iom_get( numror, jpdom_autoglo, 'vn'   , vn    )        ! now    j-component velocity
273      IF( lk_vvl ) CALL iom_get( numror, jpdom_autoglo, 'wn'   , wn    )        ! now    k-component velocity
274      CALL iom_get( numror, jpdom_autoglo, 'tn'   , tn    )        ! now    temperature
275      CALL iom_get( numror, jpdom_autoglo, 'sn'   , sn    )        ! now    salinity
276      CALL iom_get( numror, jpdom_autoglo, 'rotn' , rotn  )        ! now    curl
277      CALL iom_get( numror, jpdom_autoglo, 'hdivn', hdivn )        ! now    horizontal divergence
278
279
280      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
281         tb   (:,:,:) = tn   (:,:,:)                             ! all before fields set to now field values
282         sb   (:,:,:) = sn   (:,:,:)
283         ub   (:,:,:) = un   (:,:,:)
284         vb   (:,:,:) = vn   (:,:,:)
285         rotb (:,:,:) = rotn (:,:,:)
286         hdivb(:,:,:) = hdivn(:,:,:)
287      ENDIF
288
289      IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN
290         CALL iom_get( numror, jpdom_autoglo, 'rhd' , rhd  )
291         CALL iom_get( numror, jpdom_autoglo, 'rhop', rhop )
292      ELSE
293         CALL eos( tb, sb, rhd, rhop )        ! before potential and in situ densities
294      ENDIF
295      IF( ln_zps .AND. .NOT. lk_cfg_1d ) THEN
296         IF( iom_varid( numror, 'gtu', ldstop = .FALSE. ) > 0 ) THEN
297            CALL iom_get( numror, jpdom_autoglo, 'gtu' , gtu )
298            CALL iom_get( numror, jpdom_autoglo, 'gsu' , gsu )
299            CALL iom_get( numror, jpdom_autoglo, 'gru' , gru )
300            CALL iom_get( numror, jpdom_autoglo, 'gtv' , gtv )
301            CALL iom_get( numror, jpdom_autoglo, 'gsv' , gsv )
302            CALL iom_get( numror, jpdom_autoglo, 'grv' , grv )
303         ELSE
304            CALL zps_hde( nit000, tb , sb , rhd,   &  ! Partial steps: before Horizontal DErivative
305               &                  gtu, gsu, gru,   &  ! of t, s, rd at the bottom ocean level
306               &                  gtv, gsv, grv )
307         ENDIF
308      ENDIF
309      !
310   END SUBROUTINE rst_read
311
312
313   !!=====================================================================
314END MODULE restart
Note: See TracBrowser for help on using the repository browser.