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/2012/dev_MERGE_2012/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/TOP_SRC/trcdta.F90 @ 3827

Last change on this file since 3827 was 3827, checked in by cetlod, 11 years ago

v3.5alpha: Add missing IF(lwp) before writing in numout, see ticket #1066

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