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/NERC/dev_r5518_NOC_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/NERC/dev_r5518_NOC_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcini.F90 @ 6645

Last change on this file since 6645 was 6645, checked in by jpalmier, 8 years ago

JPALM -- 31-05-2016 -- avoid merge conflicts second tour

File size: 13.3 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_my_trc   ! MY_TRC   initialisation
27   USE trcini_medusa   ! MEDUSA   initialisation
28   USE trcini_idtra    ! idealize tracer initialisation
29   USE trcdta          ! initialisation from files
30   USE daymod          ! calendar manager
31   USE zpshde          ! partial step: hor. derivative   (zps_hde routine)
32   USE prtctl_trc      ! Print control passive tracers (prt_ctl_trc_init routine)
33   USE trcsub          ! variables to substep passive tracers
34   USE lib_mpp         ! distribued memory computing library
35   USE sbc_oce
36   USE trcice          ! tracers in sea ice
37 
38   IMPLICIT NONE
39   PRIVATE
40   
41   PUBLIC   trc_init   ! called by opa
42
43    !! * Substitutions
44#  include "domzgr_substitute.h90"
45   !!----------------------------------------------------------------------
46   !! NEMO/TOP 4.0 , NEMO Consortium (2011)
47   !! $Id$
48   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
49   !!----------------------------------------------------------------------
50CONTAINS
51   
52   SUBROUTINE trc_init
53      !!---------------------------------------------------------------------
54      !!                     ***  ROUTINE trc_init  ***
55      !!
56      !! ** Purpose :   Initialization of the passive tracer fields
57      !!
58      !! ** Method  : - read namelist
59      !!              - control the consistancy
60      !!              - compute specific initialisations
61      !!              - set initial tracer fields (either read restart
62      !!                or read data or analytical formulation
63      !!---------------------------------------------------------------------
64      INTEGER ::   jk, jn, jl    ! dummy loop indices
65      CHARACTER (len=25) :: charout
66      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrcdta   ! 4D  workspace
67      !!---------------------------------------------------------------------
68      !
69      IF( nn_timing == 1 )   CALL timing_start('trc_init')
70      !
71      IF(lwp) WRITE(numout,*)
72      IF(lwp) WRITE(numout,*) 'trc_init : initial set up of the passive tracers'
73      IF(lwp) WRITE(numout,*) '~~~~~~~'
74
75      CALL top_alloc()              ! allocate TOP arrays
76
77      l_trcdm2dc = ln_dm2dc .OR. ( ln_cpl .AND. ncpl_qsr_freq /= 1 )
78      l_trcdm2dc = l_trcdm2dc  .AND. .NOT. lk_offline
79      IF( l_trcdm2dc .AND. lwp ) &
80         &   CALL ctl_warn(' Coupling with passive tracers and used of diurnal cycle. &
81         & Computation of a daily mean shortwave for some biogeochemical models) ')
82          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
83          !!!!! CHECK For MEDUSA
84          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
85      IF( nn_cla == 1 )   &
86         &  CALL ctl_stop( ' Cross Land Advection not yet implemented with passive tracer ; nn_cla must be 0' )
87
88      CALL trc_nam      ! read passive tracers namelists
89      !
90      IF(lwp) WRITE(numout,*)
91      !
92      IF( ln_rsttr .AND. .NOT. lk_offline ) CALL trc_rst_cal( nit000, 'READ' )   ! calendar
93      !
94      IF(lwp) WRITE(numout,*)
95                                                              ! masked grid volume
96      !                                                              ! masked grid volume
97      DO jk = 1, jpk
98         cvol(:,:,jk) = e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
99      END DO
100      IF( lk_degrad ) cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:)      ! degrad option: reduction by facvol
101      !                                                              ! total volume of the ocean
102      areatot = glob_sum( cvol(:,:,:) )
103
104      IF( lk_pisces  )       CALL trc_ini_pisces       ! PISCES  bio-model
105      IF( lk_medusa  )       CALL trc_ini_medusa       ! MEDUSA  tracers
106      IF( lk_idtra   )       CALL trc_ini_idtra        ! Idealize tracers
107      IF( lk_cfc     )       CALL trc_ini_cfc          ! CFC     tracers
108      IF( lk_c14b    )       CALL trc_ini_c14b         ! C14 bomb  tracer
109      IF( lk_my_trc  )       CALL trc_ini_my_trc       ! MY_TRC  tracers
110
111      CALL trc_ice_ini                                 ! Tracers in sea ice
112
113# if defined key_debug_medusa
114         IF (lwp) write (numout,*) '------------------------------'
115         IF (lwp) write (numout,*) 'Jpalm - debug'
116         IF (lwp) write (numout,*) ' in trc_init'
117         IF (lwp) write (numout,*) ' sms init OK'
118         IF (lwp) write (numout,*) ' next: open tracer.stat'
119         IF (lwp) write (numout,*) ' '
120         CALL flush(numout)
121# endif
122
123      IF( lwp ) THEN
124         !
125         CALL ctl_opn( numstr, 'tracer.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp , narea )
126         !
127      ENDIF
128
129# if defined key_debug_medusa
130         IF (lwp) write (numout,*) '------------------------------'
131         IF (lwp) write (numout,*) 'Jpalm - debug'
132         IF (lwp) write (numout,*) ' in trc_init'
133         IF (lwp) write (numout,*) 'open tracer.stat -- OK'
134         IF (lwp) write (numout,*) ' '
135         CALL flush(numout)
136# endif
137
138
139      IF( ln_trcdta ) THEN
140#if defined key_medusa
141         IF(lwp) WRITE(numout,*) 'AXY: calling trc_dta_init'
142         IF(lwp) CALL flush(numout)
143#endif
144         CALL trc_dta_init(jptra)
145      ENDIF
146
147      IF( ln_rsttr ) THEN
148        !
149#if defined key_medusa
150        IF(lwp) WRITE(numout,*) 'AXY: calling trc_rst_read'
151        IF(lwp) CALL flush(numout)
152#endif
153        CALL trc_rst_read              ! restart from a file
154        !
155      ELSE
156        !
157        IF( ln_trcdta .AND. nb_trcdta > 0 ) THEN  ! Initialisation of tracer from a file that may also be used for damping
158            !
159            CALL wrk_alloc( jpi, jpj, jpk, ztrcdta )    ! Memory allocation
160            !
161            DO jn = 1, jptra
162               IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
163                  jl = n_trc_index(jn) 
164                  CALL trc_dta( nit000, sf_trcdta(jl),rf_trfac(jl) )   ! read tracer data at nit000
165                  ztrcdta(:,:,:) = sf_trcdta(jl)%fnow(:,:,:)
166                  trn(:,:,:,jn) = ztrcdta(:,:,:) * tmask(:,:,:) 
167                  IF( .NOT.ln_trcdmp .AND. .NOT.ln_trcdmp_clo ) THEN      !== deallocate data structure   ==!
168                     !                                                    (data used only for initialisation)
169                     IF(lwp) WRITE(numout,*) 'trc_dta: deallocate data arrays as they are only used to initialize the run'
170                                                  DEALLOCATE( sf_trcdta(jl)%fnow )     !  arrays in the structure
171                     IF( sf_trcdta(jl)%ln_tint )  DEALLOCATE( sf_trcdta(jl)%fdta )
172                     !
173                  ENDIF
174               ENDIF
175            ENDDO
176            CALL wrk_dealloc( jpi, jpj, jpk, ztrcdta )
177        ENDIF
178        !
179# if defined key_debug_medusa
180         IF (lwp) write (numout,*) '------------------------------'
181         IF (lwp) write (numout,*) 'Jpalm - debug'
182         IF (lwp) write (numout,*) ' in trc_init'
183         IF (lwp) write (numout,*) ' before trb = trn'
184         IF (lwp) write (numout,*) ' '
185         CALL flush(numout)
186# endif
187        !
188        trb(:,:,:,:) = trn(:,:,:,:)
189        !
190# if defined key_debug_medusa
191         IF (lwp) write (numout,*) '------------------------------'
192         IF (lwp) write (numout,*) 'Jpalm - debug'
193         IF (lwp) write (numout,*) ' in trc_init'
194         IF (lwp) write (numout,*) ' trb = trn -- OK'
195         IF (lwp) write (numout,*) ' '
196         CALL flush(numout)
197# endif
198        !
199      ENDIF
200 
201      tra(:,:,:,:) = 0._wp
202      IF( ln_zps .AND. .NOT. lk_c1d .AND. .NOT. ln_isfcav )   &              ! Partial steps: before horizontal gradient of passive
203        &    CALL zps_hde    ( nit000, jptra, trn, gtru, gtrv  )  ! Partial steps: before horizontal gradient
204      IF( ln_zps .AND. .NOT. lk_c1d .AND.       ln_isfcav )   &
205        &    CALL zps_hde_isf( nit000, jptra, trn, pgtu=gtru, pgtv=gtrv, pgtui=gtrui, pgtvi=gtrvi )       ! tracers at the bottom ocean level
206      !
207# if defined key_debug_medusa
208         IF (lwp) write (numout,*) '------------------------------'
209         IF (lwp) write (numout,*) 'Jpalm - debug'
210         IF (lwp) write (numout,*) ' in trc_init'
211         IF (lwp) write (numout,*) ' partial step -- OK'
212         IF (lwp) write (numout,*) ' '
213         CALL flush(numout)
214# endif
215      !
216      IF( nn_dttrc /= 1 )        CALL trc_sub_ini      ! Initialize variables for substepping passive tracers
217      !
218# if defined key_debug_medusa
219         IF (lwp) write (numout,*) '------------------------------'
220         IF (lwp) write (numout,*) 'Jpalm - debug'
221         IF (lwp) write (numout,*) ' in trc_init'
222         IF (lwp) write (numout,*) ' before initiate tracer contents'
223         IF (lwp) write (numout,*) ' '
224         CALL flush(numout)
225# endif
226      !
227      trai(:) = 0._wp                                                   ! initial content of all tracers
228      DO jn = 1, jptra
229         trai(jn) = trai(jn) + glob_sum( trn(:,:,:,jn) * cvol(:,:,:)   )
230      END DO
231
232      IF(lwp) THEN               ! control print
233         WRITE(numout,*)
234         WRITE(numout,*)
235         WRITE(numout,*) '          *** Total number of passive tracer jptra = ', jptra
236         WRITE(numout,*) '          *** Total volume of ocean                = ', areatot
237         WRITE(numout,*) '          *** Total inital content of all tracers '
238         WRITE(numout,*)
239# if defined key_debug_medusa
240         CALL flush(numout)
241# endif
242         !
243# if defined key_debug_medusa
244         WRITE(numout,*) ' litle check :  ', ctrcnm(1)
245         CALL flush(numout)
246# endif
247         DO jn = 1, jptra
248            WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), trai(jn)
249         ENDDO
250         WRITE(numout,*)
251      ENDIF
252      IF(lwp) WRITE(numout,*)
253      IF(ln_ctl) THEN            ! print mean trends (used for debugging)
254         CALL prt_ctl_trc_init
255         WRITE(charout, FMT="('ini ')")
256         CALL prt_ctl_trc_info( charout )
257         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
258      ENDIF
259
260      IF(lwp) WRITE(numout,*)
261      IF(lwp) WRITE(numout,*) 'trc_init : passive tracer set up completed'
262      IF(lwp) WRITE(numout,*) '~~~~~~~'
263      IF(lwp) CALL flush(numout)
264# if defined key_debug_medusa
265         CALL trc_rst_stat
266         CALL flush(numout)
267# endif
268
2699000  FORMAT(' tracer nb : ',i2,'      name :',a10,'      initial content :',e18.10)
270      !
271      IF( nn_timing == 1 )   CALL timing_stop('trc_init')
272      !
273   END SUBROUTINE trc_init
274
275
276   SUBROUTINE top_alloc
277      !!----------------------------------------------------------------------
278      !!                     ***  ROUTINE top_alloc  ***
279      !!
280      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
281      !!----------------------------------------------------------------------
282      USE trcadv        , ONLY:   trc_adv_alloc          ! TOP-related alloc routines...
283      USE trc           , ONLY:   trc_alloc
284      USE trcnxt        , ONLY:   trc_nxt_alloc
285      USE trczdf        , ONLY:   trc_zdf_alloc
286      USE trdtrc_oce    , ONLY:   trd_trc_oce_alloc
287#if defined key_trdmxl_trc 
288      USE trdmxl_trc    , ONLY:   trd_mxl_trc_alloc
289#endif
290      !
291      INTEGER :: ierr
292      !!----------------------------------------------------------------------
293      !
294      ierr =        trc_adv_alloc()          ! Start of TOP-related alloc routines...
295      ierr = ierr + trc_alloc    ()
296      ierr = ierr + trc_nxt_alloc()
297      ierr = ierr + trc_zdf_alloc()
298      ierr = ierr + trd_trc_oce_alloc()
299#if defined key_trdmxl_trc 
300      ierr = ierr + trd_mxl_trc_alloc()
301#endif
302      !
303      IF( lk_mpp    )   CALL mpp_sum( ierr )
304      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'top_alloc : unable to allocate standard ocean arrays' )
305      !
306   END SUBROUTINE top_alloc
307
308#else
309   !!----------------------------------------------------------------------
310   !!  Empty module :                                     No passive tracer
311   !!----------------------------------------------------------------------
312CONTAINS
313   SUBROUTINE trc_init                      ! Dummy routine   
314   END SUBROUTINE trc_init
315#endif
316
317   !!======================================================================
318END MODULE trcini
Note: See TracBrowser for help on using the repository browser.