Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

modules and intrisic functions

David_Sall
Beginner
689 Views
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
0 Kudos
4 Replies
Steven_L_Intel1
Employee
689 Views
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)
0 Kudos
David_Sall
Beginner
689 Views
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)
Hi Steve!

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
0 Kudos
lklawrie
Beginner
689 Views

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
0 Kudos
Steven_L_Intel1
Employee
689 Views
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.
0 Kudos
Reply