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

source: trunk/NEMO/OPA_SRC/restart.F90 @ 1234

Last change on this file since 1234 was 1229, checked in by smasson, 16 years ago

define restart names in the namelist, see ticket:258

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.3 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 in_out_manager  ! I/O manager
21   USE iom             ! I/O module
22   USE c1d             ! re-initialization of u-v mask for the 1D configuration
23   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
24   USE eosbn2          ! equation of state            (eos bn2 routine)
25   USE trdmld_oce      ! ocean active mixed layer tracers trends variables
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 opa  module
33
34   LOGICAL, PUBLIC ::   lrst_oce                  !: logical to control the oce restart write
35   INTEGER, PUBLIC ::   numror, numrow            !: logical unit for cean restart (read and write)
36
37   !! * Substitutions
38#  include "vectopt_loop_substitute.h90"
39   !!----------------------------------------------------------------------
40   !!  OPA 9.0 , LOCEAN-IPSL (2006)
41   !! $Id$
42   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
43   !!----------------------------------------------------------------------
44
45CONTAINS
46
47   SUBROUTINE rst_opn( kt )
48      !!---------------------------------------------------------------------
49      !!                   ***  ROUTINE rst_opn  ***
50      !!                     
51      !! ** Purpose : + initialization (should be read in the namelist) of nitrst
52      !!              + open the restart when we are one time step before nitrst
53      !!                   - restart header is defined when kt = nitrst-1
54      !!                   - restart data  are written when kt = nitrst
55      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
56      !!----------------------------------------------------------------------
57      INTEGER, INTENT(in) ::   kt     ! ocean time-step
58      !!
59      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
60      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
61      !!----------------------------------------------------------------------
62      !
63      IF( kt == nit000 ) THEN   ! default definitions
64         lrst_oce = .FALSE.   
65         nitrst = nitend
66      ENDIF
67      IF( MOD( kt - 1, nstock ) == 0 ) THEN   
68         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
69         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
70         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
71      ENDIF
72
73      ! to get better performances with NetCDF format:
74      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
75      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
76      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
77         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
78         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
79         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
80         ENDIF
81         ! create the file
82         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
83         IF(lwp) THEN
84            WRITE(numout,*)
85            SELECT CASE ( jprstlib )
86            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart binary file: '//clname
87            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart NetCDF file: '//clname
88            END SELECT
89            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
90            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
91            ENDIF
92         ENDIF
93
94         CALL iom_open( clname, numrow, ldwrt = .TRUE., kiolib = jprstlib )
95         lrst_oce = .TRUE.
96      ENDIF
97      !
98   END SUBROUTINE rst_opn
99
100
101   SUBROUTINE rst_write( kt )
102      !!---------------------------------------------------------------------
103      !!                   ***  ROUTINE rstwrite  ***
104      !!                     
105      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
106      !!
107      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
108      !!      file, save fields which are necessary for restart
109      !!----------------------------------------------------------------------
110      INTEGER, INTENT(in) ::   kt   ! ocean time-step
111      !!----------------------------------------------------------------------
112      !                                                                     ! the begining of the run [s]
113      CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt               )   ! dynamics time step
114      CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1)         )   ! surface tracer time step
115
116      ! prognostic variables
117      CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub      )   
118      CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb      )
119      CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tb      )
120      CALL iom_rstput( kt, nitrst, numrow, 'sb'     , sb      )
121      CALL iom_rstput( kt, nitrst, numrow, 'rotb'   , rotb    )
122      CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb   )
123      CALL iom_rstput( kt, nitrst, numrow, 'un'     , un      )
124      CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn      )
125      IF( lk_vvl ) CALL iom_rstput( kt, nitrst, numrow, 'wn'     , wn      )
126      CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tn      )
127      CALL iom_rstput( kt, nitrst, numrow, 'sn'     , sn      )
128      CALL iom_rstput( kt, nitrst, numrow, 'rotn'   , rotn    )
129      CALL iom_rstput( kt, nitrst, numrow, 'hdivn'  , hdivn   )
130
131      IF( nn_dynhpg_rst == 1 .OR. lk_vvl ) THEN
132         CALL iom_rstput( kt, nitrst, numrow, 'rhd' , rhd  )
133         CALL iom_rstput( kt, nitrst, numrow, 'rhop', rhop )
134         IF( ln_zps ) THEN
135            CALL iom_rstput( kt, nitrst, numrow, 'gtu' , gtu )
136            CALL iom_rstput( kt, nitrst, numrow, 'gsu' , gsu )
137            CALL iom_rstput( kt, nitrst, numrow, 'gru' , gru )
138            CALL iom_rstput( kt, nitrst, numrow, 'gtv' , gtv )
139            CALL iom_rstput( kt, nitrst, numrow, 'gsv' , gsv )
140            CALL iom_rstput( kt, nitrst, numrow, 'grv' , grv )
141         ENDIF
142      ENDIF
143
144      IF( kt == nitrst ) THEN
145         CALL iom_close( numrow )     ! close the restart file (only at last time step)
146         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
147      ENDIF
148      !
149   END SUBROUTINE rst_write
150
151
152   SUBROUTINE rst_read
153      !!----------------------------------------------------------------------
154      !!                   ***  ROUTINE rst_read  ***
155      !!
156      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
157      !!
158      !! ** Method  :   Read the previous fields on the NetCDF/binary file
159      !!      the first record indicates previous characterics
160      !!      after control with the present run, we read :
161      !!      - prognostic variables on the second record
162      !!      - elliptic solver arrays
163      !!      - barotropic stream function arrays ("key_dynspg_rl" defined)
164      !!        or free surface arrays
165      !!      - tke arrays (lk_zdftke=T)
166      !!      for this last three records,  the previous characteristics
167      !!      could be different with those used in the present run.
168      !!----------------------------------------------------------------------
169      REAL(wp) ::   zrdt, zrdttra1
170      !!----------------------------------------------------------------------
171
172      IF(lwp) THEN                                             ! Contol prints
173         WRITE(numout,*)
174         SELECT CASE ( jprstlib )
175         CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
176         CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
177         END SELECT
178         WRITE(numout,*) '~~~~~~~~'
179      ENDIF
180
181      CALL iom_open( cn_ocerst_in, numror, kiolib = jprstlib )
182
183      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
184      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
185         CALL iom_get( numror, 'rdt', zrdt )
186         IF( zrdt /= rdt )   neuler = 0
187      ENDIF
188      IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 )   THEN
189         CALL iom_get( numror, 'rdttra1', zrdttra1 )
190         IF( zrdttra1 /= rdttra(1) )   neuler = 0
191      ENDIF
192      !                                                       ! Read prognostic variables
193      CALL iom_get( numror, jpdom_autoglo, 'ub'   , ub    )        ! before i-component velocity
194      CALL iom_get( numror, jpdom_autoglo, 'vb'   , vb    )        ! before j-component velocity
195      CALL iom_get( numror, jpdom_autoglo, 'tb'   , tb    )        ! before temperature
196      CALL iom_get( numror, jpdom_autoglo, 'sb'   , sb    )        ! before salinity
197      CALL iom_get( numror, jpdom_autoglo, 'rotb' , rotb  )        ! before curl
198      CALL iom_get( numror, jpdom_autoglo, 'hdivb', hdivb )        ! before horizontal divergence
199      CALL iom_get( numror, jpdom_autoglo, 'un'   , un    )        ! now    i-component velocity
200      CALL iom_get( numror, jpdom_autoglo, 'vn'   , vn    )        ! now    j-component velocity
201      IF( lk_vvl ) CALL iom_get( numror, jpdom_autoglo, 'wn'   , wn    )        ! now    k-component velocity
202      CALL iom_get( numror, jpdom_autoglo, 'tn'   , tn    )        ! now    temperature
203      CALL iom_get( numror, jpdom_autoglo, 'sn'   , sn    )        ! now    salinity
204      CALL iom_get( numror, jpdom_autoglo, 'rotn' , rotn  )        ! now    curl
205      CALL iom_get( numror, jpdom_autoglo, 'hdivn', hdivn )        ! now    horizontal divergence
206
207
208      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
209         tb   (:,:,:) = tn   (:,:,:)                             ! all before fields set to now field values
210         sb   (:,:,:) = sn   (:,:,:)
211         ub   (:,:,:) = un   (:,:,:)
212         vb   (:,:,:) = vn   (:,:,:)
213         rotb (:,:,:) = rotn (:,:,:)
214         hdivb(:,:,:) = hdivn(:,:,:)
215      ENDIF
216
217      IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN
218         CALL iom_get( numror, jpdom_autoglo, 'rhd' , rhd  )
219         CALL iom_get( numror, jpdom_autoglo, 'rhop', rhop )
220      ELSE
221         CALL eos( tb, sb, rhd, rhop )        ! before potential and in situ densities
222      ENDIF
223      IF( ln_zps .AND. .NOT. lk_c1d ) THEN
224         IF( iom_varid( numror, 'gtu', ldstop = .FALSE. ) > 0 ) THEN
225            CALL iom_get( numror, jpdom_autoglo, 'gtu' , gtu )
226            CALL iom_get( numror, jpdom_autoglo, 'gsu' , gsu )
227            CALL iom_get( numror, jpdom_autoglo, 'gru' , gru )
228            CALL iom_get( numror, jpdom_autoglo, 'gtv' , gtv )
229            CALL iom_get( numror, jpdom_autoglo, 'gsv' , gsv )
230            CALL iom_get( numror, jpdom_autoglo, 'grv' , grv )
231         ELSE
232            CALL zps_hde( nit000, tb , sb , rhd,   &  ! Partial steps: before Horizontal DErivative
233               &                  gtu, gsu, gru,   &  ! of t, s, rd at the bottom ocean level
234               &                  gtv, gsv, grv )
235         ENDIF
236      ENDIF
237      !
238   END SUBROUTINE rst_read
239
240
241   !!=====================================================================
242END MODULE restart
Note: See TracBrowser for help on using the repository browser.