From: robin on
"glen herrmannsfeldt" <gah(a)ugcs.caltech.edu> wrote in message news:ht2ej1$21d$1(a)speranza.aioe.org...
| robin <robin51(a)dodo.com.au> wrote:
| > "Ron Shepard" <ron-shepard(a)NOSPAM.comcast.net> wrote in message
| > news:ron-shepard-2CB74D.18574819052010(a)news60.forteinc.com...
|
| > | No, fortran has always allowed variables to be used to declare the
| > | dimensions for dummy arrays.
|
| > Actually, no. Early FORTRAN compilers required declarations like
| > real x(1) for the dummy argument.
|
| Fortran 66 allows variable dimensions, but it doesn't allow for
| expressions. If you pass an N by N array to a rank 1 dummy, there
| is no way to do it.

Yes there is.
The value of n**2 is passed as an argument.
Something must be passed (either as an argument or in common)
and whether it's N or N**2 is irrelevant.

| You can't:
|
| dimension x(n*n)

Naturally.

| for example. I did run into this in WATFIV once, which does bounds
| checking (not optional). The only solution was to pass N*N as a
| separate argument. But most people used (1) unless there was a
| reason not to.

It was necessary to use (1) in early FORTRAN.


From: Peter Flass on
robin wrote:
> "glen herrmannsfeldt" <gah(a)ugcs.caltech.edu> wrote in message news:ht44qb$801$1(a)speranza.aioe.org...
> | Craig Powers <craig.powers(a)invalid.invalid> wrote:
> | > Dave Allured wrote:
> |
> | >> Perhaps you are looking for dynamic allocation. In the main program you
> | >> can do this:
> |
> | >> INTEGER N
> | >> REAL, DIMENSION(N), ALLOCATABLE :: MY_ARRAY
> |
> | > Should be DIMENSION(:), not DIMENSION(N), FYI.
> |
> | As I wrote previously, in the PL/I form you can give the dimension
> | with the declaration, and override it on ALLOCATE, or not.
>
> That's not so.
> Constant bounds given in the declaration cannot be overridden
> by ALLOCATE.
>
>

That's a difference I recently discovered between Enterprise PL/I and
PL/I 1.1. Your statement is true for the first, but not the second.
From: Tobias Burnus on
On 05/20/2010 06:37 AM, glen herrmannsfeldt wrote:
> In PL/I you can do it with BEGIN, to start a new scope and
> new set of automatic variables.

Ditto in Fortran 2008 with BLOCK:

$ gfortran test.f90 && ./a.out

5: 1, 2, 3, 4, 5,

$ cat test.f90

implicit none
integer :: n
n = 5
block
integer :: x(n)
x = [1,2,3,4,5]
print '(i0,a,*(i0,", "))', shape(x),': ', x
end block
end


Tobias
From: Dave Allured on
Craig Powers wrote:
>
> Dave Allured wrote:
> >
> > Perhaps you are looking for dynamic allocation. In the main program you
> > can do this:
> >
> > INTEGER N
> > REAL, DIMENSION(N), ALLOCATABLE :: MY_ARRAY
>
> Should be DIMENSION(:), not DIMENSION(N), FYI.

Yes, my bad. Thanks for catching that quickly.

--Dave
From: robin on
"Ron Shepard" <ron-shepard(a)NOSPAM.comcast.net> wrote in message
news:ron-shepard-81FAC7.23435119052010(a)forte.easynews.com...
| In article <4bf4b015$0$89674$c30e37c6(a)exi-reader.telstra.net>,
| "robin" <robin51(a)dodo.com.au> wrote:
|
| > | No, fortran has always allowed variables to be used to declare the
| > | dimensions for dummy arrays.
| >
| > Actually, no. Early FORTRAN compilers required declarations like
| > real x(1)
| > for the dummy argument.
|
| I have certainly seen old code written this way, but I did not know
| it was a restriction in the language. I thought it was because the
| programmers thought they could write more efficient code if they did
| the indexing themselves rather than declaring the dummy array as 2-D
| and letting the compiler do the indexing.
|
| For example, when moving down a column of a 2-D array, the loop
| would look like this (using otherwise modern syntax)
|
| k=...something...
| do i = 1, n
| ...expression involving a(i,k) ...
| enddo
|
| The general belief was that the compiler might generate the offset
| using the expression (k-1)*n+i on each pass through the loop. If
| the array were dimensioned instead as a 1-D array, then the loop
| would be written like
|
| k=...something...
| koff = (k-1)*n
| do i = 1, n
| ...expression involving a(koff+i) ...
| enddo
|
| If this is not the case, then I stand corrected, but I have always
| thought this was more a matter of programming style rather than a
| restriction of the language.
|
| In any case, this was all corrected by the late 60's and early 70's
| when I started programming in fortran. By then, the fortran
| compilers for various vendors allowed variables to be used in dummy
| array declarations, the optimization eliminated any advantage for
| manual computation of offsets into 1-D arrays. This was not true
| for many other languages, even those developed after this time,
| which allowed only constants in array declarations.

Both Algol and PL/I permitted (and still permit) variables
and expressions in array bound declarations.