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

source: branches/DEV_r2106_LOCEAN2010/NEMO/OPA_SRC/IOM/restart.F90 @ 2148

Last change on this file since 2148 was 2148, checked in by cetlod, 14 years ago

merge LOCEAN 2010 developments branches

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