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/2015/nemo_v3_6_STABLE/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/2015/nemo_v3_6_STABLE/NEMOGCM/NEMO/TOP_SRC/trcdta.F90 @ 8543

Last change on this file since 8543 was 8543, checked in by cetlod, 7 years ago

bugfix on trcdta to be consistent with dtatsd

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