You have two problems here:
a) an executable statement which is not in a routine.
What you really want is
real(8) :: b = sqrt(a)
This doesn't work either (even though a few compilers accept it), because
b) an initialization expression may only use intrinsics where argument and
result are integer or character expressions. The reason is that real
intrinsics are often linked from a library and therefore not available at
compile time.
Solutions:
1) do it by hand:
real(kind(1.d0)), parameter :: b = 3.1622776601683793319.d0 !Sqrt(10)
For small numbers of constants I would prefer that.
2) An initialization routine
module constants
integer, parameter :: dk = selected_real_kind(10)
real(dk) :: a = 10
real(dk) :: b
contains
subroutine init_constants
b = sqrt(a)
...
You have to call that routine once at the start of your program.
Note that hardwired kind values are not necessarily portable (neither is
kind(1.d0), which I used in my first example above, but it's a bit more
obvious on which platforms it will go wrong). There was a thread about this
problem on the list not long ago.
HTH,
Herbert
> -----Original Message-----
> From: celevic [mailto:[log in to unmask]]
> Sent: 10 May 2004 15:08
> To: [log in to unmask]
> Subject: modules & intrinsic functions
>
> Hallo everybody,
> it seems that is not possible defining constants inside modules using
> intrinsic functions. Any trick?
> Example:
>
> MODULE constants
> IMPLICIT NONE
> REAL(8), PARAMETER :: a=10
> REAL(8) :: b
> b=sqrt(a)
> END MODULE constants
>
> Error: This statement must not appear in the specification part of a
> module
> b=sqrt(a)
>
> Thank you,
> Celevic
This e-mail has been scanned by Trend InterScan Software.
This e-mail (and its attachment(s) if any) is intended for the named
addressee(s) only. It may
contain information which is privileged and confidential within the
meaning of the applicable law.
Unauthorised use, copying or disclosure is strictly prohibited and may
be unlawful.
If you are not the intended recipient please delete this email and
contact the sender via email return.
Fujitsu Laboratories of Europe Ltd (FLE) does not accept responsibility
for changes made to this email after
it was sent. The views expressed in this email may not necessarily be
the views held by FLE.
Unless expressly stated otherwise, this email does not form part of a
legally binding contract
or agreement between the recipient and Fujitsu Laboratories of Europe Ltd (FLE).
|