|
本帖最后由 苏坡,man 于 2016-1-20 19:21 编辑
module d7p
use ISO_C_BINDING
implicit none
type struct
integer(c_int) starti,endi,startj,endj
integer(c_int) k_N
integer(c_int) iter
! integer(c_int),pointer :: src_addr =>null()!void *src_addr
type(c_ptr) ::src_addr
end type
contains
subroutine neighbor(neighbor_addrs,num_neigh,args) !这个函数是传递给c函数使用,在c函数中需要使用到neighbor_addrs,num_neigh。neighbor_addrs在c函数那边被使用的类型是是void**,args在c函数那边被使用的类型是void*;num_neigh在c函数那边被使用的类型是int*
implicit none
include 'globals.h'
integer(c_int) starti,startj
integer(c_long),pointer :: src_p =>null()
type(c_ptr) :: src
! type(c_ptr) ::args
type(c_ptr) :: neighbor_addrs
type(struct),target :: args
integer(c_long),dimension(32),target :: addrs
integer(c_int),target :: num
!integer(c_int),pointer :: neighbor_addrs =>null()
integer(c_int),pointer :: num_neigh=>null()
starti = args%starti
startj = args%startj
src = args%src_addr
!args = c_loc(ar)
call c_f_pointer(src,src_p)
num = 1
if (starti>=BLKX)then
addrs(num) = (src_p-BLKX*BLKY*Z*8) !计算地址
neighbor_addrs = c_loc(addrs(num))!想给 neighbor_addrs使用数组addrs中的值
!neighbor_addrs => addrs(num)
num_neigh=>num
num=num+1
endif
if (starti<X-BLKX)then
addrs(num) = (src_p+BLKX*BLKY*Z*8)
! neighbor_addrs => addrs(num)
neighbor_addrs = c_loc(addrs(num))
num_neigh=>num
num=num+1
return
end subroutine neighbor
|
|