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 NEMO/trunk/src/TOP – NEMO

source: NEMO/trunk/src/TOP/trcdta.F90

Last change on this file was 15446, checked in by cetlod, 2 years ago

Minor bugfixes mostly related to PISCES/SED module

  • Property svn:keywords set to Id
File size: 12.2 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   !!            3.6   !  2015-03  (T. Lovato) revisit code I/O
12   !!----------------------------------------------------------------------
13#if defined key_top 
14   !!----------------------------------------------------------------------
15   !!   'key_top'                                                TOP model
16   !!----------------------------------------------------------------------
17   !!   trc_dta    : read and time interpolated passive tracer data
18   !!----------------------------------------------------------------------
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   !
23   USE iom           !  I/O manager
24   USE lib_mpp       !  MPP library
25   USE fldread       !  read input fields
26
27   IMPLICIT NONE
28   PRIVATE
29
30   PUBLIC   trc_dta         ! called in trcini.F90 and trcdmp.F90
31   PUBLIC   trc_dta_ini     ! called in trcini.F90
32
33   INTEGER  , PUBLIC                             :: nb_trcdta   ! number of tracers to be initialised with data
34   INTEGER  , PUBLIC, ALLOCATABLE, DIMENSION(:)  :: n_trc_index ! indice of tracer which is initialised with data
35   INTEGER  , PUBLIC                             :: ntra        ! MAX( 1, nb_trcdta ) to avoid compilation error with bounds checking
36   REAL(wp) ,         ALLOCATABLE, DIMENSION(:)  :: rf_trfac    ! multiplicative factor for tracer values
37   TYPE(FLD),         ALLOCATABLE, DIMENSION(:)  :: sf_trcdta   ! structure of input SST (file informations, fields read)
38
39   !! Substitutions
40#include "do_loop_substitute.h90"
41#include "domzgr_substitute.h90"
42   !!----------------------------------------------------------------------
43   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
44   !! $Id$
45   !! Software governed by the CeCILL license (see ./LICENSE)
46   !!----------------------------------------------------------------------
47CONTAINS
48
49   SUBROUTINE trc_dta_ini(ntrc)
50      !!----------------------------------------------------------------------
51      !!                   ***  ROUTINE trc_dta_ini  ***
52      !!                   
53      !! ** Purpose :   initialisation of passive tracer input data
54      !!
55      !! ** Method  : - Read namtsd namelist
56      !!              - allocates passive tracer data structure
57      !!----------------------------------------------------------------------
58      INTEGER,INTENT(in) ::   ntrc   ! number of tracers
59      !
60      INTEGER ::   jl, jn                            ! dummy loop indices
61      INTEGER ::   ios, ierr0, ierr1, ierr2, ierr3   ! local integers
62      REAL(wp) ::   zfact
63      CHARACTER(len=100) ::   clndta, clntrc
64      !
65      CHARACTER(len=100) ::   cn_dir
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
69      !!
70      NAMELIST/namtrc_dta/ sn_trcdta, cn_dir, rn_trfac 
71      !!----------------------------------------------------------------------
72      !
73      IF( lwp ) THEN
74         WRITE(numout,*)
75         WRITE(numout,*) 'trc_dta_ini : Tracers Initial Conditions (IC)'
76         WRITE(numout,*) '~~~~~~~~~~~ '
77      ENDIF
78      !
79      !  Initialisation
80      ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0 
81      ! Compute the number of tracers to be initialised with data
82      ALLOCATE( n_trc_index(ntrc), slf_i(ntrc), STAT=ierr0 )
83      IF( ierr0 > 0 ) THEN
84         CALL ctl_stop( 'trc_dta_ini: unable to allocate n_trc_index' )   ;   RETURN
85      ENDIF
86      nb_trcdta      = 0
87      n_trc_index(:) = 0
88      DO jn = 1, ntrc
89         IF( ln_trc_ini(jn) ) THEN
90             nb_trcdta       = nb_trcdta + 1 
91             n_trc_index(jn) = nb_trcdta 
92         ENDIF
93      END DO
94      !
95      ntra = MAX( 1, nb_trcdta )   ! To avoid compilation error with bounds checking
96      IF(lwp) THEN
97         WRITE(numout,*)
98         WRITE(numout,*) '   number of passive tracers to be initialize by data :', ntra
99      ENDIF
100      !
101      READ  ( numnat_ref, namtrc_dta, IOSTAT = ios, ERR = 901)
102901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_dta_ini in reference namelist' )
103      READ  ( numnat_cfg, namtrc_dta, IOSTAT = ios, ERR = 902 )
104902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_dta_ini in configuration namelist' )
105      IF(lwm) WRITE ( numont, namtrc_dta )
106
107      IF( lwp ) THEN
108         DO jn = 1, ntrc
109            IF( ln_trc_ini(jn) )  THEN    ! open input file only if ln_trc_ini(jn) is true
110               clndta = TRIM( sn_trcdta(jn)%clvar ) 
111               clntrc = TRIM( ctrcnm   (jn)       ) 
112               if (jn > jptra) clntrc='Dummy' ! By pass weird formats in ocean.output if ntrc > jptra
113               zfact  = rn_trfac(jn)
114               IF( clndta /=  clntrc ) THEN
115                  CALL ctl_warn( 'trc_dta_ini: passive tracer data initialisation    ',   &
116                  &              'Input name of data file : '//TRIM(clndta)//   &
117                  &              ' differs from that of tracer : '//TRIM(clntrc)//' ')
118               ENDIF
119               WRITE(numout,*)
120               WRITE(numout,'(a, i4,3a,e11.3)') '   Read IC file for tracer number :', &
121               &            jn, ', name : ', TRIM(clndta), ', Multiplicative Scaling factor : ', zfact
122            ENDIF
123         END DO
124      ENDIF
125      !
126      IF( nb_trcdta > 0 ) THEN       !  allocate only if the number of tracer to initialise is greater than zero
127         ALLOCATE( sf_trcdta(nb_trcdta), rf_trfac(nb_trcdta), STAT=ierr1 )
128         IF( ierr1 > 0 ) THEN
129            CALL ctl_stop( 'trc_dta_ini: unable to allocate  sf_trcdta structure' )   ;   RETURN
130         ENDIF
131         !
132         DO jn = 1, ntrc
133            IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
134               jl = n_trc_index(jn)
135               slf_i(jl)    = sn_trcdta(jn)
136               rf_trfac(jl) = rn_trfac(jn)
137                                            ALLOCATE( sf_trcdta(jl)%fnow(jpi,jpj,jpk)   , STAT=ierr2 )
138               IF( sn_trcdta(jn)%ln_tint )  ALLOCATE( sf_trcdta(jl)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
139               IF( ierr2 + ierr3 > 0 ) THEN
140                 CALL ctl_stop( 'trc_dta_ini : unable to allocate passive tracer data arrays' )   ;   RETURN
141               ENDIF
142            ENDIF
143            !   
144         ENDDO
145         !                         ! fill sf_trcdta with slf_i and control print
146         CALL fld_fill( sf_trcdta, slf_i, cn_dir, 'trc_dta_ini', 'Passive tracer data', 'namtrc' )
147         !
148      ENDIF
149      !
150      DEALLOCATE( slf_i )          ! deallocate local field structure
151      !
152   END SUBROUTINE trc_dta_ini
153
154
155   SUBROUTINE trc_dta( kt, kjl, ptrcdta)
156      !!----------------------------------------------------------------------
157      !!                   ***  ROUTINE trc_dta  ***
158      !!                   
159      !! ** Purpose :   provides passive tracer data at kt
160      !!
161      !! ** Method  : - call fldread routine
162      !!              - s- or mixed z-s coordinate: vertical interpolation on model mesh
163      !!              - ln_trcdmp=F: deallocates the data structure as they are not used
164      !!
165      !! ** Action  :   sf_trcdta   passive tracer data on meld mesh and interpolated at time-step kt
166      !!----------------------------------------------------------------------
167      INTEGER                          , INTENT(in   )   ::   kt         ! ocean time-step
168      INTEGER                          , INTENT(in   )   ::   kjl        ! tracer index
169      REAL(wp),  DIMENSION(jpi,jpj,jpk), INTENT(inout  ) ::   ptrcdta    ! 3D data array
170      !
171      INTEGER ::   ji, jj, jk, jl, jkk, ik    ! dummy loop indices
172      REAL(wp)::   zl, zi
173      REAL(wp), DIMENSION(jpk) ::  ztp                ! 1D workspace
174      CHARACTER(len=100) :: clndta
175      !!----------------------------------------------------------------------
176      !
177      IF( ln_timing )   CALL timing_start('trc_dta')
178      !
179      IF( kt == nit000 .AND. lwp) THEN
180         WRITE(numout,*)
181         WRITE(numout,*) 'trc_dta : passive tracers data for IC'
182         WRITE(numout,*) '~~~~~~~ '
183      ENDIF
184      !
185      IF( nb_trcdta > 0 ) THEN
186         !
187         ! read data at kt time step
188         CALL fld_read( kt, 1, sf_trcdta )
189         ptrcdta(:,:,:) = sf_trcdta(kjl)%fnow(:,:,:) * tmask(:,:,:)
190         !
191#if ! defined key_sed_off
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            DO_2D( nn_hls, nn_hls, nn_hls, nn_hls )                 ! vertical interpolation of T & S
199               DO jk = 1, jpk                        ! determines the intepolated T-S profiles at each (i,j) points
200                  zl = gdept_0(ji,jj,jk)
201                  IF(     zl < gdept_1d(1  ) ) THEN         ! above the first level of data
202                     ztp(jk) = ptrcdta(ji,jj,1)
203                  ELSEIF( zl > gdept_1d(jpk) ) THEN         ! below the last level of data
204                     ztp(jk) = ptrcdta(ji,jj,jpkm1)
205                  ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
206                     DO jkk = 1, jpkm1                                  ! when  gdept_1d(jkk) < zl < gdept_1d(jkk+1)
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))
209                           ztp(jk) = ptrcdta(ji,jj,jkk) + ( ptrcdta(ji,jj,jkk+1) - ptrcdta(ji,jj,jkk) ) * zi
210                        ENDIF
211                     END DO
212                  ENDIF
213               END DO
214               DO jk = 1, jpkm1
215                  ptrcdta(ji,jj,jk) = ztp(jk) * tmask(ji,jj,jk)     ! mask required for mixed zps-s-coord
216               END DO
217               ptrcdta(ji,jj,jpk) = 0._wp
218            END_2D
219            !
220         ELSE                                !==   z- or zps- coordinate   ==!
221            ! zps-coordinate (partial steps) interpolation at the last ocean level
222            IF( ln_zps ) THEN
223                DO_2D( nn_hls, nn_hls, nn_hls, nn_hls )
224                   ik = mbkt(ji,jj)
225                   IF( ik > 1 .AND. gdept_0(ji,jj,ik) < gdept_1d(ik) ) THEN
226                      zl = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
227                      ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik-1)
228                   ENDIF
229                   ik = mikt(ji,jj)
230                   IF( ik > 1 ) THEN
231                      zl = ( gdept_0(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) )
232                      ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik+1)
233                   ENDIF
234                 END_2D
235            ENDIF
236            !
237         ENDIF
238#endif
239         ! Scale by multiplicative factor
240         ptrcdta(:,:,:) = ptrcdta(:,:,:) * rf_trfac(kjl)
241         !
242      ENDIF
243      !
244      IF( ln_timing )  CALL timing_stop('trc_dta')
245      !
246   END SUBROUTINE trc_dta
247
248#else
249   !!----------------------------------------------------------------------
250   !!   Dummy module                              NO 3D passive tracer data
251   !!----------------------------------------------------------------------
252CONTAINS
253   SUBROUTINE trc_dta( kt, kjl, ptrcdta)        ! Empty routine
254      WRITE(*,*) 'trc_dta: You should not have seen this print! error?', kt
255   END SUBROUTINE trc_dta
256#endif
257
258   !!======================================================================
259END MODULE trcdta
Note: See TracBrowser for help on using the repository browser.