pure/impure issue...

From: Bart Vandewoestyne (MyFirstName.MyLastName_at_telenet.be)
Date: 03/24/05


Date: Thu, 24 Mar 2005 16:01:59 +0000 (UTC)

I'm having a situation like this, where I declare a function and inside
the function I'm calling the random_number intrinsic:

program test_pure

implicit none

contains

  function f(x) result(y)
    real, intent(in) :: x
    real :: y

    call random_number(x)

    y = x

  end function f

end program test_pure

Now i try to stick with F-syntax, and when I compile this, i get:

Error: test_pure.f95, line 11: Reference to impure subroutine RANDOM_NUMBER from pure procedure F

I really need random numbers, but it would also be nice to keep my f(x) as a
function and not change it to a subroutine.

Is there a way to create functions that call the random_number intrinsic in
their body? I would really like to keep my function, because if I change f(x),
this has consequences for other functions that call f(x), which i then will
also have to change to subroutines and so on and so on...

Regards,
Bart

-- 
	"Share what you know.  Learn what you don't."


Relevant Pages

  • Re: Host Association and DO Index Variables
    ... integer:: i, j, k, ijk ... end subroutine j_loop ... really recommend using implicit none. ... In particular, if you accidentally fail to declare j, then you will have ...
    (comp.lang.fortran)
  • Terminator 2.0 Fortran Source Code
    ... SUBROUTINE TailHookm ... implicit real*8 ... common/constm2/xm, gmmars, radM,rm,soiM,omm,phM,rpM ...
    (comp.lang.fortran)
  • Re: calculating the julian day
    ... SUBROUTINE calend ... Implicit None Statement .. ... TYPE, INTENT:: x ... Intrinsic Functions .. ...
    (comp.lang.fortran)
  • Re: memory leak help!
    ... a loop from the main program. ... REPLACE THE NEW COMPLEX INTO ORIGINAL ARRAY x ... END OF SUBROUTINE SCEUA ... IMPLICIT NONE ...
    (comp.lang.fortran)
  • Re: Pointers to procedures in Intel Fortran
    ... implicit none ... subroutine fooint ... end interface genfoo ...
    (comp.lang.fortran)