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

equivalence
Hi!

I was gven a source code like this:

DIMENSION A(3,3), B(3,3), C(3,3), U(6)

EQUIVALENCE ( A(1), C(1) ),( U(1), B(1) )

My compiler won't work with the equivalence statement.
I'd like to work around it, but I am not quite sure what this
equvalence stetement
here actually does, on which array elements it refers to...

Can anyone explain?


Report this thread to moderator Post Follow-up to this message
Old Post
Daniel
05-17-05 01:59 PM


Re: equivalence
"Daniel" <dalboz@gmx.net> wrote in message
news:1116327175.134413.205710@z14g2000cwz.googlegroups.com...
> Hi!
>
> I was gven a source code like this:
>
> DIMENSION A(3,3), B(3,3), C(3,3), U(6)
>
> EQUIVALENCE ( A(1), C(1) ),( U(1), B(1) )
>
> My compiler won't work with the equivalence statement.
> I'd like to work around it, but I am not quite sure what this
> equvalence stetement
> here actually does, on which array elements it refers to...
>
> Can anyone explain?
>

The compiler is correct, it should be:

EQUIVALENCE ( A(1,1), C(1,1) ),( U(1), B(1,1) )

where each array reference has the correct rank. The statement sets up a
mapping between the pairs of arrays listed; they then share the same
(common) storage.

Regards,

Mike Metcalf



Report this thread to moderator Post Follow-up to this message
Old Post
Michael Metcalf
05-17-05 01:59 PM


Re: equivalence
"Michael Metcalf" <metcalfmetcalf@compuserve.com> wrote in message
news:d6cjjt$j4j$05$1@news.t-online.com...
>
>
>
> The compiler is correct, it should be:
>
> EQUIVALENCE ( A(1,1), C(1,1) ),( U(1), B(1,1) )
>

And more readable imo is      EQUIVALENCE (A,C), (U,B)




Report this thread to moderator Post Follow-up to this message
Old Post
David Frank
05-17-05 08:59 PM


Re: equivalence
so this is not some strange kind of statement meaning something like:

(forgive this pseudocode)

EQUIVALENCE (A (1,"all elements"), C (1,"all elements")) , ( U (1), B
(1, "all elements"))

?


Report this thread to moderator Post Follow-up to this message
Old Post
Daniel
05-17-05 08:59 PM


Re: equivalence
Daniel wrote:
>
> so this is not some strange kind of statement meaning something like:
>
> (forgive this pseudocode)
>
> EQUIVALENCE (A (1,"all elements"), C (1,"all elements")) , ( U (1), B
> (1, "all elements"))
>
> ?

No (whatever your pseudocode is supposed to represent)...

The EQUIVALENCE simply aligns the subsequent elements of the arrays
beginning at the element explicitly given.

Report this thread to moderator Post Follow-up to this message
Old Post
Duane Bozarth
05-17-05 08:59 PM


Re: equivalence
"Daniel" <dalboz@gmx.net> wrote in message
news:1116332707.035488.55640@g14g2000cwa.googlegroups.com...
> so this is not some strange kind of statement meaning something like:
>
> (forgive this pseudocode)
>
> EQUIVALENCE (A (1,"all elements"), C (1,"all elements")) , ( U (1), B
> (1, "all elements"))
>
> ?
>

In your example it was apparent all arrays have base indices = 1
so my syntax:  EQUIVALENCE (A,C), (U,B)
sets  A array's starting address to C array's starting address, ditto U and
B arrays.
Then the usual Fortran array ordering takes over..
Test it out for yourself.



Report this thread to moderator Post Follow-up to this message
Old Post
David Frank
05-17-05 08:59 PM


Re: equivalence

Michael Metcalf wrote:
> "Daniel" <dalboz@gmx.net> wrote in message
> news:1116327175.134413.205710@z14g2000cwz.googlegroups.com...
> 
>
>
> The compiler is correct, it should be:
>
> EQUIVALENCE ( A(1,1), C(1,1) ),( U(1), B(1,1) )
>
> where each array reference has the correct rank. The statement sets up a
> mapping between the pairs of arrays listed; they then share the same
> (common) storage.

The relatively old FORTRAN 66 standard allowed the number of
subscripts in an EQUIVALENCE list to either be the same as
the rank of the array or to be 1.

If only one subscript was given, it was "as if" the array
element successor function was used to map the array to a
one dimension array.  For some reason, this feature was
removed in the FORTRAN 77 standard.

