Re: Initialisation of derived type array



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
.



Relevant Pages

  • Re: How to do "Compile time" initialization of record array?
    ... It should be noted that there is proposed syntax for C# 3.0 which will ... public struct MyStruct ... What actually gets compiled is the same array initialization as there is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: It Hurts When I Do This
    ... We do have a syntax that means the entire array - the array name. ... I disagree that it helps to use a special notation to indicate that ... I think it a mistake to throw all this kind of thing in the language. ...
    (comp.lang.fortran)
  • Re: IVF is a wonderful compiler (was IVF continues to disappoint (relatively))
    ... In quite a few of these cases g95 is still unable to detect ... array syntax. ... Lots of competing compilers rewrite all array syntax into F77 ...
    (comp.lang.fortran)
  • Re: What does this script means?
    ... first is a dot-notation property accessor. ... special array accessing syntax. ... In my experience (including reading 400000 odd javascript relate Usenet ...
    (comp.lang.javascript)
  • Re: What does this script means?
    ... Richard Cornford wrote: ... Will add a new array object to the object "window" under the name foo, ... it is perfectly valid to use a function reference as the operand ... But that error is the syntax error that you introduced by moving the ...
    (comp.lang.javascript)