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.
trcini.F90 in branches/2013/dev_r3996_CMCC6_topbc/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/2013/dev_r3996_CMCC6_topbc/NEMOGCM/NEMO/TOP_SRC/trcini.F90 @ 4058

Last change on this file since 4058 was 4026, checked in by vichi, 11 years ago

Correct bug in deallocation of data structure

  • Property svn:keywords set to Id
File size: 9.8 KB
RevLine 
[268]1MODULE trcini
[945]2   !!======================================================================
3   !!                         ***  MODULE trcini  ***
4   !! TOP :   Manage the passive tracer initialization
5   !!======================================================================
[2715]6   !! History :   -   ! 1991-03 (O. Marti)  original code
7   !!            1.0  ! 2005-03 (O. Aumont, A. El Moussaoui) F90
8   !!            2.0  ! 2005-10 (C. Ethe, G. Madec) revised architecture
9   !!            4.0  ! 2011-01 (A. R. Porter, STFC Daresbury) dynamical allocation
[274]10   !!----------------------------------------------------------------------
[1011]11#if defined key_top
12   !!----------------------------------------------------------------------
13   !!   'key_top'                                                TOP models
14   !!----------------------------------------------------------------------
[2715]15   !!   trc_init  :   Initialization for passive tracer
16   !!   top_alloc :   allocate the TOP arrays
[1011]17   !!----------------------------------------------------------------------
[3294]18   USE oce_trc         ! shared variables between ocean and passive tracers
19   USE trc             ! passive tracers common variables
20   USE trcrst          ! passive tracers restart
[2528]21   USE trcnam          ! Namelist read
[1254]22   USE trcini_cfc      ! CFC      initialisation
23   USE trcini_pisces   ! PISCES   initialisation
24   USE trcini_c14b     ! C14 bomb initialisation
25   USE trcini_my_trc   ! MY_TRC   initialisation
[4011]26   USE trcdta          ! initialisation from files
[3294]27   USE daymod          ! calendar manager
[2528]28   USE zpshde          ! partial step: hor. derivative   (zps_hde routine)
[1011]29   USE prtctl_trc      ! Print control passive tracers (prt_ctl_trc_init routine)
[3294]30   USE trcsub       ! variables to substep passive tracers
[1011]31   
[335]32   IMPLICIT NONE
33   PRIVATE
[1011]34   
[2528]35   PUBLIC   trc_init   ! called by opa
[268]36
[1011]37    !! * Substitutions
38#  include "domzgr_substitute.h90"
[2715]39   !!----------------------------------------------------------------------
40   !! NEMO/TOP 4.0 , NEMO Consortium (2011)
41   !! $Id$
42   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
43   !!----------------------------------------------------------------------
[335]44CONTAINS
[1011]45   
[2528]46   SUBROUTINE trc_init
[1011]47      !!---------------------------------------------------------------------
[2528]48      !!                     ***  ROUTINE trc_init  ***
[335]49      !!
[1011]50      !! ** Purpose :   Initialization of the passive tracer fields
51      !!
52      !! ** Method  : - read namelist
53      !!              - control the consistancy
54      !!              - compute specific initialisations
55      !!              - set initial tracer fields (either read restart
56      !!                or read data or analytical formulation
57      !!---------------------------------------------------------------------
[3294]58      INTEGER ::   jk, jn, jl    ! dummy loop indices
[1011]59      CHARACTER (len=25) :: charout
[4011]60      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrcdta   ! 4D  workspace
[1011]61      !!---------------------------------------------------------------------
[3294]62      !
63      IF( nn_timing == 1 )   CALL timing_start('trc_init')
64      !
[945]65      IF(lwp) WRITE(numout,*)
[2528]66      IF(lwp) WRITE(numout,*) 'trc_init : initial set up of the passive tracers'
[945]67      IF(lwp) WRITE(numout,*) '~~~~~~~'
[1011]68
[2715]69      CALL top_alloc()              ! allocate TOP arrays
70
[3680]71      IF( ln_dm2dc .AND. lk_pisces )    &
72         &  CALL ctl_stop( ' The diurnal cycle is not compatible with PISCES ' )
[1254]73
[3294]74      IF( nn_cla == 1 )   &
75         &  CALL ctl_stop( ' Cross Land Advection not yet implemented with passive tracer ; nn_cla must be 0' )
[1011]76
[2715]77      CALL trc_nam                  ! read passive tracers namelists
[3294]78      !
79      IF(lwp) WRITE(numout,*)
[2528]80      IF( ln_rsttr ) THEN
[3294]81        !
82        IF( lk_offline )  neuler = 1   ! Set time-step indicator at nit000 (leap-frog)
83        CALL trc_rst_cal( nittrc000, 'READ' )   ! calendar
84        !
[2528]85      ELSE
[3294]86        IF( lk_offline )  THEN
87           neuler = 0                  ! Set time-step indicator at nit000 (euler)
88           CALL day_init               ! set calendar
89        ENDIF
90        !
[2528]91      ENDIF
[3294]92      IF(lwp) WRITE(numout,*)
93                                                              ! masked grid volume
94      !                                                              ! masked grid volume
95      DO jk = 1, jpk
96         cvol(:,:,jk) = e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
97      END DO
98      IF( lk_degrad ) cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:)      ! degrad option: reduction by facvol
99      !                                                              ! total volume of the ocean
100      areatot = glob_sum( cvol(:,:,:) )
[1011]101
[3294]102      IF( lk_pisces  )       CALL trc_ini_pisces       ! PISCES  bio-model
103      IF( lk_cfc     )       CALL trc_ini_cfc          ! CFC     tracers
104      IF( lk_c14b    )       CALL trc_ini_c14b         ! C14 bomb  tracer
105      IF( lk_my_trc  )       CALL trc_ini_my_trc       ! MY_TRC  tracers
[2528]106
[3294]107      IF( lwp ) THEN
108         !
109         CALL ctl_opn( numstr, 'tracer.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
110         !
[945]111      ENDIF
[1254]112
[4011]113      IF( ln_trcdta )      CALL trc_dta_init(jptra)
[1011]114
[3294]115
[2528]116      IF( ln_rsttr ) THEN
117        !
118        CALL trc_rst_read              ! restart from a file
119        !
[1011]120      ELSE
[3294]121        !
122        IF( ln_trcdta .AND. nb_trcdta > 0 ) THEN  ! Initialisation of tracer from a file that may also be used for damping
123            !
[4011]124            CALL wrk_alloc( jpi, jpj, jpk, ztrcdta )    ! Memory allocation
[3294]125            !
126            DO jn = 1, jptra
127               IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
128                  jl = n_trc_index(jn) 
[4011]129                  CALL trc_dta( kt, sf_trcdta(jl),rf_trfac(jl) )   ! read tracer data at nit000
130                  ztrcdta(:,:,:) = sf_trcdta(jl)%fnow(:,:,:)
131                  trn(:,:,:,jn) = ztrcdta(:,:,:) * tmask(:,:,:) 
[4026]132                  IF( .NOT.ln_trcdmp .AND. .NOT.ln_trcdmp_clo ) THEN      !== deallocate data structure   ==!
133                     !                                                    (data used only for initialisation)
134                     IF(lwp) WRITE(numout,*) 'trc_dta: deallocate data arrays as they are only used to initialize the run'
135                                                  DEALLOCATE( sf_trcdta(jl)%fnow )     !  arrays in the structure
136                     IF( sf_trcdta(jl)%ln_tint )  DEALLOCATE( sf_trcdta(jl)%fdta )
137                     !
138                  ENDIF
[3294]139               ENDIF
140            ENDDO
[4011]141            CALL wrk_dealloc( jpi, jpj, jpk, ztrcdta )
[2528]142        ENDIF
[3294]143        !
[2528]144        trb(:,:,:,:) = trn(:,:,:,:)
145        !
[1011]146      ENDIF
[2528]147 
[2715]148      tra(:,:,:,:) = 0._wp
[1286]149     
[2528]150      IF( ln_zps .AND. .NOT. lk_c1d )   &              ! Partial steps: before horizontal gradient of passive
[2715]151        &    CALL zps_hde( nit000, jptra, trn, gtru, gtrv )       ! tracers at the bottom ocean level
[1177]152
[3294]153      !
154      IF( nn_dttrc /= 1 )        CALL trc_sub_ini      ! Initialize variables for substepping passive tracers
155      !
[1286]156
[3294]157      trai(:) = 0._wp                                                   ! initial content of all tracers
[1011]158      DO jn = 1, jptra
[3294]159         trai(jn) = trai(jn) + glob_sum( trn(:,:,:,jn) * cvol(:,:,:)   )
160      END DO
[1011]161
[2715]162      IF(lwp) THEN               ! control print
163         WRITE(numout,*)
164         WRITE(numout,*)
165         WRITE(numout,*) '          *** Total number of passive tracer jptra = ', jptra
166         WRITE(numout,*) '          *** Total volume of ocean                = ', areatot
[3294]167         WRITE(numout,*) '          *** Total inital content of all tracers '
[2715]168         WRITE(numout,*)
[3294]169         DO jn = 1, jptra
170            WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), trai(jn)
171         ENDDO
172         WRITE(numout,*)
[2715]173      ENDIF
[3294]174      IF(lwp) WRITE(numout,*)
[2715]175      IF(ln_ctl) THEN            ! print mean trends (used for debugging)
176         CALL prt_ctl_trc_init
[1011]177         WRITE(charout, FMT="('ini ')")
178         CALL prt_ctl_trc_info( charout )
179         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
180      ENDIF
[3294]1819000  FORMAT(' tracer nb : ',i2,'      name :',a10,'      initial content :',e18.10)
[2715]182      !
[3294]183      IF( nn_timing == 1 )   CALL timing_stop('trc_init')
184      !
[2528]185   END SUBROUTINE trc_init
[268]186
[2715]187
188   SUBROUTINE top_alloc
189      !!----------------------------------------------------------------------
190      !!                     ***  ROUTINE top_alloc  ***
191      !!
192      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
193      !!----------------------------------------------------------------------
194      USE trcadv        , ONLY:   trc_adv_alloc          ! TOP-related alloc routines...
195      USE trc           , ONLY:   trc_alloc
196      USE trcnxt        , ONLY:   trc_nxt_alloc
197      USE trczdf        , ONLY:   trc_zdf_alloc
198      USE trdmod_trc_oce, ONLY:   trd_mod_trc_oce_alloc
[3294]199#if defined key_trdmld_trc 
[2715]200      USE trdmld_trc    , ONLY:   trd_mld_trc_alloc
201#endif
202      !
203      INTEGER :: ierr
204      !!----------------------------------------------------------------------
205      !
206      ierr =        trc_adv_alloc()          ! Start of TOP-related alloc routines...
207      ierr = ierr + trc_alloc    ()
208      ierr = ierr + trc_nxt_alloc()
209      ierr = ierr + trc_zdf_alloc()
210      ierr = ierr + trd_mod_trc_oce_alloc()
[3294]211#if defined key_trdmld_trc 
[2715]212      ierr = ierr + trd_mld_trc_alloc()
213#endif
214      !
215      IF( lk_mpp    )   CALL mpp_sum( ierr )
216      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'top_alloc : unable to allocate standard ocean arrays' )
217      !
218   END SUBROUTINE top_alloc
219
[1011]220#else
221   !!----------------------------------------------------------------------
222   !!  Empty module :                                     No passive tracer
223   !!----------------------------------------------------------------------
224CONTAINS
[2528]225   SUBROUTINE trc_init                      ! Dummy routine   
226   END SUBROUTINE trc_init
[1011]227#endif
228
[335]229   !!======================================================================
[268]230END MODULE trcini
Note: See TracBrowser for help on using the repository browser.