I’m using pgf77 5.2-1 x86-64 on a linux AMD opteron system. I’m trying to access the function “rand”, which according to the manual is a “3F subroutine”. Supposedly, these functions are “automatically loaded from the PGI’s Fortran run-time library if referenced by a Fortran program.” However, when try to compile a program (testrand.f) containing rand, I get:
PGFTN-S-0038-Symbol, rand, has not been explicitly declared (testrand.f: 8)
Isn’t rand supposed to generate a number between 0 and 1???
Here’s my test code:
program testrand
implicit none
integer i
do i=1,20
print*,‘rand(0)’,rand(0)
enddo
end
If I remove the “implicit none” then it compiles and gives me the wild numbers like in the above example, as it seems to be accessing an unitialized “variable”. G77 outputs values between 0 and 1 as expected.
Ooops, yes your right. I forgot to declare ‘x’ and ‘rand’ as a double precision so they implicitly get defined as a REALs thus changing the value. In your case, the error “rand, has not been explicitly declared” is because you also need to declare ‘rand’ as a double precision. Example:
Ok, thanks - seems to work right now. I guess this arises from rand being double-precision in pgf77 but real in g77? Current test code produces an error in g77. Is there an easy way to make it work right in both?
For this example, you could declare rand as “REAL” instead of “double precision”. Then when compiling with pgf77 add “-r8” to promote all reals to “REAL*8”.