| 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 |
module atlas_connectivity_module |
| 12 |
|
| 13 |
use, intrinsic :: iso_c_binding, only : c_int, c_ptr, c_null_ptr |
| 14 |
use fckit_owned_object_module, only : fckit_owned_object |
| 15 |
use fckit_object_module, only : fckit_object |
| 16 |
use atlas_kinds_module, only : ATLAS_KIND_IDX |
| 17 |
use atlas_allocate_module, only : atlas_allocate_managedmem, atlas_deallocate_managedmem |
| 18 |
use fckit_exception_module, only : fckit_exception |
| 19 |
implicit none |
| 20 |
|
| 21 |
private :: c_ptr |
| 22 |
private :: c_int |
| 23 |
private :: c_null_ptr |
| 24 |
private :: fckit_owned_object |
| 25 |
private :: fckit_object |
| 26 |
private :: atlas_allocate_managedmem |
| 27 |
private :: atlas_deallocate_managedmem |
| 28 |
|
| 29 |
public :: atlas_Connectivity |
| 30 |
public :: atlas_MultiBlockConnectivity |
| 31 |
public :: atlas_BlockConnectivity |
| 32 |
|
| 33 |
|
| 34 |
private |
| 35 |
|
| 36 |
!----------------------------- |
| 37 |
! atlas_Connectivity ! |
| 38 |
!----------------------------- |
| 39 |
|
| 40 |
type, extends(fckit_owned_object) :: atlas_Connectivity |
| 41 |
|
| 42 |
! Public members |
| 43 |
type( atlas_ConnectivityAccess ), public, pointer :: access => null() |
| 44 |
|
| 45 |
contains |
| 46 |
|
| 47 |
procedure, public :: assignment_operator_hook |
| 48 |
procedure, public :: set_access |
| 49 |
|
| 50 |
! Public methods |
| 51 |
procedure, public :: name => atlas_Connectivity__name |
| 52 |
procedure, private :: value_args_int => atlas_Connectivity__value_args_int |
| 53 |
procedure, private :: value_args_long => atlas_Connectivity__value_args_long |
| 54 |
generic, public :: value => value_args_int, value_args_long |
| 55 |
procedure, public :: rows => atlas_Connectivity__rows |
| 56 |
procedure, public :: cols => atlas_Connectivity__cols |
| 57 |
procedure, public :: maxcols => atlas_Connectivity__maxcols |
| 58 |
procedure, public :: mincols => atlas_Connectivity__mincols |
| 59 |
procedure, public :: padded_data => atlas_Connectivity__padded_data |
| 60 |
procedure, private :: atlas_Connectivity__data |
| 61 |
procedure, private :: atlas_Connectivity__data_int |
| 62 |
procedure, private :: atlas_Connectivity__data_long |
| 63 |
generic, public :: data => atlas_Connectivity__data, atlas_Connectivity__data_int, atlas_Connectivity__data_long |
| 64 |
procedure, private :: atlas_Connectivity__row_int |
| 65 |
procedure, private :: atlas_Connectivity__row_long |
| 66 |
generic, public :: row => atlas_Connectivity__row_int, atlas_Connectivity__row_long |
| 67 |
procedure, public :: missing_value => atlas_Connectivity__missing_value |
| 68 |
procedure, private :: add_values_args_idx => atlas_Connectivity__add_values_args_idx |
| 69 |
#if ATLAS_BITS_LOCAL != 32 |
| 70 |
procedure, private :: add_values_args_int32 => atlas_Connectivity__add_values_args_int32 |
| 71 |
#define _add_values_args_int32 , add_values_args_int32 |
| 72 |
#else |
| 73 |
#define _add_values_args_int32 |
| 74 |
#endif |
| 75 |
procedure, private :: add_values_args_long => atlas_Connectivity__add_values_args_long |
| 76 |
procedure, private :: add_missing_args_int => atlas_Connectivity__add_missing_args_int |
| 77 |
procedure, private :: add_missing_args_long => atlas_Connectivity__add_missing_args_long |
| 78 |
generic, public :: add => add_values_args_idx, add_values_args_long, add_missing_args_int, & |
| 79 |
& add_missing_args_long _add_values_args_int32 |
| 80 |
#if FCKIT_FINAL_NOT_INHERITING |
| 81 |
final :: atlas_Connectivity__final_auto |
| 82 |
#endif |
| 83 |
|
| 84 |
end type |
| 85 |
|
| 86 |
!--------------------------------------- |
| 87 |
! atlas_MultiBlockConnectivity ! |
| 88 |
!--------------------------------------- |
| 89 |
|
| 90 |
type, extends(atlas_Connectivity) :: atlas_MultiBlockConnectivity |
| 91 |
contains |
| 92 |
! Public methods |
| 93 |
procedure, public :: blocks => atlas_MultiBlockConnectivity__blocks |
| 94 |
procedure, public :: block => atlas_MultiBlockConnectivity__block |
| 95 |
|
| 96 |
! PGI compiler bug won't accept "assignment_operator_hook" from atlas_Connectivity parent class... grrr |
| 97 |
procedure, public :: assignment_operator_hook => atlas_MBC__assignment_operator_hook |
| 98 |
|
| 99 |
#if FCKIT_FINAL_NOT_INHERITING |
| 100 |
final :: atlas_MultiBlockConnectivity__final_auto |
| 101 |
#endif |
| 102 |
|
| 103 |
end type |
| 104 |
|
| 105 |
!----------------------------! |
| 106 |
! atlas_BlockConnectivity ! |
| 107 |
!----------------------------! |
| 108 |
|
| 109 |
type, extends(fckit_object) :: atlas_BlockConnectivity |
| 110 |
contains |
| 111 |
procedure, public :: rows => atlas_BlockConnectivity__rows |
| 112 |
procedure, public :: cols => atlas_BlockConnectivity__cols |
| 113 |
procedure, public :: data => atlas_BlockConnectivity__data |
| 114 |
procedure, public :: missing_value => atlas_BlockConnectivity__missing_value |
| 115 |
end type |
| 116 |
|
| 117 |
interface atlas_Connectivity |
| 118 |
module procedure Connectivity_cptr |
| 119 |
module procedure Connectivity_constructor |
| 120 |
end interface |
| 121 |
|
| 122 |
interface atlas_MultiBlockConnectivity |
| 123 |
module procedure MultiBlockConnectivity_cptr |
| 124 |
module procedure MultiBlockConnectivity_constructor |
| 125 |
end interface |
| 126 |
|
| 127 |
interface atlas_BlockConnectivity |
| 128 |
module procedure BlockConnectivity_cptr |
| 129 |
end interface |
| 130 |
|
| 131 |
|
| 132 |
!------------------------------- |
| 133 |
! Helper types ! |
| 134 |
!------------------------------- |
| 135 |
|
| 136 |
type :: atlas_ConnectivityAccessRow |
| 137 |
integer(ATLAS_KIND_IDX), pointer :: col(:) |
| 138 |
contains |
| 139 |
end type |
| 140 |
|
| 141 |
type :: atlas_ConnectivityAccess |
| 142 |
integer(ATLAS_KIND_IDX), private, pointer :: values_(:) => null() |
| 143 |
integer(ATLAS_KIND_IDX), private, pointer :: displs_(:) => null() |
| 144 |
integer(ATLAS_KIND_IDX), public, pointer :: cols(:) => null() |
| 145 |
type(atlas_ConnectivityAccessRow), public, pointer :: row(:) => null() |
| 146 |
integer(ATLAS_KIND_IDX), private :: rows_ |
| 147 |
integer(ATLAS_KIND_IDX), private, pointer :: padded_(:,:) => null() |
| 148 |
integer(ATLAS_KIND_IDX), private :: maxcols_, mincols_ |
| 149 |
integer(ATLAS_KIND_IDX), private :: missing_value_ |
| 150 |
type(c_ptr), private :: connectivity_ptr = c_null_ptr |
| 151 |
contains |
| 152 |
procedure, public :: rows => access_rows |
| 153 |
procedure, public :: value => access_value |
| 154 |
end type |
| 155 |
|
| 156 |
! ---------------------------------------------------------------------------- |
| 157 |
interface |
| 158 |
subroutine atlas__connectivity__register_ctxt(This,ptr) bind(c,name="atlas__connectivity__register_ctxt") |
| 159 |
use, intrinsic :: iso_c_binding, only: c_ptr |
| 160 |
type(c_ptr), value :: This |
| 161 |
type(c_ptr), value :: ptr |
| 162 |
end subroutine |
| 163 |
|
| 164 |
subroutine atlas__connectivity__register_update(This,funptr) bind(c,name="atlas__connectivity__register_update") |
| 165 |
use, intrinsic :: iso_c_binding, only: c_ptr, c_funptr |
| 166 |
type(c_ptr), value :: This |
| 167 |
type(c_funptr), value :: funptr |
| 168 |
end subroutine |
| 169 |
|
| 170 |
subroutine atlas__connectivity__register_delete(This,funptr) bind(c,name="atlas__connectivity__register_delete") |
| 171 |
use, intrinsic :: iso_c_binding, only: c_ptr, c_funptr |
| 172 |
type(c_ptr), value :: This |
| 173 |
type(c_funptr), value :: funptr |
| 174 |
end subroutine |
| 175 |
|
| 176 |
function atlas__connectivity__ctxt(This,ptr) bind(c,name="atlas__connectivity__ctxt") |
| 177 |
use, intrinsic :: iso_c_binding, only: c_ptr, c_int |
| 178 |
integer(c_int) :: atlas__connectivity__ctxt |
| 179 |
type(c_ptr), value :: This |
| 180 |
type(c_ptr) :: ptr |
| 181 |
end function |
| 182 |
|
| 183 |
end interface |
| 184 |
|
| 185 |
contains |
| 186 |
|
| 187 |
subroutine assignment_operator_hook(this,other) |
| 188 |
class(atlas_Connectivity) :: this |
| 189 |
class(fckit_owned_object) :: other |
| 190 |
call this%set_access() |
| 191 |
FCKIT_SUPPRESS_UNUSED(other) |
| 192 |
end subroutine |
| 193 |
|
| 194 |
! Following routine is exact copy of "assignment_operator_hook" above, because of bug in PGI compiler (17.7) |
| 195 |
! Without it, wrongly the "fckit_owned_object::assignment_operator_hook" is used instead of |
| 196 |
! "atlas_Connectivity::assignment_operator_hook". |
| 197 |
subroutine atlas_MBC__assignment_operator_hook(this,other) |
| 198 |
class(atlas_MultiBlockConnectivity) :: this |
| 199 |
class(fckit_owned_object) :: other |
| 200 |
call this%set_access() |
| 201 |
FCKIT_SUPPRESS_UNUSED(other) |
| 202 |
end subroutine |
| 203 |
|
| 204 |
function Connectivity_cptr(cptr) result(this) |
| 205 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 206 |
use atlas_connectivity_c_binding |
| 207 |
type(atlas_Connectivity) :: this |
| 208 |
type(c_ptr) :: cptr |
| 209 |
call this%reset_c_ptr( cptr ) |
| 210 |
call this%set_access() |
| 211 |
call this%return() |
| 212 |
end function |
| 213 |
|
| 214 |
function Connectivity_constructor(name) result(this) |
| 215 |
use atlas_connectivity_c_binding |
| 216 |
use fckit_c_interop_module, only : c_str |
| 217 |
type(atlas_Connectivity) :: this |
| 218 |
character(len=*), intent(in), optional :: name |
| 219 |
call this%reset_c_ptr( atlas__Connectivity__create() ) |
| 220 |
call this%set_access() |
| 221 |
if( present(name) ) then |
| 222 |
call atlas__Connectivity__rename(this%CPTR_PGIBUG_A,c_str(name)) |
| 223 |
endif |
| 224 |
call this%return() |
| 225 |
end function |
| 226 |
|
| 227 |
|
| 228 |
function atlas_Connectivity__name(this) result(name) |
| 229 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 230 |
use atlas_connectivity_c_binding |
| 231 |
use fckit_c_interop_module, only : c_ptr_to_string |
| 232 |
class(atlas_Connectivity), intent(in) :: this |
| 233 |
character(len=:), allocatable :: name |
| 234 |
type(c_ptr) :: name_c_str |
| 235 |
name_c_str = atlas__Connectivity__name(this%CPTR_PGIBUG_A) |
| 236 |
name = c_ptr_to_string(name_c_str) |
| 237 |
end function |
| 238 |
|
| 239 |
pure function access_value(this,c,r) result(val) |
| 240 |
use, intrinsic :: iso_c_binding, only : c_int |
| 241 |
integer(ATLAS_KIND_IDX) :: val |
| 242 |
class(atlas_ConnectivityAccess), intent(in) :: this |
| 243 |
integer(ATLAS_KIND_IDX), intent(in) :: r,c |
| 244 |
val = this%values_(c+this%displs_(r)) |
| 245 |
end function |
| 246 |
|
| 247 |
pure function access_rows(this) result(val) |
| 248 |
use atlas_kinds_module |
| 249 |
integer(ATLAS_KIND_IDX) :: val |
| 250 |
class(atlas_ConnectivityAccess), intent(in) :: this |
| 251 |
val = this%rows_ |
| 252 |
end function |
| 253 |
|
| 254 |
pure function atlas_Connectivity__value_args_long(this,c,r) result(val) |
| 255 |
use, intrinsic :: iso_c_binding, only : c_long |
| 256 |
integer(ATLAS_KIND_IDX) :: val |
| 257 |
class(atlas_Connectivity), intent(in) :: this |
| 258 |
integer(c_long), intent(in) :: r,c |
| 259 |
val = this%access%values_(c+this%access%displs_(r)) |
| 260 |
end function |
| 261 |
|
| 262 |
pure function atlas_Connectivity__value_args_int(this,c,r) result(val) |
| 263 |
use, intrinsic :: iso_c_binding, only : c_int |
| 264 |
integer(ATLAS_KIND_IDX) :: val |
| 265 |
class(atlas_Connectivity), intent(in) :: this |
| 266 |
integer(c_int), intent(in) :: r,c |
| 267 |
val = this%access%values_(c+this%access%displs_(r)) |
| 268 |
end function |
| 269 |
|
| 270 |
pure function atlas_Connectivity__rows(this) result(val) |
| 271 |
integer(ATLAS_KIND_IDX) :: val |
| 272 |
class(atlas_Connectivity), intent(in) :: this |
| 273 |
val = this%access%rows_ |
| 274 |
end function |
| 275 |
|
| 276 |
function atlas_Connectivity__missing_value(this) result(val) |
| 277 |
use atlas_connectivity_c_binding |
| 278 |
integer(ATLAS_KIND_IDX) :: val |
| 279 |
class(atlas_Connectivity), intent(in) :: this |
| 280 |
val = atlas__Connectivity__missing_value(this%CPTR_PGIBUG_A) |
| 281 |
end function |
| 282 |
|
| 283 |
pure function atlas_Connectivity__cols(this,r) result(val) |
| 284 |
integer(ATLAS_KIND_IDX) :: val |
| 285 |
class(atlas_Connectivity), intent(in) :: this |
| 286 |
integer(c_int), intent(in) :: r |
| 287 |
val = this%access%cols(r) |
| 288 |
end function |
| 289 |
|
| 290 |
pure function atlas_Connectivity__mincols(this) result(val) |
| 291 |
integer(ATLAS_KIND_IDX) :: val |
| 292 |
class(atlas_Connectivity), intent(in) :: this |
| 293 |
val = this%access%mincols_ |
| 294 |
end function |
| 295 |
|
| 296 |
pure function atlas_Connectivity__maxcols(this) result(val) |
| 297 |
integer(ATLAS_KIND_IDX) :: val |
| 298 |
class(atlas_Connectivity), intent(in) :: this |
| 299 |
val = this%access%maxcols_ |
| 300 |
end function |
| 301 |
|
| 302 |
subroutine atlas_Connectivity__padded_data(this, padded, cols) |
| 303 |
use, intrinsic :: iso_c_binding, only : c_int |
| 304 |
class(atlas_Connectivity), intent(inout) :: this |
| 305 |
integer(ATLAS_KIND_IDX), pointer, intent(inout) :: padded(:,:) |
| 306 |
integer(ATLAS_KIND_IDX), pointer, intent(inout), optional :: cols(:) |
| 307 |
if( .not. associated(this%access%padded_) ) call update_padded(this%access) |
| 308 |
padded => this%access%padded_ |
| 309 |
if( present(cols) ) cols => this%access%cols |
| 310 |
end subroutine |
| 311 |
|
| 312 |
function c_loc_idx(x) |
| 313 |
use, intrinsic :: iso_c_binding |
| 314 |
integer(ATLAS_KIND_IDX), target :: x |
| 315 |
type(c_ptr) :: c_loc_idx |
| 316 |
c_loc_idx = c_loc(x) |
| 317 |
end function |
| 318 |
|
| 319 |
subroutine atlas_Connectivity__data(this, data) |
| 320 |
use, intrinsic :: iso_c_binding, only : c_f_pointer, c_loc, c_int |
| 321 |
class(atlas_Connectivity), intent(in) :: this |
| 322 |
integer(ATLAS_KIND_IDX), pointer, intent(inout) :: data(:,:) |
| 323 |
integer(ATLAS_KIND_IDX) :: maxcols |
| 324 |
|
| 325 |
maxcols = this%maxcols() |
| 326 |
if( maxcols == this%mincols() ) then |
| 327 |
if( size(this%access%values_) > 0 ) then |
| 328 |
call c_f_pointer (c_loc_idx(this%access%values_(1)), data, & |
| 329 |
& (/maxcols,this%access%rows_/)) |
| 330 |
endif |
| 331 |
else |
| 332 |
call fckit_exception%abort("ERROR: Cannot point connectivity pointer data(:,:) to irregular table",& |
| 333 |
& "atlas_Connectivity_module.F90", __LINE__ ) |
| 334 |
endif |
| 335 |
end subroutine |
| 336 |
|
| 337 |
subroutine atlas_Connectivity__data_int(this, data, ncols) |
| 338 |
use, intrinsic :: iso_c_binding, only : c_f_pointer, c_loc, c_int |
| 339 |
class(atlas_Connectivity), intent(in) :: this |
| 340 |
integer(ATLAS_KIND_IDX), pointer, intent(inout) :: data(:,:) |
| 341 |
integer(c_int), intent(out) :: ncols |
| 342 |
integer(ATLAS_KIND_IDX) :: maxcols |
| 343 |
|
| 344 |
maxcols = this%maxcols() |
| 345 |
if( maxcols == this%mincols() ) then |
| 346 |
if( size(this%access%values_) > 0 ) then |
| 347 |
call c_f_pointer (c_loc_idx(this%access%values_(1)), data, & |
| 348 |
& (/maxcols,this%access%rows_/)) |
| 349 |
ncols = maxcols |
| 350 |
endif |
| 351 |
else |
| 352 |
call fckit_exception%abort("ERROR: Cannot point connectivity pointer data(:,:) to irregular table",& |
| 353 |
& "atlas_Connectivity_module.F90", __LINE__ ) |
| 354 |
endif |
| 355 |
end subroutine |
| 356 |
|
| 357 |
subroutine atlas_Connectivity__data_long(this, data, ncols) |
| 358 |
use, intrinsic :: iso_c_binding, only : c_f_pointer, c_loc, c_long |
| 359 |
class(atlas_Connectivity), intent(in) :: this |
| 360 |
integer(ATLAS_KIND_IDX), pointer, intent(inout) :: data(:,:) |
| 361 |
integer(c_long), intent(out) :: ncols |
| 362 |
integer(ATLAS_KIND_IDX) :: maxcols |
| 363 |
|
| 364 |
maxcols = this%maxcols() |
| 365 |
if( maxcols == this%mincols() ) then |
| 366 |
if( size(this%access%values_) > 0 ) then |
| 367 |
call c_f_pointer (c_loc_idx(this%access%values_(1)), data, & |
| 368 |
& (/maxcols,this%access%rows_/)) |
| 369 |
ncols = maxcols |
| 370 |
endif |
| 371 |
else |
| 372 |
call fckit_exception%abort("ERROR: Cannot point connectivity pointer data(:,:) to irregular table",& |
| 373 |
& "atlas_Connectivity_module.F90", __LINE__ ) |
| 374 |
endif |
| 375 |
end subroutine |
| 376 |
|
| 377 |
subroutine atlas_Connectivity__row_int(this, row_idx, row, cols) |
| 378 |
use, intrinsic :: iso_c_binding, only : c_int |
| 379 |
class(atlas_Connectivity), intent(in) :: this |
| 380 |
integer(c_int), intent(in) :: row_idx |
| 381 |
integer(ATLAS_KIND_IDX), pointer, intent(inout) :: row(:) |
| 382 |
integer(c_int), intent(out) :: cols |
| 383 |
row => this%access%values_(this%access%displs_(row_idx)+1:this%access%displs_(row_idx+1)+1) |
| 384 |
cols = this%access%cols(row_idx) |
| 385 |
end subroutine |
| 386 |
|
| 387 |
subroutine atlas_Connectivity__row_long(this, row_idx, row, cols) |
| 388 |
use, intrinsic :: iso_c_binding, only : c_long |
| 389 |
class(atlas_Connectivity), intent(in) :: this |
| 390 |
integer(c_long), intent(in) :: row_idx |
| 391 |
integer(ATLAS_KIND_IDX), pointer, intent(inout) :: row(:) |
| 392 |
integer(c_long), intent(out) :: cols |
| 393 |
row => this%access%values_(this%access%displs_(row_idx)+1:this%access%displs_(row_idx+1)+1) |
| 394 |
cols = this%access%cols(row_idx) |
| 395 |
end subroutine |
| 396 |
|
| 397 |
subroutine atlas_Connectivity__add_values_args_long(this,rows,cols,values) |
| 398 |
use atlas_connectivity_c_binding |
| 399 |
use, intrinsic :: iso_c_binding, only : c_long |
| 400 |
class(atlas_Connectivity), intent(in) :: this |
| 401 |
integer(c_long), intent(in) :: rows |
| 402 |
integer(c_long), intent(in) :: cols |
| 403 |
integer(ATLAS_KIND_IDX) :: values(:) |
| 404 |
call atlas__connectivity__add_values(this%CPTR_PGIBUG_A,int(rows,ATLAS_KIND_IDX),int(cols,ATLAS_KIND_IDX),values) |
| 405 |
end subroutine |
| 406 |
|
| 407 |
subroutine atlas_Connectivity__add_values_args_idx(this,rows,cols,values) |
| 408 |
use atlas_connectivity_c_binding |
| 409 |
use, intrinsic :: iso_c_binding, only : c_int |
| 410 |
class(atlas_Connectivity), intent(in) :: this |
| 411 |
integer(c_int), intent(in) :: rows |
| 412 |
integer(c_int), intent(in) :: cols |
| 413 |
integer(ATLAS_KIND_IDX), intent(in) :: values(:) |
| 414 |
call atlas__connectivity__add_values(this%CPTR_PGIBUG_A,int(rows,ATLAS_KIND_IDX),int(cols,ATLAS_KIND_IDX),values) |
| 415 |
end subroutine |
| 416 |
|
| 417 |
#if ATLAS_BITS_LOCAL != 32 |
| 418 |
subroutine atlas_Connectivity__add_values_args_int32(this,rows,cols,values) |
| 419 |
use atlas_connectivity_c_binding |
| 420 |
use, intrinsic :: iso_c_binding, only : c_int |
| 421 |
class(atlas_Connectivity), intent(in) :: this |
| 422 |
integer(c_int), intent(in) :: rows |
| 423 |
integer(c_int), intent(in) :: cols |
| 424 |
integer(c_int), intent(in) :: values(:) |
| 425 |
integer(ATLAS_KIND_IDX) :: idx_values(rows*cols) |
| 426 |
idx_values(:) = values(:) |
| 427 |
call atlas__connectivity__add_values(this%CPTR_PGIBUG_A,int(rows,ATLAS_KIND_IDX),int(cols,ATLAS_KIND_IDX),idx_values) |
| 428 |
end subroutine |
| 429 |
#endif |
| 430 |
|
| 431 |
|
| 432 |
subroutine atlas_Connectivity__add_missing_args_long(this,rows,cols) |
| 433 |
use atlas_connectivity_c_binding |
| 434 |
use, intrinsic :: iso_c_binding, only : c_long |
| 435 |
class(atlas_Connectivity), intent(in) :: this |
| 436 |
integer(c_long) :: rows |
| 437 |
integer(c_long) :: cols |
| 438 |
call atlas__connectivity__add_missing(this%CPTR_PGIBUG_A,int(rows,ATLAS_KIND_IDX),int(cols,ATLAS_KIND_IDX)) |
| 439 |
end subroutine |
| 440 |
|
| 441 |
subroutine atlas_Connectivity__add_missing_args_int(this,rows,cols) |
| 442 |
use atlas_connectivity_c_binding |
| 443 |
use, intrinsic :: iso_c_binding, only : c_int |
| 444 |
class(atlas_Connectivity), intent(in) :: this |
| 445 |
integer(c_int) :: rows |
| 446 |
integer(c_int) :: cols |
| 447 |
call atlas__connectivity__add_missing(this%CPTR_PGIBUG_A,int(rows,ATLAS_KIND_IDX),int(cols,ATLAS_KIND_IDX)) |
| 448 |
end subroutine |
| 449 |
|
| 450 |
!======================================================== |
| 451 |
|
| 452 |
function MultiBlockConnectivity_cptr(cptr) result(this) |
| 453 |
use atlas_connectivity_c_binding |
| 454 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 455 |
type(atlas_MultiBlockConnectivity) :: this |
| 456 |
type(c_ptr) :: cptr |
| 457 |
call this%reset_c_ptr( cptr ) |
| 458 |
call this%set_access() |
| 459 |
call this%return() |
| 460 |
end function |
| 461 |
|
| 462 |
function MultiBlockConnectivity_constructor(name) result(this) |
| 463 |
use atlas_connectivity_c_binding |
| 464 |
use fckit_c_interop_module |
| 465 |
type(atlas_MultiBlockConnectivity) :: this |
| 466 |
character(len=*), intent(in), optional :: name |
| 467 |
call this%reset_c_ptr( atlas__MultiBlockConnectivity__create() ) |
| 468 |
call this%set_access() |
| 469 |
if( present(name) ) then |
| 470 |
call atlas__Connectivity__rename(this%CPTR_PGIBUG_A,c_str(name)) |
| 471 |
endif |
| 472 |
call this%return() |
| 473 |
end function |
| 474 |
|
| 475 |
function atlas_MultiBlockConnectivity__blocks(this) result(val) |
| 476 |
use atlas_connectivity_c_binding |
| 477 |
integer(ATLAS_KIND_IDX) :: val |
| 478 |
class(atlas_MultiBlockConnectivity), intent(in) :: this |
| 479 |
val = atlas__MultiBlockConnectivity__blocks(this%CPTR_PGIBUG_A) |
| 480 |
end function |
| 481 |
|
| 482 |
function atlas_MultiBlockConnectivity__block(this,block_idx) result(block) |
| 483 |
use atlas_connectivity_c_binding |
| 484 |
type(atlas_BlockConnectivity) :: block |
| 485 |
class(atlas_MultiBlockConnectivity), intent(in) :: this |
| 486 |
integer(ATLAS_KIND_IDX) :: block_idx |
| 487 |
call block%reset_c_ptr( atlas__MultiBlockConnectivity__block( & |
| 488 |
this%CPTR_PGIBUG_A,int(block_idx-1_ATLAS_KIND_IDX,ATLAS_KIND_IDX) ) ) |
| 489 |
end function |
| 490 |
|
| 491 |
!======================================================== |
| 492 |
|
| 493 |
function BlockConnectivity_cptr(cptr) result(this) |
| 494 |
use atlas_connectivity_c_binding |
| 495 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 496 |
type(atlas_BlockConnectivity) :: this |
| 497 |
type(c_ptr) :: cptr |
| 498 |
call this%reset_c_ptr( cptr ) |
| 499 |
end function |
| 500 |
|
| 501 |
subroutine atlas_BlockConnectivity__data(this,data) |
| 502 |
use atlas_connectivity_c_binding |
| 503 |
use, intrinsic :: iso_c_binding, only : c_int, c_ptr, c_f_pointer |
| 504 |
class(atlas_BlockConnectivity), intent(in) :: this |
| 505 |
integer(ATLAS_KIND_IDX), pointer, intent(inout) :: data(:,:) |
| 506 |
type(c_ptr) :: data_cptr |
| 507 |
integer(ATLAS_KIND_IDX) :: rows |
| 508 |
integer(ATLAS_KIND_IDX) :: cols |
| 509 |
call atlas__BlockConnectivity__data(this%CPTR_PGIBUG_A,data_cptr,rows,cols) |
| 510 |
call c_f_pointer (data_cptr, data, [cols,rows]) |
| 511 |
end subroutine |
| 512 |
|
| 513 |
function atlas_BlockConnectivity__rows(this) result(val) |
| 514 |
use atlas_connectivity_c_binding |
| 515 |
integer(ATLAS_KIND_IDX) :: val |
| 516 |
class(atlas_BlockConnectivity), intent(in) :: this |
| 517 |
val = atlas__BlockConnectivity__rows(this%CPTR_PGIBUG_A) |
| 518 |
end function |
| 519 |
|
| 520 |
function atlas_BlockConnectivity__cols(this) result(val) |
| 521 |
use atlas_connectivity_c_binding |
| 522 |
integer(ATLAS_KIND_IDX) :: val |
| 523 |
class(atlas_BlockConnectivity), intent(in) :: this |
| 524 |
val = atlas__BlockConnectivity__cols(this%CPTR_PGIBUG_A) |
| 525 |
end function |
| 526 |
|
| 527 |
function atlas_BlockConnectivity__missing_value(this) result(val) |
| 528 |
use atlas_connectivity_c_binding |
| 529 |
integer(ATLAS_KIND_IDX) :: val |
| 530 |
class(atlas_BlockConnectivity), intent(in) :: this |
| 531 |
val = atlas__BlockConnectivity__missing_value(this%CPTR_PGIBUG_A) + 1 |
| 532 |
end function |
| 533 |
|
| 534 |
!======================================================== |
| 535 |
|
| 536 |
subroutine set_access(this) |
| 537 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_f_pointer, c_funloc, c_loc |
| 538 |
class(atlas_Connectivity), intent(inout) :: this |
| 539 |
type(c_ptr) :: ctxt |
| 540 |
integer(c_int) :: have_ctxt |
| 541 |
have_ctxt = atlas__connectivity__ctxt(this%CPTR_PGIBUG_A,ctxt) |
| 542 |
if( have_ctxt == 1 ) then |
| 543 |
call c_f_pointer(ctxt,this%access) |
| 544 |
else |
| 545 |
allocate( this%access ) |
| 546 |
call atlas__connectivity__register_ctxt ( this%CPTR_PGIBUG_A, c_loc(this%access) ) |
| 547 |
call atlas__connectivity__register_update( this%CPTR_PGIBUG_A, c_funloc(update_access_c) ) |
| 548 |
call atlas__connectivity__register_delete( this%CPTR_PGIBUG_A, c_funloc(delete_access_c) ) |
| 549 |
|
| 550 |
this%access%connectivity_ptr = this%CPTR_PGIBUG_A |
| 551 |
call update_access(this%access) |
| 552 |
endif |
| 553 |
end subroutine |
| 554 |
|
| 555 |
subroutine update_access_c(this_ptr) bind(c) |
| 556 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_f_pointer |
| 557 |
type(c_ptr), value :: this_ptr |
| 558 |
type(atlas_ConnectivityAccess), pointer :: this |
| 559 |
call c_f_pointer(this_ptr,this) |
| 560 |
call update_access(this) |
| 561 |
end subroutine |
| 562 |
|
| 563 |
subroutine update_access(this) |
| 564 |
use atlas_connectivity_c_binding |
| 565 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_f_pointer |
| 566 |
type(atlas_ConnectivityAccess), intent(inout) :: this |
| 567 |
integer :: jrow |
| 568 |
|
| 569 |
type(c_ptr) :: values_cptr |
| 570 |
type(c_ptr) :: displs_cptr |
| 571 |
type(c_ptr) :: counts_cptr |
| 572 |
integer(ATLAS_KIND_IDX) :: values_size |
| 573 |
integer(ATLAS_KIND_IDX) :: displs_size |
| 574 |
integer(ATLAS_KIND_IDX) :: counts_size |
| 575 |
|
| 576 |
this%missing_value_ = atlas__Connectivity__missing_value(this%connectivity_ptr) |
| 577 |
call atlas__Connectivity__values(this%connectivity_ptr,values_cptr,values_size) |
| 578 |
call atlas__Connectivity__displs(this%connectivity_ptr,displs_cptr,displs_size) |
| 579 |
call atlas__Connectivity__counts(this%connectivity_ptr,counts_cptr,counts_size) |
| 580 |
|
| 581 |
call c_f_pointer(values_cptr, this%values_, (/values_size/)) |
| 582 |
call c_f_pointer(displs_cptr, this%displs_, (/displs_size/)) |
| 583 |
call c_f_pointer(counts_cptr, this%cols, (/counts_size/)) |
| 584 |
this%rows_ = atlas__Connectivity__rows(this%connectivity_ptr) |
| 585 |
if( associated( this%row ) ) deallocate(this%row) |
| 586 |
allocate( this%row(this%rows_) ) |
| 587 |
this%maxcols_ = 0 |
| 588 |
this%mincols_ = huge(this%maxcols_) |
| 589 |
do jrow=1,this%rows_ |
| 590 |
this%row(jrow)%col => this%values_(this%displs_(jrow)+1:this%displs_(jrow+1)+1) |
| 591 |
this%maxcols_ = max(this%maxcols_, this%cols(jrow) ) |
| 592 |
this%mincols_ = min(this%mincols_, this%cols(jrow) ) |
| 593 |
enddo |
| 594 |
if( associated( this%padded_) ) call update_padded(this) |
| 595 |
end subroutine |
| 596 |
|
| 597 |
subroutine update_padded(this) |
| 598 |
class(atlas_ConnectivityAccess), intent(inout) :: this |
| 599 |
integer(ATLAS_KIND_IDX) :: jrow, jcol |
| 600 |
if( associated(this%padded_) ) call atlas_deallocate_managedmem( this%padded_ ) |
| 601 |
call atlas_allocate_managedmem( this%padded_, [this%maxcols_,this%rows()] ) |
| 602 |
if( associated(this%padded_) ) then |
| 603 |
this%padded_(:,:) = this%missing_value_ |
| 604 |
do jrow=1,this%rows() |
| 605 |
do jcol=1,this%cols(jrow) |
| 606 |
this%padded_(jcol,jrow) = this%value(jcol,jrow) |
| 607 |
enddo |
| 608 |
enddo |
| 609 |
endif |
| 610 |
end subroutine |
| 611 |
|
| 612 |
subroutine delete_access_c(this_ptr) bind(c) |
| 613 |
use, intrinsic :: iso_c_binding, only : c_ptr, c_f_pointer |
| 614 |
type(c_ptr), value :: this_ptr |
| 615 |
type(atlas_ConnectivityAccess), pointer :: this |
| 616 |
call c_f_pointer(this_ptr,this) |
| 617 |
call delete_access(this) |
| 618 |
end subroutine |
| 619 |
|
| 620 |
subroutine delete_access(this) |
| 621 |
use, intrinsic :: iso_c_binding, only : c_int |
| 622 |
use atlas_connectivity_c_binding |
| 623 |
type(atlas_ConnectivityAccess), pointer, intent(inout) :: this |
| 624 |
if( associated( this%row ) ) deallocate(this%row) |
| 625 |
if( associated( this%padded_) ) call atlas_deallocate_managedmem(this%padded_) |
| 626 |
#ifndef _CRAYFTN |
| 627 |
! Cray compiler bug (CCE/8.7) leads to following runtime error here. |
| 628 |
! lib-4412 : UNRECOVERABLE library error |
| 629 |
! An argument in the DEALLOCATE statement is a disassociated pointer, an |
| 630 |
! unallocated array, or a pointer not allocated as a pointer. |
| 631 |
! --> Does this lead to a (tiny) memory leak? |
| 632 |
deallocate(this) |
| 633 |
#endif |
| 634 |
end subroutine |
| 635 |
|
| 636 |
!------------------------------------------------------------------------------- |
| 637 |
|
| 638 |
#if FCKIT_FINAL_NOT_INHERITING |
| 639 |
ATLAS_FINAL subroutine atlas_Connectivity__final_auto(this) |
| 640 |
type(atlas_Connectivity), intent(inout) :: this |
| 641 |
#if FCKIT_FINAL_DEBUGGING |
| 642 |
write(0,*) "atlas_Connectivity__final_auto" |
| 643 |
#endif |
| 644 |
#if FCKIT_FINAL_NOT_PROPAGATING |
| 645 |
call this%final() |
| 646 |
#endif |
| 647 |
FCKIT_SUPPRESS_UNUSED( this ) |
| 648 |
end subroutine |
| 649 |
#endif |
| 650 |
|
| 651 |
!------------------------------------------------------------------------------- |
| 652 |
|
| 653 |
#if FCKIT_FINAL_NOT_INHERITING |
| 654 |
ATLAS_FINAL subroutine atlas_MultiBlockConnectivity__final_auto(this) |
| 655 |
type(atlas_MultiBlockConnectivity), intent(inout) :: this |
| 656 |
#if FCKIT_FINAL_DEBUGGING |
| 657 |
write(0,*) "atlas_MultiBlockConnectivity__final_auto" |
| 658 |
#endif |
| 659 |
#if FCKIT_FINAL_NOT_PROPAGATING |
| 660 |
call this%final() |
| 661 |
#endif |
| 662 |
FCKIT_SUPPRESS_UNUSED( this ) |
| 663 |
end subroutine |
| 664 |
#endif |
| 665 |
|
| 666 |
!------------------------------------------------------------------------------- |
| 667 |
|
| 668 |
end module atlas_connectivity_module |
| 669 |
|