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

dimension query
hi there,
I have what is probably a very stupid question :
why use DIMENSION statements to define arrays, when simply writing indices
seems to be sufficient ?
or is it ?

thanks
G.

Report this thread to moderator Post Follow-up to this message
Old Post
news
09-13-04 02:03 PM


Re: dimension query
news <tperzo@wanadoo.fr> wrote:
>hi there,
>I have what is probably a very stupid question :
>why use DIMENSION statements to define arrays, when simply writing indices
>seems to be sufficient ?
>or is it ?

I generally agree with you and rarely use DIMENSION statements. But they
can be convenient if you have several arrays with the same shape:

real, dimension(2,5) :: a,b,c,d

is more concise and easier to modify than

real :: a(2,5),b(2,5),c(2,5),d(2,5)

One could use DIMENSION when there are several ALLOCATABLE arrays with the
same number of dimensions, writing the slightly shorter

real, allocatable, dimension(:,:,:) :: a,b,c

instead of

real, allocatable :: a(:,:,:),b(:,:,:),c(:,:,:)

I think Walt Brainerd, one of the creators of the F (Fortran 95 subset) lang
uage,
which requires DIMENSION, has said that writing DIMENSION explicitly makes
it easier to find array declarations in code.



----== 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
09-13-04 02:03 PM


Re: dimension query
"beliavsky@aol.com" <beliavsky@127.0.0.1:7501> wrote in message
news:41458ef2$1_1@127.0.0.1...
>
> news <tperzo@wanadoo.fr> wrote: 
indices 
>
> I generally agree with you and rarely use DIMENSION statements. But they
> can be convenient if you have several arrays with the same shape:
>
> real, dimension(2,5) :: a,b,c,d
>
etc.

Correct, but that's not a DIMENSION statement, that's a DIMENSION attribute.
I think OP may have meant

DIMENSION  a(2,5),b(2,5),c(2,5),d(2,5)

which, as we all know, in the absence of an IMPLICIT NONE statement, can
lead one to forget the type specification, with potentially disastrous
consequences.

Regards,

Mike Metcalf



Report this thread to moderator Post Follow-up to this message
Old Post
Michael Metcalf
09-13-04 02:03 PM


Re: dimension query
On Mon, 13 Sep 2004 13:47:28 +0100, "Michael Metcalf"
<michael.metcalf@t-online.de> wrote:

[snip]
>DIMENSION  a(2,5),b(2,5),c(2,5),d(2,5)
>
>which, as we all know, in the absence of an IMPLICIT NONE statement, can
>lead one to forget the type specification, with potentially disastrous
>consequences.

But in the absence of IMPLICIT NONE, those are all real.  No need to
look back at the top of the program to see what they are.

Ken Plotkin


Report this thread to moderator Post Follow-up to this message
Old Post
Ken Plotkin
09-14-04 01:56 AM


Re: dimension query
Ken Plotkin <kplotkin@nospam-cox.net> wrote in message news:<31cck0t3d3aesbkg1tmcqeotto62p4
q7tk@4ax.com>...
> On Mon, 13 Sep 2004 13:47:28 +0100, "Michael Metcalf"
> <michael.metcalf@t-online.de> wrote:
>
> [snip] 
>
> But in the absence of IMPLICIT NONE, those are all real.  No need to
> look back at the top of the program to see what they are.
>
> Ken Plotkin

For the program

integer a
dimension a(2)
end

you DO need to look at the top of the program to know what kind of
variable 'a' is. By writing

integer a(2)
end

the information about 'a' is in one place. One wouldn't use 'a' as an
integer variable in a real program, but I think it is better to
localize information by using REAL, INTEGER, CHARACTER, or LOGICAL in
array declarations.

Report this thread to moderator Post Follow-up to this message
Old Post
beliavsky@aol.com
09-14-04 08:59 PM


Re: dimension query
beliavsky@aol.com wrote:

(snip)

> integer a(2)

> the information about 'a' is in one place. One wouldn't use 'a' as an
> integer variable in a real program, but I think it is better to
> localize information by using REAL, INTEGER, CHARACTER, or LOGICAL in
> array declarations.

Well, a could be an INTEGER variable in a program that only
used integer variables.  I know a program that started out

 INTEGERA,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q
,R,S,T,U,V,W,X,Y,Z

There is some advantage to using I though N to start
variable names, even in languages without Fortran's type rules.

-- glen


Report this thread to moderator Post Follow-up to this message
Old Post
glen herrmannsfeldt
09-16-04 10:01 AM


Re: dimension query
In article <31cck0t3d3aesbkg1tmcqeotto62p4q7tk@4ax.com>, Ken Plotkin
<kplotkin@nospam-cox.net> writes
>On Mon, 13 Sep 2004 13:47:28 +0100, "Michael Metcalf"
><michael.metcalf@t-online.de> wrote:
>
>[snip] 
>
>But in the absence of IMPLICIT NONE, those are all real.  No need to
>look back at the top of the program to see what they are.
>
>Ken Plotkin
>
The compiler knows they are real. We have no way of telling, other than
by trusting the programmer to have self-imposed coding standards for
variable names, whether they should have been double precision, logical
or even character. It's much easier to forget to put a declaration in
than it is to type the wrong one, and without IMPLICIT NONE, almost
impossible to detect.

Catherine.
--
Catherine Rees Lay
To email me, use my first name in front of the "at".

Report this thread to moderator Post Follow-up to this message
Old Post
Catherine Rees Lay
09-21-04 02:04 PM


Re: dimension query
In article <RW82d.97838$3l3.71366@attbi_s03>, glen herrmannsfeldt
<gah@ugcs.caltech.edu> writes
>beliavsky@aol.com wrote:
>
>(snip)
> 
> 
>
>Well, a could be an INTEGER variable in a program that only
>used integer variables.  I know a program that started out
>
>       INTEGERA,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q
,R,S,T,U,V,W,X,Y,Z
>
>There is some advantage to using I though N to start
>variable names, even in languages without Fortran's type rules.
>
>-- glen
>
I first learnt to program aged about 12, in BASIC on a ZX81. At the time
I thought it strange that all the sample programs used

FOR I = 1 TO N

It took another 9 years before I found out where it came from!

Catherine.
--
Catherine Rees Lay
To email me, use my first name in front of the "at".

Report this thread to moderator Post Follow-up to this message
Old Post
Catherine Rees Lay
09-22-04 02:09 PM


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:06 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.