- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
i would appreciate it if someone tells me why this code does not work and how to get it to work? i get sigsegv with ifort (and with g95).
i followed the example on this page: http://www.pcc.qub.ac.uk/tec/courses/f77tof90/ohp/f90ohp_6.html
implicit none
real(8), pointer :: a(:)
integer(4) :: n
write(*,*)'enter size of matrix:'
read(*,*)n
allocate(a(n))
call sub1(a,n)
end
subroutine sub1(u,n)
implicit none
real(8) :: u(:)
integer(4) :: i,n
do i=1,n
write(*,*)i,u(i)
end do
end subroutine sub1
Thanks for any help!
i would appreciate it if someone tells me why this code does not work and how to get it to work? i get sigsegv with ifort (and with g95).
i followed the example on this page: http://www.pcc.qub.ac.uk/tec/courses/f77tof90/ohp/f90ohp_6.html
implicit none
real(8), pointer :: a(:)
integer(4) :: n
write(*,*)'enter size of matrix:'
read(*,*)n
allocate(a(n))
call sub1(a,n)
end
subroutine sub1(u,n)
implicit none
real(8) :: u(:)
integer(4) :: i,n
do i=1,n
write(*,*)i,u(i)
end do
end subroutine sub1
Thanks for any help!
o.
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Among the first suspects would be stack overflow. Lookupprevious articles on that on this forum.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The program is not legal Fortran - because sub1 has an assumed-shape argument, an explicit interface is required to be visible to the caller, as that web page states.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
according to the website i referenced, i do NOT need an interface in this case -- one only needs an interface in the second example (sub2) where the argument is also a pointer.
does the website have it backwards?
i'll appreciate further help.
thanks again!
o.
does the website have it backwards?
i'll appreciate further help.
thanks again!
o.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Either that website is not a very good reference or you have misinterpreted what it has to say, because sub1 definitedly requires an explicit interface. In sub1, if u were dimensioned u(n) [making it an adjustable array] or u(*) [an assumed-size array], an explicit interface would not be required, but since it is u(:) [an assumed-shape array], an explicit interface is required.
Rather than using an interface block, many people would prefer to make sub1's interface explicit by putting it in a module and then using the module in the main program.
-Kurt
Rather than using an interface block, many people would prefer to make sub1's interface explicit by putting it in a module and then using the module in the main program.
-Kurt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Technically, for this to be recognized as assumed-size, so that the explicit interface is not required, the f77 style upper bound * must be supplied:
real(kind(1d0)) :: u(1:*)
I don't find a discussion of this on the qub web site. Most compilers have some extensions in the area of assumed-size, not all implemented identically, so it's possible some might work with your example. It does look like an easy mistake to make, when there is no clear compile error message. ifort -gen-interfaces -warn-interfaces does diagnose that your example is taken as assumed shape and requires explicit interface.
real(kind(1d0)) :: u(1:*)
I don't find a discussion of this on the qub web site. Most compilers have some extensions in the area of assumed-size, not all implemented identically, so it's possible some might work with your example. It does look like an easy mistake to make, when there is no clear compile error message. ifort -gen-interfaces -warn-interfaces does diagnose that your example is taken as assumed shape and requires explicit interface.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is assumed-shape, not assumed-size. I looked at the web page referenced and did not see this specific example. Where I did see similar code it said "don't forget the explicit interface!". Ideally you would use a contained or module procedure and not write an interface block.
I wrote more on this topic some years ago. Doctor Fortran Gets Explicit
I wrote more on this topic some years ago. Doctor Fortran Gets Explicit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, Kurt, Tim,
thanks for your help.
i finally included my subroutines as part of the main code using "CONTAINS". i guess this is equivalent to using a module although less convenient.
thanks again.
o.
PS: i guess the website i sent or this one (which has similar code and wrong explanation) should be corrected.
http://www.pcc.qub.ac.uk/tec/courses/f77tof90/stu-notes/f90studentMIF_6.html
it says this just after the incorrect code snippet. (i'm including this to verify i did not read this wrong)
thanks for your help.
i finally included my subroutines as part of the main code using "CONTAINS". i guess this is equivalent to using a module although less convenient.
thanks again.
o.
PS: i guess the website i sent or this one (which has similar code and wrong explanation) should be corrected.
http://www.pcc.qub.ac.uk/tec/courses/f77tof90/stu-notes/f90studentMIF_6.html
it says this just after the incorrect code snippet. (i'm including this to verify i did not read this wrong)
The important points here are:
Both sub1 and sub2 are external procedures. Because sub2 has a pointer dummy argument, an interface block is required to provide an explicit interface in the calling program unit (not for sub1 since it has an assumed shape array as a dummy argument). An alternative approach would be using a module or internal procedure to provide an explicit interface by default.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If that is what it says, then it is wrong. Assuned-shape array requires explicit interface, and if you build with:
-gen-interface -warn interface
ifort will complain about this.
-gen-interface -warn interface
ifort will complain about this.

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