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 @ 2412

Last change on this file since 2412 was 2364, checked in by acc, 14 years ago

Added basic NetCDF4 chunking and compression support (key_netcdf4). See ticket #754

  • Property svn:keywords set to Id
File size: 11.7 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 , NEMO Consortium (2010)
50   !! $Id$
51   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_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 ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
98            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
99            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
100            ENDIF
101         ENDIF
102
103         CALL iom_open( clname, numrow, ldwrt = .TRUE., kiolib = jprstlib )
104         lrst_oce = .TRUE.
105      ENDIF
106      !
107   END SUBROUTINE rst_opn
108
109
110   SUBROUTINE rst_write( kt )
111      !!---------------------------------------------------------------------
112      !!                   ***  ROUTINE rstwrite  ***
113      !!                     
114      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
115      !!
116      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
117      !!              file, save fields which are necessary for restart
118      !!----------------------------------------------------------------------
119      INTEGER, INTENT(in) ::   kt   ! ocean time-step
120      !!----------------------------------------------------------------------
121
122      CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt       )   ! dynamics time step
123      CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1) )   ! surface tracer time step
124
125      CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub      )     ! before fields
126      CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb      )
127      CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tb      )
128      CALL iom_rstput( kt, nitrst, numrow, 'sb'     , sb      )
129      CALL iom_rstput( kt, nitrst, numrow, 'rotb'   , rotb    )
130      CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb   )
131      CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb    )
132      IF( lk_vvl ) &
133      CALL iom_rstput( kt, nitrst, numrow, 'fse3t_b', fse3t_b(:,:,:) )
134      !
135      CALL iom_rstput( kt, nitrst, numrow, 'un'     , un      )     ! now fields
136      CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn      )
137      CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tn      )
138      CALL iom_rstput( kt, nitrst, numrow, 'sn'     , sn      )
139      CALL iom_rstput( kt, nitrst, numrow, 'rotn'   , rotn    )
140      CALL iom_rstput( kt, nitrst, numrow, 'hdivn'  , hdivn   )
141      CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , sshn    )
142
143      CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop    )
144#if defined key_zdfkpp
145      CALL iom_rstput( kt, nitrst, numrow, 'rhd'    , rhd     )
146#endif
147
148#if defined key_zdfgls
149      ! Save bottom stresses
150      CALL iom_rstput( kt, nitrst, numrow, 'wbotu' , wbotu )
151      CALL iom_rstput( kt, nitrst, numrow, 'wbotv' , wbotv )
152#endif
153
154      IF( kt == nitrst ) THEN
155         CALL iom_close( numrow )     ! close the restart file (only at last time step)
156         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
157      ENDIF
158      !
159   END SUBROUTINE rst_write
160
161
162   SUBROUTINE rst_read
163      !!----------------------------------------------------------------------
164      !!                   ***  ROUTINE rst_read  ***
165      !!
166      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
167      !!
168      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
169      !!----------------------------------------------------------------------
170      REAL(wp) ::   zrdt, zrdttra1
171      INTEGER  ::   jk, jlibalt = jprstlib
172      LOGICAL  ::   llok
173      !!----------------------------------------------------------------------
174
175      IF(lwp) THEN                                             ! Contol prints
176         WRITE(numout,*)
177         SELECT CASE ( jprstlib )
178         CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
179         CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
180         END SELECT
181         IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
182         WRITE(numout,*) '~~~~~~~~'
183      ENDIF
184
185      IF ( jprstlib == jprstdimg ) THEN
186        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
187        ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90
188        INQUIRE( FILE = TRIM(cn_ocerst_in)//'.nc', EXIST = llok )
189        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
190      ENDIF
191      CALL iom_open( cn_ocerst_in, numror, kiolib = jlibalt )
192
193      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
194      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
195         CALL iom_get( numror, 'rdt', zrdt )
196         IF( zrdt /= rdt )   neuler = 0
197      ENDIF
198      IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 )   THEN
199         CALL iom_get( numror, 'rdttra1', zrdttra1 )
200         IF( zrdttra1 /= rdttra(1) )   neuler = 0
201      ENDIF
202      !
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'   , tb    )
206      CALL iom_get( numror, jpdom_autoglo, 'sb'   , sb    )
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      IF( lk_vvl )  &
211      CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) )
212      !
213      CALL iom_get( numror, jpdom_autoglo, 'un'   , un    )        ! now    fields
214      CALL iom_get( numror, jpdom_autoglo, 'vn'   , vn    )
215      CALL iom_get( numror, jpdom_autoglo, 'tn'   , tn    )
216      CALL iom_get( numror, jpdom_autoglo, 'sn'   , sn    )
217      CALL iom_get( numror, jpdom_autoglo, 'rotn' , rotn  )
218      CALL iom_get( numror, jpdom_autoglo, 'hdivn', hdivn )
219      CALL iom_get( numror, jpdom_autoglo, 'sshn' , sshn  )
220
221      CALL iom_get( numror, jpdom_autoglo, 'rhop' , rhop  )        ! now    potential density
222#if defined key_zdfkpp
223      IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN
224         CALL iom_get( numror, jpdom_autoglo, 'rhd' , rhd  )       ! now    in situ density anomaly
225      ELSE
226         CALL tra_swap
227         CALL eos( tsn, rhd )   ! compute rhd
228      ENDIF
229#endif
230
231      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
232         tb   (:,:,:) = tn   (:,:,:)                             ! all before fields set to now values
233         sb   (:,:,:) = sn   (:,:,:)
234         ub   (:,:,:) = un   (:,:,:)
235         vb   (:,:,:) = vn   (:,:,:)
236         rotb (:,:,:) = rotn (:,:,:)
237         hdivb(:,:,:) = hdivn(:,:,:)
238         sshb (:,:)   = sshn (:,:)
239         IF( lk_vvl ) THEN
240            DO jk = 1, jpk
241               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
242            ENDDO
243         ENDIF
244      ENDIF
245      !
246   END SUBROUTINE rst_read
247
248   !!=====================================================================
249END MODULE restart
Note: See TracBrowser for help on using the repository browser.