Print

Print


On Thu, 2013-12-26 at 08:20 +0000, Xiaogang Wang wrote:
> Hi, Van,
> Thanks for your quick reply. Your suggestion solves the problem.
> I confused the dummy argument with the module variable.
> In fact, I have a long list of dummy arguments and their values are actually
> equal to the corresponding module arguments. So I rename the dummy arguments pi1
> as pi1_x etc and in the initialization subroutine add pi1 = pi1_x etc.
> 
> Part of the code now is,
> 
> module mymod
>   public :: initialize_mymod
>   public :: pi1, pi2,pi3
>   real*8 :: pi1,pi2,pi3
> 
>   subroutine initialize_mymod(pi1_x,pi2_x,pi3_x)
>   real*8, intent(in) :: pi1_x, pi2_x,pi3_x
>   pi1 = pi1_x
>   pi2 = pi2_x
>   pi3 = pi3_x
>   end subroutine initialize_mymod
> end module mymod

Again, "real*8" has never been part of a standard.  Declare a named
constant, for example "wp" for "working precision," in a module that is
used all your other program units.  The value of the named constant
specifies which kind of "real" to use.  There are several ways to
specify it, depending upon what you want.  If you want double precision,
the value could be declared by something like "integer, parameter :: WP
= kind(0.0d0)".  If you want, say, 14 digits, use something like
"integer, parameter :: WP = selected_real_kind(14)".  Use that named
constant to specify the value of the kind type parameter in "real"
declarations, for example using something like "real(wp)".  Don't use
literal constants because they're not portable.  For example, Intel
ifort uses 4 and 8 for default real and double precision.  By default,
NAG uses 1 and 2.  If you need to change the working precision of your
program, you can then change the value of the named constant, in one
place, instead of needing to edit your entire program to change "real*8"
to something else.

This is described in several textbooks, including "Modern Fortran
Explained" by Mike Metcalf, John Reid and Malcolm Cohen, or "Numerical
Computing with Modern Fortran" by Richard Hanson and Tim Hopkins.

> Xiaogang