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

source: branches/UKMO/CO6_KD490/NEMOGCM/NEMO/TOP_SRC/trcdta.F90 @ 9336

Last change on this file since 9336 was 6332, checked in by deazer, 8 years ago

Tested Initial run one day physics only in rose suite.

File size: 13.8 KB
RevLine 
[268]1MODULE trcdta
2   !!======================================================================
[433]3   !!                     ***  MODULE  trcdta  ***
[945]4   !! TOP :  reads passive tracer data
[268]5   !!=====================================================================
[945]6   !! History :   1.0  !  2002-04  (O. Aumont)  original code
7   !!              -   !  2004-03  (C. Ethe)  module
8   !!              -   !  2005-03  (O. Aumont, A. El Moussaoui) F90
[3294]9   !!            3.4   !  2010-11  (C. Ethe, G. Madec)  use of fldread + dynamical allocation
[4230]10   !!            3.5   !  2013-08  (M. Vichi)  generalization for other BGC models
[6332]11   !!            3.6   !  2015-03  (T. Lovato) revision of code log info
[274]12   !!----------------------------------------------------------------------
[3294]13#if  defined key_top 
[268]14   !!----------------------------------------------------------------------
[3294]15   !!   'key_top'                                                TOP model
[268]16   !!----------------------------------------------------------------------
[3294]17   !!   trc_dta    : read and time interpolated passive tracer data
[268]18   !!----------------------------------------------------------------------
[3294]19   USE par_trc       !  passive tracers parameters
20   USE oce_trc       !  shared variables between ocean and passive tracers
21   USE trc           !  passive tracers common variables
22   USE iom           !  I/O manager
23   USE lib_mpp       !  MPP library
24   USE fldread       !  read input fields
[268]25
26   IMPLICIT NONE
27   PRIVATE
28
[2715]29   PUBLIC   trc_dta         ! called in trcini.F90 and trcdmp.F90
[3294]30   PUBLIC   trc_dta_init    ! called in trcini.F90
[268]31
[3294]32   INTEGER  , SAVE, PUBLIC                             :: nb_trcdta   ! number of tracers to be initialised with data
33   INTEGER  , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: n_trc_index ! indice of tracer which is initialised with data
[4230]34   INTEGER  , SAVE, PUBLIC                             :: ntra        ! MAX( 1, nb_trcdta ) to avoid compilation error with bounds checking
35   REAL(wp) , SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: rf_trfac    ! multiplicative factor for tracer values
[4489]36!$AGRIF_DO_NOT_TREAT
[4230]37   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trcdta   ! structure of input SST (file informations, fields read)
[4489]38!$AGRIF_END_DO_NOT_TREAT
[268]39   !! * Substitutions
[3294]40#  include "domzgr_substitute.h90"
[268]41   !!----------------------------------------------------------------------
[3294]42   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
[6331]43   !! $Id$
[2715]44   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
[268]45   !!----------------------------------------------------------------------
46CONTAINS
47
[4230]48   SUBROUTINE trc_dta_init(ntrc)
[335]49      !!----------------------------------------------------------------------
[3294]50      !!                   ***  ROUTINE trc_dta_init  ***
51      !!                   
52      !! ** Purpose :   initialisation of passive tracer input data
53      !!
54      !! ** Method  : - Read namtsd namelist
55      !!              - allocates passive tracer data structure
[335]56      !!----------------------------------------------------------------------
[3294]57      !
[4230]58      INTEGER,INTENT(IN) :: ntrc                             ! number of tracers
59      INTEGER            :: jl, jn                           ! dummy loop indices
[3294]60      INTEGER            :: ierr0, ierr1, ierr2, ierr3       ! temporary integers
[4147]61      INTEGER            :: ios                              ! Local integer output status for namelist read
[3294]62      CHARACTER(len=100) :: clndta, clntrc
63      REAL(wp)           :: zfact
64      !
[4147]65      CHARACTER(len=100)            :: cn_dir
[4230]66      TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) :: slf_i ! array of namelist informations on the fields to read
67      TYPE(FLD_N), DIMENSION(jpmaxtrc) :: sn_trcdta
68      REAL(wp)   , DIMENSION(jpmaxtrc) :: rn_trfac    ! multiplicative factor for tracer values
[945]69      !!
[3294]70      NAMELIST/namtrc_dta/ sn_trcdta, cn_dir, rn_trfac 
[335]71      !!----------------------------------------------------------------------
[3294]72      !
73      IF( nn_timing == 1 )  CALL timing_start('trc_dta_init')
74      !
[6332]75      IF( lwp ) THEN
76         WRITE(numout,*) ' '
77         WRITE(numout,*) '  trc_dta_init : Tracers Initial Conditions (IC)'
78         WRITE(numout,*) '  ~~~~~~~~~~~ '
79      ENDIF
80      !
[3294]81      !  Initialisation
82      ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0 
83      ! Compute the number of tracers to be initialised with data
[4230]84      ALLOCATE( n_trc_index(ntrc), slf_i(ntrc), STAT=ierr0 )
[3294]85      IF( ierr0 > 0 ) THEN
[6332]86         CALL ctl_stop( 'trc_dta_init: unable to allocate n_trc_index' )   ;   RETURN
[3294]87      ENDIF
88      nb_trcdta      = 0
89      n_trc_index(:) = 0
[4230]90      DO jn = 1, ntrc
[3294]91         IF( ln_trc_ini(jn) ) THEN
92             nb_trcdta       = nb_trcdta + 1 
93             n_trc_index(jn) = nb_trcdta 
94         ENDIF
95      ENDDO
96      !
97      ntra = MAX( 1, nb_trcdta )   ! To avoid compilation error with bounds checking
[3827]98      IF(lwp) THEN
99         WRITE(numout,*) ' '
100         WRITE(numout,*) ' number of passive tracers to be initialize by data :', ntra
101         WRITE(numout,*) ' '
102      ENDIF
[3294]103      !
[4147]104      REWIND( numnat_ref )              ! Namelist namtrc_dta in reference namelist : Passive tracer input data
105      READ  ( numnat_ref, namtrc_dta, IOSTAT = ios, ERR = 901)
[6332]106901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta_init in reference namelist', lwp )
[268]107
[4147]108      REWIND( numnat_cfg )              ! Namelist namtrc_dta in configuration namelist : Passive tracer input data
109      READ  ( numnat_cfg, namtrc_dta, IOSTAT = ios, ERR = 902 )
[6332]110902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta_init in configuration namelist', lwp )
[4624]111      IF(lwm) WRITE ( numont, namtrc_dta )
[4147]112
[3294]113      IF( lwp ) THEN
[4230]114         DO jn = 1, ntrc
[3294]115            IF( ln_trc_ini(jn) )  THEN    ! open input file only if ln_trc_ini(jn) is true
116               clndta = TRIM( sn_trcdta(jn)%clvar ) 
117               clntrc = TRIM( ctrcnm   (jn)       ) 
[6332]118               if (jn > jptra) clntrc='Dummy' ! By pass weird formats in ocean.output if ntrc > jptra
[3294]119               zfact  = rn_trfac(jn)
120               IF( clndta /=  clntrc ) THEN
[6332]121                  CALL ctl_warn( 'trc_dta_init: passive tracer data initialisation    ',   &
122                  &              'Input name of data file : '//TRIM(clndta)//   &
123                  &              ' differs from that of tracer : '//TRIM(clntrc)//' ')
[3294]124               ENDIF
[6332]125               WRITE(numout,*) ' '
126               WRITE(numout,'(a, i3,3a,e11.3)') ' Read IC file for tracer number :', &
127               &            jn, ', name : ', TRIM(clndta), ', Multiplicative Scaling factor : ', zfact
[335]128            ENDIF
[3294]129         END DO
130      ENDIF
131      !
132      IF( nb_trcdta > 0 ) THEN       !  allocate only if the number of tracer to initialise is greater than zero
133         ALLOCATE( sf_trcdta(nb_trcdta), rf_trfac(nb_trcdta), STAT=ierr1 )
134         IF( ierr1 > 0 ) THEN
[6332]135            CALL ctl_stop( 'trc_dta_init: unable to allocate  sf_trcdta structure' )   ;   RETURN
[3294]136         ENDIF
137         !
[4230]138         DO jn = 1, ntrc
[3294]139            IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
140               jl = n_trc_index(jn)
141               slf_i(jl)    = sn_trcdta(jn)
142               rf_trfac(jl) = rn_trfac(jn)
143                                            ALLOCATE( sf_trcdta(jl)%fnow(jpi,jpj,jpk)   , STAT=ierr2 )
144               IF( sn_trcdta(jn)%ln_tint )  ALLOCATE( sf_trcdta(jl)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
145               IF( ierr2 + ierr3 > 0 ) THEN
[6332]146                 CALL ctl_stop( 'trc_dta_init : unable to allocate passive tracer data arrays' )   ;   RETURN
[3294]147               ENDIF
148            ENDIF
149            !   
150         ENDDO
151         !                         ! fill sf_trcdta with slf_i and control print
[6332]152         CALL fld_fill( sf_trcdta, slf_i, cn_dir, 'trc_dta_init', 'Passive tracer data', 'namtrc' )
[3294]153         !
154      ENDIF
155      !
[4230]156      DEALLOCATE( slf_i )          ! deallocate local field structure
[3294]157      IF( nn_timing == 1 )  CALL timing_stop('trc_dta_init')
158      !
159   END SUBROUTINE trc_dta_init
[268]160
[493]161
[4230]162   SUBROUTINE trc_dta( kt, sf_dta, zrf_trfac )
[3294]163      !!----------------------------------------------------------------------
164      !!                   ***  ROUTINE trc_dta  ***
165      !!                   
166      !! ** Purpose :   provides passive tracer data at kt
167      !!
168      !! ** Method  : - call fldread routine
169      !!              - s- or mixed z-s coordinate: vertical interpolation on model mesh
170      !!              - ln_trcdmp=F: deallocates the data structure as they are not used
171      !!
[4230]172      !! ** Action  :   sf_dta   passive tracer data on medl mesh and interpolated at time-step kt
[3294]173      !!----------------------------------------------------------------------
174      INTEGER                     , INTENT(in   ) ::   kt     ! ocean time-step
[4230]175      TYPE(FLD), DIMENSION(1)   , INTENT(inout) ::   sf_dta     ! array of information on the field to read
176      REAL(wp)                  , INTENT(in   ) ::   zrf_trfac  ! multiplication factor
[3294]177      !
[4230]178      INTEGER ::   ji, jj, jk, jl, jkk, ik    ! dummy loop indices
[3294]179      REAL(wp)::   zl, zi
180      REAL(wp), DIMENSION(jpk) ::  ztp                ! 1D workspace
181      CHARACTER(len=100) :: clndta
182      !!----------------------------------------------------------------------
183      !
184      IF( nn_timing == 1 )  CALL timing_start('trc_dta')
185      !
186      IF( nb_trcdta > 0 ) THEN
187         !
[4230]188         CALL fld_read( kt, 1, sf_dta )      !==   read data at kt time step   ==!
[3294]189         !
190         IF( ln_sco ) THEN                   !==   s- or mixed s-zps-coordinate   ==!
191            !
192            IF( kt == nit000 .AND. lwp )THEN
193               WRITE(numout,*)
194               WRITE(numout,*) 'trc_dta: interpolates passive tracer data onto the s- or mixed s-z-coordinate mesh'
[268]195            ENDIF
[3294]196            !
197               DO jj = 1, jpj                         ! vertical interpolation of T & S
198                  DO ji = 1, jpi
199                     DO jk = 1, jpk                        ! determines the intepolated T-S profiles at each (i,j) points
[4292]200                        zl = fsdept_n(ji,jj,jk)
201                        IF(     zl < gdept_1d(1  ) ) THEN         ! above the first level of data
[4230]202                           ztp(jk) =  sf_dta(1)%fnow(ji,jj,1)
[4292]203                        ELSEIF( zl > gdept_1d(jpk) ) THEN         ! below the last level of data
[4230]204                           ztp(jk) =  sf_dta(1)%fnow(ji,jj,jpkm1)
[3294]205                        ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
206                           DO jkk = 1, jpkm1                                  ! when  gdept(jkk) < zl < gdept(jkk+1)
[4292]207                              IF( (zl-gdept_1d(jkk)) * (zl-gdept_1d(jkk+1)) <= 0._wp ) THEN
208                                 zi = ( zl - gdept_1d(jkk) ) / (gdept_1d(jkk+1)-gdept_1d(jkk))
[4230]209                                 ztp(jk) = sf_dta(1)%fnow(ji,jj,jkk) + ( sf_dta(1)%fnow(ji,jj,jkk+1) - &
210                                           sf_dta(1)%fnow(ji,jj,jkk) ) * zi 
[3294]211                              ENDIF
212                           END DO
213                        ENDIF
[335]214                     END DO
[3294]215                     DO jk = 1, jpkm1
[4230]216                        sf_dta(1)%fnow(ji,jj,jk) = ztp(jk) * tmask(ji,jj,jk)     ! mask required for mixed zps-s-coord
[3294]217                     END DO
[4230]218                     sf_dta(1)%fnow(ji,jj,jpk) = 0._wp
[3294]219                  END DO
[268]220               END DO
[3294]221            !
222         ELSE                                !==   z- or zps- coordinate   ==!
223            !                             
[4230]224               sf_dta(1)%fnow(:,:,:) = sf_dta(1)%fnow(:,:,:) * tmask(:,:,:)    ! Mask
[3294]225               !
226               IF( ln_zps ) THEN                      ! zps-coordinate (partial steps) interpolation at the last ocean level
227                  DO jj = 1, jpj
228                     DO ji = 1, jpi
229                        ik = mbkt(ji,jj) 
230                        IF( ik > 1 ) THEN
[4292]231                           zl = ( gdept_1d(ik) - fsdept_n(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
[4230]232                           sf_dta(1)%fnow(ji,jj,ik) = (1.-zl) * sf_dta(1)%fnow(ji,jj,ik) + zl * sf_dta(1)%fnow(ji,jj,ik-1)
[3294]233                        ENDIF
[5385]234                        ik = mikt(ji,jj)
235                        IF( ik > 1 ) THEN
236                           zl = ( gdept_0(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) )
237                           sf_dta(1)%fnow(ji,jj,ik) = (1.-zl) * sf_dta(1)%fnow(ji,jj,ik) + zl * sf_dta(1)%fnow(ji,jj,ik+1)
238                        ENDIF
[3294]239                     END DO
240                  END DO
241               ENDIF
242            !
243         ENDIF
244         !
[4230]245         sf_dta(1)%fnow(:,:,:) = sf_dta(1)%fnow(:,:,:) * zrf_trfac   !  multiplicative factor
[3294]246         !
247         IF( lwp .AND. kt == nit000 ) THEN
[4230]248               clndta = TRIM( sf_dta(1)%clvar ) 
[3294]249               WRITE(numout,*) ''//clndta//' data '
[335]250               WRITE(numout,*)
[3294]251               WRITE(numout,*)'  level = 1'
[4230]252               CALL prihre( sf_dta(1)%fnow(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
[3294]253               WRITE(numout,*)'  level = ', jpk/2
[4230]254               CALL prihre( sf_dta(1)%fnow(:,:,jpk/2), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
[3294]255               WRITE(numout,*)'  level = ', jpkm1
[4230]256               CALL prihre( sf_dta(1)%fnow(:,:,jpkm1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
[3294]257               WRITE(numout,*)
[945]258         ENDIF
[3294]259      ENDIF
[4230]260      !
[3294]261      IF( nn_timing == 1 )  CALL timing_stop('trc_dta')
[945]262      !
[1011]263   END SUBROUTINE trc_dta
[268]264#else
265   !!----------------------------------------------------------------------
[945]266   !!   Dummy module                              NO 3D passive tracer data
[268]267   !!----------------------------------------------------------------------
268CONTAINS
[4230]269   SUBROUTINE trc_dta( kt, sf_dta, zrf_trfac )        ! Empty routine
[1011]270      WRITE(*,*) 'trc_dta: You should not have seen this print! error?', kt
271   END SUBROUTINE trc_dta
[268]272#endif
[945]273   !!======================================================================
[268]274END MODULE trcdta
Note: See TracBrowser for help on using the repository browser.