Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do I call a function within a function in Fortran77?

0 votes
asked Dec 25, 2020 by Rija Rehman (120 points)
I 've written this code but it is not working, Can anyone please tell me what is the mistake here?

program abc

real func

real g=9.8

real f

external f

print*,'func= ',func(f)

end program

function func(F)

real a=3

func= a*F

return

print*, 'func =',func

end function

function F(g)

F=g*2

return

end function

1 Answer

0 votes
answered Jan 4 by Peter Minarik (15,580 points)
edited Jan 4 by Peter Minarik

I've never written a Fortran code.

But it seems like you have to declare your variables first, then assign values, which you violate in your code (you declare and assign g on the same line and you declare a after you have assigned value to g).

I suggest having a look on a Fortran tutorial, such as this: https://www.tutorialspoint.com/fortran/index.htm

I played around a bit with the help of some tutorials and this is what I came up with:

program FunctionCallTest

! Declare your variable
real g
real a

! Assign your values
g = 9.8
a = 3

print *, 'func = ', func(a, g)
end program


function func(a, F)
func = a * F
end function func


function F(g)
F = g * 2
end function F

Feel free to modify it to suit your needs.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...