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.
trcrst.F90 in trunk/NEMOGCM/NEMO/TOP_SRC – NEMO

source: trunk/NEMOGCM/NEMO/TOP_SRC/trcrst.F90 @ 4990

Last change on this file since 4990 was 4990, checked in by timgraham, 9 years ago

Merged branches/2014/dev_MERGE_2014 back onto the trunk as follows:

In the working copy of branch ran:
svn merge svn+ssh://forge.ipsl.jussieu.fr/ipsl/forge/projets/nemo/svn/trunk@HEAD
1 conflict in LIM_SRC_3/limdiahsb.F90
Resolved by keeping the version from dev_MERGE_2014 branch
and commited at r4989

In working copy run:
svn switch svn+ssh://forge.ipsl.jussieu.fr/ipsl/forge/projets/nemo/svn/trunk
to switch working copy

Run:
svn merge --reintegrate svn+ssh://forge.ipsl.jussieu.fr/ipsl/forge/projets/nemo/svn/branches/2014/dev_MERGE_2014
to merge the branch into the trunk - no conflicts at this stage.

  • Property svn:keywords set to Id
File size: 13.9 KB
RevLine 
[268]1MODULE trcrst
[335]2   !!======================================================================
[1801]3   !!                         ***  MODULE trcrst  ***
4   !! TOP :   Manage the passive tracer restart
[335]5   !!======================================================================
[1801]6   !! History :    -   !  1991-03  ()  original code
7   !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
8   !!              -   !  2005-10 (C. Ethe) print control
9   !!             2.0  !  2005-10 (C. Ethe, G. Madec) revised architecture
[274]10   !!----------------------------------------------------------------------
[945]11#if defined key_top
[335]12   !!----------------------------------------------------------------------
[945]13   !!   'key_top'                                                TOP models
14   !!----------------------------------------------------------------------
[1801]15   !!----------------------------------------------------------------------
16   !!   trc_rst :   Restart for passive tracer
17   !!----------------------------------------------------------------------
18   !!----------------------------------------------------------------------
19   !!   'key_top'                                                TOP models
20   !!----------------------------------------------------------------------
[945]21   !!   trc_rst_opn    : open  restart file
22   !!   trc_rst_read   : read  restart file
23   !!   trc_rst_wri    : write restart file
24   !!----------------------------------------------------------------------
[335]25   USE oce_trc
26   USE trc
[2528]27   USE trcnam_trp
[616]28   USE iom
[2528]29   USE daymod
[335]30   IMPLICIT NONE
31   PRIVATE
[1801]32
[945]33   PUBLIC   trc_rst_opn       ! called by ???
34   PUBLIC   trc_rst_read      ! called by ???
35   PUBLIC   trc_rst_wri       ! called by ???
[3294]36   PUBLIC   trc_rst_cal
[1801]37
[350]38   !! * Substitutions
[945]39#  include "top_substitute.h90"
[335]40   
[268]41CONTAINS
[335]42   
[616]43   SUBROUTINE trc_rst_opn( kt )
44      !!----------------------------------------------------------------------
45      !!                    ***  trc_rst_opn  ***
46      !!
47      !! ** purpose  :   output of sea-trc variable in a netcdf file
48      !!----------------------------------------------------------------------
49      INTEGER, INTENT(in) ::   kt       ! number of iteration
50      !
51      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step define as a character
52      CHARACTER(LEN=50)   ::   clname   ! trc output restart file name
53      !!----------------------------------------------------------------------
54      !
[2528]55      IF( lk_offline ) THEN
[3294]56         IF( kt == nittrc000 ) THEN
[2528]57            lrst_trc = .FALSE.
58            nitrst = nitend
59         ENDIF
60
61         IF( MOD( kt - 1, nstock ) == 0 ) THEN
[3294]62            ! we use kt - 1 and not kt - nittrc000 to keep the same periodicity from the beginning of the experiment
[2528]63            nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
64            IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
65         ENDIF
66      ELSE
[3294]67         IF( kt == nittrc000 ) lrst_trc = .FALSE.
[1655]68      ENDIF
69
[2528]70      ! to get better performances with NetCDF format:
71      ! we open and define the tracer restart file one tracer time step before writing the data (-> at nitrst - 2*nn_dttrc + 1)
72      ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 2*nn_dttrc + 1
[3294]73      IF( kt == nitrst - 2*nn_dttrc .OR. nstock == nn_dttrc .OR. ( kt == nitend - nn_dttrc .AND. .NOT. lrst_trc ) ) THEN
[616]74         ! beware of the format used to write kt (default is i8.8, that should be large enough)
[945]75         IF( nitrst > 1.0e9 ) THEN   ;   WRITE(clkt,*       ) nitrst
76         ELSE                        ;   WRITE(clkt,'(i8.8)') nitrst
[616]77         ENDIF
78         ! create the file
79         IF(lwp) WRITE(numout,*)
[1254]80         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_trcrst_out)
[616]81         IF(lwp) WRITE(numout,*) '             open trc restart.output NetCDF file: '//clname
82         CALL iom_open( clname, numrtw, ldwrt = .TRUE., kiolib = jprstlib )
83         lrst_trc = .TRUE.
84      ENDIF
85      !
86   END SUBROUTINE trc_rst_opn
87
[1801]88   SUBROUTINE trc_rst_read
[945]89      !!----------------------------------------------------------------------
90      !!                    ***  trc_rst_opn  ***
[335]91      !!
[945]92      !! ** purpose  :   read passive tracer fields in restart files
93      !!----------------------------------------------------------------------
[1801]94      INTEGER  ::  jn     
[1287]95
[945]96      !!----------------------------------------------------------------------
[3294]97      !
[945]98      IF(lwp) WRITE(numout,*)
[3294]99      IF(lwp) WRITE(numout,*) 'trc_rst_read : read data in the TOP restart file'
[945]100      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
[350]101
[945]102      ! READ prognostic variables and computes diagnostic variable
[494]103      DO jn = 1, jptra
[1801]104         CALL iom_get( numrtr, jpdom_autoglo, 'TRN'//ctrcnm(jn), trn(:,:,:,jn) )
[335]105      END DO
[1077]106
[1287]107      DO jn = 1, jptra
[1801]108         CALL iom_get( numrtr, jpdom_autoglo, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) )
[1077]109      END DO
[945]110      !
111   END SUBROUTINE trc_rst_read
[494]112
[945]113   SUBROUTINE trc_rst_wri( kt )
114      !!----------------------------------------------------------------------
115      !!                    ***  trc_rst_wri  ***
[335]116      !!
[945]117      !! ** purpose  :   write passive tracer fields in restart files
118      !!----------------------------------------------------------------------
119      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
[335]120      !!
[1287]121      INTEGER  :: jn
122      REAL(wp) :: zarak0
[945]123      !!----------------------------------------------------------------------
[3294]124      !
[2528]125      CALL iom_rstput( kt, nitrst, numrtw, 'rdttrc1', rdttrc(1) )   ! surface passive tracer time step
[1801]126      ! prognostic variables
127      ! --------------------
[1100]128      DO jn = 1, jptra
129         CALL iom_rstput( kt, nitrst, numrtw, 'TRN'//ctrcnm(jn), trn(:,:,:,jn) )
130      END DO
[1077]131
[1100]132      DO jn = 1, jptra
133         CALL iom_rstput( kt, nitrst, numrtw, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) )
134      END DO
[3680]135      !
[1287]136      IF( kt == nitrst ) THEN
[1119]137          CALL trc_rst_stat            ! statistics
[1100]138          CALL iom_close( numrtw )     ! close the restart file (only at last time step)
[4990]139#if ! defined key_trdmxl_trc
[1100]140          lrst_trc = .FALSE.
[1177]141#endif
[1287]142      ENDIF
[945]143      !
[1801]144   END SUBROUTINE trc_rst_wri 
[268]145
[1801]146
[1287]147   SUBROUTINE trc_rst_cal( kt, cdrw )
148      !!---------------------------------------------------------------------
149      !!                   ***  ROUTINE trc_rst_cal  ***
150      !!
151      !!  ** Purpose : Read or write calendar in restart file:
152      !!
153      !!  WRITE(READ) mode:
154      !!       kt        : number of time step since the begining of the experiment at the
155      !!                   end of the current(previous) run
156      !!       adatrj(0) : number of elapsed days since the begining of the experiment at the
157      !!                   end of the current(previous) run (REAL -> keep fractions of day)
158      !!       ndastp    : date at the end of the current(previous) run (coded as yyyymmdd integer)
159      !!
160      !!   According to namelist parameter nrstdt,
[3294]161      !!       nn_rsttr = 0  no control on the date (nittrc000 is  arbitrary).
162      !!       nn_rsttr = 1  we verify that nittrc000 is equal to the last
[1287]163      !!                   time step of previous run + 1.
164      !!       In both those options, the  exact duration of the experiment
165      !!       since the beginning (cumulated duration of all previous restart runs)
[3294]166      !!       is not stored in the restart and is assumed to be (nittrc000-1)*rdt.
[1287]167      !!       This is valid is the time step has remained constant.
168      !!
[2528]169      !!       nn_rsttr = 2  the duration of the experiment in days (adatrj)
[1287]170      !!                    has been stored in the restart file.
171      !!----------------------------------------------------------------------
172      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
173      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
174      !
[3294]175      INTEGER  ::  jlibalt = jprstlib
176      LOGICAL  ::  llok
[2528]177      REAL(wp) ::  zkt, zrdttrc1
[1287]178      REAL(wp) ::  zndastp
179
180      ! Time domain : restart
181      ! ---------------------
182
183      IF( TRIM(cdrw) == 'READ' ) THEN
[3294]184
185         IF(lwp) WRITE(numout,*)
186         IF(lwp) WRITE(numout,*) 'trc_rst_cal : read the TOP restart file for calendar'
187         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
188
189         IF ( jprstlib == jprstdimg ) THEN
190           ! eventually read netcdf file (monobloc)  for restarting on different number of processors
191           ! if {cn_trcrst_in}.nc exists, then set jlibalt to jpnf90
192           INQUIRE( FILE = TRIM(cn_trcrst_in)//'.nc', EXIST = llok )
193           IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
194         ENDIF
195
196         CALL iom_open( cn_trcrst_in, numrtr, kiolib = jlibalt )
197
[1287]198         CALL iom_get ( numrtr, 'kt', zkt )   ! last time-step of previous run
[4152]199
[1287]200         IF(lwp) THEN
201            WRITE(numout,*) ' *** Info read in restart : '
202            WRITE(numout,*) '   previous time-step                               : ', NINT( zkt )
203            WRITE(numout,*) ' *** restart option'
[2528]204            SELECT CASE ( nn_rsttr )
[3294]205            CASE ( 0 )   ;   WRITE(numout,*) ' nn_rsttr = 0 : no control of nittrc000'
206            CASE ( 1 )   ;   WRITE(numout,*) ' nn_rsttr = 1 : no control the date at nittrc000 (use ndate0 read in the namelist)'
[2528]207            CASE ( 2 )   ;   WRITE(numout,*) ' nn_rsttr = 2 : calendar parameters read in restart'
[1287]208            END SELECT
209            WRITE(numout,*)
210         ENDIF
211         ! Control of date
[3294]212         IF( nittrc000  - NINT( zkt ) /= nn_dttrc .AND.  nn_rsttr /= 0 )                                  &
213            &   CALL ctl_stop( ' ===>>>> : problem with nittrc000 for the restart',                 &
[2528]214            &                  ' verify the restart file or rerun with nn_rsttr = 0 (namelist)' )
215         IF( lk_offline ) THEN      ! set the date in offline mode
216            ! Check dynamics and tracer time-step consistency and force Euler restart if changed
217            IF( iom_varid( numrtr, 'rdttrc1', ldstop = .FALSE. ) > 0 )   THEN
218               CALL iom_get( numrtr, 'rdttrc1', zrdttrc1 )
[4152]219               IF( zrdttrc1 /= rdt * nn_dttrc )   neuler = 0
[2528]220            ENDIF
221            !                          ! define ndastp and adatrj
[4152]222            IF( nn_rsttr == 2 ) THEN
[2528]223               CALL iom_get( numrtr, 'ndastp', zndastp ) 
224               ndastp = NINT( zndastp )
225               CALL iom_get( numrtr, 'adatrj', adatrj  )
226            ELSE
227               ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam
[3294]228               adatrj = ( REAL( nittrc000-1, wp ) * rdttra(1) ) / rday
[2528]229               ! note this is wrong if time step has changed during run
230            ENDIF
231            !
232            IF(lwp) THEN
233              WRITE(numout,*) ' *** Info used values : '
234              WRITE(numout,*) '   date ndastp                                      : ', ndastp
235              WRITE(numout,*) '   number of elapsed days since the begining of run : ', adatrj
236              WRITE(numout,*)
237            ENDIF
238            !
239            CALL day_init          ! compute calendar
240            !
[1287]241         ENDIF
242         !
243      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
244         !
245         IF(  kt == nitrst ) THEN
246            IF(lwp) WRITE(numout,*)
247            IF(lwp) WRITE(numout,*) 'trc_wri : write the TOP restart file (NetCDF) at it= ', kt, ' date= ', ndastp
248            IF(lwp) WRITE(numout,*) '~~~~~~~'
249         ENDIF
250         CALL iom_rstput( kt, nitrst, numrtw, 'kt'     , REAL( kt    , wp) )   ! time-step
251         CALL iom_rstput( kt, nitrst, numrtw, 'ndastp' , REAL( ndastp, wp) )   ! date
252         CALL iom_rstput( kt, nitrst, numrtw, 'adatrj' , adatrj            )   ! number of elapsed days since
253         !                                                                     ! the begining of the run [s]
254      ENDIF
255
256   END SUBROUTINE trc_rst_cal
257
[1119]258
259   SUBROUTINE trc_rst_stat
260      !!----------------------------------------------------------------------
261      !!                    ***  trc_rst_stat  ***
262      !!
263      !! ** purpose  :   Compute tracers statistics
264      !!----------------------------------------------------------------------
[3294]265      INTEGER  :: jk, jn
266      REAL(wp) :: ztraf, zmin, zmax, zmean, zdrift
[1119]267      !!----------------------------------------------------------------------
268
269      IF( lwp ) THEN
270         WRITE(numout,*) 
271         WRITE(numout,*) '           ----TRACER STAT----             '
272         WRITE(numout,*) 
273      ENDIF
[3294]274      !
[1119]275      DO jn = 1, jptra
[3294]276         ztraf = glob_sum( trn(:,:,:,jn) * cvol(:,:,:) )
277         zmin  = MINVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
278         zmax  = MAXVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
[1119]279         IF( lk_mpp ) THEN
[3294]280            CALL mpp_min( zmin )      ! min over the global domain
281            CALL mpp_max( zmax )      ! max over the global domain
[1119]282         END IF
[3294]283         zmean  = ztraf / areatot
284         zdrift = ( ( ztraf - trai(jn) ) / ( trai(jn) + 1.e-12 )  ) * 100._wp
285         IF(lwp) WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), zmean, zmin, zmax, zdrift
[1119]286      END DO
[3294]287      WRITE(numout,*) 
2889000  FORMAT(' tracer nb :',i2,'    name :',a10,'    mean :',e18.10,'    min :',e18.10, &
289      &      '    max :',e18.10,'    drift :',e18.10, ' %')
290      !
[1119]291   END SUBROUTINE trc_rst_stat
292
[268]293#else
[945]294   !!----------------------------------------------------------------------
295   !!  Dummy module :                                     No passive tracer
296   !!----------------------------------------------------------------------
[335]297CONTAINS
[945]298   SUBROUTINE trc_rst_read                      ! Empty routines
[616]299   END SUBROUTINE trc_rst_read
[945]300   SUBROUTINE trc_rst_wri( kt )
[335]301      INTEGER, INTENT ( in ) :: kt
[616]302      WRITE(*,*) 'trc_rst_wri: You should not have seen this print! error?', kt
[945]303   END SUBROUTINE trc_rst_wri   
[268]304#endif
[945]305
[2528]306   !!----------------------------------------------------------------------
307   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
308   !! $Id$
309   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
[945]310   !!======================================================================
[335]311END MODULE trcrst
Note: See TracBrowser for help on using the repository browser.