- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
program MAIN
z1=seed(2311)
z2=random(0)
end
I took an existing program and stripped it down to illustrate this problem with the run-time library, particularly the random number generator. It appears that I am using it exactly as they say in the writeup. It crashes with a run-time exception, perhaps an out-of bounds access.
How do I know if the version of the RTL I'm using is compatible with the compiler version? Does it check that before starting execution?
z1=seed(2311)
z2=random(0)
end
I took an existing program and stripped it down to illustrate this problem with the run-time library, particularly the random number generator. It appears that I am using it exactly as they say in the writeup. It crashes with a run-time exception, perhaps an out-of bounds access.
How do I know if the version of the RTL I'm using is compatible with the compiler version? Does it check that before starting execution?
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is that you passed a constant to RANDOM - its argument is an output argument and you got an access violation when RANDOM tried to store to it. Please read the documentation more closely. You should also have a USE DFLIB in there.
I would suggest instead the Fortran standard RANDOM_NUMBER intrinsic.
As for RTL compatibility - if the RTL is incompatible, you'll either get a link error or a run-time error "invalid argument to run-time library". That isn't the case here.
Steve
I would suggest instead the Fortran standard RANDOM_NUMBER intrinsic.
As for RTL compatibility - if the RTL is incompatible, you'll either get a link error or a run-time error "invalid argument to run-time library". That isn't the case here.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Steve;
I used documentation that was on my CD-ROM. Here is what it says in the A to Z section under the letter R.
====================================================
RAND, RANDOM
Portability Functions: Return real random numbers in the range 0.0 through 1.0.
Module: USE DFLIB
Syntax
result = RAND ([ iflag ])
result = RANDOM (iflag)
iflag
(Input) INTEGER(4). Optional for RAND. Controls the way the random number is selected.
Results:
The result type is REAL(4). RAND and RANDOM return random numbers in the range 0.0 through 1.0.
Value of iflag Selection process
1 The generator is restarted and the first random value is selected.
0 The next random number in the sequence is selected.
Otherwise The generator is reseeded using iflag, restarted, and the first random value is selected.
When RAND is called without an argument, iflag is assumed
====================================================
According to what they say above, these are supposed to be used as function calls. I can try to make the changes you suggested, but I was still curious as to why the documentation appears to be wrong.
I used documentation that was on my CD-ROM. Here is what it says in the A to Z section under the letter R.
====================================================
RAND, RANDOM
Portability Functions: Return real random numbers in the range 0.0 through 1.0.
Module: USE DFLIB
Syntax
result = RAND ([ iflag ])
result = RANDOM (iflag)
iflag
(Input) INTEGER(4). Optional for RAND. Controls the way the random number is selected.
Results:
The result type is REAL(4). RAND and RANDOM return random numbers in the range 0.0 through 1.0.
Value of iflag Selection process
1 The generator is restarted and the first random value is selected.
0 The next random number in the sequence is selected.
Otherwise The generator is reseeded using iflag, restarted, and the first random value is selected.
When RAND is called without an argument, iflag is assumed
====================================================
According to what they say above, these are supposed to be used as function calls. I can try to make the changes you suggested, but I was still curious as to why the documentation appears to be wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are two different RANDOM routines. The documentation you're looking at is for the one in the Portability Library - the one I described is in the "default" library. The documentation does say:
"Note: Because Visual Fortran offers an intrinsic subroutine also called RANDOM in the default library, the only way to access this portability function is with the USE DFPORT statement. Without it, you can only access the default subroutine. "
but I note that the page says USE DFLIB at the top, which is wrong - it should be USE DFPORT. I'll let the writers know about this.
Steve
"Note: Because Visual Fortran offers an intrinsic subroutine also called RANDOM in the default library, the only way to access this portability function is with the USE DFPORT statement. Without it, you can only access the default subroutine. "
but I note that the page says USE DFLIB at the top, which is wrong - it should be USE DFPORT. I'll let the writers know about this.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, but I sincerely was not aware you had two different libraries.
I take it that the portability library is for other companies or older versions of FORTRAN.
Where would I find a discussion about that, in case this comes up again?
The search on HELP did not give me anything.
I take it that the portability library is for other companies or older versions of FORTRAN.
Where would I find a discussion about that, in case this comes up again?
The search on HELP did not give me anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suggest you look through the Programmer's Guide. There's an entire chapter devoted to the Portability Library, which is mostly meant for people coming from UNIX.
Steve
Steve

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page