| 1 |
! (C) Copyright 2013 ECMWF. |
| 2 |
! |
| 3 |
! This software is licensed under the terms of the Apache Licence Version 2.0 |
| 4 |
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 5 |
! In applying this licence, ECMWF does not waive the privileges and immunities |
| 6 |
! granted to it by virtue of its status as an intergovernmental organisation nor |
| 7 |
! does it submit to any jurisdiction. |
| 8 |
|
| 9 |
#include "atlas/atlas_f.h" |
| 10 |
|
| 11 |
#:include "atlas/atlas_f.fypp" |
| 12 |
#:include "internals/atlas_generics.fypp" |
| 13 |
|
| 14 |
module atlas_field_module |
| 15 |
|
| 16 |
use fckit_owned_object_module, only : fckit_owned_object |
| 17 |
use atlas_Config_module, only: atlas_Config |
| 18 |
|
| 19 |
implicit none |
| 20 |
|
| 21 |
public :: atlas_Field |
| 22 |
public :: atlas_real |
| 23 |
public :: atlas_integer |
| 24 |
public :: atlas_logical |
| 25 |
public :: atlas_data_type |
| 26 |
public :: array_c_to_f |
| 27 |
|
| 28 |
private |
| 29 |
|
| 30 |
!------------------------------------------------------------------------------ |
| 31 |
TYPE, extends(fckit_owned_object) :: atlas_Field |
| 32 |
|
| 33 |
! Purpose : |
| 34 |
! ------- |
| 35 |
! *Field* : Object containing field data and Metadata |
| 36 |
|
| 37 |
! Methods : |
| 38 |
! ------- |
| 39 |
! name : The name or tag this field was created with |
| 40 |
! data : Return the field as a fortran array of specified shape |
| 41 |
! Metadata : Return object that can contain a variety of Metadata |
| 42 |
|
| 43 |
! Author : |
| 44 |
! ------ |
| 45 |
! 20-Nov-2013 Willem Deconinck *ECMWF* |
| 46 |
|
| 47 |
!------------------------------------------------------------------------------ |
| 48 |
contains |
| 49 |
procedure :: name => Field__name |
| 50 |
procedure :: functionspace => Field__functionspace |
| 51 |
procedure :: datatype => Field__datatype |
| 52 |
procedure :: metadata => Field__metadata |
| 53 |
procedure, private :: shape_array => Field__shape_array |
| 54 |
procedure, private :: shape_idx => Field__shape_idx |
| 55 |
procedure :: size => Field__size |
| 56 |
procedure :: rank => Field__rank |
| 57 |
procedure :: bytes => Field__bytes |
| 58 |
procedure :: levels => Field__levels |
| 59 |
procedure :: kind => Field__kind |
| 60 |
generic :: shape => shape_array, shape_idx |
| 61 |
procedure :: contiguous |
| 62 |
procedure, public :: strides_array => Field__strides_array |
| 63 |
procedure, public :: strides_idx => Field__strides_idx |
| 64 |
generic :: strides => strides_array, strides_idx |
| 65 |
generic :: stride => strides_idx |
| 66 |
|
| 67 |
procedure :: halo_exchange |
| 68 |
procedure :: dirty |
| 69 |
procedure :: set_dirty |
| 70 |
|
| 71 |
procedure :: rename => rename_ |
| 72 |
procedure :: set_levels |
| 73 |
procedure :: set_functionspace |
| 74 |
|
| 75 |
#:for rank in ranks |
| 76 |
#:for dtype in dtypes |
| 77 |
procedure, private :: access_data_${dtype}$_r${rank}$ |
| 78 |
procedure, private :: access_device_data_${dtype}$_r${rank}$ |
| 79 |
procedure, private :: access_data_${dtype}$_r${rank}$_shape |
| 80 |
procedure, private :: access_data_${dtype}$_r${rank}$_slice |
| 81 |
#:endfor |
| 82 |
#:endfor |
| 83 |
|
| 84 |
generic, public :: data => & |
| 85 |
#:for rank in ranks |
| 86 |
#:for dtype in dtypes |
| 87 |
& access_data_${dtype}$_r${rank}$, & |
| 88 |
& access_data_${dtype}$_r${rank}$_shape, & |
| 89 |
& access_data_${dtype}$_r${rank}$_slice, & |
| 90 |
#:endfor |
| 91 |
#:endfor |
| 92 |
& dummy |
| 93 |
|
| 94 |
generic, public :: device_data => & |
| 95 |
#:for rank in ranks |
| 96 |
#:for dtype in dtypes |
| 97 |
& access_device_data_${dtype}$_r${rank}$, & |
| 98 |
#:endfor |
| 99 |
#:endfor |
| 100 |
& dummy |
| 101 |
|
| 102 |
procedure, public :: device_allocated |
| 103 |
procedure, public :: allocate_device |
| 104 |
procedure, public :: deallocate_device |
| 105 |
procedure, public :: set_host_needs_update |
| 106 |
procedure, public :: set_device_needs_update |
| 107 |
procedure, public :: host_needs_update |
| 108 |
procedure, public :: device_needs_update |
| 109 |
procedure, public :: update_device |
| 110 |
procedure, public :: update_host |
| 111 |
procedure, public :: sync_host_device |
| 112 |
procedure, public :: sync_host |
| 113 |
procedure, public :: sync_device |
| 114 |
|
| 115 |
procedure, private :: dummy |
| 116 |
|
| 117 |
#if FCKIT_FINAL_NOT_INHERITING |
| 118 |
final :: atlas_Field__final_auto |
| 119 |
#endif |
| 120 |
|
| 121 |
END TYPE |
| 122 |
|
| 123 |
interface atlas_Field |
| 124 |
module procedure atlas_Field__cptr |
| 125 |
module procedure atlas_Field__create |
| 126 |
#:for dtype in integer_dtypes |
| 127 |
module procedure atlas_Field__create_name_kind_shape_${dtype}$ |
| 128 |
module procedure atlas_Field__create_kind_shape_${dtype}$ |
| 129 |
#:endfor |
| 130 |
|
| 131 |
#:for rank in ranks |
| 132 |
#:for dtype in dtypes |
| 133 |
module procedure atlas_Field__wrap_${dtype}$_r${rank}$ |
| 134 |
module procedure atlas_Field__wrap_name_${dtype}$_r${rank}$ |
| 135 |
#:endfor |
| 136 |
#:endfor |
| 137 |
end interface |
| 138 |
|
| 139 |
! ---------------------------------------------------- |
| 140 |
! ENUM DataType |
| 141 |
integer, private, parameter :: ATLAS_KIND_INT32 = -4 |
| 142 |
integer, private, parameter :: ATLAS_KIND_INT64 = -8 |
| 143 |
integer, private, parameter :: ATLAS_KIND_REAL32 = 4 |
| 144 |
integer, private, parameter :: ATLAS_KIND_REAL64 = 8 |
| 145 |
! ---------------------------------------------------- |
| 146 |
|
| 147 |
|
| 148 |
interface array_c_to_f |
| 149 |
#:for rank in ranks |
| 150 |
#:for dtype in dtypes |
| 151 |
module procedure array_c_to_f_${dtype}$_r${rank}$ |
| 152 |
#:endfor |
| 153 |
#:endfor |
| 154 |
end interface |
| 155 |
!------------------------------------------------------------------------------- |
| 156 |
|
| 157 |
private :: fckit_owned_object |
| 158 |
private :: atlas_Config |
| 159 |
|
| 160 |
!======================================================== |
| 161 |
contains |
| 162 |
!======================================================== |
| 163 |
|
| 164 |
#:for rank in ranks |
| 165 |
#:for dtype,ftype,ctype in types |
| 166 |
!------------------------------------------------------------------------------- |
| 167 |
subroutine array_c_to_f_${dtype}$_r${rank}$(array_cptr,rank,shape_cptr,strides_cptr,array_fptr) |
| 168 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_double, c_long, c_float, c_f_pointer |
| 169 |
@:ENABLE_ATLAS_MACROS() |
| 170 |
type(c_ptr), intent(in) :: array_cptr |
| 171 |
integer(c_int), intent(in) :: rank |
| 172 |
type(c_ptr), intent(in) :: shape_cptr |
| 173 |
type(c_ptr), intent(in) :: strides_cptr |
| 174 |
${ftype}$, pointer, intent(inout) :: array_fptr(${dim[rank]}$) |
| 175 |
${ftype}$, pointer :: tmp(${dim[rank]}$) |
| 176 |
integer, pointer :: shape(:) |
| 177 |
integer, pointer :: strides(:) |
| 178 |
integer :: eshape(${rank}$) |
| 179 |
integer :: j |
| 180 |
|
| 181 |
if( rank /= ${rank}$ ) then |
| 182 |
write(0,*) rank, "!=", ${rank}$ |
| 183 |
@:ATLAS_ABORT("Rank mismatch") |
| 184 |
endif |
| 185 |
|
| 186 |
call c_f_pointer ( shape_cptr, shape , [rank] ) |
| 187 |
call c_f_pointer ( strides_cptr, strides , [rank] ) |
| 188 |
do j=1,rank-1 |
| 189 |
if( strides(j) /= 0 ) then |
| 190 |
eshape(j) = strides(j+1)/strides(j) |
| 191 |
else |
| 192 |
eshape(j) = shape(j) |
| 193 |
endif |
| 194 |
enddo |
| 195 |
eshape(rank) = shape(rank) |
| 196 |
call c_f_pointer ( array_cptr , tmp , shape=eshape ) |
| 197 |
if (associated(tmp)) then |
| 198 |
#{if rank == 1}# array_fptr => tmp(1:shape(1)) #{endif}# |
| 199 |
#{if rank == 2}# array_fptr => tmp(1:shape(1),1:shape(2)) #{endif}# |
| 200 |
#{if rank == 3}# array_fptr => tmp(1:shape(1),1:shape(2),1:shape(3)) #{endif}# |
| 201 |
#{if rank == 4}# array_fptr => tmp(1:shape(1),1:shape(2),1:shape(3),1:shape(4)) #{endif}# |
| 202 |
else |
| 203 |
#{if rank == 1}# allocate(array_fptr(0)) #{endif}# |
| 204 |
#{if rank == 2}# allocate(array_fptr(0,0)) #{endif}# |
| 205 |
#{if rank == 3}# allocate(array_fptr(0,0,0)) #{endif}# |
| 206 |
#{if rank == 4}# allocate(array_fptr(0,0,0,0)) #{endif}# |
| 207 |
endif |
| 208 |
end subroutine |
| 209 |
|
| 210 |
!------------------------------------------------------------------------------- |
| 211 |
|
| 212 |
#:endfor |
| 213 |
#:endfor |
| 214 |
#:for rank in ranks |
| 215 |
#:for dtype,ftype,ctype in types |
| 216 |
subroutine access_data_${dtype}$_r${rank}$(this, field) |
| 217 |
use atlas_field_c_binding |
| 218 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double |
| 219 |
class(atlas_Field), intent(in) :: this |
| 220 |
${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$) |
| 221 |
type(c_ptr) :: field_cptr |
| 222 |
type(c_ptr) :: shape_cptr |
| 223 |
type(c_ptr) :: strides_cptr |
| 224 |
integer(c_int) :: rank |
| 225 |
call atlas__Field__data_${ctype}$_specf(this%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr) |
| 226 |
call array_c_to_f(field_cptr,rank,shape_cptr,strides_cptr, field) |
| 227 |
end subroutine |
| 228 |
|
| 229 |
subroutine access_device_data_${dtype}$_r${rank}$(this, field) |
| 230 |
use atlas_field_c_binding |
| 231 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double |
| 232 |
class(atlas_Field), intent(in) :: this |
| 233 |
${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$) |
| 234 |
type(c_ptr) :: field_cptr |
| 235 |
type(c_ptr) :: shape_cptr |
| 236 |
type(c_ptr) :: strides_cptr |
| 237 |
integer(c_int) :: rank |
| 238 |
call atlas__Field__device_data_${ctype}$_specf(this%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr) |
| 239 |
call array_c_to_f(field_cptr,rank,shape_cptr,strides_cptr, field) |
| 240 |
end subroutine |
| 241 |
|
| 242 |
subroutine access_data_${dtype}$_r${rank}$_slice(this, slice, iblk) |
| 243 |
use atlas_field_c_binding |
| 244 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double |
| 245 |
class(atlas_Field), intent(in) :: this |
| 246 |
${ftype}$, pointer :: field(${dim[rank]}$) |
| 247 |
#:if rank > 1 |
| 248 |
${ftype}$, pointer, intent(inout) :: slice(${dimr[rank]}$) |
| 249 |
#:else |
| 250 |
${ftype}$, pointer, intent(inout) :: slice |
| 251 |
#:endif |
| 252 |
integer, intent(in) :: iblk |
| 253 |
type(c_ptr) :: field_cptr |
| 254 |
type(c_ptr) :: shape_cptr |
| 255 |
type(c_ptr) :: strides_cptr |
| 256 |
integer(c_int) :: rank |
| 257 |
call atlas__Field__data_${ctype}$_specf(this%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr) |
| 258 |
call array_c_to_f(field_cptr, rank, shape_cptr, strides_cptr, field) |
| 259 |
#:if rank > 1 |
| 260 |
slice => field(${dimr[rank]}$, iblk) |
| 261 |
#:else |
| 262 |
slice => field(iblk) |
| 263 |
#:endif |
| 264 |
end subroutine |
| 265 |
|
| 266 |
!------------------------------------------------------------------------------- |
| 267 |
|
| 268 |
#:endfor |
| 269 |
#:endfor |
| 270 |
#:for rank in ranks |
| 271 |
#:for dtype,ftype,ctype in types |
| 272 |
subroutine access_data_${dtype}$_r${rank}$_shape(this, field, shape) |
| 273 |
use atlas_field_c_binding |
| 274 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double, c_f_pointer |
| 275 |
class(atlas_Field), intent(in) :: this |
| 276 |
${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$) |
| 277 |
integer(c_int), intent(in) :: shape(:) |
| 278 |
type(c_ptr) :: field_cptr |
| 279 |
type(c_ptr) :: shape_cptr |
| 280 |
type(c_ptr) :: strides_cptr |
| 281 |
integer(c_int) :: rank |
| 282 |
call atlas__Field__data_${ctype}$_specf(this%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr) |
| 283 |
call c_f_pointer( field_cptr, field, shape ) |
| 284 |
end subroutine |
| 285 |
|
| 286 |
!------------------------------------------------------------------------------- |
| 287 |
#:endfor |
| 288 |
#:endfor |
| 289 |
subroutine dummy(this) |
| 290 |
use atlas_field_c_binding |
| 291 |
class(atlas_Field), intent(in) :: this |
| 292 |
FCKIT_SUPPRESS_UNUSED(this) |
| 293 |
end subroutine |
| 294 |
|
| 295 |
!------------------------------------------------------------------------------- |
| 296 |
|
| 297 |
integer function atlas_real(kind) |
| 298 |
use, intrinsic :: iso_c_binding, only : c_double, c_float |
| 299 |
@:ENABLE_ATLAS_MACROS() |
| 300 |
integer :: kind |
| 301 |
if (kind == c_double) then |
| 302 |
atlas_real = ATLAS_KIND_REAL64 |
| 303 |
else if (kind == c_float) then |
| 304 |
atlas_real = ATLAS_KIND_REAL32 |
| 305 |
else |
| 306 |
@:ATLAS_ABORT("Unsupported real kind") |
| 307 |
end if |
| 308 |
end function |
| 309 |
|
| 310 |
!------------------------------------------------------------------------------- |
| 311 |
|
| 312 |
integer function atlas_integer(kind) |
| 313 |
use, intrinsic :: iso_c_binding, only : c_int, c_long |
| 314 |
@:ENABLE_ATLAS_MACROS() |
| 315 |
integer, optional :: kind |
| 316 |
atlas_integer = ATLAS_KIND_INT32 |
| 317 |
if ( present(kind) ) then |
| 318 |
if (kind == c_int) then |
| 319 |
atlas_integer = ATLAS_KIND_INT32 |
| 320 |
else if (kind == c_long) then |
| 321 |
atlas_integer = ATLAS_KIND_INT64 |
| 322 |
else |
| 323 |
@:ATLAS_ABORT("Unsupported integer kind") |
| 324 |
end if |
| 325 |
end if |
| 326 |
end function |
| 327 |
|
| 328 |
!------------------------------------------------------------------------------- |
| 329 |
|
| 330 |
integer function atlas_logical(kind) |
| 331 |
integer, optional :: kind |
| 332 |
atlas_logical = ATLAS_KIND_INT32 |
| 333 |
FCKIT_SUPPRESS_UNUSED(kind) |
| 334 |
end function |
| 335 |
|
| 336 |
!------------------------------------------------------------------------------- |
| 337 |
|
| 338 |
function atlas_data_type(kind) |
| 339 |
@:ENABLE_ATLAS_MACROS() |
| 340 |
character(len=6) :: atlas_data_type |
| 341 |
integer, intent(in) :: kind |
| 342 |
if( kind == ATLAS_KIND_INT32 ) then |
| 343 |
atlas_data_type = "int32" |
| 344 |
else if( kind == ATLAS_KIND_INT64 ) then |
| 345 |
atlas_data_type = "int64" |
| 346 |
else if( kind == ATLAS_KIND_REAL32 ) then |
| 347 |
atlas_data_type = "real32" |
| 348 |
else if( kind == ATLAS_KIND_REAL64 ) then |
| 349 |
atlas_data_type = "real64" |
| 350 |
else |
| 351 |
@:ATLAS_ABORT("cannot convert kind to data_type") |
| 352 |
endif |
| 353 |
end function |
| 354 |
|
| 355 |
!------------------------------------------------------------------------------- |
| 356 |
|
| 357 |
function atlas_Field__cptr(cptr) result(field) |
| 358 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 359 |
type(atlas_Field) :: field |
| 360 |
type(c_ptr), intent(in) :: cptr |
| 361 |
call field%reset_c_ptr( cptr ) |
| 362 |
call field%return() |
| 363 |
end function |
| 364 |
|
| 365 |
!------------------------------------------------------------------------------- |
| 366 |
|
| 367 |
function atlas_Field__create(params) result(field) |
| 368 |
use atlas_field_c_binding |
| 369 |
type(atlas_Field) :: field |
| 370 |
class(atlas_Config), intent(in) :: params |
| 371 |
field = atlas_Field__cptr( atlas__Field__create(params%CPTR_PGIBUG_B) ) |
| 372 |
call field%return() |
| 373 |
end function |
| 374 |
|
| 375 |
!------------------------------------------------------------------------------- |
| 376 |
|
| 377 |
#:for dtype, ftype, ctype in integer_types |
| 378 |
function atlas_Field__create_name_kind_shape_${dtype}$(name,kind,shape,alignment) result(field) |
| 379 |
use atlas_field_c_binding |
| 380 |
use, intrinsic :: iso_c_binding, only : c_int, c_long |
| 381 |
type(atlas_Field) :: field |
| 382 |
character(len=*), intent(in) :: name |
| 383 |
integer(c_int), intent(in) :: kind |
| 384 |
${ftype}$, intent(in) :: shape(:) |
| 385 |
integer(c_int), intent(in), optional :: alignment |
| 386 |
|
| 387 |
type(atlas_Config) :: params |
| 388 |
|
| 389 |
params = atlas_Config() |
| 390 |
call params%set("creator","ArraySpec") |
| 391 |
call params%set("shape",shape) |
| 392 |
call params%set("fortran",.True.) |
| 393 |
call params%set("kind",kind) |
| 394 |
call params%set("name",name) |
| 395 |
if( present(alignment) ) call params%set("alignment",alignment) |
| 396 |
|
| 397 |
field = atlas_Field__cptr( atlas__Field__create(params%CPTR_PGIBUG_B) ) |
| 398 |
call params%final() |
| 399 |
call field%return() |
| 400 |
end function |
| 401 |
|
| 402 |
!------------------------------------------------------------------------------- |
| 403 |
|
| 404 |
function atlas_Field__create_kind_shape_${dtype}$(kind,shape,alignment) result(field) |
| 405 |
use atlas_field_c_binding |
| 406 |
use, intrinsic :: iso_c_binding, only : c_int, c_long |
| 407 |
type(atlas_Field) :: field |
| 408 |
integer(c_int), intent(in) :: kind |
| 409 |
${ftype}$, intent(in) :: shape(:) |
| 410 |
integer(c_int), intent(in), optional :: alignment |
| 411 |
|
| 412 |
type(atlas_Config) :: params |
| 413 |
|
| 414 |
params = atlas_Config() |
| 415 |
call params%set("creator","ArraySpec") |
| 416 |
call params%set("shape",shape) |
| 417 |
call params%set("fortran",.True.) |
| 418 |
call params%set("kind",kind) |
| 419 |
if( present(alignment) ) call params%set("alignment",alignment) |
| 420 |
|
| 421 |
field = atlas_Field__cptr( atlas__Field__create(params%CPTR_PGIBUG_B) ) |
| 422 |
call params%final() |
| 423 |
call field%return() |
| 424 |
end function |
| 425 |
#:endfor |
| 426 |
|
| 427 |
!------------------------------------------------------------------------------- |
| 428 |
|
| 429 |
#:for rank in ranks |
| 430 |
#:for dtype, ftype, ctype in types |
| 431 |
function atlas_Field__wrap_name_${dtype}$_r${rank}$(name,data) result(field) |
| 432 |
use atlas_field_c_binding |
| 433 |
use fckit_array_module, only : array_strides, array_view1d |
| 434 |
use, intrinsic :: iso_c_binding, only : c_int, c_long, c_float, c_double, c_loc, c_int32_t, c_sizeof |
| 435 |
use fckit_c_interop_module, only : c_str, c_ptr_to_loc |
| 436 |
type(atlas_Field) :: field |
| 437 |
character(len=*), intent(in) :: name |
| 438 |
${ftype}$, intent(in), target :: data(${dim[rank]}$) |
| 439 |
${ftype}$, pointer :: data_ptr(${dim[rank]}$) |
| 440 |
integer(c_int) :: shapef(${rank}$) |
| 441 |
integer(c_int) :: stridesf(${rank}$) |
| 442 |
integer(c_int32_t) :: value_size ! bytes of one data value |
| 443 |
#:if ftype != "logical(4)" |
| 444 |
${ftype}$ :: val ! dummy to compute value_size |
| 445 |
${ftype}$, pointer :: data1d(:) |
| 446 |
! For some reason, with nvhpc/22.11 we need create a pointer to pass to array_view1d |
| 447 |
! This is not reproducible all the time. |
| 448 |
! Test atlas_fctest_functionspace started failing when fckit was compiled with -Mnotarget_temps (nvidia/22.11) |
| 449 |
data_ptr => data |
| 450 |
data1d => array_view1d(data_ptr) |
| 451 |
#:else |
| 452 |
! Case for logical only |
| 453 |
integer(c_int) :: val ! dummy to compute value_size |
| 454 |
integer(c_int), pointer :: data1d(:) |
| 455 |
data_ptr => data |
| 456 |
data1d => array_view1d( data_ptr, int(0,c_int) ) |
| 457 |
#:endif |
| 458 |
value_size = int(c_sizeof(val),c_int32_t) |
| 459 |
shapef = shape(data) |
| 460 |
if( size(data)>0 ) then |
| 461 |
!!! See issue https://github.com/ecmwf/atlas/pull/213 : problem with array_strides(data) with NAG compiler. |
| 462 |
#:if rank == 4 |
| 463 |
stridesf = 1 |
| 464 |
if (ubound(data,1) > 1) stridesf(1) = & |
| 465 |
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 |
| 466 |
if (ubound(data,2) > 1) stridesf(2) = & |
| 467 |
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 |
| 468 |
if (ubound(data,3) > 1) stridesf(3) = & |
| 469 |
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 |
| 470 |
if (ubound(data,4) > 1) stridesf(4) = & |
| 471 |
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 |
| 472 |
#:elif rank == 3 |
| 473 |
stridesf = 1 |
| 474 |
if (ubound(data,1) > 1) stridesf(1) = & |
| 475 |
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 |
| 476 |
if (ubound(data,2) > 1) stridesf(2) = & |
| 477 |
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 |
| 478 |
if (ubound(data,3) > 1) stridesf(3) = & |
| 479 |
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 |
| 480 |
#:elif rank == 2 |
| 481 |
stridesf = 1 |
| 482 |
if (ubound(data,1) > 1) stridesf(1) = & |
| 483 |
int(c_ptr_to_loc(c_loc(data(2,1)))-c_ptr_to_loc(c_loc(data(1,1))),c_int32_t)/value_size |
| 484 |
if (ubound(data,2) > 1) stridesf(2) = & |
| 485 |
int(c_ptr_to_loc(c_loc(data(1,2)))-c_ptr_to_loc(c_loc(data(1,1))),c_int32_t)/value_size |
| 486 |
#:elif rank == 1 |
| 487 |
stridesf = 1 |
| 488 |
if (ubound(data,1) > 1) stridesf(1) = & |
| 489 |
int(c_ptr_to_loc(c_loc(data(2)))-c_ptr_to_loc(c_loc(data(1))),c_int32_t)/value_size |
| 490 |
#:else |
| 491 |
stridesf = array_strides(data) |
| 492 |
#:endif |
| 493 |
else |
| 494 |
stridesf = 0 |
| 495 |
endif |
| 496 |
|
| 497 |
field = atlas_Field__cptr( & |
| 498 |
atlas__Field__wrap_${ctype}$_specf( c_str(name), data1d, size(shapef), shapef, stridesf ) ) |
| 499 |
call field%return() |
| 500 |
end function |
| 501 |
function atlas_Field__wrap_${dtype}$_r${rank}$(data) result(field) |
| 502 |
use, intrinsic :: iso_c_binding, only : c_int, c_long, c_float, c_double, c_loc, c_int32_t, c_sizeof |
| 503 |
use :: fckit_c_interop_module, only : c_str, c_ptr_to_loc |
| 504 |
use atlas_field_c_binding |
| 505 |
use fckit_array_module, only : array_strides, array_view1d |
| 506 |
type(atlas_Field) :: field |
| 507 |
${ftype}$, intent(in), target :: data(${dim[rank]}$) |
| 508 |
${ftype}$, pointer :: data_ptr(${dim[rank]}$) |
| 509 |
integer(c_int) :: shapef(${rank}$) |
| 510 |
integer(c_int) :: stridesf(${rank}$) |
| 511 |
integer(c_int32_t) :: value_size ! bytes of one data value |
| 512 |
#:if ftype != "logical(4)" |
| 513 |
${ftype}$ :: val ! dummy to compute value_size |
| 514 |
${ftype}$, pointer :: data1d(:) |
| 515 |
data_ptr => data |
| 516 |
data1d => array_view1d(data_ptr) |
| 517 |
#:else |
| 518 |
integer(c_int) :: val ! dummy to compute value_size |
| 519 |
integer(c_int), pointer :: data1d(:) |
| 520 |
data_ptr => data |
| 521 |
data1d => array_view1d( data_ptr, int(0,c_int) ) |
| 522 |
#:endif |
| 523 |
value_size = int(c_sizeof(val),c_int32_t) |
| 524 |
shapef = shape(data) |
| 525 |
if( size(data)>0 ) then |
| 526 |
!!! See issue https://github.com/ecmwf/atlas/pull/213 : problem with array_strides(data) with NAG compiler. |
| 527 |
#:if rank == 4 |
| 528 |
stridesf = 1 |
| 529 |
if (ubound(data,1) > 1) stridesf(1) = & |
| 530 |
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 |
| 531 |
if (ubound(data,2) > 1) stridesf(2) = & |
| 532 |
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 |
| 533 |
if (ubound(data,3) > 1) stridesf(3) = & |
| 534 |
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 |
| 535 |
if (ubound(data,4) > 1) stridesf(4) = & |
| 536 |
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 |
| 537 |
#:elif rank == 3 |
| 538 |
stridesf = 1 |
| 539 |
if (ubound(data,1) > 1) stridesf(1) = & |
| 540 |
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 |
| 541 |
if (ubound(data,2) > 1) stridesf(2) = & |
| 542 |
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 |
| 543 |
if (ubound(data,3) > 1) stridesf(3) = & |
| 544 |
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 |
| 545 |
#:elif rank == 2 |
| 546 |
stridesf = 1 |
| 547 |
if (ubound(data,1) > 1) stridesf(1) = & |
| 548 |
int(c_ptr_to_loc(c_loc(data(2,1)))-c_ptr_to_loc(c_loc(data(1,1))),c_int32_t)/value_size |
| 549 |
if (ubound(data,2) > 1) stridesf(2) = & |
| 550 |
int(c_ptr_to_loc(c_loc(data(1,2)))-c_ptr_to_loc(c_loc(data(1,1))),c_int32_t)/value_size |
| 551 |
#:elif rank == 1 |
| 552 |
stridesf = 1 |
| 553 |
if (ubound(data,1) > 1) stridesf(1) = & |
| 554 |
int(c_ptr_to_loc(c_loc(data(2)))-c_ptr_to_loc(c_loc(data(1))),c_int32_t)/value_size |
| 555 |
#:else |
| 556 |
stridesf = array_strides(data) |
| 557 |
#:endif |
| 558 |
else |
| 559 |
stridesf = 0 |
| 560 |
endif |
| 561 |
field = atlas_Field__cptr( & |
| 562 |
atlas__Field__wrap_${ctype}$_specf( c_str(""),data1d,size(shapef),shapef, stridesf) ) |
| 563 |
call field%return() |
| 564 |
end function |
| 565 |
#:endfor |
| 566 |
#:endfor |
| 567 |
|
| 568 |
!------------------------------------------------------------------------------- |
| 569 |
|
| 570 |
function Field__name(this) result(field_name) |
| 571 |
use atlas_field_c_binding |
| 572 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 573 |
use fckit_c_interop_module, only : c_ptr_to_string, c_str |
| 574 |
class(atlas_Field), intent(in) :: this |
| 575 |
character(len=:), allocatable :: field_name |
| 576 |
type(c_ptr) :: field_name_c_str |
| 577 |
field_name_c_str = atlas__Field__name(this%CPTR_PGIBUG_A) |
| 578 |
field_name = c_ptr_to_string(field_name_c_str) |
| 579 |
end function Field__name |
| 580 |
|
| 581 |
!------------------------------------------------------------------------------- |
| 582 |
|
| 583 |
function Field__functionspace(this) result(functionspace) |
| 584 |
use atlas_field_c_binding |
| 585 |
type(fckit_owned_object) :: functionspace |
| 586 |
class(atlas_Field), intent(in) :: this |
| 587 |
call functionspace%reset_c_ptr( atlas__Field__functionspace(this%CPTR_PGIBUG_A) ) |
| 588 |
call functionspace%return() |
| 589 |
end function Field__functionspace |
| 590 |
|
| 591 |
!------------------------------------------------------------------------------- |
| 592 |
|
| 593 |
function Field__datatype(this) result(datatype) |
| 594 |
use atlas_field_c_binding |
| 595 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int |
| 596 |
use fckit_c_interop_module, only : c_ptr_free, c_ptr_to_string |
| 597 |
class(atlas_Field), intent(in) :: this |
| 598 |
character(len=:), allocatable :: datatype |
| 599 |
type(c_ptr) :: datatype_cptr |
| 600 |
integer(c_int) :: datatype_size |
| 601 |
integer(c_int) :: datatype_allocated |
| 602 |
call atlas__Field__datatype(this%CPTR_PGIBUG_A,datatype_cptr,datatype_size,datatype_allocated) |
| 603 |
allocate(character(len=datatype_size) :: datatype ) |
| 604 |
datatype= c_ptr_to_string(datatype_cptr) |
| 605 |
if( datatype_allocated == 1 ) call c_ptr_free(datatype_cptr) |
| 606 |
end function Field__datatype |
| 607 |
|
| 608 |
!------------------------------------------------------------------------------- |
| 609 |
|
| 610 |
function Field__size(this) result(fieldsize) |
| 611 |
use atlas_field_c_binding |
| 612 |
class(atlas_Field), intent(in) :: this |
| 613 |
integer :: fieldsize |
| 614 |
fieldsize = atlas__Field__size(this%CPTR_PGIBUG_A) |
| 615 |
end function Field__size |
| 616 |
|
| 617 |
!------------------------------------------------------------------------------- |
| 618 |
|
| 619 |
function Field__rank(this) result(rank) |
| 620 |
use atlas_field_c_binding |
| 621 |
class(atlas_Field), intent(in) :: this |
| 622 |
integer :: rank |
| 623 |
rank = atlas__Field__rank(this%CPTR_PGIBUG_A) |
| 624 |
end function Field__rank |
| 625 |
|
| 626 |
!------------------------------------------------------------------------------- |
| 627 |
|
| 628 |
function Field__bytes(this) result(bytes) |
| 629 |
use atlas_field_c_binding |
| 630 |
use, intrinsic :: iso_c_binding, only : c_double |
| 631 |
class(atlas_Field), intent(in) :: this |
| 632 |
real(c_double) :: bytes |
| 633 |
bytes = atlas__Field__bytes(this%CPTR_PGIBUG_A) |
| 634 |
end function Field__bytes |
| 635 |
|
| 636 |
!------------------------------------------------------------------------------- |
| 637 |
|
| 638 |
function Field__kind(this) result(kind) |
| 639 |
use atlas_field_c_binding |
| 640 |
class(atlas_Field), intent(in) :: this |
| 641 |
integer :: kind |
| 642 |
kind = atlas__Field__kind(this%CPTR_PGIBUG_A) |
| 643 |
end function Field__kind |
| 644 |
|
| 645 |
!------------------------------------------------------------------------------- |
| 646 |
|
| 647 |
function Field__levels(this) result(levels) |
| 648 |
use atlas_field_c_binding |
| 649 |
class(atlas_Field), intent(in) :: this |
| 650 |
integer :: levels |
| 651 |
levels = atlas__Field__levels(this%CPTR_PGIBUG_A) |
| 652 |
end function Field__levels |
| 653 |
|
| 654 |
!------------------------------------------------------------------------------- |
| 655 |
|
| 656 |
function Field__metadata(this) result(metadata) |
| 657 |
use atlas_field_c_binding |
| 658 |
use atlas_metadata_module |
| 659 |
class(atlas_Field), intent(in) :: this |
| 660 |
type(atlas_Metadata) :: Metadata |
| 661 |
call metadata%reset_c_ptr( atlas__Field__metadata(this%CPTR_PGIBUG_A) ) |
| 662 |
end function Field__metadata |
| 663 |
|
| 664 |
!------------------------------------------------------------------------------- |
| 665 |
|
| 666 |
function Field__shape_array(this) result(shape) |
| 667 |
use atlas_field_c_binding |
| 668 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_f_pointer |
| 669 |
class(atlas_Field), intent(in) :: this |
| 670 |
integer, allocatable :: shape(:) |
| 671 |
type(c_ptr) :: shape_c_ptr |
| 672 |
integer, pointer :: shape_f_ptr(:) |
| 673 |
integer(c_int) :: field_rank |
| 674 |
call atlas__Field__shapef(this%CPTR_PGIBUG_A, shape_c_ptr, field_rank) |
| 675 |
call c_f_pointer ( shape_c_ptr , shape_f_ptr , (/field_rank/) ) |
| 676 |
allocate( shape(field_rank) ) |
| 677 |
shape(:) = shape_f_ptr(:) |
| 678 |
end function Field__shape_array |
| 679 |
|
| 680 |
!------------------------------------------------------------------------------- |
| 681 |
|
| 682 |
function Field__shape_idx(this,idx) result(shape_val) |
| 683 |
use atlas_field_c_binding |
| 684 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_f_pointer |
| 685 |
@:ENABLE_ATLAS_MACROS() |
| 686 |
integer :: shape_val |
| 687 |
class(atlas_Field), intent(in) :: this |
| 688 |
integer, intent(in) :: idx |
| 689 |
type(c_ptr) :: shape_c_ptr |
| 690 |
integer, pointer :: shape_f_ptr(:) |
| 691 |
integer(c_int) :: field_rank |
| 692 |
call atlas__Field__shapef(this%CPTR_PGIBUG_A, shape_c_ptr, field_rank) |
| 693 |
call c_f_pointer ( shape_c_ptr , shape_f_ptr , (/field_rank/) ) |
| 694 |
@:ATLAS_ASSERT( idx <= field_rank ) |
| 695 |
shape_val = shape_f_ptr(idx) |
| 696 |
end function Field__shape_idx |
| 697 |
|
| 698 |
!------------------------------------------------------------------------------- |
| 699 |
|
| 700 |
function Field__strides_array(this) result(strides) |
| 701 |
use atlas_field_c_binding |
| 702 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_f_pointer |
| 703 |
class(atlas_Field), intent(in) :: this |
| 704 |
integer, allocatable :: strides(:) |
| 705 |
type(c_ptr) :: strides_c_ptr |
| 706 |
integer, pointer :: strides_f_ptr(:) |
| 707 |
integer(c_int) :: field_rank |
| 708 |
call atlas__Field__stridesf(this%CPTR_PGIBUG_A, strides_c_ptr, field_rank) |
| 709 |
call c_f_pointer ( strides_c_ptr , strides_f_ptr , (/field_rank/) ) |
| 710 |
allocate( strides(field_rank) ) |
| 711 |
strides(:) = strides_f_ptr(:) |
| 712 |
end function |
| 713 |
|
| 714 |
!------------------------------------------------------------------------------- |
| 715 |
|
| 716 |
function Field__strides_idx(this,idx) result(strides_val) |
| 717 |
use atlas_field_c_binding |
| 718 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_f_pointer |
| 719 |
@:ENABLE_ATLAS_MACROS() |
| 720 |
integer :: strides_val |
| 721 |
class(atlas_Field), intent(in) :: this |
| 722 |
integer, intent(in) :: idx |
| 723 |
type(c_ptr) :: strides_c_ptr |
| 724 |
integer, pointer :: strides_f_ptr(:) |
| 725 |
integer(c_int) :: field_rank |
| 726 |
call atlas__Field__stridesf(this%CPTR_PGIBUG_A, strides_c_ptr, field_rank) |
| 727 |
call c_f_pointer ( strides_c_ptr , strides_f_ptr , (/field_rank/) ) |
| 728 |
@:ATLAS_ASSERT( idx <= field_rank ) |
| 729 |
strides_val = strides_f_ptr(idx) |
| 730 |
end function |
| 731 |
|
| 732 |
!------------------------------------------------------------------------------- |
| 733 |
|
| 734 |
subroutine set_levels(this,nb_levels) |
| 735 |
use atlas_field_c_binding |
| 736 |
class(atlas_Field), intent(inout) :: this |
| 737 |
integer, intent(in) :: nb_levels |
| 738 |
call atlas__field__set_levels(this%CPTR_PGIBUG_A,nb_levels) |
| 739 |
end subroutine |
| 740 |
|
| 741 |
!------------------------------------------------------------------------------- |
| 742 |
|
| 743 |
subroutine rename_(this,name) |
| 744 |
use atlas_field_c_binding |
| 745 |
use fckit_c_interop_module, only : c_str |
| 746 |
class(atlas_Field), intent(inout) :: this |
| 747 |
character(len=*), intent(in) :: name |
| 748 |
call atlas__field__rename(this%CPTR_PGIBUG_A,c_str(name)) |
| 749 |
end subroutine |
| 750 |
|
| 751 |
!------------------------------------------------------------------------------- |
| 752 |
|
| 753 |
subroutine set_functionspace(this,functionspace) |
| 754 |
use atlas_field_c_binding |
| 755 |
class(atlas_Field), intent(inout) :: this |
| 756 |
class(fckit_owned_object), intent(in) :: functionspace |
| 757 |
call atlas__field__set_functionspace(this%CPTR_PGIBUG_A,functionspace%CPTR_PGIBUG_A) |
| 758 |
end subroutine |
| 759 |
|
| 760 |
!------------------------------------------------------------------------------- |
| 761 |
|
| 762 |
subroutine set_host_needs_update(this,value) |
| 763 |
use atlas_field_c_binding |
| 764 |
class(atlas_Field), intent(in) :: this |
| 765 |
logical, optional, intent(in) :: value |
| 766 |
integer :: value_int |
| 767 |
value_int = 1 |
| 768 |
if (present(value)) then |
| 769 |
if (.not. value) then |
| 770 |
value_int = 0 |
| 771 |
endif |
| 772 |
endif |
| 773 |
call atlas__field__set_host_needs_update(this%CPTR_PGIBUG_A,value_int) |
| 774 |
end subroutine |
| 775 |
|
| 776 |
!------------------------------------------------------------------------------- |
| 777 |
|
| 778 |
subroutine set_device_needs_update(this,value) |
| 779 |
use atlas_field_c_binding |
| 780 |
class(atlas_Field), intent(in) :: this |
| 781 |
logical, optional, intent(in) :: value |
| 782 |
integer :: value_int |
| 783 |
value_int = 1 |
| 784 |
if (present(value)) then |
| 785 |
if (.not. value) then |
| 786 |
value_int = 0 |
| 787 |
endif |
| 788 |
endif |
| 789 |
call atlas__field__set_device_needs_update(this%CPTR_PGIBUG_A,value_int) |
| 790 |
end subroutine |
| 791 |
|
| 792 |
!------------------------------------------------------------------------------- |
| 793 |
|
| 794 |
function host_needs_update(this) |
| 795 |
use atlas_field_c_binding |
| 796 |
logical :: host_needs_update |
| 797 |
class(atlas_Field), intent(in) :: this |
| 798 |
if( atlas__Field__host_needs_update(this%CPTR_PGIBUG_A) == 1 ) then |
| 799 |
host_needs_update = .true. |
| 800 |
else |
| 801 |
host_needs_update = .false. |
| 802 |
endif |
| 803 |
end function |
| 804 |
|
| 805 |
!------------------------------------------------------------------------------- |
| 806 |
|
| 807 |
function device_needs_update(this) |
| 808 |
use atlas_field_c_binding |
| 809 |
logical :: device_needs_update |
| 810 |
class(atlas_Field), intent(in) :: this |
| 811 |
if( atlas__Field__device_needs_update(this%CPTR_PGIBUG_A) == 1 ) then |
| 812 |
device_needs_update = .true. |
| 813 |
else |
| 814 |
device_needs_update = .false. |
| 815 |
endif |
| 816 |
end function |
| 817 |
|
| 818 |
!------------------------------------------------------------------------------- |
| 819 |
|
| 820 |
subroutine update_device(this) |
| 821 |
use atlas_field_c_binding |
| 822 |
class(atlas_Field), intent(inout) :: this |
| 823 |
call atlas__Field__update_device(this%CPTR_PGIBUG_A) |
| 824 |
end subroutine |
| 825 |
|
| 826 |
!------------------------------------------------------------------------------- |
| 827 |
|
| 828 |
subroutine update_host(this) |
| 829 |
use atlas_field_c_binding |
| 830 |
class(atlas_Field), intent(inout) :: this |
| 831 |
call atlas__Field__update_host(this%CPTR_PGIBUG_A) |
| 832 |
end subroutine |
| 833 |
|
| 834 |
!------------------------------------------------------------------------------- |
| 835 |
|
| 836 |
subroutine sync_host_device(this) |
| 837 |
use atlas_field_c_binding |
| 838 |
class(atlas_Field), intent(inout) :: this |
| 839 |
call atlas__Field__sync_host_device(this%CPTR_PGIBUG_A) |
| 840 |
end subroutine |
| 841 |
|
| 842 |
!------------------------------------------------------------------------------- |
| 843 |
|
| 844 |
subroutine sync_host(this) |
| 845 |
use atlas_field_c_binding |
| 846 |
class(atlas_Field), intent(inout) :: this |
| 847 |
call atlas__Field__sync_host(this%CPTR_PGIBUG_A) |
| 848 |
end subroutine |
| 849 |
|
| 850 |
!------------------------------------------------------------------------------- |
| 851 |
subroutine sync_device(this) |
| 852 |
use atlas_field_c_binding |
| 853 |
class(atlas_Field), intent(inout) :: this |
| 854 |
call atlas__Field__sync_device(this%CPTR_PGIBUG_A) |
| 855 |
end subroutine |
| 856 |
|
| 857 |
!------------------------------------------------------------------------------- |
| 858 |
|
| 859 |
subroutine allocate_device(this) |
| 860 |
use atlas_field_c_binding |
| 861 |
class(atlas_Field), intent(inout) :: this |
| 862 |
call atlas__Field__allocate_device(this%CPTR_PGIBUG_A) |
| 863 |
end subroutine |
| 864 |
|
| 865 |
!------------------------------------------------------------------------------- |
| 866 |
|
| 867 |
subroutine deallocate_device(this) |
| 868 |
use atlas_field_c_binding |
| 869 |
class(atlas_Field), intent(inout) :: this |
| 870 |
call atlas__Field__deallocate_device(this%CPTR_PGIBUG_A) |
| 871 |
end subroutine |
| 872 |
|
| 873 |
!------------------------------------------------------------------------------- |
| 874 |
|
| 875 |
function device_allocated(this) |
| 876 |
use atlas_field_c_binding |
| 877 |
logical :: device_allocated |
| 878 |
class(atlas_Field), intent(in) :: this |
| 879 |
if( atlas__Field__device_allocated(this%CPTR_PGIBUG_A) == 1 ) then |
| 880 |
device_allocated = .true. |
| 881 |
else |
| 882 |
device_allocated = .false. |
| 883 |
endif |
| 884 |
end function |
| 885 |
|
| 886 |
!------------------------------------------------------------------------------- |
| 887 |
|
| 888 |
subroutine halo_exchange(this,on_device) |
| 889 |
use, intrinsic :: iso_c_binding, only : c_int |
| 890 |
use atlas_field_c_binding |
| 891 |
class(atlas_Field), intent(in) :: this |
| 892 |
logical, optional :: on_device |
| 893 |
integer(c_int) :: on_device_int |
| 894 |
on_device_int = 0 |
| 895 |
if( present(on_device) ) then |
| 896 |
if( on_device ) on_device_int = 1 |
| 897 |
endif |
| 898 |
call atlas__Field__halo_exchange(this%CPTR_PGIBUG_A, on_device_int) |
| 899 |
end subroutine |
| 900 |
|
| 901 |
!------------------------------------------------------------------------------- |
| 902 |
|
| 903 |
subroutine set_dirty(this,value) |
| 904 |
use, intrinsic :: iso_c_binding, only : c_int |
| 905 |
use atlas_field_c_binding |
| 906 |
class(atlas_Field), intent(in) :: this |
| 907 |
logical, optional, intent(in) :: value |
| 908 |
integer(c_int) :: value_int |
| 909 |
if( present(value) ) then |
| 910 |
if( value ) then |
| 911 |
value_int = 1 |
| 912 |
else |
| 913 |
value_int = 0 |
| 914 |
endif |
| 915 |
else |
| 916 |
value_int = 1 |
| 917 |
endif |
| 918 |
call atlas__Field__set_dirty(this%CPTR_PGIBUG_A, value_int) |
| 919 |
end subroutine |
| 920 |
|
| 921 |
!------------------------------------------------------------------------------- |
| 922 |
|
| 923 |
function dirty(this) result(value) |
| 924 |
use, intrinsic :: iso_c_binding, only : c_int |
| 925 |
use atlas_field_c_binding |
| 926 |
class(atlas_Field), intent(inout) :: this |
| 927 |
logical :: value |
| 928 |
integer(c_int) :: value_int |
| 929 |
value_int = atlas__Field__dirty(this%CPTR_PGIBUG_A) |
| 930 |
if( value_int == 0 ) then |
| 931 |
value = .false. |
| 932 |
else |
| 933 |
value = .true. |
| 934 |
endif |
| 935 |
end function |
| 936 |
|
| 937 |
!------------------------------------------------------------------------------- |
| 938 |
|
| 939 |
function contiguous(this) |
| 940 |
use atlas_field_c_binding |
| 941 |
logical :: contiguous |
| 942 |
class(atlas_Field), intent(in) :: this |
| 943 |
if( atlas__Field__contiguous(this%CPTR_PGIBUG_A) == 1 ) then |
| 944 |
contiguous = .true. |
| 945 |
else |
| 946 |
contiguous = .false. |
| 947 |
endif |
| 948 |
end function |
| 949 |
|
| 950 |
!------------------------------------------------------------------------------- |
| 951 |
|
| 952 |
#if FCKIT_FINAL_NOT_INHERITING |
| 953 |
ATLAS_FINAL subroutine atlas_Field__final_auto(this) |
| 954 |
type(atlas_Field), intent(inout) :: this |
| 955 |
#if FCKIT_FINAL_DEBUGGING |
| 956 |
write(0,*) "atlas_Field__final_auto" |
| 957 |
#endif |
| 958 |
#if FCKIT_FINAL_NOT_PROPAGATING |
| 959 |
call this%final() |
| 960 |
#endif |
| 961 |
FCKIT_SUPPRESS_UNUSED( this ) |
| 962 |
end subroutine |
| 963 |
#endif |
| 964 |
|
| 965 |
!------------------------------------------------------------------------------- |
| 966 |
|
| 967 |
end module atlas_field_module |
| 968 |
|