31 & t_comin_var_descriptor, t_comin_var_handle, &
32 & comin_var_request_add, &
33 & comin_descrdata_get_domain, t_comin_descrdata_domain, &
34 & comin_descrdata_get_global, t_comin_descrdata_global, &
35 & t_comin_setup_version_info, comin_setup_get_version, &
36 & ep_secondary_constructor, ep_destructor, ep_atm_physics_before, &
37 & comin_flag_read, comin_flag_write, comin_zaxis_2d, &
38 & comin_parallel_get_host_mpi_rank, comin_current_get_domain_id, &
39 & t_comin_plugin_info, comin_current_get_plugin_info, &
40 & comin_plugin_finish, comin_metadata_set, &
41 & comin_metadata_get, &
42 & comin_error_set_errors_return, comin_success, comin_error_get, &
44 & comin_dim_semantics_nproma, comin_dim_semantics_level,&
45 & comin_dim_semantics_block, comin_dim_semantics_unused
50 CHARACTER(LEN=*),
PARAMETER :: pluginname =
"calc_water_column_plugin"
53 INTEGER,
PARAMETER :: wp = selected_real_kind(12,307)
54 TYPE(t_comin_setup_version_info) :: version
58 TYPE(t_comin_var_handle) :: rho
59 TYPE(t_comin_var_handle) :: qv
60 TYPE(t_comin_var_handle) :: qc
61 TYPE(t_comin_var_handle) :: qi
62 TYPE(t_comin_var_handle) :: qr
63 TYPE(t_comin_var_handle) :: qs
64 TYPE(t_comin_var_handle) :: qg
66 TYPE(t_comin_var_handle) :: lwp
67 TYPE(t_comin_var_handle) :: iwp
68 TYPE(t_comin_var_handle) :: twc
69 END type t_plugin_vars
71 TYPE(t_plugin_vars),
DIMENSION(:),
ALLOCATABLE ::
pvpp
74 TYPE(t_comin_descrdata_domain),
POINTER :: p_patch
76 TYPE(t_comin_descrdata_global),
POINTER :: p_global
78 LOGICAL :: lqg = .true.
80 CHARACTER(LEN=120) :: text
96 TYPE(t_comin_plugin_info) :: this_plugin
97 TYPE(t_comin_var_descriptor) :: lwp_d, iwp_d, twc_d
100 CALL comin_print_info(
'- setup')
102 version = comin_setup_get_version()
103 IF (version%version_no_major > 1)
THEN
104 CALL comin_plugin_finish(
'comin_main ('//pluginname//
')',
"incompatible version!")
108 p_global => comin_descrdata_get_global()
110 WRITE (text,
'(a,i4)')
'- number of domains: ', p_global%n_dom
111 CALL comin_print_info(text)
114 CALL comin_current_get_plugin_info(this_plugin)
115 WRITE (text,
'(a,a,a,i4)')
"- plugin ", this_plugin%name,
" has id: ", this_plugin%id
116 CALL comin_print_info(text)
122 DO jg = 1, p_global%n_dom
124 lwp_d = t_comin_var_descriptor( id = jg, name =
"lwp" )
125 CALL comin_var_request_add_wrapper(lwp_d, lmode_exclusive=.false. &
126 , zaxis_id = comin_zaxis_2d, tracer =.false., restart=.false., units=
'kg/m2')
129 iwp_d = t_comin_var_descriptor( id = jg, name =
"iwp" )
130 CALL comin_var_request_add_wrapper(iwp_d, lmode_exclusive=.false. &
131 , zaxis_id = comin_zaxis_2d, tracer =.false., restart=.false., units=
'kg/m2')
134 twc_d = t_comin_var_descriptor( id = jg, name =
"twc" )
135 CALL comin_var_request_add_wrapper(twc_d, lmode_exclusive=.false. &
136 , zaxis_id = comin_zaxis_2d, tracer =.false., restart=.false., units=
'kg/m2')
153 TYPE(t_comin_var_descriptor) :: var_desc
156 ALLOCATE(
pvpp(p_global%n_dom))
158 domain_loop:
DO jg = 1, p_global%n_dom
159 WRITE (text,
'(a,i4)')
' - get required meteorological data. dom: ', jg
160 CALL comin_print_info(text)
164 var_desc = t_comin_var_descriptor(
'rho', jg)
165 CALL comin_var_get([ep_atm_physics_before], &
166 & var_desc, comin_flag_read,
pvpp(jg)%rho)
167 CALL check_variable(
pvpp(jg)%rho,
'rho')
169 WRITE (text,
'(a,i4)')
' - get humidity tracer. dom: ',jg
170 CALL comin_print_info(text)
172 var_desc = t_comin_var_descriptor(
'qv', jg)
173 CALL comin_var_get([ep_atm_physics_before], &
174 & var_desc, comin_flag_read,
pvpp(jg)%qv)
175 CALL check_variable(
pvpp(jg)%qv,
'qv')
177 var_desc = t_comin_var_descriptor(
'qc', jg)
178 CALL comin_var_get([ep_atm_physics_before], &
179 & var_desc, comin_flag_read,
pvpp(jg)%qc)
180 CALL check_variable(
pvpp(jg)%qc,
'qc')
182 var_desc = t_comin_var_descriptor(
'qi', jg)
183 CALL comin_var_get([ep_atm_physics_before], &
184 & var_desc, comin_flag_read,
pvpp(jg)%qi)
185 CALL check_variable(
pvpp(jg)%qi,
'qi')
187 var_desc = t_comin_var_descriptor(
'qr', jg)
188 CALL comin_var_get([ep_atm_physics_before], &
189 & var_desc, comin_flag_read,
pvpp(jg)%qr)
190 CALL check_variable(
pvpp(jg)%qr,
'qr')
192 var_desc = t_comin_var_descriptor(
'qs', jg)
193 CALL comin_var_get([ep_atm_physics_before], &
194 & var_desc, comin_flag_read,
pvpp(jg)%qs)
195 CALL check_variable(
pvpp(jg)%qs,
'qs')
197 var_desc = t_comin_var_descriptor(
'qg', jg)
198 CALL comin_error_set_errors_return(.true.)
199 CALL comin_var_get([ep_atm_physics_before], &
200 & var_desc, comin_flag_read,
pvpp(jg)%qg)
201 lqg = (comin_error_get() == comin_success)
202 CALL comin_error_set_errors_return(.false.)
203 IF (lqg)
CALL check_variable(
pvpp(jg)%qg,
'qg')
205 WRITE (text,
'(a,i4)')
' - get plugin variables - requested to be created by ICON. dom: ', jg
206 CALL comin_print_info(text)
209 CALL comin_var_get([ep_atm_physics_before], &
210 & t_comin_var_descriptor(name=
'lwp', id=jg),&
211 & comin_flag_write,
pvpp(jg)%lwp)
212 CALL check_variable(
pvpp(jg)%lwp,
'lwp',dim=2)
214 CALL comin_var_get([ep_atm_physics_before], &
215 & t_comin_var_descriptor(name=
'iwp', id=jg), &
216 & comin_flag_write,
pvpp(jg)%iwp)
217 CALL check_variable(
pvpp(jg)%iwp,
'iwp',dim=2)
219 CALL comin_var_get([ep_atm_physics_before], &
220 & t_comin_var_descriptor(name=
'twc', id=jg), &
221 & comin_flag_write,
pvpp(jg)%twc)
222 CALL check_variable(
pvpp(jg)%twc,
'twc',dim=2)
235 TYPE(t_comin_var_descriptor) :: lwp_d, iwp_d, twc_d
238 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: rho_3d => null()
240 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: lwp_3d => null()
241 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: iwp_3d => null()
242 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: twc_3d => null()
244 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: qv_3d => null()
245 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: qc_3d => null()
246 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: qi_3d => null()
247 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: qr_3d => null()
248 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: qs_3d => null()
249 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: qg_3d => null()
251 REAL(wp),
POINTER,
DIMENSION(:,:,:) :: conv => null()
253 CHARACTER(LEN=:),
ALLOCATABLE :: units
254 CHARACTER(LEN=200) :: text =
''
257 jg = comin_current_get_domain_id()
259 p_patch => comin_descrdata_get_domain(jg)
261 WRITE (text,
'(a,i4)')
'- calculate water columns before physics. dom: ', jg
262 CALL comin_print_info(text)
264 CALL pvpp(jg)%qv%to_3d(qv_3d)
265 CALL pvpp(jg)%qi%to_3d(qi_3d)
266 CALL pvpp(jg)%qr%to_3d(qr_3d)
267 CALL pvpp(jg)%qs%to_3d(qs_3d)
268 CALL pvpp(jg)%qc%to_3d(qc_3d)
269 IF (lqg)
CALL pvpp(jg)%qg%to_3d(qg_3d)
271 CALL pvpp(jg)%rho%to_3d(rho_3d)
273 CALL pvpp(jg)%lwp%to_3d(lwp_3d)
274 CALL pvpp(jg)%iwp%to_3d(iwp_3d)
275 CALL pvpp(jg)%twc%to_3d(twc_3d)
278 ALLOCATE(conv(
SIZE(qv_3d,1),
SIZE(qv_3d,2),
SIZE(qv_3d,3)))
280 DO jk=1,
SIZE(qv_3d,2)
282 conv(:,jk,:) = rho_3d(:,jk,:) * &
283 (p_patch%cells%hhl(:,jk,:) - p_patch%cells%hhl(:,jk+1,:))
287 lwp_3d(:,:,:) = 0._wp
288 iwp_3d(:,:,:) = 0._wp
289 twc_3d(:,:,:) = 0._wp
290 DO jk=1,
SIZE(qv_3d,2)
291 lwp_3d(:,:,1) = lwp_3d(:,:,1) &
292 + (qr_3d(:,jk,:) + qc_3d(:,jk,:)) * conv(:,jk,:)
293 iwp_3d(:,:,1) = iwp_3d(:,:,1) &
294 + (qi_3d(:,jk,:)+qs_3d(:,jk,:)) * conv(:,jk,:)
297 DO jk=1,
SIZE(qv_3d,2)
298 iwp_3d(:,:,1) = iwp_3d(:,:,1) + qg_3d(:,jk,:) * conv(:,jk,:)
301 twc_3d(:,:,1) = iwp_3d(:,:,1) + lwp_3d(:,:,1)
302 DO jk=1,
SIZE(qv_3d,2)
303 twc_3d(:,:,1) = twc_3d(:,:,1) + qv_3d(:,jk,:) * conv(:,jk,:)
306 WRITE (text,
'(a,i4)')
'- results of plugin calc_water_column. dom: ', jg
308 lwp_d = t_comin_var_descriptor( id = jg, name =
"lwp" )
309 CALL comin_metadata_get(lwp_d,
"units", units)
310 write (text,fmt=
'(A,A5,A,F8.4)')
'- maximum liquid water path (',trim(units),
'): ', maxval(lwp_3d(:,:,1))
311 CALL message(text, idom=jg,lall=.true.)
312 iwp_d = t_comin_var_descriptor( id = jg, name =
"iwp" )
313 CALL comin_metadata_get(iwp_d,
"units", units)
314 write (text,fmt=
'(A,A5,A,F8.4)')
'- maximum ice water path (',trim(units),
'): ', maxval(iwp_3d(:,:,1))
315 CALL message(text, idom=jg,lall=.true.)
316 twc_d = t_comin_var_descriptor( id = jg, name =
"twc" )
317 write (text,fmt=
'(A,A5,A,F8.4)')
'- maximum total water column (',trim(units),
'): ', maxval(twc_3d(:,:,1))
318 CALL message(text, idom=jg,lall=.true.)
321 DEALLOCATE(conv);
NULLIFY(conv)
322 NULLIFY(lwp_3d, iwp_3d, twc_3d)
323 NULLIFY(qv_3d,qc_3d,qi_3d,qr_3d,qs_3d,qg_3d, rho_3d)
336 CALL comin_print_info(
' - destructor.')
348 SUBROUTINE comin_var_request_add_wrapper(descriptor, lmode_exclusive, zaxis_id &
349 , tracer, restart, units)
354 TYPE(t_comin_var_descriptor),
INTENT(IN) :: descriptor
355 LOGICAL,
OPTIONAL,
INTENT(IN) :: lmode_exclusive
356 INTEGER,
OPTIONAL,
INTENT(IN) :: zaxis_id
357 LOGICAL,
OPTIONAL,
INTENT(IN) :: tracer
358 LOGICAL,
OPTIONAL,
INTENT(IN) :: restart
359 CHARACTER(LEN=*),
OPTIONAL,
INTENT(IN) :: units
361 LOGICAL :: lexclusive
363 IF (
PRESENT(lmode_exclusive))
THEN
364 lexclusive = lmode_exclusive
369 CALL comin_var_request_add(descriptor, lexclusive)
371 IF (
PRESENT(zaxis_id))
THEN
372 CALL comin_metadata_set(descriptor,
"zaxis_id", zaxis_id)
374 IF (
PRESENT(tracer))
THEN
375 CALL comin_metadata_set(descriptor,
"tracer", tracer)
377 IF (
PRESENT(restart))
THEN
378 CALL comin_metadata_set(descriptor,
"restart", restart)
380 IF (
PRESENT(units))
THEN
381 CALL comin_metadata_set(descriptor,
"units", trim(units))
384 END SUBROUTINE comin_var_request_add_wrapper
388 SUBROUTINE check_variable(var, name, dim)
393 TYPE(t_comin_var_handle),
INTENT(IN) :: var
394 CHARACTER(LEN=*),
INTENT(IN) :: name
395 INTEGER,
INTENT(IN),
OPTIONAL :: dim
399 IF (
PRESENT(dim))
THEN
406 CALL check_dimensions_2d(var, name)
408 CALL check_dimensions_3d(var, name)
410 CALL comin_plugin_finish (pluginname//
' unsupported dimension',
'check variable')
413 END SUBROUTINE check_variable
417 SUBROUTINE check_dimensions_3d(var, name)
421 TYPE(t_comin_var_handle),
INTENT(IN) :: var
422 CHARACTER(LEN=*),
INTENT(IN) :: name
424 IF (any(var%dim_semantics() /= [comin_dim_semantics_nproma, &
425 & comin_dim_semantics_level, &
426 & comin_dim_semantics_block, &
427 & comin_dim_semantics_unused, &
428 & comin_dim_semantics_unused] )) &
429 &
CALL comin_plugin_finish(pluginname//
': '//trim(name) &
430 & ,
"Dimension check failed!")
432 END SUBROUTINE check_dimensions_3d
438 SUBROUTINE check_dimensions_2d(var, name)
442 TYPE(t_comin_var_handle),
INTENT(IN) :: var
443 CHARACTER(LEN=*),
INTENT(IN) :: name
445 IF (any(var%dim_semantics() /= [comin_dim_semantics_nproma, &
446 & comin_dim_semantics_block, &
447 & comin_dim_semantics_unused, &
448 & comin_dim_semantics_unused, &
449 & comin_dim_semantics_unused] )) &
450 &
CALL comin_plugin_finish(pluginname//
': '//trim(name) &
451 ,
"Dimension check failed!")
453 END SUBROUTINE check_dimensions_2d
457 SUBROUTINE message(text, idom, lall)
461 CHARACTER(LEN=*) :: text
462 INTEGER,
OPTIONAL :: idom
463 LOGICAL,
OPTIONAL :: lall
468 IF (
PRESENT(lall))
THEN
474 IF (comin_parallel_get_host_mpi_rank() == 0 .OR. la)
THEN
475 IF (
PRESENT(idom))
THEN
476 WRITE (0,fmt=
'(A,I2,A)') pluginname//
' domain: ',idom,
' '//trim(text)
478 WRITE (0,fmt=
'(A,A)') pluginname//
' ',trim(text)
482 END SUBROUTINE message
Example plugin for the ICON Community Interface (ComIn)
type(t_plugin_vars), dimension(:), allocatable pvpp
subroutine, public comin_main()
subroutine, public calc_water_column_constructor()
subroutine, public calc_water_column_destructor()
subroutine, public calc_water_column_diagfct()