- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We were just talking about initializers and DATA statements.
I have a situation where I need constants that are repeated.
I am not sure one can do that with just a DATA statement or
an INITIALIZER. Of course, it can done with a DO loop that executes only once.
But this would be cleaner, if i can only find the right syntax.
See uploaded file test23.f90
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can do it, but it's not pretty:
[fortran] real(16), save :: y1(21) = reshape([real(16)::],[21],pad=[real(16)::3.,2.,1.]) real(16), save :: y2(21) = reshape([real(16)::],[21],pad=[3.0_16]) real(16), save :: y3(21) = reshape([real(16)::],[21],pad=[real(16)::7.,2.,4.]) [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yeah, thats more ugly than the DO LOOP, IMHO.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
But it's compile-time. Up to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nested array constructors can be handy for this too.
real(16), save :: y1(21) = [ ( [
real
(16)::3.,2.,1.], i=1, 7) ]
For higher rank arrays, the SPREAD intrinsic will be handy, one day...

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page