# Error with a function !

## Error with a function !

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```

6 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

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).

Retired 12/31/2016

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
```

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.

Retired 12/31/2016

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.

Thanks guys a bunch. Solved