Re: Strange behavior using a module which uses another module



In article <ba7b849c-3c46-4bc8-98e4-9f48fed9c4ba@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
deltaquattro <deltaquattro@xxxxxxxxx> writes:

it's me again :-) I'm testing my function libraries against a standard
library and I don't understand what's happening. The libraries I
developed are called md_Jacobi and md_Global_funcs. The standard
library function is dgamma.f from SPECFUN.

module md_Global_funcs

private ! Make all symbols private
public dgamma, ... ! Only make the desired symbols public.

contains
...
real function lgamma(x)
...
write(*,*) 'foo' ! Keep in mind this instruction...
...
end function lgamma
...
end module md_Global_funcs


module md_Jacobi
use md_Global_funcs

Use md_Global_funcs, only : foobar ! Only need foobar().

....
end module md_Jacobi


program main
use md_Jacobi

Use md_Jacobi, only : dgamma

external dgamma

Remove the above line.

....
do i=1,10
write(*,*) 'x', i, 'dgamma', dgamma(real(i)), 'gamma',
gamma(real(i)), 'n!',factorial(i), lgamma(real(i))
end do
....
end program main

1) I was surprised that main was able to access gamma, lgamma and
factorial, defined in md_Global_funcs, since main only uses md_Jacobi
and not md_Global_funcs. However, I looked at MRC and found that since
md_Jacobi uses md_Global_funcs, then main has access to it also. Is it
possible to let a program unit A use a module B, without having access
to any module used by B unless explicitly used by A?

See above.

2) compiling with EFC, I get the following error:

due to the "write" instruction in lgamma. Why is the compiler
complaining about a recursive I/O?

Because you have an instance of recursive IO

write(*,*) lgamma(x)

function lgamma(x)
write(*,*) 'foo'
end function lgamma


How can I use print/write
statements to debug my libraries without incurring in this error?
Thanks,

See if your compiler has a unit attached to stderr.

--
Steve
http://troutmask.apl.washington.edu/~kargl/
.