Apart from what has been correctly pointed out, I think this person was trying to use the 'statement function' concept.
All other things being correct, I presume that still works but needs to appear in the 'main' program ?!
Best regards to all
Gary Hargraves
Senior Policy Officer, Water Management
Department of Natural Resources, Mines and Energy
Mobile: 0421 641 690
Landline: 322 76608
Email: [log in to unmask]
-----Original Message-----
From: Richard Maine [mailto:[log in to unmask]]
Sent: Tuesday, 11 May 2004 12:47 AM
To: [log in to unmask]
Subject: Re: modules & intrinsic functions
--On Monday, May 10, 2004 3:08 PM +0100 celevic <[log in to unmask]>
wrote:
> 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)
That's because your b is *NOT* a constant. It is a plain old ordinary
variable. The b=sqrt(a) statement is an executable statement, not a
declaration. Modules aren't executed, so this makes no sense. (Procedures
in modules can be executed, but not the module itself).
Your main problem here has nothing to do with modules. Since you
show that you do know how to declare a constant (your "a" is one),
I assume, though you didn't say, that you tried to declare b the same
way and it didn't work (as it wouldn't have). That's because you
can't use the sqrt intrinsic in initialization expressions. "Initialization
expression" is standard-speak for something that must be evaluated at
compile time. Constants must be defined by initialization expressions.
The upcoming f2003 standard does allow sqrt in this role, but none of the
prior versions did. Up through f95, you'll have to use an executable
statement to define sqrt - as your code above tries to do. You'll need to
find something that is actually executed to put the statement in. A module
procedure would do. You could have a module procedure named, perhaps,
initialize_constants. DOn't forget to call it from somewhere.
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
************************************************************************
The information in this e-mail together with any attachments is
intended only for the person or entity to which it is addressed
and may contain confidential and/or privileged material.
Any form of review, disclosure, modification, distribution
and/or publication of this e-mail message is prohibited.
If you have received this message in error, you are asked to
inform the sender as quickly as possible and delete this message
and any copies of this message from your computer and/or your
computer system network.
************************************************************************
|