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

Error with a function !

Andrew_F_1
Beginner
410 Views

Hello,

Every time I try to execute this program, it says : error #6236: A specification statement cannot appear in the executable section. Does anybody has any idea about the reason ? Thanks

 

program FP
implicit none

real ::  Thita_PD
double precision::pi


pi=3.1415926536d0
Thita_PD = 25

!------------------------------!
FUNCTION Acw(r)    
real :: Acw
real, intent(in) :: r
Acw = 3*(r**2)*(cos(Thita_PD*pi/180d0)*((1/tan(30.0*pi/180d0))*cos(Thita_PD*pi/180d0)-sin(Thita_PD*pi/180d0)) &
+ Thita_PD*pi/180d0 + 30*pi/180d0 - pi/2) 
END function Acw
!------------------------------!
end program FP

 

0 Kudos
5 Replies
Steven_L_Intel1
Employee
410 Views

Since your function references things declared in the main program, what you want to do is make Acw a "contained" function. Add the single line:

CONTAINS

before the FUNCTION line. That will resolve the syntax error. I assume you're going to be adding a call to Acw somewhere (before the CONTAINS).

0 Kudos
Andrew_F_1
Beginner
410 Views

Thanks for your reply. The point is that I'm gonna use the equation 

Acw = 3*(r**2)*(cos(Thita_PD*pi/180d0)*((1/tan(30.0*pi/180d0))*cos(Thita_PD*pi/180d0)-sin(Thita_PD*pi/180d0)) &
16 + Thita_PD*pi/180d0 + 30*pi/180d0 - pi/2)

 

many times in my program so this is why I preferred to make it as a function. I tried doing what you told me but I got error #6633: The type of the actual argument differs from the type of the dummy argument.

program FP
implicit none
 
real ::  Thita_PD,x
double precision::pi
 pi=3.1415926536d0
Thita_PD = 25
!------------------------------!
x=Awc(5)
Contains
FUNCTION Acw(r)   
real :: Acw
real, intent(in) :: r
Acw = 3*(r**2)*(cos(Thita_PD*pi/180d0)*((1/tan(30.0*pi/180d0))*cos(Thita_PD*pi/180d0)-sin(Thita_PD*pi/180d0)) &
+ Thita_PD*pi/180d0 + 30*pi/180d0 - pi/2)
END function Acw
!------------------------------!
end program FP

 

 

0 Kudos
Steven_L_Intel1
Employee
410 Views

You want in line 9:

x = Acw(5.0)

5 is an integer and this doesn't match your declaration of the dummy argument as real.

0 Kudos
mecej4
Honored Contributor III
410 Views

Line-9 has two errors. The function name is not spelled correctly, and the argument should be of type real; change "5" to "5.0".

Secondly, note that the function could be written more compactly as "acw=C*r*r", where C is a constant multiplier -- everything in the expression that you showed except for "r**2". This constant may be declared and computed in the main program once for all, before calling the function any number of times.

0 Kudos
Andrew_F_1
Beginner
410 Views

Thanks guys a bunch. Solved

0 Kudos
Reply