- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I am trying to run the following program but I am ending up with an error.
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 0000000000402BFA Unknown Unknown Unknown
a.out 0000000000402AAC Unknown Unknown Unknown
libc.so.6 000000341AC1ED1D Unknown Unknown Unknown
a.out 00000000004029A9 Unknown Unknown Unknown
Please help me
program roots
implicit none
real :: p,q,r, x_r1,x_r2,x_im1,x_im2
write(*,*)"please enter the values of the follwing variables"
write(*,*)"a,b,c"
read(*,*) p,q,r
call rootsfind
write(*,*) "x_real1=",x_r1,"x_real2=", x_r2
write(*,*) "x_imag1=",x_im1,"x_imag2=", x_im2
stop
end program roots
! started writing the subroutine
subroutine rootsfind(a,b,c,x_real1,x_real2,x_imag1,x_imag2,i)
implicit none
real::discr,d
real,intent(in)::a,b,c
real,intent(out)::x_real1,x_real2,x_imag1,x_imag2
integer,intent(out)::i
real,parameter::epsilon=1e-05
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (abs(a)<=epsilon) then
x_real1=-b/2*a;x_real2=0
x_imag1=0;x_imag2=0
i=1
return
end if
discr=b*b-4*a*c
d=sqrt(discr)
if (discr>=0)then
i=2
x_real1=(-b+d)/2*a
x_real2=(-b-d)/2*a
x_imag1=0;x_imag2=0
else
i=3
x_real1=-0.5*b/a; x_real2=x_real1
x_imag1=0.5*d/a;x_imag2=-x_imag1
end if
end subroutine rootsfind
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your
call rootsfind
is not supplying the arguments to
subroutine rootsfind(a,b,c,x_real1,x_real2,x_imag1,x_imag2,i)
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Jim Dempsey,
I am new to Fortran programming Please elaborate it a bit
Thank you
Santosh R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Jim Dempsey,
Thank you so much I could rectify this error now.
Santosh R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Additional information you may find of use.
In your original program, you were setting variables in the scope of the PROGRAM ROOTS, then making the call to ROOTSFIND. This is one instance of performing the method in rootsfind. Now then, assume in your PROGRAM ROOTS you want to make the call to ROOTSFIND in multiple places, each call using the same argument lists. Also assume that ROOTSFIND is never to be called from elsewhere from ROOTS. In Fortran there is a means to permit the called subroutine to have access to the namespace of the CALL-er.
**** untested code ***
program roots implicit none real :: a,b,c, x_real1,x_real2,x_imag1,x_imag2 integer :: i write(*,*)"please enter the values of the follwing variables" write(*,*)"a,b,c" read(*,*) a,b,c call rootsfind write(*,*)"a,b,c", a,b,c write(*,*) "x_real1=",x_real1,"x_real2=", x_real2 write(*,*) "x_imag1=",x_imag1,"x_imag2=", x_imag2 write(*,*) "i=",i c = 0.0 call rootsfind write(*,*)"a,b,c", a,b,c write(*,*) "x_real1=",x_real1,"x_real2=", x_real2 write(*,*) "x_imag1=",x_imag1,"x_imag2=", x_imag2 write(*,*) "i=",i b = 0.0 call rootsfind write(*,*)"a,b,c", a,b,c write(*,*) "x_real1=",x_real1,"x_real2=", x_real2 write(*,*) "x_imag1=",x_imag1,"x_imag2=", x_imag2 write(*,*) "i=",i stop contains subroutine rootsfind implicit none real::discr,d real,parameter::epsilon=1e-05 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (abs(a)<=epsilon) then x_real1=-b/2*a;x_real2=0 x_imag1=0;x_imag2=0 i=1 return end if discr=b*b-4*a*c d=sqrt(discr) if (discr>=0)then i=2 x_real1=(-b+d)/2*a x_real2=(-b-d)/2*a x_imag1=0;x_imag2=0 else i=3 x_real1=-0.5*b/a; x_real2=x_real1 x_imag1=0.5*d/a;x_imag2=-x_imag1 end if end subroutine rootsfind end program roots
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Jim Dempsey,
Thank you ver much for your kind reply. It is very useful for beginners like me.
I will definitely be in touch with you and need your help
Thank you.
Santosh R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Santosh R. wrote:
.. I am new to Fortran programming ..
@Santosh R.,
You may want to look up these sources if you plan to delve more into Fortran:
- https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world
- http://fortranwiki.org/fortran/show/HomePage
- http://www.egr.unlv.edu/~ed/fortran.html
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page