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/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/TOP_SRC/trcini.F90 @ 11738

Last change on this file since 11738 was 11738, checked in by marc, 5 years ago

The Dr Hook changes from my perl code.

File size: 16.1 KB
Line 
1MODULE trcini
2   !!======================================================================
3   !!                         ***  MODULE trcini  ***
4   !! TOP :   Manage the passive tracer initialization
5   !!======================================================================
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
10   !!             -   ! 2014-06 (A. Yool, J. Palmieri) adding MEDUSA-2
11   !!----------------------------------------------------------------------
12#if defined key_top
13   !!----------------------------------------------------------------------
14   !!   'key_top'                                                TOP models
15   !!----------------------------------------------------------------------
16   !!   trc_init  :   Initialization for passive tracer
17   !!   top_alloc :   allocate the TOP arrays
18   !!----------------------------------------------------------------------
19   USE oce_trc         ! shared variables between ocean and passive tracers
20   USE trc             ! passive tracers common variables
21   USE trcrst          ! passive tracers restart
22   USE trcnam          ! Namelist read
23   USE trcini_cfc      ! CFC      initialisation
24   USE trcini_pisces   ! PISCES   initialisation
25   USE trcini_c14b     ! C14 bomb initialisation
26   USE trcini_age      ! AGE      initialisation
27   USE trcini_my_trc   ! MY_TRC   initialisation
28   USE trcini_idtra    ! idealize tracer initialisation
29   USE trcini_medusa   ! MEDUSA   initialisation
30   USE par_medusa      ! MEDUSA   parameters (needed for elemental cycles)
31   USE trcdta          ! initialisation from files
32   USE daymod          ! calendar manager
33   USE prtctl_trc      ! Print control passive tracers (prt_ctl_trc_init routine)
34   USE trcsub          ! variables to substep passive tracers
35   USE lib_mpp         ! distribued memory computing library
36   USE sbc_oce
37   USE trcice          ! tracers in sea ice
38   USE sms_medusa      ! MEDUSA   initialisation
39   USE yomhook, ONLY: lhook, dr_hook
40   USE parkind1, ONLY: jprb, jpim
41
42   IMPLICIT NONE
43   PRIVATE
44   
45   PUBLIC   trc_init   ! called by opa
46
47    !! * Substitutions
48#  include "domzgr_substitute.h90"
49   !!----------------------------------------------------------------------
50   !! NEMO/TOP 4.0 , NEMO Consortium (2011)
51   !! $Id$
52   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
53   !!----------------------------------------------------------------------
54CONTAINS
55   
56   SUBROUTINE trc_init
57      !!---------------------------------------------------------------------
58      !!                     ***  ROUTINE trc_init  ***
59      !!
60      !! ** Purpose :   Initialization of the passive tracer fields
61      !!
62      !! ** Method  : - read namelist
63      !!              - control the consistancy
64      !!              - compute specific initialisations
65      !!              - set initial tracer fields (either read restart
66      !!                or read data or analytical formulation
67      !!---------------------------------------------------------------------
68      INTEGER ::   ji, jj, jk, jn, jl    ! dummy loop indices
69# if defined key_medusa && defined key_roam
70      !! AXY (23/11/2017)
71      REAL(wp)                         :: zsum3d, zsum2d
72      REAL(wp)                         :: zq1, zq2, loc_vol, loc_area
73      REAL(wp), DIMENSION(6)           :: loc_cycletot3, loc_cycletot2
74      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztot3d
75      REAL(wp), DIMENSION(jpi,jpj)     :: ztot2d, carea
76# endif
77      CHARACTER (len=25) :: charout
78      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
79      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
80      REAL(KIND=jprb)               :: zhook_handle
81
82      CHARACTER(LEN=*), PARAMETER :: RoutineName='TRC_INIT'
83
84      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
85
86      !!---------------------------------------------------------------------
87      !
88      IF( nn_timing == 1 )   CALL timing_start('trc_init')
89      !
90      IF(lwp) WRITE(numout,*)
91      IF(lwp) WRITE(numout,*) 'trc_init : initial set up of the passive tracers'
92      IF(lwp) WRITE(numout,*) '~~~~~~~'
93
94      CALL top_alloc()              ! allocate TOP arrays
95
96      l_trcdm2dc = ln_dm2dc .OR. ( ln_cpl .AND. ncpl_qsr_freq /= 1 )
97      l_trcdm2dc = l_trcdm2dc  .AND. .NOT. lk_offline
98      IF( l_trcdm2dc .AND. lwp ) &
99         &   CALL ctl_warn(' Coupling with passive tracers and used of diurnal cycle. &
100         & Computation of a daily mean shortwave for some biogeochemical models) ')
101
102      IF( nn_cla == 1 )   &
103         &  CALL ctl_stop( ' Cross Land Advection not yet implemented with passive tracer ; nn_cla must be 0' )
104
105      CALL trc_nam      ! read passive tracers namelists
106      !
107      IF(lwp) WRITE(numout,*)
108      !
109      IF( ln_rsttr .AND. .NOT. lk_offline ) CALL trc_rst_cal( nit000, 'READ' )   ! calendar
110      !
111      IF(lwp) WRITE(numout,*)
112                                                              ! masked grid volume
113      !                                                              ! masked grid volume
114      DO jk = 1, jpk
115         cvol(:,:,jk) = e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
116      END DO
117      IF( lk_degrad ) cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:)      ! degrad option: reduction by facvol
118      !                                                              ! total volume of the ocean
119      areatot = glob_sum( cvol(:,:,:) )
120      carea(:,:) = e1e2t(:,:) * tmask(:,:,1) 
121
122      IF( lk_pisces  )       CALL trc_ini_pisces       ! PISCES  bio-model
123      IF( lk_cfc     )       CALL trc_ini_cfc          ! CFC     tracers
124      IF( lk_c14b    )       CALL trc_ini_c14b         ! C14 bomb  tracer
125      IF( lk_age     )       CALL trc_ini_age          ! AGE       tracer
126      IF( lk_my_trc  )       CALL trc_ini_my_trc       ! MY_TRC  tracers
127      IF( lk_idtra   )       CALL trc_ini_idtra        ! Idealize tracers
128      IF( lk_medusa  )       CALL trc_ini_medusa       ! MEDUSA  tracers
129
130      CALL trc_ice_ini                                 ! Tracers in sea ice
131
132      IF( ln_ctl ) THEN
133         !
134         IF (narea == 1) THEN 
135            ! The tracer.stat file only contains global tracer sum values, if
136            ! it contains anything at all. Hence it only needs to be opened
137            ! and written to on the master PE, not on all PEs. 
138            CALL ctl_opn( numstr, 'tracer.stat', 'REPLACE','FORMATTED',  & 
139                          'SEQUENTIAL', -1, numout, lwp , narea ) 
140         ENDIF 
141         !
142      ENDIF
143
144      IF( ln_trcdta ) THEN
145         CALL trc_dta_init(jptra)
146      ENDIF
147
148      IF( ln_rsttr ) THEN
149        !
150        CALL trc_rst_read              ! restart from a file
151        !
152      ELSE
153        !
154        IF( ln_trcdta .AND. nb_trcdta > 0 ) THEN  ! Initialisation of tracer from a file that may also be used for damping
155            !
156            DO jn = 1, jptra
157               IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
158                  jl = n_trc_index(jn) 
159                  CALL trc_dta( nit000, sf_trcdta(jl), rf_trfac(jl) )   ! read tracer data at nit000
160                  trn(:,:,:,jn) = sf_trcdta(jl)%fnow(:,:,:) 
161                  IF( .NOT.ln_trcdmp .AND. .NOT.ln_trcdmp_clo ) THEN      !== deallocate data structure   ==!
162                     !                                                    (data used only for initialisation)
163                     IF(lwp) WRITE(numout,*) 'trc_dta: deallocate data arrays as they are only used to initialize the run'
164                                                  DEALLOCATE( sf_trcdta(jl)%fnow )     !  arrays in the structure
165                     IF( sf_trcdta(jl)%ln_tint )  DEALLOCATE( sf_trcdta(jl)%fdta )
166                     !
167                  ENDIF
168               ENDIF
169            ENDDO
170            !
171        ENDIF
172        !
173        trb(:,:,:,:) = trn(:,:,:,:)
174        !
175      ENDIF
176 
177      tra(:,:,:,:) = 0._wp
178      !
179      IF( nn_dttrc /= 1 )        CALL trc_sub_ini      ! Initialize variables for substepping passive tracers
180      !
181
182      trai(:) = 0._wp                                                   ! initial content of all tracers
183      DO jn = 1, jptra
184         trai(jn) = trai(jn) + glob_sum( trn(:,:,:,jn) * cvol(:,:,:)   )
185      END DO
186
187      IF(lwp) THEN               ! control print
188         WRITE(numout,*)
189         WRITE(numout,*)
190         WRITE(numout,*) '          *** Total number of passive tracer jptra = ', jptra
191         WRITE(numout,*) '          *** Total volume of ocean                = ', areatot
192         WRITE(numout,*) '          *** Total inital content of all tracers '
193         WRITE(numout,*)
194# if defined key_debug_medusa
195         CALL flush(numout)
196# endif
197         !
198# if defined key_debug_medusa
199         WRITE(numout,*) ' litle check :  ', ctrcnm(1)
200         CALL flush(numout)
201# endif
202         DO jn = 1, jptra
203            WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), trai(jn)
204         ENDDO
205         WRITE(numout,*)
206      ENDIF
207      IF(lwp) WRITE(numout,*)
208      IF(ln_ctl) THEN            ! print mean trends (used for debugging)
209         CALL prt_ctl_trc_init
210         WRITE(charout, FMT="('ini ')")
211         CALL prt_ctl_trc_info( charout )
212         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
213      ENDIF
214
215# if defined key_medusa && defined key_roam
216      ! AXY (17/11/2017): calculate initial totals of elemental cycles
217      !
218      ! This is done in a very hard-wired way here; in future, this could be
219      ! replaced with loops and using a 2D array; one dimension would cover
220      ! the tracers, the other would be for the elements; each tracer would
221      ! have a factor for each element to say how much of that element was
222      ! in that tracer; for example, PHN would be 1.0 for N, xrfn for Fe and
223      ! xthetapn for C, with the other elements 0.0; the array entry for PHN
224      ! would then be (1. 0. xrfn xthetapn 0. 0.) for (N, Si, Fe, C, A, O2);
225      ! saving this for the next iteration
226      !
227      cycletot(:) = 0._wp
228      ! report elemental totals at initialisation as we go along
229      IF ( lwp ) WRITE(numout,*)
230      IF ( lwp ) WRITE(numout,*)    ' Elemental cycle totals: '
231      ! nitrogen
232      ztot3d(:,:,:) = trn(:,:,:,jpphn) + trn(:,:,:,jpphd) + trn(:,:,:,jpzmi) + &
233                      trn(:,:,:,jpzme) + trn(:,:,:,jpdet) + trn(:,:,:,jpdin)
234      ztot2d(:,:)   = zn_sed_n(:,:)
235      zsum3d        = glob_sum( ztot3d(:,:,:) * cvol(:,:,:) )
236      zsum2d        = glob_sum( ztot2d(:,:) * carea(:,:) )
237      cycletot(1)   = zsum3d + zsum2d
238      IF ( lwp ) WRITE(numout,9010) 'nitrogen', zsum3d, zsum2d, cycletot(1)
239      ! silicon
240      ztot3d(:,:,:) = trn(:,:,:,jppds) + trn(:,:,:,jpsil)
241      ztot2d(:,:)   = zn_sed_si(:,:)
242      zsum3d        = glob_sum( ztot3d(:,:,:) * cvol(:,:,:) )
243      zsum2d        = glob_sum( ztot2d(:,:) * carea(:,:) )
244      cycletot(2)   = zsum3d + zsum2d
245      IF ( lwp ) WRITE(numout,9010) 'silicon', zsum3d, zsum2d, cycletot(2)
246      ! iron
247      ztot3d(:,:,:) = ((trn(:,:,:,jpphn) + trn(:,:,:,jpphd) + trn(:,:,:,jpzmi) + &
248                      trn(:,:,:,jpzme) + trn(:,:,:,jpdet)) * xrfn) + trn(:,:,:,jpfer)
249      ztot2d(:,:)   = zn_sed_fe(:,:)
250      zsum3d        = glob_sum( ztot3d(:,:,:) * cvol(:,:,:) )
251      zsum2d        = glob_sum( ztot2d(:,:) * carea(:,:) )
252      cycletot(3)   = zsum3d + zsum2d
253      IF ( lwp ) WRITE(numout,9010) 'iron', zsum3d, zsum2d, cycletot(3)
254      ! carbon (uses fixed C:N ratios on plankton tracers)
255      ztot3d(:,:,:) = (trn(:,:,:,jpphn) * xthetapn)  + (trn(:,:,:,jpphd) * xthetapd)  +  &
256                      (trn(:,:,:,jpzmi) * xthetazmi) + (trn(:,:,:,jpzme) * xthetazme) +  &
257                      trn(:,:,:,jpdtc) + trn(:,:,:,jpdic)
258      ztot2d(:,:)   = zn_sed_c(:,:) + zn_sed_ca(:,:)
259      zsum3d        = glob_sum( ztot3d(:,:,:) * cvol(:,:,:) )
260      zsum2d        = glob_sum( ztot2d(:,:) * carea(:,:) )
261      cycletot(4)   = zsum3d + zsum2d
262      IF ( lwp ) WRITE(numout,9010) 'carbon', zsum3d, zsum2d, cycletot(4)
263      ! alkalinity (note benthic correction)
264      ztot3d(:,:,:) = trn(:,:,:,jpalk)
265      ztot2d(:,:)   = zn_sed_ca(:,:) * 2._wp
266      zsum3d        = glob_sum( ztot3d(:,:,:) * cvol(:,:,:) )
267      zsum2d        = glob_sum( ztot2d(:,:) * carea(:,:) )
268      cycletot(5)   = zsum3d + zsum2d
269      IF ( lwp ) WRITE(numout,9010) 'alkalinity', zsum3d, zsum2d, cycletot(5)
270      ! oxygen (note no benthic)
271      ztot3d(:,:,:) = trn(:,:,:,jpoxy)
272      ztot2d(:,:)   = 0._wp
273      zsum3d        = glob_sum( ztot3d(:,:,:) * cvol(:,:,:) )
274      zsum2d        = glob_sum( ztot2d(:,:) * carea(:,:) )
275      cycletot(6)   = zsum3d + zsum2d
276      IF ( lwp ) WRITE(numout,9010) 'oxygen', zsum3d, zsum2d, cycletot(6)
277      ! Check
278      zsum3d        = glob_sum( cvol(:,:,:) )
279      zsum2d        = glob_sum( carea(:,:) )     
280      IF ( lwp ) THEN
281         WRITE(numout,*)
282         WRITE(numout,*) ' check : cvol    : ', zsum3d
283         WRITE(numout,*) ' check : carea   : ', zsum2d
284         WRITE(numout,*)
285      ENDIF
286      !
287# endif
288
289      IF(lwp) THEN
290          WRITE(numout,*)
291          WRITE(numout,*) 'trc_init : passive tracer set up completed'
292          WRITE(numout,*) '~~~~~~~'
293      ENDIF 
294# if defined key_debug_medusa
295         CALL trc_rst_stat
296         CALL flush(numout)
297# endif
298
2999000  FORMAT(' tracer nb : ',i2,'      name :',a10,'      initial content :',e18.10)
3009010  FORMAT(' element:',a10,                     &
301             ' 3d sum:',e18.10,' 2d sum:',e18.10, &
302             ' total:',e18.10)
303      !
304      IF( nn_timing == 1 )   CALL timing_stop('trc_init')
305      !
306      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
307   END SUBROUTINE trc_init
308
309
310   SUBROUTINE top_alloc
311      !!----------------------------------------------------------------------
312      !!                     ***  ROUTINE top_alloc  ***
313      !!
314      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
315      !!----------------------------------------------------------------------
316      USE trcadv        , ONLY:   trc_adv_alloc          ! TOP-related alloc routines...
317      USE trc           , ONLY:   trc_alloc
318      USE trcnxt        , ONLY:   trc_nxt_alloc
319      USE trczdf        , ONLY:   trc_zdf_alloc
320      USE trdtrc_oce    , ONLY:   trd_trc_oce_alloc
321#if defined key_trdmxl_trc 
322      USE trdmxl_trc    , ONLY:   trd_mxl_trc_alloc
323#endif
324# if defined key_medusa
325      USE bio_medusa_mod, ONLY:   bio_medusa_alloc
326# endif
327
328      !
329      INTEGER :: ierr
330      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
331      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
332      REAL(KIND=jprb)               :: zhook_handle
333
334      CHARACTER(LEN=*), PARAMETER :: RoutineName='TOP_ALLOC'
335
336      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
337
338      !!----------------------------------------------------------------------
339      !
340      ierr =        trc_adv_alloc()          ! Start of TOP-related alloc routines...
341      ierr = ierr + trc_alloc    ()
342      ierr = ierr + trc_nxt_alloc()
343      ierr = ierr + trc_zdf_alloc()
344      ierr = ierr + trd_trc_oce_alloc()
345#if defined key_trdmxl_trc 
346      ierr = ierr + trd_mxl_trc_alloc()
347#endif
348#if defined key_medusa
349      ierr = ierr + bio_medusa_alloc()
350#endif
351      !
352      IF( lk_mpp    )   CALL mpp_sum( ierr )
353      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'top_alloc : unable to allocate standard ocean arrays' )
354      !
355      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
356   END SUBROUTINE top_alloc
357
358#else
359   !!----------------------------------------------------------------------
360   !!  Empty module :                                     No passive tracer
361   !!----------------------------------------------------------------------
362CONTAINS
363   SUBROUTINE trc_init                      ! Dummy routine   
364   INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
365   INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
366   REAL(KIND=jprb)               :: zhook_handle
367
368   CHARACTER(LEN=*), PARAMETER :: RoutineName='TRC_INIT'
369
370   IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
371
372   IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
373   END SUBROUTINE trc_init
374#endif
375
376   !!======================================================================
377END MODULE trcini
Note: See TracBrowser for help on using the repository browser.