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

PURE Functions

RobP
Beginner
1,345 Views

I've defined a code module (a Fortran F90 file) and supplied it with these two subroutines:

pure Subroutine XRotation (x, y, z, Xrot, xp, yp, zp)
! Rotate about X-axis through the angle Xrot

real*4, INTENT(IN) :: x, y, z, xrot
real*4, INTENT(OUT) :: xp, yp, zp
real*4 xrad

Xrad = Xrot * 3.141592627 / 180 ! Convert to radians
yp = y * COS(Xrad) + z * SIN(Xrad)
xp = x
zp = z * COS(Xrad) - y * SIN(Xrad)


END


Pure Subroutine DummyDummy()

Call XRotation(1,2,3,4,5,6,7)

End Subroutine

The compiler (Intel Fortran 12, targeting 32-bit Windows, for whatever that's worth) returns a single error message:

error #7137: Any procedure referenced in a PURE procedure, including one referenced via a defined operation or assignment, must be explicitly declared PURE. [XROTATION]

I'm a little bit stumped. How can I change this code so that the PURE Subroutine "DummyDummy" compiles?

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,345 Views
You have a couple of problems. First, you don't have a module - you just have two external procedures. When DummyDummy is compiled, it has no idea what the interface to Xrotation is - in particular, it doesn't know it's PURE. If you actually put these in a module and made the two procedures contained, then it would see that. So you'd have...

module mymod
contains
pure subroutine Xrotation...
...
end subroutine Xrotation
pure subroutine DummyDummy ...
...
end subroutine DummyDummy
end module mymod

The second problem is that you have passed all constants as arguments to Xrotation, but three of them are INTENT(OUT) - the compiler won't like that either if you make the interface visible.

View solution in original post

0 Kudos
2 Replies
Steven_L_Intel1
Employee
1,346 Views
You have a couple of problems. First, you don't have a module - you just have two external procedures. When DummyDummy is compiled, it has no idea what the interface to Xrotation is - in particular, it doesn't know it's PURE. If you actually put these in a module and made the two procedures contained, then it would see that. So you'd have...

module mymod
contains
pure subroutine Xrotation...
...
end subroutine Xrotation
pure subroutine DummyDummy ...
...
end subroutine DummyDummy
end module mymod

The second problem is that you have passed all constants as arguments to Xrotation, but three of them are INTENT(OUT) - the compiler won't like that either if you make the interface visible.
0 Kudos
RobP
Beginner
1,345 Views
With respect to that second problem, it's a poorly written question. DummyDummy was written only to expose the compiler error.

Thanks for the reminder about modules.
0 Kudos
Reply