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/2016/dev_INGV_UKMO_2016/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/2016/dev_INGV_UKMO_2016/NEMOGCM/NEMO/TOP_SRC/trcdta.F90 @ 7351

Last change on this file since 7351 was 7351, checked in by emanuelaclementi, 7 years ago

ticket #1805 step 3: /2016/dev_INGV_UKMO_2016 aligned to the trunk at revision 7161

  • Property svn:keywords set to Id
File size: 13.4 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) revision of code log info
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   USE iom           !  I/O manager
23   USE lib_mpp       !  MPP library
24   USE fldread       !  read input fields
25
26   IMPLICIT NONE
27   PRIVATE
28
29   PUBLIC   trc_dta         ! called in trcini.F90 and trcdmp.F90
30   PUBLIC   trc_dta_init    ! called in trcini.F90
31
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
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
36!$AGRIF_DO_NOT_TREAT
37   TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:)  :: sf_trcdta   ! structure of input SST (file informations, fields read)
38!$AGRIF_END_DO_NOT_TREAT
39
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      IF( lwp ) THEN
75         WRITE(numout,*) ' '
76         WRITE(numout,*) '  trc_dta_init : Tracers Initial Conditions (IC)'
77         WRITE(numout,*) '  ~~~~~~~~~~~ '
78      ENDIF
79      !
80      !  Initialisation
81      ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0 
82      ! Compute the number of tracers to be initialised with data
83      ALLOCATE( n_trc_index(ntrc), slf_i(ntrc), STAT=ierr0 )
84      IF( ierr0 > 0 ) THEN
85         CALL ctl_stop( 'trc_dta_init: unable to allocate n_trc_index' )   ;   RETURN
86      ENDIF
87      nb_trcdta      = 0
88      n_trc_index(:) = 0
89      DO jn = 1, ntrc
90         IF( ln_trc_ini(jn) ) THEN
91             nb_trcdta       = nb_trcdta + 1 
92             n_trc_index(jn) = nb_trcdta 
93         ENDIF
94      ENDDO
95      !
96      ntra = MAX( 1, nb_trcdta )   ! To avoid compilation error with bounds checking
97      IF(lwp) THEN
98         WRITE(numout,*) ' '
99         WRITE(numout,*) ' number of passive tracers to be initialize by data :', ntra
100         WRITE(numout,*) ' '
101      ENDIF
102      !
103      REWIND( numnat_ref )              ! Namelist namtrc_dta in reference namelist : Passive tracer input data
104      READ  ( numnat_ref, namtrc_dta, IOSTAT = ios, ERR = 901)
105901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta_init in reference namelist', lwp )
106
107      REWIND( numnat_cfg )              ! Namelist namtrc_dta in configuration namelist : Passive tracer input data
108      READ  ( numnat_cfg, namtrc_dta, IOSTAT = ios, ERR = 902 )
109902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta_init in configuration namelist', lwp )
110      IF(lwm) WRITE ( numont, namtrc_dta )
111
112      IF( lwp ) THEN
113         DO jn = 1, ntrc
114            IF( ln_trc_ini(jn) )  THEN    ! open input file only if ln_trc_ini(jn) is true
115               clndta = TRIM( sn_trcdta(jn)%clvar ) 
116               clntrc = TRIM( ctrcnm   (jn)       ) 
117               if (jn > jptra) clntrc='Dummy' ! By pass weird formats in ocean.output if ntrc > jptra
118               zfact  = rn_trfac(jn)
119               IF( clndta /=  clntrc ) THEN
120                  CALL ctl_warn( 'trc_dta_init: passive tracer data initialisation    ',   &
121                  &              'Input name of data file : '//TRIM(clndta)//   &
122                  &              ' differs from that of tracer : '//TRIM(clntrc)//' ')
123               ENDIF
124               WRITE(numout,*) ' '
125               WRITE(numout,'(a, i4,3a,e11.3)') ' Read IC file for tracer number :', &
126               &            jn, ', name : ', TRIM(clndta), ', Multiplicative Scaling factor : ', zfact
127            ENDIF
128         END DO
129      ENDIF
130      !
131      IF( nb_trcdta > 0 ) THEN       !  allocate only if the number of tracer to initialise is greater than zero
132         ALLOCATE( sf_trcdta(nb_trcdta), rf_trfac(nb_trcdta), STAT=ierr1 )
133         IF( ierr1 > 0 ) THEN
134            CALL ctl_stop( 'trc_dta_init: unable to allocate  sf_trcdta structure' )   ;   RETURN
135         ENDIF
136         !
137         DO jn = 1, ntrc
138            IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
139               jl = n_trc_index(jn)
140               slf_i(jl)    = sn_trcdta(jn)
141               rf_trfac(jl) = rn_trfac(jn)
142                                            ALLOCATE( sf_trcdta(jl)%fnow(jpi,jpj,jpk)   , STAT=ierr2 )
143               IF( sn_trcdta(jn)%ln_tint )  ALLOCATE( sf_trcdta(jl)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
144               IF( ierr2 + ierr3 > 0 ) THEN
145                 CALL ctl_stop( 'trc_dta_init : unable to allocate passive tracer data arrays' )   ;   RETURN
146               ENDIF
147            ENDIF
148            !   
149         ENDDO
150         !                         ! fill sf_trcdta with slf_i and control print
151         CALL fld_fill( sf_trcdta, slf_i, cn_dir, 'trc_dta_init', 'Passive tracer data', 'namtrc' )
152         !
153      ENDIF
154      !
155      DEALLOCATE( slf_i )          ! deallocate local field structure
156      IF( nn_timing == 1 )  CALL timing_stop('trc_dta_init')
157      !
158   END SUBROUTINE trc_dta_init
159
160
161   SUBROUTINE trc_dta( kt, sf_trcdta, ptrfac, ptrc)
162      !!----------------------------------------------------------------------
163      !!                   ***  ROUTINE trc_dta  ***
164      !!                   
165      !! ** Purpose :   provides passive tracer data at kt
166      !!
167      !! ** Method  : - call fldread routine
168      !!              - s- or mixed z-s coordinate: vertical interpolation on model mesh
169      !!              - ln_trcdmp=F: deallocates the data structure as they are not used
170      !!
171      !! ** Action  :   sf_trcdta   passive tracer data on medl mesh and interpolated at time-step kt
172      !!----------------------------------------------------------------------
173      INTEGER                     , INTENT(in   ) ::   kt     ! ocean time-step
174      TYPE(FLD), DIMENSION(1)     , INTENT(inout) ::   sf_trcdta     ! array of information on the field to read
175      REAL(wp)                    , INTENT(in   ) ::   ptrfac  ! multiplication factor
176      REAL(wp), DIMENSION(jpi,jpj,jpk), OPTIONAL  , INTENT(out  ) ::   ptrc
177      !
178      INTEGER ::   ji, jj, jk, jl, jkk, ik    ! dummy loop indices
179      REAL(wp)::   zl, zi
180      REAL(wp), DIMENSION(jpk) ::  ztp                ! 1D workspace
181      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrcdta   ! 3D  workspace
182      CHARACTER(len=100) :: clndta
183      !!----------------------------------------------------------------------
184      !
185      IF( nn_timing == 1 )  CALL timing_start('trc_dta')
186      !
187      IF( nb_trcdta > 0 ) THEN
188         !
189         CALL wrk_alloc( jpi, jpj, jpk, ztrcdta )    ! Memory allocation
190         !
191         CALL fld_read( kt, 1, sf_trcdta )      !==   read data at kt time step   ==!
192         ztrcdta(:,:,:) = sf_trcdta(1)%fnow(:,:,:) * tmask(:,:,:)    ! Mask
193         !
194         IF( ln_sco ) THEN                   !==   s- or mixed s-zps-coordinate   ==!
195            !
196            IF( kt == nit000 .AND. lwp )THEN
197               WRITE(numout,*)
198               WRITE(numout,*) 'trc_dta: interpolates passive tracer data onto the s- or mixed s-z-coordinate mesh'
199            ENDIF
200            DO jj = 1, jpj                         ! vertical interpolation of T & S
201               DO ji = 1, jpi
202                  DO jk = 1, jpk                        ! determines the intepolated T-S profiles at each (i,j) points
203                     zl = gdept_n(ji,jj,jk)
204                     IF(     zl < gdept_1d(1  ) ) THEN         ! above the first level of data
205                        ztp(jk) = ztrcdta(ji,jj,1)
206                     ELSEIF( zl > gdept_1d(jpk) ) THEN         ! below the last level of data
207                        ztp(jk) =  ztrcdta(ji,jj,jpkm1)
208                     ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
209                        DO jkk = 1, jpkm1                                  ! when  gdept(jkk) < zl < gdept(jkk+1)
210                           IF( (zl-gdept_1d(jkk)) * (zl-gdept_1d(jkk+1)) <= 0._wp ) THEN
211                              zi = ( zl - gdept_1d(jkk) ) / (gdept_1d(jkk+1)-gdept_1d(jkk))
212                              ztp(jk) = ztrcdta(ji,jj,jkk) + ( ztrcdta(ji,jj,jkk+1) - &
213                                        ztrcdta(ji,jj,jkk) ) * zi 
214                           ENDIF
215                        END DO
216                     ENDIF
217                  END DO
218                  DO jk = 1, jpkm1
219                    ztrcdta(ji,jj,jk) = ztp(jk) * tmask(ji,jj,jk)     ! mask required for mixed zps-s-coord
220                  END DO
221                  ztrcdta(ji,jj,jpk) = 0._wp
222                END DO
223            END DO
224            !
225         ELSE                                !==   z- or zps- coordinate   ==!
226            !
227            IF( ln_zps ) THEN                      ! zps-coordinate (partial steps) interpolation at the last ocean level
228               DO jj = 1, jpj
229                  DO ji = 1, jpi
230                     ik = mbkt(ji,jj) 
231                     IF( ik > 1 ) THEN
232                        zl = ( gdept_1d(ik) - gdept_n(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
233                        ztrcdta(ji,jj,ik) = (1.-zl) * ztrcdta(ji,jj,ik) + zl * ztrcdta(ji,jj,ik-1)
234                     ENDIF
235                     ik = mikt(ji,jj)
236                     IF( ik > 1 ) THEN
237                        zl = ( gdept_n(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) )
238                        ztrcdta(ji,jj,ik) = (1.-zl) * ztrcdta(ji,jj,ik) + zl * ztrcdta(ji,jj,ik+1)
239                     ENDIF
240                  END DO
241              END DO
242            ENDIF
243            !
244         ENDIF
245         !
246         ! Add multiplicative factor
247         ztrcdta(:,:,:) = ztrcdta(:,:,:) * ptrfac
248         !
249         ! Data structure for trc_ini (and BFMv5.1 coupling)
250         IF( .NOT. PRESENT(ptrc) ) sf_trcdta(1)%fnow(:,:,:) = ztrcdta(:,:,:)
251         !
252         ! Data structure for trc_dmp
253         IF( PRESENT(ptrc) )  ptrc(:,:,:) = ztrcdta(:,:,:)
254         !
255         CALL wrk_dealloc( jpi, jpj, jpk, ztrcdta )
256         !
257      ENDIF
258      !
259      IF( nn_timing == 1 )  CALL timing_stop('trc_dta')
260      !
261   END SUBROUTINE trc_dta
262
263#else
264   !!----------------------------------------------------------------------
265   !!   Dummy module                              NO 3D passive tracer data
266   !!----------------------------------------------------------------------
267CONTAINS
268   SUBROUTINE trc_dta( kt, sf_trcdta, ptrfac, ptrc)        ! Empty routine
269      WRITE(*,*) 'trc_dta: You should not have seen this print! error?', kt
270   END SUBROUTINE trc_dta
271#endif
272
273   !!======================================================================
274END MODULE trcdta
Note: See TracBrowser for help on using the repository browser.