Re: Strange behavior using a module which uses another module



On Jul 31, 6:27 pm, deltaquattro <deltaquat...@xxxxxxxxx> wrote:
module md_Global_funcs
contains
  real function lgamma(x)
end module md_Global_funcs

module md_Jacobi
use md_Global_funcs
end module md_Jacobi

program main
use md_Jacobi

Here, you should be able to access lgamma of module md_Global_funcs,
which you import via module md_Jacobi. If this is not desired, you
have to use either "USE ..., ONLY:" or use PRIVATE/PUBLIC statements
in md_Jacobi.

external dgamma

(This declares dgamma as external procedure.)

I want to point out that some compilers such as xlf or gfortran 4.3
come as vendor extension with (d)gamma and lgamma; in Fortran 2008
they are called gamma and log_gamma. In your case there is no
ambiguity as lgamma will come from the module md_Global_funcs while
dgamma should come from the user-supplied library.

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?

module B
use A
private
public :: B_subroutine1, B_subroutine2, B_global_var1, B_type


2) compiling with EFC, I get the following error:
forrtl: severe (40): recursive I/O operation, unit -1, file unknown

due to the "write" instruction in lgamma. Why is the compiler
complaining about a recursive I/O? How can I use print/write
statements to debug my libraries without incurring in this error?

The problem is that you use:

write(*,*) gamma(real(i))

and then gamma not only return a real variable which is printed by the
WRITE but it also writes something itself. Assume you have in gamma:
write(*,*) 'foo'
and do then
write(*,*) 'a', gamma(0.0), 'B'
What should the program print?
foo
A 1.0 B
or
A foo
1.0 B
Now use also tabbing in the format for write... You see this causes
all kind of problems and is thus not allowed in Fortran.

Alternative for debugging: Keep the I/O in gamma but use:
r = gamma(real(i))
write(*,*) r
Alternatively, you could try not to print to STDOUT but to STDERR in
gamma, which might work. (Something like that is also allowed by newer
Fortrans, I forgot whether F 2003 or F 2008 and I forgot whether
STDERR + STDOUT was OK or not.)

Tobias
.



Relevant Pages

  • Re: floating point number help
    ... The C standard library doesn't contain a gamma() function. ... C99, they introduced the tgammafunction; I'm not sure why they didn't ... presence of a true gamma function, was considered to be too confusing ... so the committee opted for lgamma() and tgamma. ...
    (comp.lang.c)
  • Re: [9fans] Problems with pcc
    ... gamma isn't in my copy of c99 though: it defines lgamma and tgamma. ...
    (comp.os.plan9)