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

source: branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90 @ 2281

Last change on this file since 2281 was 2281, checked in by smasson, 14 years ago

set proper svn properties to all files...

  • Property svn:keywords set to Id
File size: 11.5 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 dom_oce         ! ocean space and time domain
19   USE oce             ! ocean dynamics and tracers
20   USE phycst          ! physical constants
21   USE in_out_manager  ! I/O manager
22   USE iom             ! I/O module
23   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
24   USE eosbn2          ! equation of state            (eos bn2 routine)
25   USE zdfddm          ! double diffusion mixing
26   USE zdfmxl          ! mixed layer depth
27   USE trdmld_oce      ! ocean active mixed layer tracers trends variables
28   USE domvvl          ! variable volume
29   USE traswp          ! swap from 4D T-S to 3D T & S and vice versa
30#if defined key_zdfgls
31   USE zdfbfr, ONLY : wbotu, wbotv ! bottom stresses
32   USE zdf_oce
33#endif
34
35   IMPLICIT NONE
36   PRIVATE
37
38   PUBLIC   rst_opn    ! routine called by step module
39   PUBLIC   rst_write  ! routine called by step module
40   PUBLIC   rst_read   ! routine called by opa  module
41
42   LOGICAL, PUBLIC ::   lrst_oce =  .FALSE.   !: logical to control the oce restart write
43   INTEGER, PUBLIC ::   numror, numrow        !: logical unit for cean restart (read and write)
44
45   !! * Substitutions
46#  include "domzgr_substitute.h90"
47#  include "vectopt_loop_substitute.h90"
48   !!----------------------------------------------------------------------
49   !! NEMO/OPA 3.3 , LOCEAN-IPSL (2010)
50   !! $Id$
51   !! Software governed by the CeCILL licence  (NEMOGCM/License_CeCILL.txt)
52   !!----------------------------------------------------------------------
53
54CONTAINS
55
56   SUBROUTINE rst_opn( kt )
57      !!---------------------------------------------------------------------
58      !!                   ***  ROUTINE rst_opn  ***
59      !!                     
60      !! ** Purpose : + initialization (should be read in the namelist) of nitrst
61      !!              + open the restart when we are one time step before nitrst
62      !!                   - restart header is defined when kt = nitrst-1
63      !!                   - restart data  are written when kt = nitrst
64      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
65      !!----------------------------------------------------------------------
66      INTEGER, INTENT(in) ::   kt     ! ocean time-step
67      !!
68      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
69      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
70      !!----------------------------------------------------------------------
71      !
72      IF( kt == nit000 ) THEN   ! default definitions
73         lrst_oce = .FALSE.   
74         nitrst = nitend
75      ENDIF
76      IF( MOD( kt - 1, nstock ) == 0 ) THEN   
77         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
78         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
79         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
80      ENDIF
81      ! to get better performances with NetCDF format:
82      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
83      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
84      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
85         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
86         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
87         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
88         ENDIF
89         ! create the file
90         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
91         IF(lwp) THEN
92            WRITE(numout,*)
93            SELECT CASE ( jprstlib )
94            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart binary file: '//clname
95            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart NetCDF file: '//clname
96            END SELECT
97            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
98            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
99            ENDIF
100         ENDIF
101
102         CALL iom_open( clname, numrow, ldwrt = .TRUE., kiolib = jprstlib )
103         lrst_oce = .TRUE.
104      ENDIF
105      !
106   END SUBROUTINE rst_opn
107
108
109   SUBROUTINE rst_write( kt )
110      !!---------------------------------------------------------------------
111      !!                   ***  ROUTINE rstwrite  ***
112      !!                     
113      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
114      !!
115      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
116      !!              file, save fields which are necessary for restart
117      !!----------------------------------------------------------------------
118      INTEGER, INTENT(in) ::   kt   ! ocean time-step
119      !!----------------------------------------------------------------------
120
121      CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       )   ! dynamics time step
122      CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1) )   ! surface tracer time step
123
124      CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub      )     ! before fields
125      CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb      )
126      CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tb      )
127      CALL iom_rstput( kt, nitrst, numrow, 'sb'     , sb      )
128      CALL iom_rstput( kt, nitrst, numrow, 'rotb'   , rotb    )
129      CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb   )
130      CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb    )
131      IF( lk_vvl ) &
132      CALL iom_rstput( kt, nitrst, numrow, 'fse3t_b', fse3t_b(:,:,:) )
133      !
134      CALL iom_rstput( kt, nitrst, numrow, 'un'     , un      )     ! now fields
135      CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn      )
136      CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tn      )
137      CALL iom_rstput( kt, nitrst, numrow, 'sn'     , sn      )
138      CALL iom_rstput( kt, nitrst, numrow, 'rotn'   , rotn    )
139      CALL iom_rstput( kt, nitrst, numrow, 'hdivn'  , hdivn   )
140      CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , sshn    )
141
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
147#if defined key_zdfgls
148      ! Save bottom stresses
149      CALL iom_rstput( kt, nitrst, numrow, 'wbotu' , wbotu )
150      CALL iom_rstput( kt, nitrst, numrow, 'wbotv' , wbotv )
151#endif
152
153      IF( kt == nitrst ) THEN
154         CALL iom_close( numrow )     ! close the restart file (only at last time step)
155         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
156      ENDIF
157      !
158   END SUBROUTINE rst_write
159
160
161   SUBROUTINE rst_read
162      !!----------------------------------------------------------------------
163      !!                   ***  ROUTINE rst_read  ***
164      !!
165      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
166      !!
167      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
168      !!----------------------------------------------------------------------
169      REAL(wp) ::   zrdt, zrdttra1
170      INTEGER  ::   jk, jlibalt = jprstlib
171      LOGICAL  ::   llok
172      !!----------------------------------------------------------------------
173
174      IF(lwp) THEN                                             ! Contol prints
175         WRITE(numout,*)
176         SELECT CASE ( jprstlib )
177         CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
178         CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
179         END SELECT
180         WRITE(numout,*) '~~~~~~~~'
181      ENDIF
182
183      IF ( jprstlib == jprstdimg ) THEN
184        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
185        ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90
186        INQUIRE( FILE = TRIM(cn_ocerst_in)//'.nc', EXIST = llok )
187        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
188      ENDIF
189      CALL iom_open( cn_ocerst_in, numror, kiolib = jlibalt )
190
191      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
192      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
193         CALL iom_get( numror, 'rdt', zrdt )
194         IF( zrdt /= rdt )   neuler = 0
195      ENDIF
196      IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 )   THEN
197         CALL iom_get( numror, 'rdttra1', zrdttra1 )
198         IF( zrdttra1 /= rdttra(1) )   neuler = 0
199      ENDIF
200      !
201      CALL iom_get( numror, jpdom_autoglo, 'ub'   , ub    )        ! before fields
202      CALL iom_get( numror, jpdom_autoglo, 'vb'   , vb    )
203      CALL iom_get( numror, jpdom_autoglo, 'tb'   , tb    )
204      CALL iom_get( numror, jpdom_autoglo, 'sb'   , sb    )
205      CALL iom_get( numror, jpdom_autoglo, 'rotb' , rotb  )
206      CALL iom_get( numror, jpdom_autoglo, 'hdivb', hdivb )
207      CALL iom_get( numror, jpdom_autoglo, 'sshb' , sshb  )
208      IF( lk_vvl )  &
209      CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) )
210      !
211      CALL iom_get( numror, jpdom_autoglo, 'un'   , un    )        ! now    fields
212      CALL iom_get( numror, jpdom_autoglo, 'vn'   , vn    )
213      CALL iom_get( numror, jpdom_autoglo, 'tn'   , tn    )
214      CALL iom_get( numror, jpdom_autoglo, 'sn'   , sn    )
215      CALL iom_get( numror, jpdom_autoglo, 'rotn' , rotn  )
216      CALL iom_get( numror, jpdom_autoglo, 'hdivn', hdivn )
217      CALL iom_get( numror, jpdom_autoglo, 'sshn' , sshn  )
218
219      CALL iom_get( numror, jpdom_autoglo, 'rhop' , rhop  )        ! now    potential density
220#if defined key_zdfkpp
221      IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN
222         CALL iom_get( numror, jpdom_autoglo, 'rhd' , rhd  )       ! now    in situ density anomaly
223      ELSE
224         CALL tra_swap
225         CALL eos( tsn, rhd )   ! compute rhd
226      ENDIF
227#endif
228
229      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
230         tb   (:,:,:) = tn   (:,:,:)                             ! all before fields set to now values
231         sb   (:,:,:) = sn   (:,:,:)
232         ub   (:,:,:) = un   (:,:,:)
233         vb   (:,:,:) = vn   (:,:,:)
234         rotb (:,:,:) = rotn (:,:,:)
235         hdivb(:,:,:) = hdivn(:,:,:)
236         sshb (:,:)   = sshn (:,:)
237         IF( lk_vvl ) THEN
238            DO jk = 1, jpk
239               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
240            ENDDO
241         ENDIF
242      ENDIF
243      !
244   END SUBROUTINE rst_read
245
246   !!=====================================================================
247END MODULE restart
Note: See TracBrowser for help on using the repository browser.