Back in the good old days, (before optimization was very
good, when machines had few registers, and integer multiply
took a long time) it was a reasonably common extension
to allow multidimensional arrays to be referenced with
only one subscript (which often was out of bounds) as
a way to linearize whole array processing in a single
DO loop and gain significant efficiency.

Dick Hendrickson
>
> Regards,
>
> Mike Metcalf
>
>


Report this thread to moderator Post Follow-up to this message
Old Post
Dick Hendrickson
05-17-05 08:59 PM


Re: equivalence
Dick Hendrickson wrote:
 
 
 
 
(snip)

> The relatively old FORTRAN 66 standard allowed the number of
> subscripts in an EQUIVALENCE list to either be the same as
> the rank of the array or to be 1.

> If only one subscript was given, it was "as if" the array
> element successor function was used to map the array to a
> one dimension array.  For some reason, this feature was
> removed in the FORTRAN 77 standard.

It does seem that it was removed in Fortran 77.  However,
as someone else mentioned, an array name representing the
first element of the array is still allowed.

While the appropriate number of subscripts are required, I
don't (yet) see the restriction that they be within the
bounds declared.  One could possibly, using sequence association,
EQUIVALENCE to array elements.  It might be that

REAL A(10,10),B(2)
EQUIVALENCE (A(99,1),B)

would still work.   I wouldn't recommend using it, though.

> Back in the good old days, (before optimization was very
> good, when machines had few registers, and integer multiply
> took a long time) it was a reasonably common extension
> to allow multidimensional arrays to be referenced with
> only one subscript (which often was out of bounds) as
> a way to linearize whole array processing in a single
> DO loop and gain significant efficiency.

This feature is still in new Fortran standards.  That is,
for assumed size arrays, one may use a dummy argument array
with a different number of subscripts, usually one.  This
allows one to write array processing routines independent of
the number of dimensions specified.

Given that case is still allowed, I wonder why the EQUIVALENCE
case was removed.

-- glen


Report this thread to moderator Post Follow-up to this message
Old Post
glen herrmannsfeldt
05-18-05 01:58 AM


Re: equivalence
Daniel wrote:
> Hi!
>
> I was gven a source code like this:
>
> DIMENSION A(3,3), B(3,3), C(3,3), U(6)
>
> EQUIVALENCE ( A(1), C(1) ),( U(1), B(1) )

Try:

EQUIVALENCE ( A(1,1), C(1,1) ), ( U(1), B(1,1))

> My compiler won't work with the equivalence statement.
> I'd like to work around it, but I am not quite sure what this
> equvalence stetement
> here actually does, on which array elements it refers to...

Compiler make and version, host O/S, and exact compiler messages
are very helpful in diagnosing problems.  However, the EQUIVALENCE
statement you showed should make most compilers give an error
message because of the way A, B and C were specified (wrongly) in
that statement.

> Can anyone explain?

This is "storage association".  It makes the array A and the array
C use the same storage locations, such that a change to, e.g., C(2,1)
changes the value of A(2,1) to the same value (these amount to aliases
for the same storage).  Similarly, U(5) refers to the same storage as
B(2,2), etc.

Regards, Ken
--
I don't speak for Intel, Intel doesn't speak for me...

Ken Fairfield
D1C Automation VMS System Support
who:   kenneth dot h dot fairfield
where: intel dot com

Report this thread to moderator Post Follow-up to this message
Old Post
Ken Fairfield
05-18-05 01:58 AM


Re: equivalence
In article <w4OdnY76T9Au0RffRVn-uw@comcast.com>,
glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:

[about equivalence]
> While the appropriate number of subscripts are required, I
> don't (yet) see the restriction that they be within the
> bounds declared.

That's probably because you are looking in the wrong place. I bet you
are looking under equivalence. It isn't there because it is much more
general restriction than that. But it isn't too hard to trace starting
from there.

In the f77 standard (because that seems to be the topical version here),
you can see in the section on equivalence (8.2.1) that one of the things
allowed in an equivalence is an "array element name" (F90 doesn't call
things like this "names", but I'll stick to f77 for now). "Array element
name" is defined in the eponymous section 5.3, where we see that it
involves "subscript expressions". "Subscript expression is defined in
5.4.2." The second para of 5.4.2 is the limitation in question.

> Given that case is still allowed, I wonder why the EQUIVALENCE
> case was removed.

Beats me. That was done in the change from f66 to f77, which predates my
involvement in standards activities. I was programming in Fortran then,
but didn't know much of anything about standards (a failing that I
apparently shared with most programers of the era).

--
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
05-18-05 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
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 10:08 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.