- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
I am trying to initialize a constant in a module by means of an intrinsic function.
MODULE Constants
IMPLICIT none
REAL*8 :: pi = acos(-1.d0)
END MODULE Constants
This is not allowed. Is there a way I can do this association within a MODULE? I realize that I can explicitly set pi = 3.14159...
but I would prefer to do it this way.
Thanks for your help.
Sincerely,
David
I am trying to initialize a constant in a module by means of an intrinsic function.
MODULE Constants
IMPLICIT none
REAL*8 :: pi = acos(-1.d0)
END MODULE Constants
This is not allowed. Is there a way I can do this association within a MODULE? I realize that I can explicitly set pi = 3.14159...
but I would prefer to do it this way.
Thanks for your help.
Sincerely,
David
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This compiles fine for me with 11.0. Perhaps you are using a much older compiler? Fortran 95 did not allow real-valued functions in initialization expressions.
I would suggest you use:
REAL(KIND=0.0D0), PARAMETER :: PI = ACOS(-1.0D0)
I would suggest you use:
REAL(KIND=0.0D0), PARAMETER :: PI = ACOS(-1.0D0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
This compiles fine for me with 11.0. Perhaps you are using a much older compiler? Fortran 95 did not allow real-valued functions in initialization expressions.
I would suggest you use:
REAL(KIND=0.0D0), PARAMETER :: PI = ACOS(-1.0D0)
I would suggest you use:
REAL(KIND=0.0D0), PARAMETER :: PI = ACOS(-1.0D0)
I am running the Intel Visual Fortran Compiler for Windowsversion 9.1 (I can not upgrade at this time since I am compiling MEx functions for Matlab and only version 9.1 is supported) and got the following errors using your suggestion,
Error: This is an incorrect value for a kind type parameter in this context. [0.0D0]
Error: This instrinsic function is invalid in constant expressions.
REAL(KIND=0.D0), PARAMETER :: PI = ACOS(-1.d0)
----------------------------------------------^
Can version Intel Fortran 9.1 support this construct?
Thanks again Steve.
Sincerely,
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A slightly different question but similar. In the documentation, ACOS appears to be only single precision and you would use DACOS for double precision. Is ACOS, in fact, generic? (and was it in V9.1)?
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I meant to write:
REAL(KIND(0.0D0))
not
REAL(KIND=0.0D0)
9.1 does not accept ACOS in an initialization expression. 10.1 does. I don't have 10.0 installed to try. This is a new feature of Fortran 2003.
Linda, ACOS is a generic name and has been since Fortran 77. I recommend always using the generic name unless you are passing an intrinsic function name as an actual argument.
REAL(KIND(0.0D0))
not
REAL(KIND=0.0D0)
9.1 does not accept ACOS in an initialization expression. 10.1 does. I don't have 10.0 installed to try. This is a new feature of Fortran 2003.
Linda, ACOS is a generic name and has been since Fortran 77. I recommend always using the generic name unless you are passing an intrinsic function name as an actual argument.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page