problem with use of DFPORT library

problem with use of DFPORT library

i have the following code to re-seed a random number stream:

subroutine SetSeed (seed)
!i have the relevant meta commands in here
use DFPORT
real(4) seed
call SRAND(seed)
end

I have compiled this and created a debug version of the DLL, which i call from VB. When i execute the line

call SRAND(seed)

a dialogue box appears asking me to specify a path for the library file DFPORT.FOR. The library file I have installed on my machine is DFPORT.F90, as I would have expected, and so I can not get this line to execute and re-seed the random number.

I have the same problem with the function to generate the random number which uses DRAND().

What am I doing wrong ?

Thanks

Phil.

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

an afterthought - dont know if it is relevant, but i am using windows 2k, and compaq vf professional 6.1.0.

phil

Use Step Over, not Step Into. You're stepping into the source of SRAND, which isn't available to you.

Steve

Steve - Intel Developer Support

thanks - the seeder seems to work ok. now having problems with the generator - I want double precision random numbers, so i am using DRAND in the following DLL function:

function GetRand()
use DFPORT
!DEC$ attributes dllexport :: GetRand
!DEC$ attributes alias : "GetRand" :: GetRand
real(8) GetRand
GetRand = DRAND(0)
return
end

When i call the dll function from XL I get an access violation error ????

grateful for any help.

phil.

Have you declared the value returned by GetRand as double precision in Excel?

Mike

thanks - but i had the following VBA declare statement, which does as you suggest, i think...

Declare Function GetRand _
Lib "h:...simstuff.DLL" () As Double

I have another couple of things to check but it looks OK to me ??

obviously any other ideas would be gratefully received - getting this working is rather a fundamental element of what I am trying to do.

phil.

the one other aspect of this i am not sure about is how the random no generator uses the seed to control the stream of random numbers. Am i doing this correctly ?

First I call the seeding subroutine:

subroutine SetSeed (seed)
use DFPORT
real(4) seed
call SRAND(seed)
end

from the VB sub:

Sub vbSetSeed()
Dim X As Single
X = Range("Seed").Value
Call SetSeed(X)
End Sub

(which seems to be working)

Then I execute a function call from VB to ask for the random number from the seeded stream:

VBGetRand = GetRand()

where GetRand is as described in the previous post.

Is this use of SRAND(seed) and DRAND(0) consistent ?

thanks again

Phil.

Have you considered using the standard Fortran intrinsic RANDOM_NUMBER (and RANDOM_SEED) instead? It's a better generator and is probably easier to understand.

Steve

Steve - Intel Developer Support

i might have to try it - can i use RANDOM_NUMBER to generate real(8) rather than real(4) numbers ? Also, because I have to generate a very large number of random nos, i have done a bit of work testing the true randomness of the rand() stream and it seems to be quite good. I do not know if random_number is as good - i am pretty wary of most pseudo rn generators.

Also I'd still like to understand why my use of SRAND and DRAND is not working.

Phil

Yes, RANDOM_NUMBER can return REAL(8). It's a very good generator - L'Ecuyer '83.

Steve

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today