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/UKMO/dev_r8864_restart_date/NEMOGCM/TOOLS/DOMAINcfg/src – NEMO

source: branches/UKMO/dev_r8864_restart_date/NEMOGCM/TOOLS/DOMAINcfg/src/restart.f90 @ 9235

Last change on this file since 9235 was 9235, checked in by davestorkey, 6 years ago

UKMO/dev_r8864_restart_date : clear SVN keywords.

File size: 14.0 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   !!            3.7  !  2014-01  (G. Madec) suppression of curl and hdiv from the restart
12   !!             -   !  2014-12  (G. Madec) remove KPP scheme
13   !!----------------------------------------------------------------------
14
15   !!----------------------------------------------------------------------
16   !!   rst_opn    : open the ocean restart file
17   !!   rst_write  : write the ocean restart file
18   !!   rst_read   : read the ocean restart file
19   !!----------------------------------------------------------------------
20   USE oce             ! ocean dynamics and tracers
21   USE dom_oce         ! ocean space and time domain
22   USE sbc_ice         ! only lk_lim3
23   USE phycst          ! physical constants
24   USE eosbn2          ! equation of state            (eos bn2 routine)
25   USE trdmxl_oce      ! ocean active mixed layer tracers trends variables
26   !
27   USE in_out_manager  ! I/O manager
28   USE iom             ! I/O module
29   USE diurnal_bulk
30   
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 istate module
37   PUBLIC   rst_read_open   ! routine called in rst_read and (possibly) in dom_vvl_init
38
39   !! * Substitutions
40   !!----------------------------------------------------------------------
41   !!                   ***  vectopt_loop_substitute  ***
42   !!----------------------------------------------------------------------
43   !! ** purpose :   substitute the inner loop start/end indices with CPP macro
44   !!                allow unrolling of do-loop (useful with vector processors)
45   !!----------------------------------------------------------------------
46   !!----------------------------------------------------------------------
47   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
48   !! $Id$
49   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
50   !!----------------------------------------------------------------------
51   !!----------------------------------------------------------------------
52   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
53   !! $Id$
54   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
55   !!----------------------------------------------------------------------
56CONTAINS
57
58   SUBROUTINE rst_opn( kt )
59      !!---------------------------------------------------------------------
60      !!                   ***  ROUTINE rst_opn  ***
61      !!                     
62      !! ** Purpose : + initialization (should be read in the namelist) of nitrst
63      !!              + open the restart when we are one time step before nitrst
64      !!                   - restart header is defined when kt = nitrst-1
65      !!                   - restart data  are written when kt = nitrst
66      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
67      !!----------------------------------------------------------------------
68      INTEGER, INTENT(in) ::   kt     ! ocean time-step
69      !!
70      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
71      CHARACTER(LEN=50)   ::   clname   ! ocean output restart file name
72      CHARACTER(lc)       ::   clpath   ! full path to ocean output restart file
73      !!----------------------------------------------------------------------
74      !
75      IF( kt == nit000 ) THEN   ! default definitions
76         lrst_oce = .FALSE.   
77         IF( ln_rst_list ) THEN
78            nrst_lst = 1
79            nitrst = nstocklist( nrst_lst )
80         ELSE
81            nitrst = nitend
82         ENDIF
83      ENDIF
84
85      ! frequency-based restart dumping (nn_stock)
86      IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN   
87         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
88         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
89         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
90      ENDIF
91      ! to get better performances with NetCDF format:
92      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
93      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
94      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
95         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN 
96            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
97            IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
98            ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
99            ENDIF
100            ! create the file
101            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
102            clpath = TRIM(cn_ocerst_outdir)
103            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
104            IF(lwp) THEN
105               WRITE(numout,*)
106               SELECT CASE ( jprstlib )
107               CASE DEFAULT         ;   WRITE(numout,*)                            &
108                   '             open ocean restart NetCDF file: ',TRIM(clpath)//clname
109               END SELECT
110               IF ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
111               IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
112               ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
113               ENDIF
114            ENDIF
115            !
116            CALL iom_open( TRIM(clpath)//TRIM(clname), numrow, ldwrt = .TRUE., kiolib = jprstlib )
117            lrst_oce = .TRUE.
118         ENDIF
119      ENDIF
120      !
121   END SUBROUTINE rst_opn
122
123
124   SUBROUTINE rst_write( kt )
125      !!---------------------------------------------------------------------
126      !!                   ***  ROUTINE rstwrite  ***
127      !!                     
128      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
129      !!
130      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
131      !!              file, save fields which are necessary for restart
132      !!----------------------------------------------------------------------
133      INTEGER, INTENT(in) ::   kt   ! ocean time-step
134      !!----------------------------------------------------------------------
135
136                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       )   ! dynamics and tracer time step
137
138      IF ( .NOT. ln_diurnal_only ) THEN
139                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub        )     ! before fields
140                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb        )
141                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tsb(:,:,:,jp_tem) )
142                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , tsb(:,:,:,jp_sal) )
143                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb      )
144                     !
145                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , un        )     ! now fields
146                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn        )
147                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tsn(:,:,:,jp_tem) )
148                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , tsn(:,:,:,jp_sal) )
149                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , sshn      )
150                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop      )
151
152                  ! extra variable needed for the ice sheet coupling
153                  IF ( ln_iscpl ) THEN
154                     CALL iom_rstput( kt, nitrst, numrow, 'tmask'  , tmask     ) ! need to extrapolate T/S
155                     CALL iom_rstput( kt, nitrst, numrow, 'umask'  , umask     ) ! need to correct barotropic velocity
156                     CALL iom_rstput( kt, nitrst, numrow, 'vmask'  , vmask     ) ! need to correct barotropic velocity
157                     CALL iom_rstput( kt, nitrst, numrow, 'smask'  , ssmask    ) ! need to correct barotropic velocity
158                     CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t_n(:,:,:) )   ! need to compute temperature correction
159                     CALL iom_rstput( kt, nitrst, numrow, 'e3u_n', e3u_n(:,:,:) )   ! need to compute bt conservation
160                     CALL iom_rstput( kt, nitrst, numrow, 'e3v_n', e3v_n(:,:,:) )   ! need to compute bt conservation
161                     CALL iom_rstput( kt, nitrst, numrow, 'gdepw_n', gdepw_n(:,:,:) ) ! need to compute extrapolation if vvl
162                  END IF
163      ENDIF
164     
165      IF (ln_diurnal) CALL iom_rstput( kt, nitrst, numrow, 'Dsst', x_dsst    ) 
166
167      IF( kt == nitrst ) THEN
168         CALL iom_close( numrow )     ! close the restart file (only at last time step)
169!!gm         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
170!!gm  not sure what to do here   ===>>>  ask to Sebastian
171         lrst_oce = .FALSE.
172            IF( ln_rst_list ) THEN
173               nrst_lst = MIN(nrst_lst + 1, SIZE(nstocklist,1))
174               nitrst = nstocklist( nrst_lst )
175            ENDIF
176            lrst_oce = .FALSE.
177      ENDIF
178      !
179   END SUBROUTINE rst_write
180
181
182   SUBROUTINE rst_read_open
183      !!----------------------------------------------------------------------
184      !!                   ***  ROUTINE rst_read_open  ***
185      !!
186      !! ** Purpose :   Open read files for restart (format fixed by jprstlib )
187      !!
188      !! ** Method  :   Use a non-zero, positive value of numror to assess whether or not
189      !!                the file has already been opened
190      !!----------------------------------------------------------------------
191      INTEGER        ::   jlibalt = jprstlib
192      LOGICAL        ::   llok
193      CHARACTER(lc)  ::   clpath   ! full path to ocean output restart file
194      !!----------------------------------------------------------------------
195      !
196      IF( numror <= 0 ) THEN
197         IF(lwp) THEN                                             ! Contol prints
198            WRITE(numout,*)
199            SELECT CASE ( jprstlib )
200            CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
201            END SELECT
202            IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
203            WRITE(numout,*) '~~~~~~~~'
204         ENDIF
205
206         clpath = TRIM(cn_ocerst_indir)
207         IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
208         CALL iom_open( TRIM(clpath)//cn_ocerst_in, numror, kiolib = jlibalt )
209      ENDIF
210   END SUBROUTINE rst_read_open
211
212
213   SUBROUTINE rst_read
214      !!----------------------------------------------------------------------
215      !!                   ***  ROUTINE rst_read  ***
216      !!
217      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
218      !!
219      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
220      !!----------------------------------------------------------------------
221      REAL(wp) ::   zrdt
222      INTEGER  ::   jk
223      !!----------------------------------------------------------------------
224
225      CALL rst_read_open           ! open restart for reading (if not already opened)
226
227      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
228      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
229         CALL iom_get( numror, 'rdt', zrdt )
230         IF( zrdt /= rdt )   neuler = 0
231      ENDIF
232
233      ! Diurnal DSST
234      IF( ln_diurnal ) CALL iom_get( numror, jpdom_autoglo, 'Dsst' , x_dsst  ) 
235      IF ( ln_diurnal_only ) THEN
236         IF(lwp) WRITE( numout, * ) &
237         &   "rst_read:- ln_diurnal_only set, setting rhop=rau0" 
238         rhop = rau0
239         CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,1,jp_tem) ) 
240         RETURN
241      ENDIF 
242     
243      IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
244         CALL iom_get( numror, jpdom_autoglo, 'ub'     , ub      )   ! before fields
245         CALL iom_get( numror, jpdom_autoglo, 'vb'     , vb      )
246         CALL iom_get( numror, jpdom_autoglo, 'tb'     , tsb(:,:,:,jp_tem) )
247         CALL iom_get( numror, jpdom_autoglo, 'sb'     , tsb(:,:,:,jp_sal) )
248         CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb    )
249      ELSE
250         neuler = 0
251      ENDIF
252      !
253      CALL iom_get( numror, jpdom_autoglo, 'un'     , un      )   ! now    fields
254      CALL iom_get( numror, jpdom_autoglo, 'vn'     , vn      )
255      CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,:,jp_tem) )
256      CALL iom_get( numror, jpdom_autoglo, 'sn'     , tsn(:,:,:,jp_sal) )
257      CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn    )
258      IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN
259         CALL iom_get( numror, jpdom_autoglo, 'rhop'   , rhop    )   ! now    potential density
260      ELSE
261         CALL eos( tsn, rhd, rhop, gdept_n(:,:,:) )   
262      ENDIF
263      !
264      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
265         tsb  (:,:,:,:) = tsn  (:,:,:,:)                             ! all before fields set to now values
266         ub   (:,:,:)   = un   (:,:,:)
267         vb   (:,:,:)   = vn   (:,:,:)
268         sshb (:,:)     = sshn (:,:)
269         !
270         IF( .NOT.ln_linssh ) THEN
271            DO jk = 1, jpk
272               e3t_b(:,:,jk) = e3t_n(:,:,jk)
273            END DO
274         ENDIF
275         !
276      ENDIF
277      !
278   END SUBROUTINE rst_read
279
280   !!=====================================================================
281END MODULE restart
Note: See TracBrowser for help on using the repository browser.