Am I understanding this example correctly?

Is my understanding of following code correct?

By the way, I am not looking for answers to school questions,
I am 86. If my suspicion is correct, I have hit upon some text
from Harvard, that is, going by its layout.

SUBROUTINE nag_rand(table)
INTERFACE
SUBROUTINE g05faf(a,b,n,x)
REAL, INTENT(IN) :: a, b
INTEGER, INTENT(IN) :: n
REAL, INTENT(OUT) :: x(n)
END SUBROUTINE g05faf
END INTERFACE
REAL, DIMENSION(:), INTENT(OUT) :: table

call g05faf(-1.0,-1.0, SIZE(table), table)

What I understand
. a subroutine is being called from within a subroutine
. the subroutine produces an array called x with n elements
. it seems like the array is 2 fimensional
. it seems that the array, is being called table, and has n rows
. it seems that the starting values of the table are -1 per column
. but what the heck a nag_rand table might be?

1 Like

It looks like a wrapper built around a subroutine written in an older version of Fortran…

This could well be G05FAF from the NAG library. There are copies of the documentation online. It returns a vector of pseudo-random numbers uniformly distributed over the interval [a,b].

Specification

SUBROUTINE G05FAF(A, B, N, X, IFAIL)
INTEGER N, IFAIL
real A, B, X(N)

Re homework: you are never too old to learn, right? :slight_smile:

But the argument “table” is declared in the interface and the subroutine itself as one-dimensional.

The subroutine G05FAF was withdrawn from the NAG Fortran library as of Mark 22 (year 2009). The call shown in the OP makes no sense if G05FAF is the NAG library routine, however, since the width of the interval (-1.0, -1.0) is zero, and there can be no randomness in the values returned in table; they will all have to be -1.0, as well.

I am under the impression that the code I posted takes me too much outside the domain of modal Fortran use. So I am not pursuing the issue any further. Many thanks for the responses. Much appreciated. Patrick.