1 | MODULE 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 | !!---------------------------------------------------------------------- |
---|
47 | CONTAINS |
---|
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) |
---|
102 | 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_dta_ini in reference namelist' ) |
---|
103 | READ ( numnat_cfg, namtrc_dta, IOSTAT = ios, ERR = 902 ) |
---|
104 | 902 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( ln_sco ) THEN !== s- or mixed s-zps-coordinate ==! |
---|
192 | ! |
---|
193 | IF( kt == nit000 .AND. lwp )THEN |
---|
194 | WRITE(numout,*) |
---|
195 | WRITE(numout,*) 'trc_dta: interpolates passive tracer data onto the s- or mixed s-z-coordinate mesh' |
---|
196 | ENDIF |
---|
197 | DO_2D( 1, 1, 1, 1 ) ! vertical interpolation of T & S |
---|
198 | DO jk = 1, jpk ! determines the intepolated T-S profiles at each (i,j) points |
---|
199 | zl = gdept_0(ji,jj,jk) |
---|
200 | IF( zl < gdept_1d(1 ) ) THEN ! above the first level of data |
---|
201 | ztp(jk) = ptrcdta(ji,jj,1) |
---|
202 | ELSEIF( zl > gdept_1d(jpk) ) THEN ! below the last level of data |
---|
203 | ztp(jk) = ptrcdta(ji,jj,jpkm1) |
---|
204 | ELSE ! inbetween : vertical interpolation between jkk & jkk+1 |
---|
205 | DO jkk = 1, jpkm1 ! when gdept_1d(jkk) < zl < gdept_1d(jkk+1) |
---|
206 | IF( (zl-gdept_1d(jkk)) * (zl-gdept_1d(jkk+1)) <= 0._wp ) THEN |
---|
207 | zi = ( zl - gdept_1d(jkk) ) / (gdept_1d(jkk+1)-gdept_1d(jkk)) |
---|
208 | ztp(jk) = ptrcdta(ji,jj,jkk) + ( ptrcdta(ji,jj,jkk+1) - ptrcdta(ji,jj,jkk) ) * zi |
---|
209 | ENDIF |
---|
210 | END DO |
---|
211 | ENDIF |
---|
212 | END DO |
---|
213 | DO jk = 1, jpkm1 |
---|
214 | ptrcdta(ji,jj,jk) = ztp(jk) * tmask(ji,jj,jk) ! mask required for mixed zps-s-coord |
---|
215 | END DO |
---|
216 | ptrcdta(ji,jj,jpk) = 0._wp |
---|
217 | END_2D |
---|
218 | ! |
---|
219 | ELSE !== z- or zps- coordinate ==! |
---|
220 | ! zps-coordinate (partial steps) interpolation at the last ocean level |
---|
221 | IF( ln_zps ) THEN |
---|
222 | DO_2D( 1, 1, 1, 1 ) |
---|
223 | ik = mbkt(ji,jj) |
---|
224 | IF( ik > 1 ) THEN |
---|
225 | zl = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) ) |
---|
226 | ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik-1) |
---|
227 | ENDIF |
---|
228 | ik = mikt(ji,jj) |
---|
229 | IF( ik > 1 ) THEN |
---|
230 | zl = ( gdept_0(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) ) |
---|
231 | ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik+1) |
---|
232 | ENDIF |
---|
233 | END_2D |
---|
234 | ENDIF |
---|
235 | ! |
---|
236 | ENDIF |
---|
237 | ! Scale by multiplicative factor |
---|
238 | ptrcdta(:,:,:) = ptrcdta(:,:,:) * rf_trfac(kjl) |
---|
239 | ! |
---|
240 | ENDIF |
---|
241 | ! |
---|
242 | IF( ln_timing ) CALL timing_stop('trc_dta') |
---|
243 | ! |
---|
244 | END SUBROUTINE trc_dta |
---|
245 | |
---|
246 | #else |
---|
247 | !!---------------------------------------------------------------------- |
---|
248 | !! Dummy module NO 3D passive tracer data |
---|
249 | !!---------------------------------------------------------------------- |
---|
250 | CONTAINS |
---|
251 | SUBROUTINE trc_dta( kt, kjl, ptrcdta) ! Empty routine |
---|
252 | WRITE(*,*) 'trc_dta: You should not have seen this print! error?', kt |
---|
253 | END SUBROUTINE trc_dta |
---|
254 | #endif |
---|
255 | |
---|
256 | !!====================================================================== |
---|
257 | END MODULE trcdta |
---|