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

source: branches/2015/dev_r5218_CNRS17_coupling/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90 @ 5381

Last change on this file since 5381 was 5381, checked in by smasson, 9 years ago

dev_r5218_CNRS17_coupling: continue...

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