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.
trcstp.F90 in branches/UKMO/dev_r5518_GO6_package_text_diagnostics/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/UKMO/dev_r5518_GO6_package_text_diagnostics/NEMOGCM/NEMO/TOP_SRC/trcstp.F90 @ 10867

Last change on this file since 10867 was 10745, checked in by andmirek, 5 years ago

GMED 450 GO8 changes to namelist namctl

File size: 11.2 KB
RevLine 
[1457]1MODULE trcstp
2   !!======================================================================
3   !!                       ***  MODULE trcstp  ***
4   !! Time-stepping    : time loop of opa for passive tracer
5   !!======================================================================
[2528]6   !! History :  1.0  !  2004-03  (C. Ethe)  Original
7   !!----------------------------------------------------------------------
[1457]8#if defined key_top
9   !!----------------------------------------------------------------------
10   !!   trc_stp      : passive tracer system time-stepping
11   !!----------------------------------------------------------------------
12   USE oce_trc          ! ocean dynamics and active tracers variables
[4306]13   USE sbc_oce
[2528]14   USE trc
[1457]15   USE trctrp           ! passive tracers transport
16   USE trcsms           ! passive tracers sources and sinks
17   USE prtctl_trc       ! Print control for debbuging
18   USE trcdia
19   USE trcwri
20   USE trcrst
[9163]21   USE trcstat
[4990]22   USE trdtrc_oce
23   USE trdmxl_trc
[1457]24   USE iom
25   USE in_out_manager
[3294]26   USE trcsub
[1457]27
28   IMPLICIT NONE
29   PRIVATE
30
[2528]31   PUBLIC   trc_stp    ! called by step
[3294]32
[5385]33   REAL(wp), DIMENSION(:,:,:), SAVE, ALLOCATABLE ::   qsr_arr ! save qsr during TOP time-step
34   REAL(wp) :: rdt_sampl
[6487]35   INTEGER  :: nb_rec_per_day
[5385]36   INTEGER  :: isecfst, iseclast
37   LOGICAL  :: llnew
38
[3294]39   !! * Substitutions
40#  include "domzgr_substitute.h90"
[1457]41   !!----------------------------------------------------------------------
[2528]42   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
[6486]43   !! $Id$
[2528]44   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
[1457]45   !!----------------------------------------------------------------------
46CONTAINS
47
48   SUBROUTINE trc_stp( kt )
49      !!-------------------------------------------------------------------
50      !!                     ***  ROUTINE trc_stp  ***
51      !!                     
52      !! ** Purpose : Time loop of opa for passive tracer
53      !!
54      !! ** Method  :
55      !!              Compute the passive tracers trends
56      !!              Update the passive tracers
57      !!-------------------------------------------------------------------
[8280]58
59      USE dom_oce, ONLY: narea
60
[3294]61      INTEGER, INTENT( in ) ::  kt      ! ocean time-step index
62      INTEGER               ::  jk, jn  ! dummy loop indices
63      REAL(wp)              ::  ztrai
[10745]64      LOGICAL ::   ll_trcstat ! local logical
[4306]65      CHARACTER (len=25)    ::  charout 
[2528]66      !!-------------------------------------------------------------------
[3294]67      !
68      IF( nn_timing == 1 )   CALL timing_start('trc_stp')
69      !
[10745]70      ll_trcstat  = ( ln_ctl .OR. sn_cfctl%l_trcstat ) .AND. &
71     &              ( ( MOD( kt, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend ) )
[4990]72      IF( kt == nittrc000 .AND. lk_trdmxl_trc )  CALL trd_mxl_trc_init    ! trends: Mixed-layer
[3294]73      !
[3319]74      IF( lk_vvl ) THEN                                                   ! update ocean volume due to ssh temporal evolution
[3294]75         DO jk = 1, jpk
76            cvol(:,:,jk) = e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
77         END DO
[3319]78         IF( lk_degrad )  cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:)       ! degrad option: reduction by facvol
[3294]79         areatot         = glob_sum( cvol(:,:,:) )
80      ENDIF
[5385]81      !
82      IF( l_trcdm2dc )   CALL trc_mean_qsr( kt )
[3294]83      !   
[4306]84      IF( nn_dttrc /= 1 )   CALL trc_sub_stp( kt )  ! averaging physical variables for sub-stepping
85      !   
86      IF( MOD( kt , nn_dttrc ) == 0 ) THEN      ! only every nn_dttrc time step
[2528]87         !
88         IF(ln_ctl) THEN
89            WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
90            CALL prt_ctl_trc_info(charout)
91         ENDIF
92         !
93         tra(:,:,:,:) = 0.e0
94         !
[3294]95                                   CALL trc_rst_opn  ( kt )       ! Open tracer restart file
[3680]96         IF( lrst_trc )            CALL trc_rst_cal  ( kt, 'WRITE' )   ! calendar
[3294]97         IF( lk_iomput ) THEN  ;   CALL trc_wri      ( kt )       ! output of passive tracers with iom I/O manager
98         ELSE                  ;   CALL trc_dia      ( kt )       ! output of passive tracers with old I/O manager
[2528]99         ENDIF
[3294]100                                   CALL trc_sms      ( kt )       ! tracers: sinks and sources
[8280]101# if defined key_debug_medusa
102         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp SMS complete at kt =', kt
103         CALL trc_rst_stat
104         CALL trc_rst_tra_stat
105         CALL flush(numout)
106# endif
[3294]107                                   CALL trc_trp      ( kt )       ! transport of passive tracers
[8280]108# if defined key_debug_medusa
109         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp transport complete at kt =', kt
110         CALL trc_rst_stat
111         CALL trc_rst_tra_stat
112         CALL flush(numout)
113# endif
[4147]114         IF( kt == nittrc000 ) THEN
115            CALL iom_close( numrtr )       ! close input tracer restart file
[4624]116            IF(lwm) CALL FLUSH( numont )   ! flush namelist output
[4147]117         ENDIF
[3294]118         IF( lrst_trc )            CALL trc_rst_wri  ( kt )       ! write tracer restart file
[4990]119         IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt )       ! trends: Mixed-layer
[2528]120         !
[3294]121         IF( nn_dttrc /= 1   )     CALL trc_sub_reset( kt )       ! resetting physical variables when sub-stepping
122         !
[1457]123      ENDIF
[3294]124      !
[10745]125      IF (ll_trcstat) THEN 
[8280]126         ! The following code is very expensive since it involves multiple
127         ! reproducible global sums over all tracer fields and is potentially 
128         ! called on every timestep. The results it produces are purely for
129         ! informational purposes and do not affect model evolution.
130         ! Hence we restrict its use by protecting it with the ln_ctl RTL
131         ! which should normally only be used under debugging conditions
132         ! and not in operational runs. We also need to restrict output 
133         ! to the master PE since there's no point duplicating the same results
134         ! on all processors.   
135         ztrai = 0._wp                                                   !  content of all tracers
136         DO jn = 1, jptra
137            ztrai = ztrai + glob_sum( trn(:,:,:,jn) * cvol(:,:,:)   )
138         END DO
139         IF( numstr /= -1 ) WRITE(numstr,9300) kt,  ztrai / areatot
[8356]1409300     FORMAT(i10,D23.16)
[8280]141      ENDIF
[3294]142      !
143      IF( nn_timing == 1 )   CALL timing_stop('trc_stp')
144      !
[1457]145   END SUBROUTINE trc_stp
146
[5385]147   SUBROUTINE trc_mean_qsr( kt )
148      !!----------------------------------------------------------------------
149      !!             ***  ROUTINE trc_mean_qsr  ***
150      !!
151      !! ** Purpose :  Compute daily mean qsr for biogeochemical model in case
152      !!               of diurnal cycle
153      !!
[6487]154      !! ** Method  : store in TOP the qsr every hour ( or every time-step if the latter
[5385]155      !!              is greater than 1 hour ) and then, compute the  mean with
156      !!              a moving average over 24 hours.
157      !!              In coupled mode, the sampling is done at every coupling frequency
158      !!----------------------------------------------------------------------
159      INTEGER, INTENT(in) ::   kt
160      INTEGER  :: jn
[8356]161      REAL(wp) :: zsecfst
162      CHARACTER(len=1)               ::   cl1                      ! 1 character
163      CHARACTER(len=2)               ::   cl2                      ! 2 characters
[5385]164
165      IF( kt == nittrc000 ) THEN
[5407]166         IF( ln_cpl )  THEN 
[5385]167            rdt_sampl = 86400. / ncpl_qsr_freq
[6487]168            nb_rec_per_day = ncpl_qsr_freq
[5385]169         ELSE 
170            rdt_sampl = MAX( 3600., rdt * nn_dttrc )
[6487]171            nb_rec_per_day = INT( 86400 / rdt_sampl )
[5385]172         ENDIF
173         !
174         IF( lwp ) THEN
175            WRITE(numout,*) 
[6487]176            WRITE(numout,*) ' Sampling frequency dt = ', rdt_sampl, 's','   Number of sampling per day  nrec = ', nb_rec_per_day
[5385]177            WRITE(numout,*) 
178         ENDIF
179         !
[8356]180         ALLOCATE( qsr_arr(jpi,jpj,nb_rec_per_day ) )
181         !
[6487]182         !                                            !* Restart: read in restart file
[9237]183         IF( ln_rsttr .AND. nn_rsttr /= 0 .AND. iom_varid( numrtr, 'qsr_mean' , ldstop = .FALSE. ) > 0 &
184                                          .AND. iom_varid( numrtr, 'qsr_arr_1', ldstop = .FALSE. ) > 0 &
185                                          .AND. iom_varid( numrtr, 'zsecfst'  , ldstop = .FALSE. ) > 0 ) THEN
[6487]186            IF(lwp) WRITE(numout,*) 'trc_qsr_mean:   qsr_mean read in the restart file'
187            CALL iom_get( numrtr, jpdom_autoglo, 'qsr_mean', qsr_mean )   !  A mean of qsr
[8356]188            CALL iom_get( numrtr, 'zsecfst', zsecfst )   !  A mean of qsr
189            isecfst = INT( zsecfst )
190            DO jn = 1, nb_rec_per_day 
191             IF( jn <= 9 )  THEN
192               WRITE(cl1,'(i1)') jn
193               CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )   !  A mean of qsr
194             ELSE
195               WRITE(cl2,'(i2.2)') jn
196               CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )   !  A mean of qsr
197             ENDIF
198           ENDDO
[6487]199         ELSE                                         !* no restart: set from nit000 values
200            IF(lwp) WRITE(numout,*) 'trc_qsr_mean:   qsr_mean set to nit000 values'
[8356]201            isecfst  = nsec_year + nsec1jan000   !   number of seconds between Jan. 1st 00h of nit000 year and the middle of time step
202            !
[6487]203            qsr_mean(:,:) = qsr(:,:)
[8356]204            DO jn = 1, nb_rec_per_day
205               qsr_arr(:,:,jn) = qsr_mean(:,:)
206            ENDDO
[6487]207         ENDIF
208         !
[5385]209      ENDIF
210      !
211      iseclast = nsec_year + nsec1jan000
[8356]212      !
[5385]213      llnew   = ( iseclast - isecfst )  > INT( rdt_sampl )   !   new shortwave to store
[8356]214      IF( llnew ) THEN
[5385]215          IF( lwp ) WRITE(numout,*) ' New shortwave to sample for TOP at time kt = ', kt, &
216             &                      ' time = ', (iseclast+rdt*nn_dttrc/2.)/3600.,'hours '
217          isecfst = iseclast
[6487]218          DO jn = 1, nb_rec_per_day - 1
[5385]219             qsr_arr(:,:,jn) = qsr_arr(:,:,jn+1)
220          ENDDO
[6487]221          qsr_arr (:,:,nb_rec_per_day) = qsr(:,:)
222          qsr_mean(:,:                ) = SUM( qsr_arr(:,:,:), 3 ) / nb_rec_per_day
[5385]223      ENDIF
224      !
[6487]225      IF( lrst_trc ) THEN    !* Write the mean of qsr in restart file
226         IF(lwp) WRITE(numout,*)
227         IF(lwp) WRITE(numout,*) 'trc_mean_qsr : write qsr_mean in restart file  kt =', kt
228         IF(lwp) WRITE(numout,*) '~~~~~~~'
[8356]229          DO jn = 1, nb_rec_per_day 
230             IF( jn <= 9 )  THEN
231               WRITE(cl1,'(i1)') jn
232               CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )
233             ELSE
234               WRITE(cl2,'(i2.2)') jn
235               CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )
236             ENDIF
237         ENDDO
[6487]238         CALL iom_rstput( kt, nitrst, numrtw, 'qsr_mean', qsr_mean(:,:) )
[8356]239         zsecfst = REAL( isecfst, wp )
240         CALL iom_rstput( kt, nitrst, numrtw, 'zsecfst', zsecfst )
[6487]241      ENDIF
[8356]242      !
[5385]243   END SUBROUTINE trc_mean_qsr
244
[1457]245#else
246   !!----------------------------------------------------------------------
247   !!   Default key                                     NO passive tracers
248   !!----------------------------------------------------------------------
249CONTAINS
250   SUBROUTINE trc_stp( kt )        ! Empty routine
251      WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
252   END SUBROUTINE trc_stp
253#endif
254
255   !!======================================================================
256END MODULE trcstp
Note: See TracBrowser for help on using the repository browser.