@ArneBab while I'm at it with unnecessary comments, you don't *have* to set the return value of a function to a variable of the same name, but if you don't want to, you need to be explicit about what the name of the result is called.
function myfunc result(ans)
real :: ans
ans = 3.0
end function