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

Zero-size array literals
Hi all --

How does one express zero-sized array (vector) literal in Fortran
90/95/2000. Intuition would suggest something of the form (//), but what
then defines the type of the array?

cheers,

Rich

Report this thread to moderator Post Follow-up to this message
Old Post
Rich Townsend
06-03-05 08:57 AM


Re: Zero-size array literals
On Thu, 02 Jun 2005 22:38:42 -0400, Rich Townsend wrote:
> Hi all --

> How does one express zero-sized array (vector) literal in Fortran
> 90/95/2000. Intuition would suggest something of the form (//), but what
> then defines the type of the array?

Use an implied DO, such as

(/ (0.0, i=1,0) /)

which produces an empty array of type REAL.


--
Dave Seaman
Judge Yohn's mistakes revealed in Mumia Abu-Jamal ruling.
<http://www.commoncouragepress.com/i...book&bookid=228>

Report this thread to moderator Post Follow-up to this message
Old Post
Dave Seaman
06-03-05 08:57 AM


Re: Zero-size array literals
Dave Seaman wrote:

> On Thu, 02 Jun 2005 22:38:42 -0400, Rich Townsend wrote:
> 
>
> 
>
>
> Use an implied DO, such as
>
> 	(/ (0.0, i=1,0) /)
>
> which produces an empty array of type REAL.
>

Just to be clear: (/ /) is not allowed; what is
between must be a *list* of things, which cannot
be empty. Oops, g95 doesn't catch the error.

Another way is to use an empty section of another array:

program empty_array
real, dimension(99) :: a = 99

print *, "x", (/ a(1:0) /) , "x"
!                ^^^^^^

end program empty_array

--
Walt Brainerd         +1-877-355-6640 (voice & fax)
The Fortran Company   +1-520-760-1397 (outside USA)
6025 N. Wilmot Road   walt@fortran.com
Tucson, AZ 85750 USA  http://www.fortran.com

Report this thread to moderator Post Follow-up to this message
Old Post
Walt Brainerd
06-03-05 08:57 AM


Re: Zero-size array literals
In article <d7ofra$ekn$1@scrotar.nss.udel.edu>,
Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote:

> How does one express zero-sized array (vector) literal in Fortran
> 90/95/2000. Intuition would suggest something of the form (//), but what
> then defines the type of the array?

Excellent question. And you have hit upon exactly the reason for the
problem.  (What establishes the type). In f90/f95 you have to use
awkward workarounds like those mentioned by Dave and Walt. The zero-trip
implied DO is the "classic" answer, but I sure think it ugly and
nonintuitive. You add a DO loop, but then make sure that it doesn't
actually contribute any elements because you are really using it just as
a way to establish a type? Yukk. I'll note that zero-trip implied DO
loops in array constructors have several subtleties that required
multiple iterations of interpretations. Most of the subtleties involved
things uglier and more subtle than the examples here.  A "favorite"
involved using a function result to establish a character length...when
the function was invoked zero times. Ouch. You "obviously" can't do
that, but drawing the exact line between what you can and can't do was
very difficult.

F2003 has a syntax that addresses this. The syntax was introduced for
other reasons, but it turns out that it gives a (relatively) simple form
for a zero-sized array constructor as a side benefit. A zero-sized
default real array in f2003 could be written as

[real::]

(You can also use the (/ and /) in place of the [ and ], but I prefer
the square brackets). In place of the "real", you can have any type
specifier. A favorite example of mine is something like

[character(16):: 'tom', 'dick', 'harry']

To write something like that in f90/f95, you'd have needed to pad the
strings all to the same length. The type specifier establishes what the
type parameters for the constructor are, so that they don't have to be
inferred from the elements.

--
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
06-03-05 09:00 PM


Re: Zero-size array literals
On Thu, 2 Jun 2005, Walt Brainerd wrote:

> Dave Seaman wrote:
> 
>
> Just to be clear: (/ /) is not allowed; what is
> between must be a *list* of things, which cannot
> be empty. Oops, g95 doesn't catch the error.

It does now...

Thanks,
Andy


Report this thread to moderator Post Follow-up to this message
Old Post
Andy Vaught
06-03-05 09:00 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 06:43 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.