I am building a program that must call a subroutine in a function subprogram and be able to call the same subroutine in the main program.
program main
implicit double precision (a-h,o-z)
parameter (ncmax=20)
dimension z(ncmax)
xI=1.0
xII=2.0
z(1)=1.0
outI = fncn (xI,xII,z,ncmax)
call Sub (xI,xII,xIII,z)
outII = 2.0*xIII
end program
function fncn (xI,xII,z,ncmax)
implicit double precision (a-h,o-z)
dimension z(ncmax)
Call Sub (xI,xII,xIII,z)
fncn = xIII
return
end function
subroutine Sub (xI,xII,xIII,z)
parameter (ncmax=20)
implicit double precision (a-h,o-z)
dimension z(ncmax)
xIII = xI + xII + z(1)
return
end subroutine
This is all in fixed format fortran 77 ('.f' extension). The error I receive is a segmentation fault. Am I supposed to make a module as some of the other posts on this site suggest? I am still a beginner and am not sure how to make a module in 77. The subroutine must be able to be accessed in the function and in the main program. My current program structure has the function and subroutine split into two separate .f files and include statements are used at the end of main.
I searched this site for similar problems and could only find help regarding fortran 90. I am using gfortran from gcc 4.6.1.
EDIT: I solved the problem. The subroutine that I was attempting to call in the function had both numerical and character outputs. I was overlooking the character outputs and did not have a character defined variable to handle the character output. Once I defined a character variable within the function everything worked fine. Thank you everyone for your patience and help.
-gand then run it in a debugger? I am curious why it would segfault at all (since I too don't see any apparent reason for a segfault).