For Programmers: Free Programming Magazines  


Home > Archive > Fortran > November 2004 > declared array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author declared array
victor

2004-11-15, 8:56 am

Hi Experts,

I have seen many tutorial declared array in this form
INTEGER, DIMENSION(6) :: myArray
I an using a simpler form like this
INTEGER :: myArray(6)

Do you know any difference between those two forms?
David Ham

2004-11-15, 8:56 am

On 15 Nov 2004 03:45:57 -0800
victor@in-box.net (victor) wrote:

> Hi Experts,
>
> I have seen many tutorial declared array in this form
> INTEGER, DIMENSION(6) :: myArray
> I an using a simpler form like this
> INTEGER :: myArray(6)
>
> Do you know any difference between those two forms?


Only programming style. I prefer the former but an a lot of people
prefer the latter. Use whatever makes sense to you.

David
beliavsky@aol.com

2004-11-15, 8:56 am


victor@in-box.net (victor) wrote:
>Hi Experts,
>
>I have seen many tutorial declared array in this form
>INTEGER, DIMENSION(6) :: myArray
>I an using a simpler form like this
>INTEGER :: myArray(6)
>
>Do you know any difference between those two forms?


There is no difference. The F subset of Fortran 95 tries to ensure that there
is only one way to express something, and its authors chose the
form with DIMENSION. Both are ok in Fortran 95. When you have several arrays
of the same shape, it is convenient to write

real, DIMENSION(m,n) :: x,y,z

but when the arrays have different shapes I prefer

real :: x(m,n),y(m),z(n)

to writing

real, DIMENSION(m,n) :: x
real, DIMENSION(m) :: y
real, DIMENSION(n) :: z



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jim Giles

2004-11-15, 3:59 pm

victor@in-box.net (victor) wrote in message news:<aec1ceb.0411150345.c75330@posting.google.com>...
> Hi Experts,
>
> I have seen many tutorial declared array in this form
> INTEGER, DIMENSION(6) :: myArray
> I an using a simpler form like this
> INTEGER :: myArray(6)
>
> Do you know any difference between those two forms?


Semantically there is no difference. It's purely a
matter of coding style. When the F90 committee decided
to make all attributes of declared names declarable in
either separate attribute declaration statements or as
part of the type declaration statement, they added the
DIMENSION syntax you show above. At the time, the
DIMENSION statement itself was quite unpopular and
was really a likely candidate to be removed. But, it
was an attribute specification statement, so consistency
required it to be added to the type declaration syntax.

I personally would prefer that *all* uses of the DIMENSION
keyword be considered obsolescent and that the keyword
should be removed from the standard entirely. On the
other hand, there are those that claim to find the above
use of DIMENSION more legible.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
glen herrmannsfeldt

2004-11-15, 3:59 pm



Jim Giles wrote:

(regarding the difference between)

and[color=darkred]
[color=darkred]
> Semantically there is no difference. It's purely a
> matter of coding style.


Well, I would say as far as style, with more arrays the former
would be preferred,

INTEGER, DIMENSION(6) :: myArray1, myArray2, myArray3, myArray4

If you change the dimension you only need to change it
in one place, and it is easy to see that it applies to all.

(snip)

> I personally would prefer that *all* uses of the DIMENSION
> keyword be considered obsolescent and that the keyword
> should be removed from the standard entirely. On the
> other hand, there are those that claim to find the above
> use of DIMENSION more legible.


-- glen

Richard E Maine

2004-11-15, 3:59 pm

David Ham <d.a.ham@citg.tudelft.nl> writes:

> On 15 Nov 2004 03:45:57 -0800
> victor@in-box.net (victor) wrote:
>
....[color=darkred]
>
> Only programming style. I prefer the former but an a lot of people
> prefer the latter. Use whatever makes sense to you.


Swap the words "former" and "latter" in David's reply and you'll
get mine... complete with David's last sentence.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
victor

2004-11-15, 8:56 pm

Thanks David!

David Ham <d.a.ham@citg.tudelft.nl> wrote in message news:<20041115130122.792dd72f.d.a.ham@citg.tudelft.nl>...
> On 15 Nov 2004 03:45:57 -0800
> victor@in-box.net (victor) wrote:
>
>
> Only programming style. I prefer the former but an a lot of people
> prefer the latter. Use whatever makes sense to you.
>
> David

victor

2004-11-15, 8:56 pm

Thanks a lot for your help.

"beliavsky@aol.com" <beliavsky@127.0.0.1:7501> wrote in message news:<41989bf5_1@127.0.0.1>...
> victor@in-box.net (victor) wrote:
>
> There is no difference. The F subset of Fortran 95 tries to ensure that there
> is only one way to express something, and its authors chose the
> form with DIMENSION. Both are ok in Fortran 95. When you have several arrays
> of the same shape, it is convenient to write
>
> real, DIMENSION(m,n) :: x,y,z
>
> but when the arrays have different shapes I prefer
>
> real :: x(m,n),y(m),z(n)
>
> to writing
>
> real, DIMENSION(m,n) :: x
> real, DIMENSION(m) :: y
> real, DIMENSION(n) :: z
>
>
>
> ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
> http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
> ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

Jim Giles

2004-11-16, 3:56 am

glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote in message news:<cnaovl$hsl$1@gnus01.u.washington.edu>...
> Jim Giles wrote:
>
> (regarding the difference between)
>
> and
>
>
> Well, I would say as far as style, with more arrays the former
> would be preferred,
>
> INTEGER, DIMENSION(6) :: myArray1, myArray2, myArray3, myArray4
>
> If you change the dimension you only need to change it
> in one place, and it is easy to see that it applies to all.


A more common case, at least in my code, is a lot
of arrays with *related* but not *identical* bounds:

Integer :: a(5), b(-2:2) ! same size, different bounds
Real :: R(J,K), S(K,L), T(J,L) ! conformable for matrix mult.
etc.

And, if you really want to change the dimensions in
one place, use named constants as the bounds.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com