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

source: branches/DEV_r2006_merge_TRA_TRC/NEMO/OPA_SRC/IOM/restart.F90 @ 2082

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

Improve the merge of TRA-TRC, see ticket #717

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