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

error with a calling a PURE procedure.

oleglebedev
New Contributor I
752 Views
Good day,
I have coded a subroutine which called another PURE procedure. I would like the first one to be a PURE procedure, too.
There is a simple snippet model of my code:
[fortran]PURE subroutine theAnotherOne(a,n,np,d,e)
    implicit none
    integer, intent(IN) :: n, np
    double precision, intent(INOUT) :: e(np), a(np,np)
    double precision, intent(OUT) :: d(np)
! ...
end subroutine theAnotherOne

!...

PURE subroutine theFirstOne(foo) ! I got the error about this procedure
    implicit none
    class(someClass), intent(INOUT) :: foo
!...
call theAnotherOne(a,n,np, foo%one,e) ! on this line...
!...
end subroutine theFirstOne
[/fortran]
I have read that
A PURE subroutine has no side effects other than changing the values of the INTENT(OUT) and INTENT(INOUT) arguments and/or pointer associations.
and I get the error#7137:Any procedure referenced in a PURE procedure, including one referenced via a defined operation or assignment, must be explicitly declared PURE

best regards,
Oleg.
0 Kudos
1 Solution
IanH
Honored Contributor III
752 Views
Are those procedures both module procedures or internal procedures - are they both after the contains statement of the same module or other program unit (and still inside that program unit)?

If they are not internal procedures or module procedures, then while compiling theFirstOne the compiler knows nothing about theAnotherOne - program units in Fortran are separately compiled even when they are in the same file. To fix this you ether need to provide an interface block for theAnotherOne inside theFirstOne; or make theAnotherOne an internal procedure of theFirstOne (put it after a contains statement in theFirstOne); or (best) make both procedures module procedures by putting both of them inside a module.

Note also, that if theFirstOne is not an internal procedure or module procedure then anything that calls it also needs to have access to its corresponding interface block due to the polymorphic argument (hence it is best if it is a module procedure).

If those procedures are already both internal procedures or module procedures inside the same program unit, then... ummm.... errr.... (I haven't got a clue...)... provide more information!

View solution in original post

0 Kudos
2 Replies
IanH
Honored Contributor III
753 Views
Are those procedures both module procedures or internal procedures - are they both after the contains statement of the same module or other program unit (and still inside that program unit)?

If they are not internal procedures or module procedures, then while compiling theFirstOne the compiler knows nothing about theAnotherOne - program units in Fortran are separately compiled even when they are in the same file. To fix this you ether need to provide an interface block for theAnotherOne inside theFirstOne; or make theAnotherOne an internal procedure of theFirstOne (put it after a contains statement in theFirstOne); or (best) make both procedures module procedures by putting both of them inside a module.

Note also, that if theFirstOne is not an internal procedure or module procedure then anything that calls it also needs to have access to its corresponding interface block due to the polymorphic argument (hence it is best if it is a module procedure).

If those procedures are already both internal procedures or module procedures inside the same program unit, then... ummm.... errr.... (I haven't got a clue...)... provide more information!
0 Kudos
oleglebedev
New Contributor I
752 Views
Thanks!
Your solution works.
I`ve been thinking about a module for theAnotherOne... But I have been trying a whole day to fix a couple of bug and I was a little bit tired.
Oleg.
0 Kudos
Reply