Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

declared array
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?

Report this thread to moderator Post Follow-up to this message
Old Post
victor
11-15-04 01:56 PM


Re: declared array
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

Report this thread to moderator Post Follow-up to this message
Old Post
David Ham
11-15-04 01:56 PM


Re: declared array
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 ther
e
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 News
groups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =
---

Report this thread to moderator Post Follow-up to this message
Old Post
beliavsky@aol.com
11-15-04 01:56 PM


Re: declared array
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

Report this thread to moderator Post Follow-up to this message
Old Post
Jim Giles
11-15-04 08:59 PM


Re: declared array

Jim Giles wrote:

(regarding the difference between)
 
and 

> 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


Report this thread to moderator Post Follow-up to this message
Old Post
glen herrmannsfeldt
11-15-04 08:59 PM


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

> 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.

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

Report this thread to moderator Post Follow-up to this message
Old Post
Richard E Maine
11-15-04 08:59 PM


Re: declared array
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

Report this thread to moderator Post Follow-up to this message
Old Post
victor
11-16-04 01:56 AM


Re: declared array
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 th
ere
> 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 arra
ys
> 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 Ne
wsgroups
> ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---[/c
olor]

Report this thread to moderator Post Follow-up to this message
Old Post
victor
11-16-04 01:56 AM


Re: declared array
glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote in message news:<cnaovl$hsl$1@gnus01.u.was
hington.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

Report this thread to moderator Post Follow-up to this message
Old Post
Jim Giles
11-16-04 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:28 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.