Re: Initialisation of derived type array
- From: nospam@xxxxxxxxxxxxx (Richard E Maine)
- Date: Thu, 6 Apr 2006 07:45:36 -0700
Walter Spector <w6ws_xthisoutx@xxxxxxxxxxxxx> wrote:
David Flower wrote:
...
OK So far; but I want to initialise each array element to a different
value, and cannot find the syntax
I think you are looking for something like:
TYPE ( WRITE ) :: R(42) = (/ &
WRITE (1st set of values), &
WRITE (2nd set of values), &
...
WRITE (42nd set of values) &
/)
The main message I'd try to get across, again, is that there is no
special syntax for any of this stuff. You get this by putting together
the 3 pieces, namely:
1. The syntax of initialization in a type declaration, which is roughly
(omitting side matters)
type-specification :: object = value
All your questions are in essence about how to write a value.
2. To write a derived-type value, use a derived-type constructor,
as in
write(component-values)
This is not a syntax for writing a derived type value in
initialization. It is a syntax for writing a derived type value wherever
you happen to need one.
3. To write an array value, use an array constructor, as in
(/ list-of-values /)
or, using the f2003 brackets, supported by some current compilers,
[ list-of-values ]
This is not a syntax for writing array values in initialization. It is
a syntax for writing an array value wherever you happen to need one.
(And it has alternatives using implied DO, which are often handy).
Walter's example above just puts together those 3 parts.
--
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
.
- References:
- Initialisation of derived type array
- From: David Flower
- Re: Initialisation of derived type array
- From: Joost
- Re: Initialisation of derived type array
- From: Richard E Maine
- Re: Initialisation of derived type array
- From: David Flower
- Re: Initialisation of derived type array
- From: Walter Spector
- Initialisation of derived type array
- Prev by Date: Re: Fortran has little support for object-oriented
- Next by Date: Re: backslash escapes
- Previous by thread: Re: Initialisation of derived type array
- Next by thread: Re: Initialisation of derived type array
- Index(es):
Relevant Pages
|
|