! (C) Copyright 2013 ECMWF. ! ! This software is licensed under the terms of the Apache Licence Version 2.0 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. ! In applying this licence, ECMWF does not waive the privileges and immunities ! granted to it by virtue of its status as an intergovernmental organisation nor ! does it submit to any jurisdiction. #include "atlas/atlas_f.h" #:include "atlas/atlas_f.fypp" #:include "internals/atlas_generics.fypp" module atlas_field_module use fckit_owned_object_module, only : fckit_owned_object use atlas_Config_module, only: atlas_Config implicit none public :: atlas_Field public :: atlas_real public :: atlas_integer public :: atlas_logical public :: atlas_data_type public :: array_c_to_f private !------------------------------------------------------------------------------ TYPE, extends(fckit_owned_object) :: atlas_Field ! Purpose : ! ------- ! *Field* : Object containing field data and Metadata ! Methods : ! ------- ! name : The name or tag this field was created with ! data : Return the field as a fortran array of specified shape ! Metadata : Return object that can contain a variety of Metadata ! Author : ! ------ ! 20-Nov-2013 Willem Deconinck *ECMWF* !------------------------------------------------------------------------------ contains procedure :: name => Field__name procedure :: functionspace => Field__functionspace procedure :: datatype => Field__datatype procedure :: metadata => Field__metadata procedure, private :: shape_array => Field__shape_array procedure, private :: shape_idx => Field__shape_idx procedure :: size => Field__size procedure :: rank => Field__rank procedure :: bytes => Field__bytes procedure :: levels => Field__levels procedure :: kind => Field__kind generic :: shape => shape_array, shape_idx procedure :: contiguous procedure, public :: strides_array => Field__strides_array procedure, public :: strides_idx => Field__strides_idx generic :: strides => strides_array, strides_idx generic :: stride => strides_idx procedure :: halo_exchange procedure :: dirty procedure :: set_dirty procedure :: rename => rename_ procedure :: set_levels procedure :: set_functionspace #:for rank in ranks #:for dtype in dtypes procedure, private :: access_data_${dtype}$_r${rank}$ procedure, private :: access_device_data_${dtype}$_r${rank}$ procedure, private :: access_data_${dtype}$_r${rank}$_shape procedure, private :: access_data_${dtype}$_r${rank}$_slice #:endfor #:endfor generic, public :: data => & #:for rank in ranks #:for dtype in dtypes & access_data_${dtype}$_r${rank}$, & & access_data_${dtype}$_r${rank}$_shape, & & access_data_${dtype}$_r${rank}$_slice, & #:endfor #:endfor & dummy generic, public :: device_data => & #:for rank in ranks #:for dtype in dtypes & access_device_data_${dtype}$_r${rank}$, & #:endfor #:endfor & dummy procedure, public :: device_allocated procedure, public :: allocate_device procedure, public :: deallocate_device procedure, public :: set_host_needs_update procedure, public :: set_device_needs_update procedure, public :: host_needs_update procedure, public :: device_needs_update procedure, public :: update_device procedure, public :: update_host procedure, public :: sync_host_device procedure, public :: sync_host procedure, public :: sync_device procedure, private :: dummy #if FCKIT_FINAL_NOT_INHERITING final :: atlas_Field__final_auto #endif END TYPE interface atlas_Field module procedure atlas_Field__cptr module procedure atlas_Field__create #:for dtype in integer_dtypes module procedure atlas_Field__create_name_kind_shape_${dtype}$ module procedure atlas_Field__create_kind_shape_${dtype}$ #:endfor #:for rank in ranks #:for dtype in dtypes module procedure atlas_Field__wrap_${dtype}$_r${rank}$ module procedure atlas_Field__wrap_name_${dtype}$_r${rank}$ #:endfor #:endfor end interface ! ---------------------------------------------------- ! ENUM DataType integer, private, parameter :: ATLAS_KIND_INT32 = -4 integer, private, parameter :: ATLAS_KIND_INT64 = -8 integer, private, parameter :: ATLAS_KIND_REAL32 = 4 integer, private, parameter :: ATLAS_KIND_REAL64 = 8 ! ---------------------------------------------------- interface array_c_to_f #:for rank in ranks #:for dtype in dtypes module procedure array_c_to_f_${dtype}$_r${rank}$ #:endfor #:endfor end interface !------------------------------------------------------------------------------- private :: fckit_owned_object private :: atlas_Config !======================================================== contains !======================================================== #:for rank in ranks #:for dtype,ftype,ctype in types !------------------------------------------------------------------------------- subroutine array_c_to_f_${dtype}$_r${rank}$(array_cptr,rank,shape_cptr,strides_cptr,array_fptr) use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_double, c_long, c_float, c_f_pointer @:ENABLE_ATLAS_MACROS() type(c_ptr), intent(in) :: array_cptr integer(c_int), intent(in) :: rank type(c_ptr), intent(in) :: shape_cptr type(c_ptr), intent(in) :: strides_cptr ${ftype}$, pointer, intent(inout) :: array_fptr(${dim[rank]}$) ${ftype}$, pointer :: tmp(${dim[rank]}$) integer, pointer :: shape(:) integer, pointer :: strides(:) integer :: eshape(${rank}$) integer :: j if( rank /= ${rank}$ ) then write(0,*) rank, "!=", ${rank}$ @:ATLAS_ABORT("Rank mismatch") endif call c_f_pointer ( shape_cptr, shape , [rank] ) call c_f_pointer ( strides_cptr, strides , [rank] ) do j=1,rank-1 if( strides(j) /= 0 ) then eshape(j) = strides(j+1)/strides(j) else eshape(j) = shape(j) endif enddo eshape(rank) = shape(rank) call c_f_pointer ( array_cptr , tmp , shape=eshape ) if (associated(tmp)) then #{if rank == 1}# array_fptr => tmp(1:shape(1)) #{endif}# #{if rank == 2}# array_fptr => tmp(1:shape(1),1:shape(2)) #{endif}# #{if rank == 3}# array_fptr => tmp(1:shape(1),1:shape(2),1:shape(3)) #{endif}# #{if rank == 4}# array_fptr => tmp(1:shape(1),1:shape(2),1:shape(3),1:shape(4)) #{endif}# else #{if rank == 1}# allocate(array_fptr(0)) #{endif}# #{if rank == 2}# allocate(array_fptr(0,0)) #{endif}# #{if rank == 3}# allocate(array_fptr(0,0,0)) #{endif}# #{if rank == 4}# allocate(array_fptr(0,0,0,0)) #{endif}# endif end subroutine !------------------------------------------------------------------------------- #:endfor #:endfor #:for rank in ranks #:for dtype,ftype,ctype in types subroutine access_data_${dtype}$_r${rank}$(this, field) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double class(atlas_Field), intent(in) :: this ${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$) type(c_ptr) :: field_cptr type(c_ptr) :: shape_cptr type(c_ptr) :: strides_cptr integer(c_int) :: rank call atlas__Field__data_${ctype}$_specf(this%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr) call array_c_to_f(field_cptr,rank,shape_cptr,strides_cptr, field) end subroutine subroutine access_device_data_${dtype}$_r${rank}$(this, field) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double class(atlas_Field), intent(in) :: this ${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$) type(c_ptr) :: field_cptr type(c_ptr) :: shape_cptr type(c_ptr) :: strides_cptr integer(c_int) :: rank call atlas__Field__device_data_${ctype}$_specf(this%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr) call array_c_to_f(field_cptr,rank,shape_cptr,strides_cptr, field) end subroutine subroutine access_data_${dtype}$_r${rank}$_slice(this, slice, iblk) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double class(atlas_Field), intent(in) :: this ${ftype}$, pointer :: field(${dim[rank]}$) #:if rank > 1 ${ftype}$, pointer, intent(inout) :: slice(${dimr[rank]}$) #:else ${ftype}$, pointer, intent(inout) :: slice #:endif integer, intent(in) :: iblk type(c_ptr) :: field_cptr type(c_ptr) :: shape_cptr type(c_ptr) :: strides_cptr integer(c_int) :: rank call atlas__Field__data_${ctype}$_specf(this%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr) call array_c_to_f(field_cptr, rank, shape_cptr, strides_cptr, field) #:if rank > 1 slice => field(${dimr[rank]}$, iblk) #:else slice => field(iblk) #:endif end subroutine !------------------------------------------------------------------------------- #:endfor #:endfor #:for rank in ranks #:for dtype,ftype,ctype in types subroutine access_data_${dtype}$_r${rank}$_shape(this, field, shape) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double, c_f_pointer class(atlas_Field), intent(in) :: this ${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$) integer(c_int), intent(in) :: shape(:) type(c_ptr) :: field_cptr type(c_ptr) :: shape_cptr type(c_ptr) :: strides_cptr integer(c_int) :: rank call atlas__Field__data_${ctype}$_specf(this%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr) call c_f_pointer( field_cptr, field, shape ) end subroutine !------------------------------------------------------------------------------- #:endfor #:endfor subroutine dummy(this) use atlas_field_c_binding class(atlas_Field), intent(in) :: this FCKIT_SUPPRESS_UNUSED(this) end subroutine !------------------------------------------------------------------------------- integer function atlas_real(kind) use, intrinsic :: iso_c_binding, only : c_double, c_float @:ENABLE_ATLAS_MACROS() integer :: kind if (kind == c_double) then atlas_real = ATLAS_KIND_REAL64 else if (kind == c_float) then atlas_real = ATLAS_KIND_REAL32 else @:ATLAS_ABORT("Unsupported real kind") end if end function !------------------------------------------------------------------------------- integer function atlas_integer(kind) use, intrinsic :: iso_c_binding, only : c_int, c_long @:ENABLE_ATLAS_MACROS() integer, optional :: kind atlas_integer = ATLAS_KIND_INT32 if ( present(kind) ) then if (kind == c_int) then atlas_integer = ATLAS_KIND_INT32 else if (kind == c_long) then atlas_integer = ATLAS_KIND_INT64 else @:ATLAS_ABORT("Unsupported integer kind") end if end if end function !------------------------------------------------------------------------------- integer function atlas_logical(kind) integer, optional :: kind atlas_logical = ATLAS_KIND_INT32 FCKIT_SUPPRESS_UNUSED(kind) end function !------------------------------------------------------------------------------- function atlas_data_type(kind) @:ENABLE_ATLAS_MACROS() character(len=6) :: atlas_data_type integer, intent(in) :: kind if( kind == ATLAS_KIND_INT32 ) then atlas_data_type = "int32" else if( kind == ATLAS_KIND_INT64 ) then atlas_data_type = "int64" else if( kind == ATLAS_KIND_REAL32 ) then atlas_data_type = "real32" else if( kind == ATLAS_KIND_REAL64 ) then atlas_data_type = "real64" else @:ATLAS_ABORT("cannot convert kind to data_type") endif end function !------------------------------------------------------------------------------- function atlas_Field__cptr(cptr) result(field) use, intrinsic :: iso_c_binding, only : c_ptr type(atlas_Field) :: field type(c_ptr), intent(in) :: cptr call field%reset_c_ptr( cptr ) call field%return() end function !------------------------------------------------------------------------------- function atlas_Field__create(params) result(field) use atlas_field_c_binding type(atlas_Field) :: field class(atlas_Config), intent(in) :: params field = atlas_Field__cptr( atlas__Field__create(params%CPTR_PGIBUG_B) ) call field%return() end function !------------------------------------------------------------------------------- #:for dtype, ftype, ctype in integer_types function atlas_Field__create_name_kind_shape_${dtype}$(name,kind,shape,alignment) result(field) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_int, c_long type(atlas_Field) :: field character(len=*), intent(in) :: name integer(c_int), intent(in) :: kind ${ftype}$, intent(in) :: shape(:) integer(c_int), intent(in), optional :: alignment type(atlas_Config) :: params params = atlas_Config() call params%set("creator","ArraySpec") call params%set("shape",shape) call params%set("fortran",.True.) call params%set("kind",kind) call params%set("name",name) if( present(alignment) ) call params%set("alignment",alignment) field = atlas_Field__cptr( atlas__Field__create(params%CPTR_PGIBUG_B) ) call params%final() call field%return() end function !------------------------------------------------------------------------------- function atlas_Field__create_kind_shape_${dtype}$(kind,shape,alignment) result(field) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_int, c_long type(atlas_Field) :: field integer(c_int), intent(in) :: kind ${ftype}$, intent(in) :: shape(:) integer(c_int), intent(in), optional :: alignment type(atlas_Config) :: params params = atlas_Config() call params%set("creator","ArraySpec") call params%set("shape",shape) call params%set("fortran",.True.) call params%set("kind",kind) if( present(alignment) ) call params%set("alignment",alignment) field = atlas_Field__cptr( atlas__Field__create(params%CPTR_PGIBUG_B) ) call params%final() call field%return() end function #:endfor !------------------------------------------------------------------------------- #:for rank in ranks #:for dtype, ftype, ctype in types function atlas_Field__wrap_name_${dtype}$_r${rank}$(name,data) result(field) use atlas_field_c_binding use fckit_array_module, only : array_strides, array_view1d use, intrinsic :: iso_c_binding, only : c_int, c_long, c_float, c_double, c_loc, c_int32_t, c_sizeof use fckit_c_interop_module, only : c_str, c_ptr_to_loc type(atlas_Field) :: field character(len=*), intent(in) :: name ${ftype}$, intent(in), target :: data(${dim[rank]}$) ${ftype}$, pointer :: data_ptr(${dim[rank]}$) integer(c_int) :: shapef(${rank}$) integer(c_int) :: stridesf(${rank}$) integer(c_int32_t) :: value_size ! bytes of one data value #:if ftype != "logical(4)" ${ftype}$ :: val ! dummy to compute value_size ${ftype}$, pointer :: data1d(:) ! For some reason, with nvhpc/22.11 we need create a pointer to pass to array_view1d ! This is not reproducible all the time. ! Test atlas_fctest_functionspace started failing when fckit was compiled with -Mnotarget_temps (nvidia/22.11) data_ptr => data data1d => array_view1d(data_ptr) #:else ! Case for logical only integer(c_int) :: val ! dummy to compute value_size integer(c_int), pointer :: data1d(:) data_ptr => data data1d => array_view1d( data_ptr, int(0,c_int) ) #:endif value_size = int(c_sizeof(val),c_int32_t) shapef = shape(data) if( size(data)>0 ) then !!! See issue https://github.com/ecmwf/atlas/pull/213 : problem with array_strides(data) with NAG compiler. #:if rank == 4 stridesf = 1 if (ubound(data,1) > 1) stridesf(1) = & int(c_ptr_to_loc(c_loc(data(2,1,1,1)))-c_ptr_to_loc(c_loc(data(1,1,1,1))),c_int32_t)/value_size if (ubound(data,2) > 1) stridesf(2) = & int(c_ptr_to_loc(c_loc(data(1,2,1,1)))-c_ptr_to_loc(c_loc(data(1,1,1,1))),c_int32_t)/value_size if (ubound(data,3) > 1) stridesf(3) = & int(c_ptr_to_loc(c_loc(data(1,1,2,1)))-c_ptr_to_loc(c_loc(data(1,1,1,1))),c_int32_t)/value_size if (ubound(data,4) > 1) stridesf(4) = & int(c_ptr_to_loc(c_loc(data(1,1,1,2)))-c_ptr_to_loc(c_loc(data(1,1,1,1))),c_int32_t)/value_size #:elif rank == 3 stridesf = 1 if (ubound(data,1) > 1) stridesf(1) = & int(c_ptr_to_loc(c_loc(data(2,1,1)))-c_ptr_to_loc(c_loc(data(1,1,1))),c_int32_t)/value_size if (ubound(data,2) > 1) stridesf(2) = & int(c_ptr_to_loc(c_loc(data(1,2,1)))-c_ptr_to_loc(c_loc(data(1,1,1))),c_int32_t)/value_size if (ubound(data,3) > 1) stridesf(3) = & int(c_ptr_to_loc(c_loc(data(1,1,2)))-c_ptr_to_loc(c_loc(data(1,1,1))),c_int32_t)/value_size #:elif rank == 2 stridesf = 1 if (ubound(data,1) > 1) stridesf(1) = & int(c_ptr_to_loc(c_loc(data(2,1)))-c_ptr_to_loc(c_loc(data(1,1))),c_int32_t)/value_size if (ubound(data,2) > 1) stridesf(2) = & int(c_ptr_to_loc(c_loc(data(1,2)))-c_ptr_to_loc(c_loc(data(1,1))),c_int32_t)/value_size #:elif rank == 1 stridesf = 1 if (ubound(data,1) > 1) stridesf(1) = & int(c_ptr_to_loc(c_loc(data(2)))-c_ptr_to_loc(c_loc(data(1))),c_int32_t)/value_size #:else stridesf = array_strides(data) #:endif else stridesf = 0 endif field = atlas_Field__cptr( & atlas__Field__wrap_${ctype}$_specf( c_str(name), data1d, size(shapef), shapef, stridesf ) ) call field%return() end function function atlas_Field__wrap_${dtype}$_r${rank}$(data) result(field) use, intrinsic :: iso_c_binding, only : c_int, c_long, c_float, c_double, c_loc, c_int32_t, c_sizeof use :: fckit_c_interop_module, only : c_str, c_ptr_to_loc use atlas_field_c_binding use fckit_array_module, only : array_strides, array_view1d type(atlas_Field) :: field ${ftype}$, intent(in), target :: data(${dim[rank]}$) ${ftype}$, pointer :: data_ptr(${dim[rank]}$) integer(c_int) :: shapef(${rank}$) integer(c_int) :: stridesf(${rank}$) integer(c_int32_t) :: value_size ! bytes of one data value #:if ftype != "logical(4)" ${ftype}$ :: val ! dummy to compute value_size ${ftype}$, pointer :: data1d(:) data_ptr => data data1d => array_view1d(data_ptr) #:else integer(c_int) :: val ! dummy to compute value_size integer(c_int), pointer :: data1d(:) data_ptr => data data1d => array_view1d( data_ptr, int(0,c_int) ) #:endif value_size = int(c_sizeof(val),c_int32_t) shapef = shape(data) if( size(data)>0 ) then !!! See issue https://github.com/ecmwf/atlas/pull/213 : problem with array_strides(data) with NAG compiler. #:if rank == 4 stridesf = 1 if (ubound(data,1) > 1) stridesf(1) = & int(c_ptr_to_loc(c_loc(data(2,1,1,1)))-c_ptr_to_loc(c_loc(data(1,1,1,1))),c_int32_t)/value_size if (ubound(data,2) > 1) stridesf(2) = & int(c_ptr_to_loc(c_loc(data(1,2,1,1)))-c_ptr_to_loc(c_loc(data(1,1,1,1))),c_int32_t)/value_size if (ubound(data,3) > 1) stridesf(3) = & int(c_ptr_to_loc(c_loc(data(1,1,2,1)))-c_ptr_to_loc(c_loc(data(1,1,1,1))),c_int32_t)/value_size if (ubound(data,4) > 1) stridesf(4) = & int(c_ptr_to_loc(c_loc(data(1,1,1,2)))-c_ptr_to_loc(c_loc(data(1,1,1,1))),c_int32_t)/value_size #:elif rank == 3 stridesf = 1 if (ubound(data,1) > 1) stridesf(1) = & int(c_ptr_to_loc(c_loc(data(2,1,1)))-c_ptr_to_loc(c_loc(data(1,1,1))),c_int32_t)/value_size if (ubound(data,2) > 1) stridesf(2) = & int(c_ptr_to_loc(c_loc(data(1,2,1)))-c_ptr_to_loc(c_loc(data(1,1,1))),c_int32_t)/value_size if (ubound(data,3) > 1) stridesf(3) = & int(c_ptr_to_loc(c_loc(data(1,1,2)))-c_ptr_to_loc(c_loc(data(1,1,1))),c_int32_t)/value_size #:elif rank == 2 stridesf = 1 if (ubound(data,1) > 1) stridesf(1) = & int(c_ptr_to_loc(c_loc(data(2,1)))-c_ptr_to_loc(c_loc(data(1,1))),c_int32_t)/value_size if (ubound(data,2) > 1) stridesf(2) = & int(c_ptr_to_loc(c_loc(data(1,2)))-c_ptr_to_loc(c_loc(data(1,1))),c_int32_t)/value_size #:elif rank == 1 stridesf = 1 if (ubound(data,1) > 1) stridesf(1) = & int(c_ptr_to_loc(c_loc(data(2)))-c_ptr_to_loc(c_loc(data(1))),c_int32_t)/value_size #:else stridesf = array_strides(data) #:endif else stridesf = 0 endif field = atlas_Field__cptr( & atlas__Field__wrap_${ctype}$_specf( c_str(""),data1d,size(shapef),shapef, stridesf) ) call field%return() end function #:endfor #:endfor !------------------------------------------------------------------------------- function Field__name(this) result(field_name) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr use fckit_c_interop_module, only : c_ptr_to_string, c_str class(atlas_Field), intent(in) :: this character(len=:), allocatable :: field_name type(c_ptr) :: field_name_c_str field_name_c_str = atlas__Field__name(this%CPTR_PGIBUG_A) field_name = c_ptr_to_string(field_name_c_str) end function Field__name !------------------------------------------------------------------------------- function Field__functionspace(this) result(functionspace) use atlas_field_c_binding type(fckit_owned_object) :: functionspace class(atlas_Field), intent(in) :: this call functionspace%reset_c_ptr( atlas__Field__functionspace(this%CPTR_PGIBUG_A) ) call functionspace%return() end function Field__functionspace !------------------------------------------------------------------------------- function Field__datatype(this) result(datatype) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr, c_int use fckit_c_interop_module, only : c_ptr_free, c_ptr_to_string class(atlas_Field), intent(in) :: this character(len=:), allocatable :: datatype type(c_ptr) :: datatype_cptr integer(c_int) :: datatype_size integer(c_int) :: datatype_allocated call atlas__Field__datatype(this%CPTR_PGIBUG_A,datatype_cptr,datatype_size,datatype_allocated) allocate(character(len=datatype_size) :: datatype ) datatype= c_ptr_to_string(datatype_cptr) if( datatype_allocated == 1 ) call c_ptr_free(datatype_cptr) end function Field__datatype !------------------------------------------------------------------------------- function Field__size(this) result(fieldsize) use atlas_field_c_binding class(atlas_Field), intent(in) :: this integer :: fieldsize fieldsize = atlas__Field__size(this%CPTR_PGIBUG_A) end function Field__size !------------------------------------------------------------------------------- function Field__rank(this) result(rank) use atlas_field_c_binding class(atlas_Field), intent(in) :: this integer :: rank rank = atlas__Field__rank(this%CPTR_PGIBUG_A) end function Field__rank !------------------------------------------------------------------------------- function Field__bytes(this) result(bytes) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_double class(atlas_Field), intent(in) :: this real(c_double) :: bytes bytes = atlas__Field__bytes(this%CPTR_PGIBUG_A) end function Field__bytes !------------------------------------------------------------------------------- function Field__kind(this) result(kind) use atlas_field_c_binding class(atlas_Field), intent(in) :: this integer :: kind kind = atlas__Field__kind(this%CPTR_PGIBUG_A) end function Field__kind !------------------------------------------------------------------------------- function Field__levels(this) result(levels) use atlas_field_c_binding class(atlas_Field), intent(in) :: this integer :: levels levels = atlas__Field__levels(this%CPTR_PGIBUG_A) end function Field__levels !------------------------------------------------------------------------------- function Field__metadata(this) result(metadata) use atlas_field_c_binding use atlas_metadata_module class(atlas_Field), intent(in) :: this type(atlas_Metadata) :: Metadata call metadata%reset_c_ptr( atlas__Field__metadata(this%CPTR_PGIBUG_A) ) end function Field__metadata !------------------------------------------------------------------------------- function Field__shape_array(this) result(shape) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_f_pointer class(atlas_Field), intent(in) :: this integer, allocatable :: shape(:) type(c_ptr) :: shape_c_ptr integer, pointer :: shape_f_ptr(:) integer(c_int) :: field_rank call atlas__Field__shapef(this%CPTR_PGIBUG_A, shape_c_ptr, field_rank) call c_f_pointer ( shape_c_ptr , shape_f_ptr , (/field_rank/) ) allocate( shape(field_rank) ) shape(:) = shape_f_ptr(:) end function Field__shape_array !------------------------------------------------------------------------------- function Field__shape_idx(this,idx) result(shape_val) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_f_pointer @:ENABLE_ATLAS_MACROS() integer :: shape_val class(atlas_Field), intent(in) :: this integer, intent(in) :: idx type(c_ptr) :: shape_c_ptr integer, pointer :: shape_f_ptr(:) integer(c_int) :: field_rank call atlas__Field__shapef(this%CPTR_PGIBUG_A, shape_c_ptr, field_rank) call c_f_pointer ( shape_c_ptr , shape_f_ptr , (/field_rank/) ) @:ATLAS_ASSERT( idx <= field_rank ) shape_val = shape_f_ptr(idx) end function Field__shape_idx !------------------------------------------------------------------------------- function Field__strides_array(this) result(strides) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_f_pointer class(atlas_Field), intent(in) :: this integer, allocatable :: strides(:) type(c_ptr) :: strides_c_ptr integer, pointer :: strides_f_ptr(:) integer(c_int) :: field_rank call atlas__Field__stridesf(this%CPTR_PGIBUG_A, strides_c_ptr, field_rank) call c_f_pointer ( strides_c_ptr , strides_f_ptr , (/field_rank/) ) allocate( strides(field_rank) ) strides(:) = strides_f_ptr(:) end function !------------------------------------------------------------------------------- function Field__strides_idx(this,idx) result(strides_val) use atlas_field_c_binding use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_f_pointer @:ENABLE_ATLAS_MACROS() integer :: strides_val class(atlas_Field), intent(in) :: this integer, intent(in) :: idx type(c_ptr) :: strides_c_ptr integer, pointer :: strides_f_ptr(:) integer(c_int) :: field_rank call atlas__Field__stridesf(this%CPTR_PGIBUG_A, strides_c_ptr, field_rank) call c_f_pointer ( strides_c_ptr , strides_f_ptr , (/field_rank/) ) @:ATLAS_ASSERT( idx <= field_rank ) strides_val = strides_f_ptr(idx) end function !------------------------------------------------------------------------------- subroutine set_levels(this,nb_levels) use atlas_field_c_binding class(atlas_Field), intent(inout) :: this integer, intent(in) :: nb_levels call atlas__field__set_levels(this%CPTR_PGIBUG_A,nb_levels) end subroutine !------------------------------------------------------------------------------- subroutine rename_(this,name) use atlas_field_c_binding use fckit_c_interop_module, only : c_str class(atlas_Field), intent(inout) :: this character(len=*), intent(in) :: name call atlas__field__rename(this%CPTR_PGIBUG_A,c_str(name)) end subroutine !------------------------------------------------------------------------------- subroutine set_functionspace(this,functionspace) use atlas_field_c_binding class(atlas_Field), intent(inout) :: this class(fckit_owned_object), intent(in) :: functionspace call atlas__field__set_functionspace(this%CPTR_PGIBUG_A,functionspace%CPTR_PGIBUG_A) end subroutine !------------------------------------------------------------------------------- subroutine set_host_needs_update(this,value) use atlas_field_c_binding class(atlas_Field), intent(in) :: this logical, optional, intent(in) :: value integer :: value_int value_int = 1 if (present(value)) then if (.not. value) then value_int = 0 endif endif call atlas__field__set_host_needs_update(this%CPTR_PGIBUG_A,value_int) end subroutine !------------------------------------------------------------------------------- subroutine set_device_needs_update(this,value) use atlas_field_c_binding class(atlas_Field), intent(in) :: this logical, optional, intent(in) :: value integer :: value_int value_int = 1 if (present(value)) then if (.not. value) then value_int = 0 endif endif call atlas__field__set_device_needs_update(this%CPTR_PGIBUG_A,value_int) end subroutine !------------------------------------------------------------------------------- function host_needs_update(this) use atlas_field_c_binding logical :: host_needs_update class(atlas_Field), intent(in) :: this if( atlas__Field__host_needs_update(this%CPTR_PGIBUG_A) == 1 ) then host_needs_update = .true. else host_needs_update = .false. endif end function !------------------------------------------------------------------------------- function device_needs_update(this) use atlas_field_c_binding logical :: device_needs_update class(atlas_Field), intent(in) :: this if( atlas__Field__device_needs_update(this%CPTR_PGIBUG_A) == 1 ) then device_needs_update = .true. else device_needs_update = .false. endif end function !------------------------------------------------------------------------------- subroutine update_device(this) use atlas_field_c_binding class(atlas_Field), intent(inout) :: this call atlas__Field__update_device(this%CPTR_PGIBUG_A) end subroutine !------------------------------------------------------------------------------- subroutine update_host(this) use atlas_field_c_binding class(atlas_Field), intent(inout) :: this call atlas__Field__update_host(this%CPTR_PGIBUG_A) end subroutine !------------------------------------------------------------------------------- subroutine sync_host_device(this) use atlas_field_c_binding class(atlas_Field), intent(inout) :: this call atlas__Field__sync_host_device(this%CPTR_PGIBUG_A) end subroutine !------------------------------------------------------------------------------- subroutine sync_host(this) use atlas_field_c_binding class(atlas_Field), intent(inout) :: this call atlas__Field__sync_host(this%CPTR_PGIBUG_A) end subroutine !------------------------------------------------------------------------------- subroutine sync_device(this) use atlas_field_c_binding class(atlas_Field), intent(inout) :: this call atlas__Field__sync_device(this%CPTR_PGIBUG_A) end subroutine !------------------------------------------------------------------------------- subroutine allocate_device(this) use atlas_field_c_binding class(atlas_Field), intent(inout) :: this call atlas__Field__allocate_device(this%CPTR_PGIBUG_A) end subroutine !------------------------------------------------------------------------------- subroutine deallocate_device(this) use atlas_field_c_binding class(atlas_Field), intent(inout) :: this call atlas__Field__deallocate_device(this%CPTR_PGIBUG_A) end subroutine !------------------------------------------------------------------------------- function device_allocated(this) use atlas_field_c_binding logical :: device_allocated class(atlas_Field), intent(in) :: this if( atlas__Field__device_allocated(this%CPTR_PGIBUG_A) == 1 ) then device_allocated = .true. else device_allocated = .false. endif end function !------------------------------------------------------------------------------- subroutine halo_exchange(this,on_device) use, intrinsic :: iso_c_binding, only : c_int use atlas_field_c_binding class(atlas_Field), intent(in) :: this logical, optional :: on_device integer(c_int) :: on_device_int on_device_int = 0 if( present(on_device) ) then if( on_device ) on_device_int = 1 endif call atlas__Field__halo_exchange(this%CPTR_PGIBUG_A, on_device_int) end subroutine !------------------------------------------------------------------------------- subroutine set_dirty(this,value) use, intrinsic :: iso_c_binding, only : c_int use atlas_field_c_binding class(atlas_Field), intent(in) :: this logical, optional, intent(in) :: value integer(c_int) :: value_int if( present(value) ) then if( value ) then value_int = 1 else value_int = 0 endif else value_int = 1 endif call atlas__Field__set_dirty(this%CPTR_PGIBUG_A, value_int) end subroutine !------------------------------------------------------------------------------- function dirty(this) result(value) use, intrinsic :: iso_c_binding, only : c_int use atlas_field_c_binding class(atlas_Field), intent(inout) :: this logical :: value integer(c_int) :: value_int value_int = atlas__Field__dirty(this%CPTR_PGIBUG_A) if( value_int == 0 ) then value = .false. else value = .true. endif end function !------------------------------------------------------------------------------- function contiguous(this) use atlas_field_c_binding logical :: contiguous class(atlas_Field), intent(in) :: this if( atlas__Field__contiguous(this%CPTR_PGIBUG_A) == 1 ) then contiguous = .true. else contiguous = .false. endif end function !------------------------------------------------------------------------------- #if FCKIT_FINAL_NOT_INHERITING ATLAS_FINAL subroutine atlas_Field__final_auto(this) type(atlas_Field), intent(inout) :: this #if FCKIT_FINAL_DEBUGGING write(0,*) "atlas_Field__final_auto" #endif #if FCKIT_FINAL_NOT_PROPAGATING call this%final() #endif FCKIT_SUPPRESS_UNUSED( this ) end subroutine #endif !------------------------------------------------------------------------------- end module atlas_field_module