14 USE iso_c_binding,
ONLY: c_int, c_int64_t, c_char, c_bool, c_ptr, c_null_ptr, c_f_pointer
16 & comin_hgrid_unstructured_cell,
dp,
sp, comin_dim_semantics_container, &
17 & comin_dim_semantics_undef
25#include "comin_global.inc"
37 CHARACTER(LEN=:),
ALLOCATABLE :: name
47 TYPE,
BIND(C) :: t_comin_var_descriptor_c
48 CHARACTER(KIND=c_char) :: name(comin_max_len_var_name+1)
50 INTEGER(kind=c_int) :: id
57 TYPE(t_comin_var_item),
PRIVATE,
POINTER :: var_item
60 generic,
PUBLIC :: get_ptr => get_ptr_dp, get_ptr_sp, get_ptr_i
70 generic,
PUBLIC :: to_3d => to_3d_dp, to_3d_sp, to_3d_i
83 TYPE(c_ptr) :: cptr = c_null_ptr
89 INTEGER :: array_shape(5)
92 TYPE(c_ptr) :: device_ptr = c_null_ptr
95 INTEGER,
DIMENSION(5) :: dim_semantics
100 INTEGER :: ncontained = 0
102 LOGICAL(kind=c_bool) :: lcontainer = .false.
105 TYPE(t_comin_var_metadata) :: metadata
111 INTEGER :: access_flag
117 TYPE(t_comin_var_metadata) :: metadata
118 INTEGER,
ALLOCATABLE :: moduleid(:)
122 LOGICAL(kind=c_bool) :: lmodexclusive = .false.
129 LOGICAL,
INTENT(IN) :: direction
136 INTEGER,
INTENT(IN) :: halo_sync_mode
150 TYPE(c_ptr) :: var_list
157 CHARACTER(len=*),
INTENT(IN) :: name
158 INTEGER,
INTENT(IN) :: id
162 desc%name = trim(adjustl(name))
181 LOGICAL :: l_name, l_domain
183 l_domain = (var_descriptor1%id == var_descriptor2%id)
188 l_name = (var_descriptor1%name == var_descriptor2%name)
202 REAL(dp),
POINTER,
INTENT(INOUT) :: ptr(:,:,:,:,:)
204 CALL c_f_pointer(this%var_item%cptr, ptr, this%var_item%array_shape)
209 REAL(sp),
POINTER,
INTENT(INOUT) :: ptr(:,:,:,:,:)
211 CALL c_f_pointer(this%var_item%cptr, ptr, this%var_item%array_shape)
216 INTEGER(C_INT),
POINTER,
INTENT(INOUT) :: ptr(:,:,:,:,:)
218 CALL c_f_pointer(this%var_item%cptr, ptr, this%var_item%array_shape)
224 INTEGER :: array_shape(5)
225 array_shape = this%var_item%array_shape
232 descriptor = this%var_item%descriptor
238 LOGICAL :: lcontainer
239 lcontainer = this%var_item%lcontainer
245 INTEGER :: ncontained
246 ncontained = this%var_item%ncontained
250 result(dim_semantics)
252 INTEGER :: dim_semantics(5)
253 dim_semantics = this%var_item%dim_semantics
260 valid =
ASSOCIATED(this%var_item)
269 REAL(dp),
POINTER :: slice(:,:,:)
270 REAL(dp),
POINTER :: tmp_ptr(:,:,:,:,:)
274 IF (var%lcontainer())
THEN
276 &
" ERROR: Attempt to convert container variable into 3D field.")
279 CALL var%get_ptr(tmp_ptr)
281 pos_jn = findloc(var%dim_semantics(), comin_dim_semantics_container, dim=1)
284 slice => tmp_ptr(1, :, :, :, 1)
286 slice => tmp_ptr(:, 1, :, :, 1)
288 slice => tmp_ptr(:, :, 1, :, 1)
290 slice => tmp_ptr(:, :, :, 1, 1)
300 REAL(sp),
POINTER :: slice(:,:,:)
301 REAL(sp),
POINTER :: tmp_ptr(:,:,:,:,:)
305 IF (var%lcontainer())
THEN
307 &
" ERROR: Attempt to convert container variable into 3D field.")
310 CALL var%get_ptr(tmp_ptr)
312 pos_jn = findloc(var%dim_semantics(), comin_dim_semantics_container, dim=1)
315 slice => tmp_ptr(1, :, :, :, 1)
317 slice => tmp_ptr(:, 1, :, :, 1)
319 slice => tmp_ptr(:, :, 1, :, 1)
321 slice => tmp_ptr(:, :, :, 1, 1)
331 INTEGER(C_INT),
POINTER :: slice(:,:,:)
332 INTEGER(C_INT),
POINTER :: tmp_ptr(:,:,:,:,:)
336 IF (var%lcontainer())
THEN
338 &
" ERROR: Attempt to convert container variable into 3D field.")
341 CALL var%get_ptr(tmp_ptr)
343 pos_jn = findloc(var%dim_semantics(), comin_dim_semantics_container, dim=1)
346 slice => tmp_ptr(1, :, :, :, 1)
348 slice => tmp_ptr(:, 1, :, :, 1)
350 slice => tmp_ptr(:, :, 1, :, 1)
352 slice => tmp_ptr(:, :, :, 1, 1)
358 TYPE(c_ptr),
INTENT(IN) :: cptr
360 var%var_item%cptr = cptr
362 var%var_item%device_ptr = acc_deviceptr(cptr)
integer, parameter, public wp
working precision
subroutine comin_var_to_3d_dp(var, slice)
Convenience operation for accessing 2D/3D fields.
subroutine comin_var_to_3d_sp(var, slice)
Convenience operation for accessing 2D/3D fields.
subroutine comin_var_to_3d_i(var, slice)
Convenience operation for accessing 2D/3D fields.
integer, parameter, public dp
integer, parameter, public sp
subroutine comin_var_get_ptr_sp(this, ptr)
type(t_comin_var_handle) function comin_var_ptr_init(var_item)
subroutine comin_var_get_ptr_dp(this, ptr)
type(t_comin_var_descriptor) function create_comin_var_descriptor_from_c(desc_c)
Create a variable descriptor from a C structure.
logical function comin_var_descr_match(var_descriptor1, var_descriptor2)
compare two variable descriptors.
integer function, dimension(5) comin_var_get_dim_semantics(this)
subroutine comin_var_get_ptr_i(this, ptr)
logical function comin_var_get_lcontainer(this)
subroutine comin_var_handle_set_cptr(var, cptr)
integer function, dimension(5) comin_var_get_array_shape(this)
type(t_comin_var_descriptor) function comin_var_get_descriptor(this)
external comin_plugin_finish_external
integer function comin_var_get_ncontained(this)
type(t_comin_var_descriptor) function create_comin_var_descriptor(name, id)
Create a variable descriptor from a variable name and id.
logical function comin_var_get_valid(this)
Information on requested variables.
Variable list for context access.
Variable descriptor. identifies (uniquely) a variable. Do not confuse with meta-data.
Variable pointer. Fortran interface for accessing variables.
Array of variable lists (array of pointer lists) each entry.