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 branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/2015/dev_CMCC_merge_2015/NEMOGCM/NEMO/TOP_SRC/trcrst.F90 @ 6051

Last change on this file since 6051 was 6051, checked in by lovato, 8 years ago

Merge branches/2015/dev_r5056_CMCC4_simplification (see ticket #1456)

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