Hi.
One of our users is having a problem and I'm a bit stumped as well. They're trying to pass a pointer component of a derived type into a subroutine and treating it as a normal array at the other end. However the data is ending up as garbage.
Is this legal?
module mod
type deriv
integer :: dummy
real(kind=8), dimension), pointer :: p
end type deriv
type(deriv) :: struct
end module mod
subroutine sub1()
use mod
implicit none
interface
subroutine sub2(t)
real(kind=8), dimension(0:25), intent(in) :: t
end subroutine sub2
end interface
allocate(struct%p(0:25))
! Set values of struct%p here........
!
call sub2(struct%p)
end subroutine sub1
subroutine sub2(t)
real(kind=8), dimension(0:25), intent(in) :: t
print*, t(0), t(1), t(2)
end subroutine sub2
-----------------------------------
Although struct%p contains the value 5.0 throughout (apart from index 0 which holds 0.0), the t array in sub2 holds:
3.2e-324 <denormalised>
3.2e-324 <denormalised>
0
3.2e-324 <denormalised>
3.2e-324 <denormalised>
0
etc.
The memory address for struct%p and t are identical.
Any help appreciated!
One of our users is having a problem and I'm a bit stumped as well. They're trying to pass a pointer component of a derived type into a subroutine and treating it as a normal array at the other end. However the data is ending up as garbage.
Is this legal?
module mod
type deriv
integer :: dummy
real(kind=8), dimension), pointer :: p
end type deriv
type(deriv) :: struct
end module mod
subroutine sub1()
use mod
implicit none
interface
subroutine sub2(t)
real(kind=8), dimension(0:25), intent(in) :: t
end subroutine sub2
end interface
allocate(struct%p(0:25))
! Set values of struct%p here........
!
call sub2(struct%p)
end subroutine sub1
subroutine sub2(t)
real(kind=8), dimension(0:25), intent(in) :: t
print*, t(0), t(1), t(2)
end subroutine sub2
-----------------------------------
Although struct%p contains the value 5.0 throughout (apart from index 0 which holds 0.0), the t array in sub2 holds:
3.2e-324 <denormalised>
3.2e-324 <denormalised>
0
3.2e-324 <denormalised>
3.2e-324 <denormalised>
0
etc.
The memory address for struct%p and t are identical.
Any help appreciated!