1 | MODULE icbutl |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE icbutl *** |
---|
4 | !! Icebergs: various iceberg utility routines |
---|
5 | !!====================================================================== |
---|
6 | !! History : 3.3.1 ! 2010-01 (Martin&Adcroft) Original code |
---|
7 | !! - ! 2011-03 (Madec) Part conversion to NEMO form |
---|
8 | !! - ! Removal of mapping from another grid |
---|
9 | !! - ! 2011-04 (Alderson) Split into separate modules |
---|
10 | !! 4.2 ! 2020-07 (P. Mathiot) simplification of interpolation routine |
---|
11 | !! ! and add Nacho Merino work |
---|
12 | !!---------------------------------------------------------------------- |
---|
13 | |
---|
14 | !!---------------------------------------------------------------------- |
---|
15 | !! icb_utl_interp : |
---|
16 | !! icb_utl_pos : compute bottom left corner indice, weight and mask |
---|
17 | !! icb_utl_bilin_h : interpolation field to icb position |
---|
18 | !! icb_utl_bilin_e : interpolation of scale factor to icb position |
---|
19 | !!---------------------------------------------------------------------- |
---|
20 | USE par_oce ! ocean parameters |
---|
21 | USE oce, ONLY: ts, uu, vv |
---|
22 | USE dom_oce ! ocean domain |
---|
23 | USE in_out_manager ! IO parameters |
---|
24 | USE lbclnk ! lateral boundary condition |
---|
25 | USE lib_mpp ! MPI code and lk_mpp in particular |
---|
26 | USE icb_oce ! define iceberg arrays |
---|
27 | USE sbc_oce ! ocean surface boundary conditions |
---|
28 | #if defined key_si3 |
---|
29 | USE ice, ONLY: u_ice, v_ice, hm_i ! SI3 variables |
---|
30 | USE icevar ! ice_var_sshdyn |
---|
31 | USE sbc_ice, ONLY: snwice_mass, snwice_mass_b |
---|
32 | #endif |
---|
33 | |
---|
34 | IMPLICIT NONE |
---|
35 | PRIVATE |
---|
36 | |
---|
37 | INTERFACE icb_utl_bilin_h |
---|
38 | MODULE PROCEDURE icb_utl_bilin_2d_h, icb_utl_bilin_3d_h |
---|
39 | END INTERFACE |
---|
40 | |
---|
41 | PUBLIC icb_utl_copy ! routine called in icbstp module |
---|
42 | PUBLIC icb_utl_getkb ! routine called in icbdyn and icbthm modules |
---|
43 | PUBLIC test_icb_utl_getkb ! routine called in icbdyn and icbthm modules |
---|
44 | PUBLIC icb_utl_zavg ! routine called in icbdyn and icbthm modules |
---|
45 | PUBLIC icb_utl_interp ! routine called in icbdyn, icbthm modules |
---|
46 | PUBLIC icb_utl_bilin_h ! routine called in icbdyn module |
---|
47 | PUBLIC icb_utl_add ! routine called in icbini.F90, icbclv, icblbc and icbrst modules |
---|
48 | PUBLIC icb_utl_delete ! routine called in icblbc, icbthm modules |
---|
49 | PUBLIC icb_utl_destroy ! routine called in icbstp module |
---|
50 | PUBLIC icb_utl_track ! routine not currently used, retain just in case |
---|
51 | PUBLIC icb_utl_print_berg ! routine called in icbthm module |
---|
52 | PUBLIC icb_utl_print ! routine called in icbini, icbstp module |
---|
53 | PUBLIC icb_utl_count ! routine called in icbdia, icbini, icblbc, icbrst modules |
---|
54 | PUBLIC icb_utl_incr ! routine called in icbini, icbclv modules |
---|
55 | PUBLIC icb_utl_yearday ! routine called in icbclv, icbstp module |
---|
56 | PUBLIC icb_utl_mass ! routine called in icbdia module |
---|
57 | PUBLIC icb_utl_heat ! routine called in icbdia module |
---|
58 | |
---|
59 | !!---------------------------------------------------------------------- |
---|
60 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
61 | !! $Id$ |
---|
62 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
63 | !!---------------------------------------------------------------------- |
---|
64 | CONTAINS |
---|
65 | |
---|
66 | SUBROUTINE icb_utl_copy( Kmm ) |
---|
67 | !!---------------------------------------------------------------------- |
---|
68 | !! *** ROUTINE icb_utl_copy *** |
---|
69 | !! |
---|
70 | !! ** Purpose : iceberg initialization. |
---|
71 | !! |
---|
72 | !! ** Method : - blah blah |
---|
73 | !!---------------------------------------------------------------------- |
---|
74 | REAL(wp), DIMENSION(0:jpi+1,0:jpj+1) :: ztmp |
---|
75 | #if defined key_si3 |
---|
76 | REAL(wp), DIMENSION(jpi,jpj) :: zssh_lead_m ! ocean surface (ssh_m) if ice is not embedded |
---|
77 | ! ! ocean surface in leads if ice is embedded |
---|
78 | #endif |
---|
79 | INTEGER :: jk ! vertical loop index |
---|
80 | INTEGER :: Kmm ! ocean time levelindex |
---|
81 | ! |
---|
82 | ! copy nemo forcing arrays into iceberg versions with extra halo |
---|
83 | ! only necessary for variables not on T points |
---|
84 | ! and ssh which is used to calculate gradients |
---|
85 | ! |
---|
86 | ! surface forcing |
---|
87 | ! |
---|
88 | ssu_e(1:jpi,1:jpj) = ssu_m(:,:) * umask(:,:,1) |
---|
89 | ssv_e(1:jpi,1:jpj) = ssv_m(:,:) * vmask(:,:,1) |
---|
90 | sst_e(1:jpi,1:jpj) = sst_m(:,:) |
---|
91 | sss_e(1:jpi,1:jpj) = sss_m(:,:) |
---|
92 | fr_e (1:jpi,1:jpj) = fr_i (:,:) |
---|
93 | ua_e (1:jpi,1:jpj) = utau (:,:) * umask(:,:,1) ! maybe mask useless because mask applied in sbcblk |
---|
94 | va_e (1:jpi,1:jpj) = vtau (:,:) * vmask(:,:,1) ! maybe mask useless because mask applied in sbcblk |
---|
95 | ff_e(1:jpi,1:jpj) = ff_f (:,:) |
---|
96 | ! |
---|
97 | CALL lbc_lnk_icb( 'icbutl', ssu_e, 'U', -1._wp, 1, 1 ) |
---|
98 | CALL lbc_lnk_icb( 'icbutl', ssv_e, 'V', -1._wp, 1, 1 ) |
---|
99 | CALL lbc_lnk_icb( 'icbutl', ua_e , 'U', -1._wp, 1, 1 ) |
---|
100 | CALL lbc_lnk_icb( 'icbutl', va_e , 'V', -1._wp, 1, 1 ) |
---|
101 | #if defined key_si3 |
---|
102 | hi_e(1:jpi, 1:jpj) = hm_i (:,:) |
---|
103 | ui_e(1:jpi, 1:jpj) = u_ice(:,:) |
---|
104 | vi_e(1:jpi, 1:jpj) = v_ice(:,:) |
---|
105 | ! |
---|
106 | ! compute ssh slope using ssh_lead if embedded |
---|
107 | zssh_lead_m(:,:) = ice_var_sshdyn(ssh_m, snwice_mass, snwice_mass_b) |
---|
108 | ssh_e(1:jpi, 1:jpj) = zssh_lead_m(:,:) * tmask(:,:,1) |
---|
109 | ! |
---|
110 | CALL lbc_lnk_icb( 'icbutl', ui_e , 'U', -1._wp, 1, 1 ) |
---|
111 | CALL lbc_lnk_icb( 'icbutl', vi_e , 'V', -1._wp, 1, 1 ) |
---|
112 | #else |
---|
113 | ssh_e(1:jpi, 1:jpj) = ssh_m(:,:) * tmask(:,:,1) |
---|
114 | #endif |
---|
115 | ! |
---|
116 | ! (PM) could be improve with a 3d lbclnk gathering both variables |
---|
117 | ! should be done once extra haloe generalised |
---|
118 | IF ( ln_M2016 ) THEN |
---|
119 | DO jk = 1,jpk |
---|
120 | ! uoce |
---|
121 | ztmp(1:jpi,1:jpj) = uu(:,:,jk,Kmm) |
---|
122 | CALL lbc_lnk_icb( 'icbutl', ztmp, 'U', -1._wp, 1, 1 ) |
---|
123 | uoce_e(:,:,jk) = ztmp(:,:) |
---|
124 | ! |
---|
125 | ! voce |
---|
126 | ztmp(1:jpi,1:jpj) = vv(:,:,jk,Kmm) |
---|
127 | CALL lbc_lnk_icb( 'icbutl', ztmp, 'V', -1._wp, 1, 1 ) |
---|
128 | voce_e(:,:,jk) = ztmp(:,:) |
---|
129 | END DO |
---|
130 | toce_e(1:jpi,1:jpj,1:jpk) = ts(:,:,:,1,Kmm) |
---|
131 | e3t_e (1:jpi,1:jpj,1:jpk) = e3t(:,:,:,Kmm) |
---|
132 | END IF |
---|
133 | ! |
---|
134 | END SUBROUTINE icb_utl_copy |
---|
135 | |
---|
136 | |
---|
137 | SUBROUTINE icb_utl_interp( pi, pj, pe1 , pssu, pui, pua, pssh_i, & |
---|
138 | & pe2 , pssv, pvi, pva, pssh_j, & |
---|
139 | & psst, psss, pcn, phi, pff , & |
---|
140 | & plon, plat, ptoce, puoce, pvoce, pe3t ) |
---|
141 | !!---------------------------------------------------------------------- |
---|
142 | !! *** ROUTINE icb_utl_interp *** |
---|
143 | !! |
---|
144 | !! ** Purpose : interpolation |
---|
145 | !! |
---|
146 | !! ** Method : - interpolate from various ocean arrays onto iceberg position |
---|
147 | !! |
---|
148 | !! !!gm CAUTION here I do not care of the slip/no-slip conditions |
---|
149 | !! this can be done later (not that easy to do...) |
---|
150 | !! right now, U is 0 in land so that the coastal value of velocity parallel to the coast |
---|
151 | !! is half the off shore value, wile the normal-to-the-coast value is zero. |
---|
152 | !! This is OK as a starting point. |
---|
153 | !! !!pm HARD CODED: - rho_air now computed in sbcblk (what are the effect ?) |
---|
154 | !! - drag coefficient (should it be namelist parameter ?) |
---|
155 | !! |
---|
156 | !!---------------------------------------------------------------------- |
---|
157 | REAL(wp), INTENT(in ) :: pi , pj ! position in (i,j) referential |
---|
158 | REAL(wp), INTENT( out), OPTIONAL :: pe1, pe2 ! i- and j scale factors |
---|
159 | REAL(wp), INTENT( out), OPTIONAL :: pssu, pssv, pui, pvi, pua, pva ! ocean, ice and wind speeds |
---|
160 | REAL(wp), INTENT( out), OPTIONAL :: pssh_i, pssh_j ! ssh i- & j-gradients |
---|
161 | REAL(wp), INTENT( out), OPTIONAL :: psst, psss, pcn, phi, pff ! SST, SSS, ice concentration, ice thickness, Coriolis |
---|
162 | REAL(wp), INTENT( out), OPTIONAL :: plat, plon ! position |
---|
163 | REAL(wp), DIMENSION(jpk), INTENT( out), OPTIONAL :: ptoce, puoce, pvoce, pe3t ! 3D variables |
---|
164 | ! |
---|
165 | REAL(wp), DIMENSION(4) :: zwT , zwU , zwV , zwF ! interpolation weight |
---|
166 | REAL(wp), DIMENSION(4) :: zmskF, zmskU, zmskV, zmskT ! mask |
---|
167 | REAL(wp), DIMENSION(4) :: zwTp, zmskTp, zwTm, zmskTm |
---|
168 | REAL(wp), DIMENSION(4,jpk) :: zw1d |
---|
169 | INTEGER :: iiT, iiU, iiV, iiF, ijT, ijU, ijV, ijF ! bottom left corner |
---|
170 | INTEGER :: iiTp, iiTm, ijTp, ijTm |
---|
171 | REAL(wp) :: zcd, zmod ! local scalars |
---|
172 | !!---------------------------------------------------------------------- |
---|
173 | ! |
---|
174 | ! get position, weight and mask |
---|
175 | CALL icb_utl_pos( pi, pj, 'T', iiT, ijT, zwT, zmskT ) |
---|
176 | CALL icb_utl_pos( pi, pj, 'U', iiU, ijU, zwU, zmskU ) |
---|
177 | CALL icb_utl_pos( pi, pj, 'V', iiV, ijV, zwV, zmskV ) |
---|
178 | CALL icb_utl_pos( pi, pj, 'F', iiF, ijF, zwF, zmskF ) |
---|
179 | ! |
---|
180 | ! metrics and coordinates |
---|
181 | IF ( PRESENT(pe1 ) ) pe1 = icb_utl_bilin_e( e1t, e1u, e1v, e1f, pi, pj ) ! scale factors |
---|
182 | IF ( PRESENT(pe2 ) ) pe2 = icb_utl_bilin_e( e2t, e2u, e2v, e2f, pi, pj ) |
---|
183 | IF ( PRESENT(plon) ) plon= icb_utl_bilin_h( rlon_e, iiT, ijT, zwT, .true. ) |
---|
184 | IF ( PRESENT(plat) ) plat= icb_utl_bilin_h( rlat_e, iiT, ijT, zwT, .false. ) |
---|
185 | ! |
---|
186 | IF ( PRESENT(pssu) ) pssu = icb_utl_bilin_h( ssu_e, iiU, ijU, zwU , .false. ) ! ocean velocities |
---|
187 | IF ( PRESENT(pssv) ) pssv = icb_utl_bilin_h( ssv_e, iiV, ijV, zwV , .false. ) ! |
---|
188 | IF ( PRESENT(psst) ) psst = icb_utl_bilin_h( sst_e, iiT, ijT, zwT * zmskT, .false. ) ! sst |
---|
189 | IF ( PRESENT(psss) ) psss = icb_utl_bilin_h( sss_e, iiT, ijT, zwT * zmskT, .false. ) ! sss |
---|
190 | IF ( PRESENT(pcn ) ) pcn = icb_utl_bilin_h( fr_e , iiT, ijT, zwT * zmskT, .false. ) ! ice concentration |
---|
191 | IF ( PRESENT(pff ) ) pff = icb_utl_bilin_h( ff_e , iiF, ijF, zwF , .false. ) ! Coriolis parameter |
---|
192 | ! |
---|
193 | IF ( PRESENT(pua) .AND. PRESENT(pva) ) THEN |
---|
194 | pua = icb_utl_bilin_h( ua_e, iiU, ijU, zwU * zmskU, .false. ) ! 10m wind |
---|
195 | pva = icb_utl_bilin_h( va_e, iiV, ijV, zwV * zmskV, .false. ) ! here (ua,va) are stress => rough conversion from stress to speed |
---|
196 | zcd = 1.22_wp * 1.5e-3_wp ! air density * drag coefficient |
---|
197 | zmod = 1._wp / MAX( 1.e-20, SQRT( zcd * SQRT( pua*pua + pva*pva) ) ) |
---|
198 | pua = pua * zmod ! note: stress module=0 necessarly implies ua=va=0 |
---|
199 | pva = pva * zmod |
---|
200 | END IF |
---|
201 | ! |
---|
202 | #if defined key_si3 |
---|
203 | IF ( PRESENT(pui) ) pui = icb_utl_bilin_h( ui_e , iiU, ijU, zwU , .false. ) ! sea-ice velocities |
---|
204 | IF ( PRESENT(pvi) ) pvi = icb_utl_bilin_h( vi_e , iiV, ijV, zwV , .false. ) |
---|
205 | IF ( PRESENT(phi) ) phi = icb_utl_bilin_h( hi_e , iiT, ijT, zwT * zmskT, .false. ) ! ice thickness |
---|
206 | #else |
---|
207 | IF ( PRESENT(pui) ) pui = 0._wp |
---|
208 | IF ( PRESENT(pvi) ) pvi = 0._wp |
---|
209 | IF ( PRESENT(phi) ) phi = 0._wp |
---|
210 | #endif |
---|
211 | ! |
---|
212 | ! Estimate SSH gradient in i- and j-direction (centred evaluation) |
---|
213 | IF ( PRESENT(pssh_i) .AND. PRESENT(pssh_j) ) THEN |
---|
214 | CALL icb_utl_pos( pi+0.1, pj , 'T', iiTp, ijTp, zwTp, zmskTp ) |
---|
215 | CALL icb_utl_pos( pi-0.1, pj , 'T', iiTm, ijTm, zwTm, zmskTm ) |
---|
216 | ! |
---|
217 | IF ( .NOT. PRESENT(pe1) ) pe1 = icb_utl_bilin_e( e1t, e1u, e1v, e1f, pi, pj ) |
---|
218 | pssh_i = ( icb_utl_bilin_h( ssh_e, iiTp, ijTp, zwTp*zmskTp, .false. ) - & |
---|
219 | & icb_utl_bilin_h( ssh_e, iiTm, ijTm, zwTm*zmskTm, .false. ) ) / ( 0.2_wp * pe1 ) |
---|
220 | ! |
---|
221 | CALL icb_utl_pos( pi , pj+0.1, 'T', iiTp, ijTp, zwTp, zmskTp ) |
---|
222 | CALL icb_utl_pos( pi , pj-0.1, 'T', iiTm, ijTm, zwTm, zmskTm ) |
---|
223 | ! |
---|
224 | IF ( .NOT. PRESENT(pe2) ) pe2 = icb_utl_bilin_e( e2t, e2u, e2v, e2f, pi, pj ) |
---|
225 | pssh_j = ( icb_utl_bilin_h( ssh_e, iiTp, ijTp, zwTp*zmskTp, .false. ) - & |
---|
226 | & icb_utl_bilin_h( ssh_e, iiTm, ijTm, zwTm*zmskTm, .false. ) ) / ( 0.2_wp * pe2 ) |
---|
227 | END IF |
---|
228 | ! |
---|
229 | ! 3d interpolation |
---|
230 | IF ( PRESENT(puoce) .AND. PRESENT(pvoce) ) THEN |
---|
231 | ! no need to mask as 0 is a valid data for land |
---|
232 | zw1d(1,:) = zwU(1) ; zw1d(2,:) = zwU(2) ; zw1d(3,:) = zwU(3) ; zw1d(4,:) = zwU(4) ; |
---|
233 | puoce(:) = icb_utl_bilin_h( uoce_e , iiU, ijU, zw1d ) |
---|
234 | |
---|
235 | zw1d(1,:) = zwV(1) ; zw1d(2,:) = zwV(2) ; zw1d(3,:) = zwV(3) ; zw1d(4,:) = zwV(4) ; |
---|
236 | pvoce(:) = icb_utl_bilin_h( voce_e , iiV, ijV, zw1d ) |
---|
237 | END IF |
---|
238 | |
---|
239 | IF ( PRESENT(ptoce) ) THEN |
---|
240 | ! for temperature we need to mask the weight properly |
---|
241 | ! no need of extra halo as it is a T point variable |
---|
242 | zw1d(1,:) = tmask(iiT ,ijT ,:) * zwT(1) * zmskT(1) |
---|
243 | zw1d(2,:) = tmask(iiT+1,ijT ,:) * zwT(2) * zmskT(2) |
---|
244 | zw1d(3,:) = tmask(iiT ,ijT+1,:) * zwT(3) * zmskT(3) |
---|
245 | zw1d(4,:) = tmask(iiT+1,ijT+1,:) * zwT(4) * zmskT(4) |
---|
246 | ptoce(:) = icb_utl_bilin_h( toce_e , iiT, ijT, zw1d ) |
---|
247 | END IF |
---|
248 | ! |
---|
249 | IF ( PRESENT(pe3t) ) pe3t(:) = e3t_e(iiT,ijT,:) ! as in Nacho tarball need to be fix once we are able to reproduce Nacho results |
---|
250 | ! |
---|
251 | END SUBROUTINE icb_utl_interp |
---|
252 | |
---|
253 | SUBROUTINE icb_utl_pos( pi, pj, cd_type, kii, kij, pw, pmsk ) |
---|
254 | !!---------------------------------------------------------------------- |
---|
255 | !! *** FUNCTION icb_utl_bilin *** |
---|
256 | !! |
---|
257 | !! ** Purpose : bilinear interpolation at berg location depending on the grid-point type |
---|
258 | !! this version deals with extra halo points |
---|
259 | !! |
---|
260 | !! !!gm CAUTION an optional argument should be added to handle |
---|
261 | !! the slip/no-slip conditions ==>>> to be done later |
---|
262 | !! |
---|
263 | !!---------------------------------------------------------------------- |
---|
264 | REAL(wp) , INTENT(IN) :: pi, pj ! targeted coordinates in (i,j) referential |
---|
265 | CHARACTER(len=1) , INTENT(IN) :: cd_type ! point type |
---|
266 | REAL(wp), DIMENSION(4), INTENT(OUT) :: pw, pmsk ! weight and mask |
---|
267 | INTEGER , INTENT(OUT) :: kii, kij ! bottom left corner position in local domain |
---|
268 | ! |
---|
269 | REAL(wp) :: zwi, zwj ! distance to bottom left corner |
---|
270 | INTEGER :: ierr |
---|
271 | ! |
---|
272 | !!---------------------------------------------------------------------- |
---|
273 | ! |
---|
274 | SELECT CASE ( cd_type ) |
---|
275 | CASE ( 'T' ) |
---|
276 | ! note that here there is no +0.5 added |
---|
277 | ! since we're looking for four T points containing quadrant we're in of |
---|
278 | ! current T cell |
---|
279 | kii = MAX(0, INT( pi )) |
---|
280 | kij = MAX(0, INT( pj )) ! T-point |
---|
281 | zwi = pi - REAL(kii,wp) |
---|
282 | zwj = pj - REAL(kij,wp) |
---|
283 | CASE ( 'U' ) |
---|
284 | kii = MAX(0, INT( pi-0.5_wp )) |
---|
285 | kij = MAX(0, INT( pj )) ! U-point |
---|
286 | zwi = pi - 0.5_wp - REAL(kii,wp) |
---|
287 | zwj = pj - REAL(kij,wp) |
---|
288 | CASE ( 'V' ) |
---|
289 | kii = MAX(0, INT( pi )) |
---|
290 | kij = MAX(0, INT( pj-0.5_wp )) ! V-point |
---|
291 | zwi = pi - REAL(kii,wp) |
---|
292 | zwj = pj - 0.5_wp - REAL(kij,wp) |
---|
293 | CASE ( 'F' ) |
---|
294 | kii = MAX(0, INT( pi-0.5_wp )) |
---|
295 | kij = MAX(0, INT( pj-0.5_wp )) ! F-point |
---|
296 | zwi = pi - 0.5_wp - REAL(kii,wp) |
---|
297 | zwj = pj - 0.5_wp - REAL(kij,wp) |
---|
298 | END SELECT |
---|
299 | ! |
---|
300 | ! compute weight |
---|
301 | pw(1) = (1._wp-zwi) * (1._wp-zwj) |
---|
302 | pw(2) = zwi * (1._wp-zwj) |
---|
303 | pw(3) = (1._wp-zwi) * zwj |
---|
304 | pw(4) = zwi * zwj |
---|
305 | ! |
---|
306 | ! find position in this processor. Prevent near edge problems (see #1389) |
---|
307 | ! |
---|
308 | IF (TRIM(cd_type) == 'T' ) THEN |
---|
309 | ierr = 0 |
---|
310 | IF ( kii < mig( 1 ) ) THEN ; ierr = ierr + 1 |
---|
311 | ELSEIF( kii >= mig(jpi) ) THEN ; ierr = ierr + 1 |
---|
312 | ENDIF |
---|
313 | ! |
---|
314 | IF ( kij < mjg( 1 ) ) THEN ; ierr = ierr + 1 |
---|
315 | ELSEIF( kij >= mjg(jpj) ) THEN ; ierr = ierr + 1 |
---|
316 | ENDIF |
---|
317 | ! |
---|
318 | IF ( ierr > 0 ) THEN |
---|
319 | WRITE(numout,*) 'bottom left corner T point out of bound' |
---|
320 | WRITE(numout,*) pi, kii, mig( 1 ), mig(jpi) |
---|
321 | WRITE(numout,*) pj, kij, mjg( 1 ), mjg(jpj) |
---|
322 | WRITE(numout,*) pmsk |
---|
323 | CALL ctl_stop('STOP','icb_utl_bilin_h: an icebergs coordinates is out of valid range (out of bound error)') |
---|
324 | END IF |
---|
325 | END IF |
---|
326 | ! |
---|
327 | ! find position in this processor. Prevent near edge problems (see #1389) |
---|
328 | ! (PM) will be useless if extra halo is used in NEMO |
---|
329 | ! |
---|
330 | IF ( kii <= mig(1)-1 ) THEN ; kii = 0 |
---|
331 | ELSEIF( kii > mig(jpi) ) THEN ; kii = jpi |
---|
332 | ELSE ; kii = mi1(kii) |
---|
333 | ENDIF |
---|
334 | IF ( kij <= mjg(1)-1 ) THEN ; kij = 0 |
---|
335 | ELSEIF( kij > mjg(jpj) ) THEN ; kij = jpj |
---|
336 | ELSE ; kij = mj1(kij) |
---|
337 | ENDIF |
---|
338 | ! |
---|
339 | ! define mask array |
---|
340 | ! land value is not used in the interpolation |
---|
341 | SELECT CASE ( cd_type ) |
---|
342 | CASE ( 'T' ) |
---|
343 | pmsk = (/tmask_e(kii,kij), tmask_e(kii+1,kij), tmask_e(kii,kij+1), tmask_e(kii+1,kij+1)/) |
---|
344 | CASE ( 'U' ) |
---|
345 | pmsk = (/umask_e(kii,kij), umask_e(kii+1,kij), umask_e(kii,kij+1), umask_e(kii+1,kij+1)/) |
---|
346 | CASE ( 'V' ) |
---|
347 | pmsk = (/vmask_e(kii,kij), vmask_e(kii+1,kij), vmask_e(kii,kij+1), vmask_e(kii+1,kij+1)/) |
---|
348 | CASE ( 'F' ) |
---|
349 | ! F case only used for coriolis, ff_f is not mask so zmask = 1 |
---|
350 | pmsk = 1. |
---|
351 | END SELECT |
---|
352 | END SUBROUTINE icb_utl_pos |
---|
353 | |
---|
354 | REAL(wp) FUNCTION icb_utl_bilin_2d_h( pfld, pii, pij, pw, pllon ) |
---|
355 | !!---------------------------------------------------------------------- |
---|
356 | !! *** FUNCTION icb_utl_bilin *** |
---|
357 | !! |
---|
358 | !! ** Purpose : bilinear interpolation at berg location depending on the grid-point type |
---|
359 | !! this version deals with extra halo points |
---|
360 | !! |
---|
361 | !! !!gm CAUTION an optional argument should be added to handle |
---|
362 | !! the slip/no-slip conditions ==>>> to be done later |
---|
363 | !! |
---|
364 | !!---------------------------------------------------------------------- |
---|
365 | REAL(wp), DIMENSION(0:jpi+1,0:jpj+1), INTENT(in) :: pfld ! field to be interpolated |
---|
366 | REAL(wp), DIMENSION(4) , INTENT(in) :: pw ! weight |
---|
367 | LOGICAL , INTENT(in) :: pllon ! input data is a longitude |
---|
368 | INTEGER , INTENT(in) :: pii, pij ! bottom left corner |
---|
369 | ! |
---|
370 | REAL(wp), DIMENSION(4) :: zdat ! input data |
---|
371 | !!---------------------------------------------------------------------- |
---|
372 | ! |
---|
373 | ! data |
---|
374 | zdat(1) = pfld(pii ,pij ) |
---|
375 | zdat(2) = pfld(pii+1,pij ) |
---|
376 | zdat(3) = pfld(pii ,pij+1) |
---|
377 | zdat(4) = pfld(pii+1,pij+1) |
---|
378 | ! |
---|
379 | IF( pllon .AND. MAXVAL(zdat) - MINVAL(zdat) > 90._wp ) THEN |
---|
380 | WHERE( zdat < 0._wp ) zdat = zdat + 360._wp |
---|
381 | ENDIF |
---|
382 | ! |
---|
383 | ! compute interpolated value |
---|
384 | icb_utl_bilin_2d_h = ( zdat(1)*pw(1) + zdat(2)*pw(2) + zdat(3)*pw(3) + zdat(4)*pw(4) ) / MAX(1.e-20, pw(1)+pw(2)+pw(3)+pw(4)) |
---|
385 | ! |
---|
386 | IF( pllon .AND. icb_utl_bilin_2d_h > 180._wp ) icb_utl_bilin_2d_h = icb_utl_bilin_2d_h - 360._wp |
---|
387 | ! |
---|
388 | END FUNCTION icb_utl_bilin_2d_h |
---|
389 | |
---|
390 | FUNCTION icb_utl_bilin_3d_h( pfld, pii, pij, pw ) |
---|
391 | !!---------------------------------------------------------------------- |
---|
392 | !! *** FUNCTION icb_utl_bilin *** |
---|
393 | !! |
---|
394 | !! ** Purpose : bilinear interpolation at berg location depending on the grid-point type |
---|
395 | !! this version deals with extra halo points |
---|
396 | !! |
---|
397 | !! !!gm CAUTION an optional argument should be added to handle |
---|
398 | !! the slip/no-slip conditions ==>>> to be done later |
---|
399 | !! |
---|
400 | !!---------------------------------------------------------------------- |
---|
401 | REAL(wp), DIMENSION(0:jpi+1,0:jpj+1, jpk), INTENT(in) :: pfld ! field to be interpolated |
---|
402 | REAL(wp), DIMENSION(4,jpk) , INTENT(in) :: pw ! weight |
---|
403 | INTEGER , INTENT(in) :: pii, pij ! bottom left corner |
---|
404 | REAL(wp), DIMENSION(jpk) :: icb_utl_bilin_3d_h |
---|
405 | ! |
---|
406 | REAL(wp), DIMENSION(4,jpk) :: zdat ! input data |
---|
407 | INTEGER :: jk |
---|
408 | !!---------------------------------------------------------------------- |
---|
409 | ! |
---|
410 | ! data |
---|
411 | zdat(1,:) = pfld(pii ,pij ,:) |
---|
412 | zdat(2,:) = pfld(pii+1,pij ,:) |
---|
413 | zdat(3,:) = pfld(pii ,pij+1,:) |
---|
414 | zdat(4,:) = pfld(pii+1,pij+1,:) |
---|
415 | ! |
---|
416 | ! compute interpolated value |
---|
417 | DO jk=1,jpk |
---|
418 | icb_utl_bilin_3d_h(jk) = ( zdat(1,jk)*pw(1,jk) + zdat(2,jk)*pw(2,jk) + zdat(3,jk)*pw(3,jk) + zdat(4,jk)*pw(4,jk) ) & |
---|
419 | & / MAX(1.e-20, pw(1,jk)+pw(2,jk)+pw(3,jk)+pw(4,jk)) |
---|
420 | END DO |
---|
421 | ! |
---|
422 | END FUNCTION icb_utl_bilin_3d_h |
---|
423 | |
---|
424 | REAL(wp) FUNCTION icb_utl_bilin_e( pet, peu, pev, pef, pi, pj ) |
---|
425 | !!---------------------------------------------------------------------- |
---|
426 | !! *** FUNCTION dom_init *** |
---|
427 | !! |
---|
428 | !! ** Purpose : bilinear interpolation at berg location of horizontal scale factor |
---|
429 | !! ** Method : interpolation done using the 4 nearest grid points among |
---|
430 | !! t-, u-, v-, and f-points. |
---|
431 | !!---------------------------------------------------------------------- |
---|
432 | REAL(wp), DIMENSION(:,:), INTENT(in) :: pet, peu, pev, pef ! horizontal scale factor to be interpolated at t-,u-,v- & f-pts |
---|
433 | REAL(wp) , INTENT(IN) :: pi , pj ! iceberg position |
---|
434 | ! |
---|
435 | ! weights corresponding to corner points of a T cell quadrant |
---|
436 | REAL(wp) :: zi, zj ! local real |
---|
437 | INTEGER :: ii, ij ! bottom left corner coordinate in local domain |
---|
438 | ! |
---|
439 | ! values at corner points of a T cell quadrant |
---|
440 | ! 00 = bottom left, 10 = bottom right, 01 = top left, 11 = top right |
---|
441 | REAL(wp) :: ze00, ze10, ze01, ze11 |
---|
442 | !!---------------------------------------------------------------------- |
---|
443 | ! |
---|
444 | ! cannot used iiT because need ii/ij reltaive to global indices not local one |
---|
445 | ii = MAX(1, INT( pi )) ; ij = MAX(1, INT( pj )) ! left bottom T-point (i,j) indices |
---|
446 | ! |
---|
447 | ! fractional box spacing |
---|
448 | ! 0 <= zi < 0.5, 0 <= zj < 0.5 --> NW quadrant of current T cell |
---|
449 | ! 0.5 <= zi < 1 , 0 <= zj < 0.5 --> NE quadrant |
---|
450 | ! 0 <= zi < 0.5, 0.5 <= zj < 1 --> SE quadrant |
---|
451 | ! 0.5 <= zi < 1 , 0.5 <= zj < 1 --> SW quadrant |
---|
452 | |
---|
453 | zi = pi - REAL(ii,wp) !!gm use here mig, mjg arrays |
---|
454 | zj = pj - REAL(ij,wp) |
---|
455 | |
---|
456 | ! conversion to local domain (no need to do a sanity check already done in icbpos) |
---|
457 | ii = mi1(ii) |
---|
458 | ij = mj1(ij) |
---|
459 | ! |
---|
460 | IF( 0.0_wp <= zi .AND. zi < 0.5_wp ) THEN |
---|
461 | IF( 0.0_wp <= zj .AND. zj < 0.5_wp ) THEN ! NE quadrant |
---|
462 | ! ! i=I i=I+1/2 |
---|
463 | ze01 = pev(ii ,ij ) ; ze11 = pef(ii ,ij ) ! j=J+1/2 V ------- F |
---|
464 | ze00 = pet(ii ,ij ) ; ze10 = peu(ii ,ij ) ! j=J T ------- U |
---|
465 | zi = 2._wp * zi |
---|
466 | zj = 2._wp * zj |
---|
467 | ELSE ! SE quadrant |
---|
468 | ! ! i=I i=I+1/2 |
---|
469 | ze01 = pet(ii ,ij+1) ; ze11 = peu(ii ,ij+1) ! j=J+1 T ------- U |
---|
470 | ze00 = pev(ii ,ij ) ; ze10 = pef(ii ,ij ) ! j=J+1/2 V ------- F |
---|
471 | zi = 2._wp * zi |
---|
472 | zj = 2._wp * (zj-0.5_wp) |
---|
473 | ENDIF |
---|
474 | ELSE |
---|
475 | IF( 0.0_wp <= zj .AND. zj < 0.5_wp ) THEN ! NW quadrant |
---|
476 | ! ! i=I i=I+1/2 |
---|
477 | ze01 = pef(ii ,ij ) ; ze11 = pev(ii+1,ij) ! j=J+1/2 F ------- V |
---|
478 | ze00 = peu(ii ,ij ) ; ze10 = pet(ii+1,ij) ! j=J U ------- T |
---|
479 | zi = 2._wp * (zi-0.5_wp) |
---|
480 | zj = 2._wp * zj |
---|
481 | ELSE ! SW quadrant |
---|
482 | ! ! i=I+1/2 i=I+1 |
---|
483 | ze01 = peu(ii ,ij+1) ; ze11 = pet(ii+1,ij+1) ! j=J+1 U ------- T |
---|
484 | ze00 = pef(ii ,ij ) ; ze10 = pev(ii+1,ij ) ! j=J+1/2 F ------- V |
---|
485 | zi = 2._wp * (zi-0.5_wp) |
---|
486 | zj = 2._wp * (zj-0.5_wp) |
---|
487 | ENDIF |
---|
488 | ENDIF |
---|
489 | ! |
---|
490 | icb_utl_bilin_e = ( ze01 * (1._wp-zi) + ze11 * zi ) * zj & |
---|
491 | & + ( ze00 * (1._wp-zi) + ze10 * zi ) * (1._wp-zj) |
---|
492 | ! |
---|
493 | END FUNCTION icb_utl_bilin_e |
---|
494 | |
---|
495 | SUBROUTINE icb_utl_getkb( kb, pe3, pD ) |
---|
496 | !!---------------------------------------------------------------------- |
---|
497 | !! *** ROUTINE icb_utl_getkb *** |
---|
498 | !! |
---|
499 | !! ** Purpose : compute the latest level affected by icb |
---|
500 | !! |
---|
501 | !!---------------------------------------------------------------------- |
---|
502 | INTEGER, INTENT(out):: kb |
---|
503 | REAL(wp), DIMENSION(:), INTENT(in) :: pe3 |
---|
504 | REAL(wp), INTENT(in) :: pD |
---|
505 | !! |
---|
506 | INTEGER :: jk |
---|
507 | REAL(wp) :: zdepw |
---|
508 | !!---------------------------------------------------------------------- |
---|
509 | !! |
---|
510 | zdepw = pe3(1) ; kb = 2 |
---|
511 | DO WHILE ( zdepw < pD) |
---|
512 | zdepw = zdepw + pe3(kb) |
---|
513 | kb = kb + 1 |
---|
514 | END DO |
---|
515 | kb = MIN(kb - 1,jpk) |
---|
516 | END SUBROUTINE |
---|
517 | |
---|
518 | SUBROUTINE icb_utl_zavg(pzavg, pdat, pe3, pD, kb ) |
---|
519 | !!---------------------------------------------------------------------- |
---|
520 | !! *** ROUTINE icb_utl_getkb *** |
---|
521 | !! |
---|
522 | !! ** Purpose : compute the vertical average of ocean properties affected by icb |
---|
523 | !! |
---|
524 | !!---------------------------------------------------------------------- |
---|
525 | INTEGER, INTENT(in ) :: kb ! deepest level affected by icb |
---|
526 | REAL(wp), DIMENSION(:), INTENT(in ) :: pe3, pdat ! vertical profile |
---|
527 | REAL(wp), INTENT(in ) :: pD ! draft |
---|
528 | REAL(wp), INTENT(out) :: pzavg ! z average |
---|
529 | !!---------------------------------------------------------------------- |
---|
530 | INTEGER :: jk |
---|
531 | REAL(wp) :: zdep |
---|
532 | !!---------------------------------------------------------------------- |
---|
533 | pzavg = 0.0 ; zdep = 0.0 |
---|
534 | DO jk = 1,kb-1 |
---|
535 | pzavg = pzavg + pe3(jk)*pdat(jk) |
---|
536 | zdep = zdep + pe3(jk) |
---|
537 | END DO |
---|
538 | ! if kb is limited by mbkt => bottom value is used between bathy and icb tail |
---|
539 | ! if kb not limited by mbkt => ocean value over mask is used (ie 0.0 for u, v) |
---|
540 | pzavg = ( pzavg + (pD - zdep)*pdat(kb)) / pD |
---|
541 | END SUBROUTINE |
---|
542 | |
---|
543 | SUBROUTINE icb_utl_add( bergvals, ptvals ) |
---|
544 | !!---------------------------------------------------------------------- |
---|
545 | !! *** ROUTINE icb_utl_add *** |
---|
546 | !! |
---|
547 | !! ** Purpose : add a new berg to the iceberg list |
---|
548 | !! |
---|
549 | !!---------------------------------------------------------------------- |
---|
550 | TYPE(iceberg), INTENT(in) :: bergvals |
---|
551 | TYPE(point) , INTENT(in) :: ptvals |
---|
552 | ! |
---|
553 | TYPE(iceberg), POINTER :: new => NULL() |
---|
554 | !!---------------------------------------------------------------------- |
---|
555 | ! |
---|
556 | new => NULL() |
---|
557 | CALL icb_utl_create( new, bergvals, ptvals ) |
---|
558 | CALL icb_utl_insert( new ) |
---|
559 | new => NULL() ! Clear new |
---|
560 | ! |
---|
561 | END SUBROUTINE icb_utl_add |
---|
562 | |
---|
563 | |
---|
564 | SUBROUTINE icb_utl_create( berg, bergvals, ptvals ) |
---|
565 | !!---------------------------------------------------------------------- |
---|
566 | !! *** ROUTINE icb_utl_create *** |
---|
567 | !! |
---|
568 | !! ** Purpose : add a new berg to the iceberg list |
---|
569 | !! |
---|
570 | !!---------------------------------------------------------------------- |
---|
571 | TYPE(iceberg), INTENT(in) :: bergvals |
---|
572 | TYPE(point) , INTENT(in) :: ptvals |
---|
573 | TYPE(iceberg), POINTER :: berg |
---|
574 | ! |
---|
575 | TYPE(point) , POINTER :: pt |
---|
576 | INTEGER :: istat |
---|
577 | !!---------------------------------------------------------------------- |
---|
578 | ! |
---|
579 | IF( ASSOCIATED(berg) ) CALL ctl_stop( 'icebergs, icb_utl_create: berg already associated' ) |
---|
580 | ALLOCATE(berg, STAT=istat) |
---|
581 | IF( istat /= 0 ) CALL ctl_stop( 'failed to allocate iceberg' ) |
---|
582 | berg%number(:) = bergvals%number(:) |
---|
583 | berg%mass_scaling = bergvals%mass_scaling |
---|
584 | berg%prev => NULL() |
---|
585 | berg%next => NULL() |
---|
586 | ! |
---|
587 | ALLOCATE(pt, STAT=istat) |
---|
588 | IF( istat /= 0 ) CALL ctl_stop( 'failed to allocate first iceberg point' ) |
---|
589 | pt = ptvals |
---|
590 | berg%current_point => pt |
---|
591 | ! |
---|
592 | END SUBROUTINE icb_utl_create |
---|
593 | |
---|
594 | |
---|
595 | SUBROUTINE icb_utl_insert( newberg ) |
---|
596 | !!---------------------------------------------------------------------- |
---|
597 | !! *** ROUTINE icb_utl_insert *** |
---|
598 | !! |
---|
599 | !! ** Purpose : add a new berg to the iceberg list |
---|
600 | !! |
---|
601 | !!---------------------------------------------------------------------- |
---|
602 | TYPE(iceberg), POINTER :: newberg |
---|
603 | ! |
---|
604 | TYPE(iceberg), POINTER :: this, prev, last |
---|
605 | !!---------------------------------------------------------------------- |
---|
606 | ! |
---|
607 | IF( ASSOCIATED( first_berg ) ) THEN |
---|
608 | last => first_berg |
---|
609 | DO WHILE (ASSOCIATED(last%next)) |
---|
610 | last => last%next |
---|
611 | ENDDO |
---|
612 | newberg%prev => last |
---|
613 | last%next => newberg |
---|
614 | last => newberg |
---|
615 | ELSE ! list is empty so create it |
---|
616 | first_berg => newberg |
---|
617 | ENDIF |
---|
618 | ! |
---|
619 | END SUBROUTINE icb_utl_insert |
---|
620 | |
---|
621 | |
---|
622 | REAL(wp) FUNCTION icb_utl_yearday(kmon, kday, khr, kmin, ksec) |
---|
623 | !!---------------------------------------------------------------------- |
---|
624 | !! *** FUNCTION icb_utl_yearday *** |
---|
625 | !! |
---|
626 | !! ** Purpose : |
---|
627 | !! |
---|
628 | ! sga - improved but still only applies to 365 day year, need to do this properly |
---|
629 | ! |
---|
630 | !!gm all these info are already known in daymod, no??? |
---|
631 | !! |
---|
632 | !!---------------------------------------------------------------------- |
---|
633 | INTEGER, INTENT(in) :: kmon, kday, khr, kmin, ksec |
---|
634 | ! |
---|
635 | INTEGER, DIMENSION(12) :: imonths = (/ 0,31,28,31,30,31,30,31,31,30,31,30 /) |
---|
636 | !!---------------------------------------------------------------------- |
---|
637 | ! |
---|
638 | icb_utl_yearday = REAL( SUM( imonths(1:kmon) ), wp ) |
---|
639 | icb_utl_yearday = icb_utl_yearday + REAL(kday-1,wp) + (REAL(khr,wp) + (REAL(kmin,wp) + REAL(ksec,wp)/60.)/60.)/24. |
---|
640 | ! |
---|
641 | END FUNCTION icb_utl_yearday |
---|
642 | |
---|
643 | !!------------------------------------------------------------------------- |
---|
644 | |
---|
645 | SUBROUTINE icb_utl_delete( first, berg ) |
---|
646 | !!---------------------------------------------------------------------- |
---|
647 | !! *** ROUTINE icb_utl_delete *** |
---|
648 | !! |
---|
649 | !! ** Purpose : |
---|
650 | !! |
---|
651 | !!---------------------------------------------------------------------- |
---|
652 | TYPE(iceberg), POINTER :: first, berg |
---|
653 | !!---------------------------------------------------------------------- |
---|
654 | ! Connect neighbors to each other |
---|
655 | IF ( ASSOCIATED(berg%prev) ) THEN |
---|
656 | berg%prev%next => berg%next |
---|
657 | ELSE |
---|
658 | first => berg%next |
---|
659 | ENDIF |
---|
660 | IF (ASSOCIATED(berg%next)) berg%next%prev => berg%prev |
---|
661 | ! |
---|
662 | CALL icb_utl_destroy(berg) |
---|
663 | ! |
---|
664 | END SUBROUTINE icb_utl_delete |
---|
665 | |
---|
666 | |
---|
667 | SUBROUTINE icb_utl_destroy( berg ) |
---|
668 | !!---------------------------------------------------------------------- |
---|
669 | !! *** ROUTINE icb_utl_destroy *** |
---|
670 | !! |
---|
671 | !! ** Purpose : remove a single iceberg instance |
---|
672 | !! |
---|
673 | !!---------------------------------------------------------------------- |
---|
674 | TYPE(iceberg), POINTER :: berg |
---|
675 | !!---------------------------------------------------------------------- |
---|
676 | ! |
---|
677 | ! Remove any points |
---|
678 | IF( ASSOCIATED( berg%current_point ) ) DEALLOCATE( berg%current_point ) |
---|
679 | ! |
---|
680 | DEALLOCATE(berg) |
---|
681 | ! |
---|
682 | END SUBROUTINE icb_utl_destroy |
---|
683 | |
---|
684 | |
---|
685 | SUBROUTINE icb_utl_track( knum, cd_label, kt ) |
---|
686 | !!---------------------------------------------------------------------- |
---|
687 | !! *** ROUTINE icb_utl_track *** |
---|
688 | !! |
---|
689 | !! ** Purpose : |
---|
690 | !! |
---|
691 | !!---------------------------------------------------------------------- |
---|
692 | INTEGER, DIMENSION(nkounts) :: knum ! iceberg number |
---|
693 | CHARACTER(len=*) :: cd_label ! |
---|
694 | INTEGER :: kt ! timestep number |
---|
695 | ! |
---|
696 | TYPE(iceberg), POINTER :: this |
---|
697 | LOGICAL :: match |
---|
698 | INTEGER :: k |
---|
699 | !!---------------------------------------------------------------------- |
---|
700 | ! |
---|
701 | this => first_berg |
---|
702 | DO WHILE( ASSOCIATED(this) ) |
---|
703 | match = .TRUE. |
---|
704 | DO k = 1, nkounts |
---|
705 | IF( this%number(k) /= knum(k) ) match = .FALSE. |
---|
706 | END DO |
---|
707 | IF( match ) CALL icb_utl_print_berg(this, kt) |
---|
708 | this => this%next |
---|
709 | END DO |
---|
710 | ! |
---|
711 | END SUBROUTINE icb_utl_track |
---|
712 | |
---|
713 | |
---|
714 | SUBROUTINE icb_utl_print_berg( berg, kt ) |
---|
715 | !!---------------------------------------------------------------------- |
---|
716 | !! *** ROUTINE icb_utl_print_berg *** |
---|
717 | !! |
---|
718 | !! ** Purpose : print one |
---|
719 | !! |
---|
720 | !!---------------------------------------------------------------------- |
---|
721 | TYPE(iceberg), POINTER :: berg |
---|
722 | TYPE(point) , POINTER :: pt |
---|
723 | INTEGER :: kt ! timestep number |
---|
724 | !!---------------------------------------------------------------------- |
---|
725 | ! |
---|
726 | IF (nn_verbose_level == 0) RETURN |
---|
727 | pt => berg%current_point |
---|
728 | WRITE(numicb, 9200) kt, berg%number(1), & |
---|
729 | pt%xi, pt%yj, pt%lon, pt%lat, pt%uvel, pt%vvel, & |
---|
730 | pt%ssu, pt%ssv, pt%ua, pt%va, pt%ui, pt%vi |
---|
731 | CALL flush( numicb ) |
---|
732 | 9200 FORMAT(5x,i5,2x,i10,6(2x,2f10.4)) |
---|
733 | ! |
---|
734 | END SUBROUTINE icb_utl_print_berg |
---|
735 | |
---|
736 | |
---|
737 | SUBROUTINE icb_utl_print( cd_label, kt ) |
---|
738 | !!---------------------------------------------------------------------- |
---|
739 | !! *** ROUTINE icb_utl_print *** |
---|
740 | !! |
---|
741 | !! ** Purpose : print many |
---|
742 | !! |
---|
743 | !!---------------------------------------------------------------------- |
---|
744 | CHARACTER(len=*) :: cd_label |
---|
745 | INTEGER :: kt ! timestep number |
---|
746 | ! |
---|
747 | INTEGER :: ibergs, inbergs |
---|
748 | TYPE(iceberg), POINTER :: this |
---|
749 | !!---------------------------------------------------------------------- |
---|
750 | ! |
---|
751 | IF (nn_verbose_level == 0) RETURN |
---|
752 | this => first_berg |
---|
753 | IF( ASSOCIATED(this) ) THEN |
---|
754 | WRITE(numicb,'(a," pe=(",i3,")")' ) cd_label, narea |
---|
755 | WRITE(numicb,'(a8,4x,a6,12x,a5,15x,a7,19x,a3,17x,a5,17x,a5,17x,a5)' ) & |
---|
756 | & 'timestep', 'number', 'xi,yj','lon,lat','u,v','ssu,ssv','ua,va','ui,vi' |
---|
757 | ENDIF |
---|
758 | DO WHILE( ASSOCIATED(this) ) |
---|
759 | CALL icb_utl_print_berg(this, kt) |
---|
760 | this => this%next |
---|
761 | END DO |
---|
762 | ibergs = icb_utl_count() |
---|
763 | inbergs = ibergs |
---|
764 | CALL mpp_sum('icbutl', inbergs) |
---|
765 | IF( ibergs > 0 ) WRITE(numicb,'(a," there are",i5," bergs out of",i6," on PE ",i4)') & |
---|
766 | & cd_label, ibergs, inbergs, narea |
---|
767 | ! |
---|
768 | END SUBROUTINE icb_utl_print |
---|
769 | |
---|
770 | |
---|
771 | SUBROUTINE icb_utl_incr() |
---|
772 | !!---------------------------------------------------------------------- |
---|
773 | !! *** ROUTINE icb_utl_incr *** |
---|
774 | !! |
---|
775 | !! ** Purpose : |
---|
776 | !! |
---|
777 | ! Small routine for coping with very large integer values labelling icebergs |
---|
778 | ! num_bergs is a array of integers |
---|
779 | ! the first member is incremented in steps of jpnij starting from narea |
---|
780 | ! this means each iceberg is labelled with a unique number |
---|
781 | ! when this gets to the maximum allowed integer the second and subsequent members are |
---|
782 | ! used to count how many times the member before cycles |
---|
783 | !!---------------------------------------------------------------------- |
---|
784 | INTEGER :: ii, ibig |
---|
785 | !!---------------------------------------------------------------------- |
---|
786 | |
---|
787 | ibig = HUGE(num_bergs(1)) |
---|
788 | IF( ibig-jpnij < num_bergs(1) ) THEN |
---|
789 | num_bergs(1) = narea |
---|
790 | DO ii = 2,nkounts |
---|
791 | IF( num_bergs(ii) == ibig ) THEN |
---|
792 | num_bergs(ii) = 0 |
---|
793 | IF( ii == nkounts ) CALL ctl_stop('Sorry, run out of iceberg number space') |
---|
794 | ELSE |
---|
795 | num_bergs(ii) = num_bergs(ii) + 1 |
---|
796 | EXIT |
---|
797 | ENDIF |
---|
798 | END DO |
---|
799 | ELSE |
---|
800 | num_bergs(1) = num_bergs(1) + jpnij |
---|
801 | ENDIF |
---|
802 | ! |
---|
803 | END SUBROUTINE icb_utl_incr |
---|
804 | |
---|
805 | |
---|
806 | INTEGER FUNCTION icb_utl_count() |
---|
807 | !!---------------------------------------------------------------------- |
---|
808 | !! *** FUNCTION icb_utl_count *** |
---|
809 | !! |
---|
810 | !! ** Purpose : |
---|
811 | !!---------------------------------------------------------------------- |
---|
812 | TYPE(iceberg), POINTER :: this |
---|
813 | !!---------------------------------------------------------------------- |
---|
814 | ! |
---|
815 | icb_utl_count = 0 |
---|
816 | this => first_berg |
---|
817 | DO WHILE( ASSOCIATED(this) ) |
---|
818 | icb_utl_count = icb_utl_count+1 |
---|
819 | this => this%next |
---|
820 | END DO |
---|
821 | ! |
---|
822 | END FUNCTION icb_utl_count |
---|
823 | |
---|
824 | |
---|
825 | REAL(wp) FUNCTION icb_utl_mass( first, justbits, justbergs ) |
---|
826 | !!---------------------------------------------------------------------- |
---|
827 | !! *** FUNCTION icb_utl_mass *** |
---|
828 | !! |
---|
829 | !! ** Purpose : compute the mass all iceberg, all berg bits or all bergs. |
---|
830 | !!---------------------------------------------------------------------- |
---|
831 | TYPE(iceberg) , POINTER :: first |
---|
832 | TYPE(point) , POINTER :: pt |
---|
833 | LOGICAL, INTENT(in), OPTIONAL :: justbits, justbergs |
---|
834 | ! |
---|
835 | TYPE(iceberg), POINTER :: this |
---|
836 | !!---------------------------------------------------------------------- |
---|
837 | icb_utl_mass = 0._wp |
---|
838 | this => first |
---|
839 | ! |
---|
840 | IF( PRESENT( justbergs ) ) THEN |
---|
841 | DO WHILE( ASSOCIATED( this ) ) |
---|
842 | pt => this%current_point |
---|
843 | icb_utl_mass = icb_utl_mass + pt%mass * this%mass_scaling |
---|
844 | this => this%next |
---|
845 | END DO |
---|
846 | ELSEIF( PRESENT(justbits) ) THEN |
---|
847 | DO WHILE( ASSOCIATED( this ) ) |
---|
848 | pt => this%current_point |
---|
849 | icb_utl_mass = icb_utl_mass + pt%mass_of_bits * this%mass_scaling |
---|
850 | this => this%next |
---|
851 | END DO |
---|
852 | ELSE |
---|
853 | DO WHILE( ASSOCIATED( this ) ) |
---|
854 | pt => this%current_point |
---|
855 | icb_utl_mass = icb_utl_mass + ( pt%mass + pt%mass_of_bits ) * this%mass_scaling |
---|
856 | this => this%next |
---|
857 | END DO |
---|
858 | ENDIF |
---|
859 | ! |
---|
860 | END FUNCTION icb_utl_mass |
---|
861 | |
---|
862 | |
---|
863 | REAL(wp) FUNCTION icb_utl_heat( first, justbits, justbergs ) |
---|
864 | !!---------------------------------------------------------------------- |
---|
865 | !! *** FUNCTION icb_utl_heat *** |
---|
866 | !! |
---|
867 | !! ** Purpose : compute the heat in all iceberg, all bergies or all bergs. |
---|
868 | !!---------------------------------------------------------------------- |
---|
869 | TYPE(iceberg) , POINTER :: first |
---|
870 | LOGICAL, INTENT(in), OPTIONAL :: justbits, justbergs |
---|
871 | ! |
---|
872 | TYPE(iceberg) , POINTER :: this |
---|
873 | TYPE(point) , POINTER :: pt |
---|
874 | !!---------------------------------------------------------------------- |
---|
875 | icb_utl_heat = 0._wp |
---|
876 | this => first |
---|
877 | ! |
---|
878 | IF( PRESENT( justbergs ) ) THEN |
---|
879 | DO WHILE( ASSOCIATED( this ) ) |
---|
880 | pt => this%current_point |
---|
881 | icb_utl_heat = icb_utl_heat + pt%mass * this%mass_scaling * pt%heat_density |
---|
882 | this => this%next |
---|
883 | END DO |
---|
884 | ELSEIF( PRESENT(justbits) ) THEN |
---|
885 | DO WHILE( ASSOCIATED( this ) ) |
---|
886 | pt => this%current_point |
---|
887 | icb_utl_heat = icb_utl_heat + pt%mass_of_bits * this%mass_scaling * pt%heat_density |
---|
888 | this => this%next |
---|
889 | END DO |
---|
890 | ELSE |
---|
891 | DO WHILE( ASSOCIATED( this ) ) |
---|
892 | pt => this%current_point |
---|
893 | icb_utl_heat = icb_utl_heat + ( pt%mass + pt%mass_of_bits ) * this%mass_scaling * pt%heat_density |
---|
894 | this => this%next |
---|
895 | END DO |
---|
896 | ENDIF |
---|
897 | ! |
---|
898 | END FUNCTION icb_utl_heat |
---|
899 | |
---|
900 | SUBROUTINE test_icb_utl_getkb |
---|
901 | !!---------------------------------------------------------------------- |
---|
902 | !! *** FUNCTION test_icb_utl_getkb *** |
---|
903 | !! |
---|
904 | !! ** Purpose : Test routine icb_utl_getkb, icb_utl_zavg |
---|
905 | !! ** Methode : Call each subroutine with specific input data |
---|
906 | !! What should be the output is easy to determined and check |
---|
907 | !! if NEMO return the correct answer. |
---|
908 | !! ** Comments : not called, if needed a CALL test_icb_utl_getkb need to be added in icb_step |
---|
909 | !!---------------------------------------------------------------------- |
---|
910 | INTEGER :: ikb |
---|
911 | REAL(wp) :: zD, zout |
---|
912 | REAL(wp), DIMENSION(jpk) :: ze3, zin |
---|
913 | WRITE(numout,*) 'Test icb_utl_getkb : ' |
---|
914 | zD = 0.0 ; ze3= 20.0 |
---|
915 | WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1) |
---|
916 | CALL icb_utl_getkb(ikb, ze3, zD) |
---|
917 | WRITE(numout,*) 'OUTPUT : kb = ',ikb |
---|
918 | |
---|
919 | zD = 8000000.0 ; ze3= 20.0 |
---|
920 | WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1) |
---|
921 | CALL icb_utl_getkb(ikb, ze3, zD) |
---|
922 | WRITE(numout,*) 'OUTPUT : kb = ',ikb |
---|
923 | |
---|
924 | zD = 80.0 ; ze3= 20.0 |
---|
925 | WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1) |
---|
926 | CALL icb_utl_getkb(ikb, ze3, zD) |
---|
927 | WRITE(numout,*) 'OUTPUT : kb = ',ikb |
---|
928 | |
---|
929 | zD = 85.0 ; ze3= 20.0 |
---|
930 | WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1) |
---|
931 | CALL icb_utl_getkb(ikb, ze3, zD) |
---|
932 | WRITE(numout,*) 'OUTPUT : kb = ',ikb |
---|
933 | |
---|
934 | zD = 75.0 ; ze3= 20.0 |
---|
935 | WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1) |
---|
936 | CALL icb_utl_getkb(ikb, ze3, zD) |
---|
937 | WRITE(numout,*) 'OUTPUT : kb = ',ikb |
---|
938 | |
---|
939 | WRITE(numout,*) '==================================' |
---|
940 | WRITE(numout,*) 'Test icb_utl_zavg' |
---|
941 | zD = 0.0 ; ze3= 20.0 ; zin=1.0 |
---|
942 | CALL icb_utl_getkb(ikb, ze3, zD) |
---|
943 | CALL icb_utl_zavg(zout, zin, ze3, zD, ikb) |
---|
944 | WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1),' zin = ', zin, ' ikb = ',ikb |
---|
945 | WRITE(numout,*) 'OUTPUT : zout = ',zout |
---|
946 | |
---|
947 | zD = 50.0 ; ze3= 20.0 ; zin=1.0; zin(3:jpk) = 0.0 |
---|
948 | CALL icb_utl_getkb(ikb, ze3, zD) |
---|
949 | CALL icb_utl_zavg(zout, zin, ze3, zD, ikb) |
---|
950 | WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1),' zin = ', zin, ' ikb = ',ikb |
---|
951 | WRITE(numout,*) 'OUTPUT : zout = ',zout |
---|
952 | CALL FLUSH(numout) |
---|
953 | |
---|
954 | zD = 80.0 ; ze3= 20.0 ; zin=1.0; zin(3:jpk) = 0.0 |
---|
955 | CALL icb_utl_getkb(ikb, ze3, zD) |
---|
956 | CALL icb_utl_zavg(zout, zin, ze3, zD, ikb) |
---|
957 | WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1),' zin = ', zin, ' ikb = ',ikb |
---|
958 | WRITE(numout,*) 'OUTPUT : zout = ',zout |
---|
959 | |
---|
960 | zD = 80 ; ze3= 20.0 ; zin=1.0 ; zin(3:jpk) = 0.0 |
---|
961 | CALL icb_utl_getkb(ikb, ze3, zD) |
---|
962 | ikb = 2 |
---|
963 | CALL icb_utl_zavg(zout, zin, ze3, zD, ikb) |
---|
964 | WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1),' zin = ', zin, ' ikb = ',ikb |
---|
965 | WRITE(numout,*) 'OUTPUT : zout = ',zout |
---|
966 | |
---|
967 | CALL FLUSH(numout) |
---|
968 | |
---|
969 | END SUBROUTINE test_icb_utl_getkb |
---|
970 | |
---|
971 | !!====================================================================== |
---|
972 | END MODULE icbutl |
---|