- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If an array is described in a subroutine larger than in the main program, it is not transferred correctly. Here is the source.
--------------------------------------------------------
program bpro
implicit none
external :: bsub
integer*8 :: i, j
real*8, dimension(1:3, 1:3) :: a
a(1, 1) = 1.0d0
a(1, 2) = 2.0d0
a(1, 3) = 3.0d0
a(2, 1) = 4.0d0
a(2, 2) = 5.0d0
a(2, 3) = 6.0d0
a(3, 1) = 7.0d0
a(3, 2) = 8.0d0
a(3, 3) = 9.0d0
write(6, '(3D25.16)') ((a(i, j), j = 1, 3), i = 1, 3)
write(6, *)
call bsub(a)
stop
end program bpro
--------------------------------------------------------
subroutine bsub(array)
implicit none
real*8, dimension(1:10, 1:10) :: array
integer*8 i, j
write(6, '(3D25.16)') ((array(i, j), j = 1, 3), i = 1, 3)
return
end subroutine bsub
--------------------------------------------------------
Screen output:
0.1000000000000000D+01 0.2000000000000000D+01 0.3000000000000000D+01
0.4000000000000000D+01 0.5000000000000000D+01 0.6000000000000000D+01
0.7000000000000000D+01 0.8000000000000000D+01 0.9000000000000000D+01
0.1000000000000000D+01 0.0000000000000000D+00 0.0000000000000000D+00
0.4000000000000000D+01 0.0000000000000000D+00 0.0000000000000000D+00
0.7000000000000000D+01 0.0000000000000000D+00 0.0000000000000000D+00
Please comment on this... Sure, I can overcome this by a more careful definition of the matrix, e.g. like
subroutine bsub(array, n)
implicit none
real*8, dimension(1:n, 1:n) :: array
orinanother way. But I expected the simple source above towork properly.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To fix the basic problem, declare bsub as taking a ( : , : )size array. Or as you suggested, pass in the dimensions as a argument.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
t.f90(17) : Error: The storage extent of the dummy argument exceeds that of the
actual argument.
call bsub(a)
----------------^
Otherwise, the compiler doesn't have the information to connect the two and diagnose the error.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page