From: Ron Shepard on
In article <pf78v5tb326geernjm91h7prml0d0maait(a)4ax.com>,
ivan martin <i.martin(a)invalid.com> wrote:

> Shouldn't parameter keyword be used every time we wish to,
> for example, declare an array ?

No, fortran has always allowed variables to be used to declare the
dimensions for dummy arrays. It is only the lesser languages such as C
and pascal that are restricted to constants. This is why it is so
tedious to write, for example, general linear algebra libraries in some
of these other languages.

$.02 -Ron Shepard
From: glen herrmannsfeldt on
Ron Shepard <ron-shepard(a)nospam.comcast.net> wrote:
> In article <pf78v5tb326geernjm91h7prml0d0maait(a)4ax.com>,
> ivan martin <i.martin(a)invalid.com> wrote:

>> Shouldn't parameter keyword be used every time we wish to,
>> for example, declare an array ?

> No, fortran has always allowed variables to be used to declare the
> dimensions for dummy arrays.

At least since Fortran 66. I am not so sure about Fortran II,
where user supplied subroutines and functions were first added.

> It is only the lesser languages such as C
> and pascal that are restricted to constants.

Fixed in C99. Though in C89 much of the time an array of pointers
are used instead of a 2D arrays, so the problem really doesn't occur.

> This is why it is so tedious to write, for example, general
> linear algebra libraries in some of these other languages.

The linear algebra libraries I used to see in the Fortran 66
days were even more tedious, most using (1) for the dummy array
and calculating the appropriate subscript. That was especially
true for routines allowing triangular or diagonal matrices as
arguments.

-- glen
From: robin on
"mecej4" <mecej4_no_spam(a)operamail.com> wrote in message news:ht181t$8vf$1(a)news.eternal-september.org...
| On 5/19/2010 12:26 PM, ivan martin wrote:
| > Maybe a naive question, but why do we need when in main program
| > !************
| > integer, parameter :: n=100
| > real, dimension(n) :: my_array
| >
| > end
| > !************
| > but when in a subroutine
| >
| > !************
| > subroutine my_subroutine(n,array)
| > integer, intent(in) :: n
| > real, dimension(n), intent(inout) :: array
| > <snip some code>
| >
| > end subroutine my_subroutine
| > !************
| >
| > e.g. where did the "parameter" go ?
| > (I'm sure you understand what I'm aiming on by now)
| >
| > Shouldn't parameter keyword be used every time we wish to,
| > for example, declare an array ?
| >
| > -- Ivan
|
| That is a valid, if naive, question.
|
| The use of a parameter (named constant) is not required, but using one
| makes the code more readable and easier to modify. If I have 15 arrays
| of size 100, and I want one day to enlarge them to size 200, with the
| declared parameter I change one instance of 100 to 200, instead of 15
| instances of 100.

That used to be the case with FORTRAN 77 and earlier
(not using adjustable dimensions).
With Fortran 90 (which the OP is using), the use of PARAMETER
for array bounds is not warranted, for Fortran 90 +
have dynamic arrays. Thus, the bound (n) of an array could be
read in, and all arrays defined in terms of such a variable.


From: robin on
"Ron Shepard" <ron-shepard(a)NOSPAM.comcast.net> wrote in message
news:ron-shepard-2CB74D.18574819052010(a)news60.forteinc.com...
| In article <pf78v5tb326geernjm91h7prml0d0maait(a)4ax.com>,
| ivan martin <i.martin(a)invalid.com> wrote:
|
| > Shouldn't parameter keyword be used every time we wish to,
| > for example, declare an array ?
|
| 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.

| It is only the lesser languages such as C
| and pascal that are restricted to constants. This is why it is so
| tedious to write, for example, general linear algebra libraries in some
| of these other languages.


From: glen herrmannsfeldt on
robin <robin51(a)dodo.com.au> wrote:
> "mecej4" <mecej4_no_spam(a)operamail.com> wrote in message news:ht181t$8vf$1(a)news.eternal-september.org...
> | On 5/19/2010 12:26 PM, ivan martin wrote:
> | > Maybe a naive question, but why do we need when in main program

> | > integer, parameter :: n=100
> | > real, dimension(n) :: my_array
(snip)

> That used to be the case with FORTRAN 77 and earlier
> (not using adjustable dimensions).
> With Fortran 90 (which the OP is using), the use of PARAMETER
> for array bounds is not warranted, for Fortran 90 +
> have dynamic arrays. Thus, the bound (n) of an array could be
> read in, and all arrays defined in terms of such a variable.

I don't believe so. Note that the OP said MAIN. N would have
to be defined before entry to MAIN, but no statements, especially
no I/O, have yet been executed. It could be automatic or static,
but must be a compile time constant.

In PL/I you can do it with BEGIN, to start a new scope and
new set of automatic variables.

-- glen