- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can't I put in recurring strings of data like this?
When I compile it, it gives me a syntax error, doesn't like the closing parenthesis.
see attached file.
When I compile it, it gives me a syntax error, doesn't like the closing parenthesis.
see attached file.
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The constants in a data-stmt are limited to scalars. You can have implied-do's on the object side, but I don't think that helps here without a lot of typing.
The alternative initializers that you can use in type declaration statements can be complicated array expressions. If ifort supported the F2003 capability of (polite cough, followed by expectant pause...) SPREAD in initialization expressions then the syntax is quite brief. Until then you might consider some games with RESHAPE.
The alternative initializers that you can use in type declaration statements can be complicated array expressions. If ifort supported the F2003 capability of (polite cough, followed by expectant pause...) SPREAD in initialization expressions then the syntax is quite brief. Until then you might consider some games with RESHAPE.
[fortran] IMPLICIT NONE
INTEGER :: i
integer(1) :: scale(14,16) &
= RESHAPE([([0, 2, 3, 5, 7, 9,11,12,14,15,17,19,21,23],i=1,16)], [14,16])
! With more complete F2003 support:
! INTEGER(1) :: scale(14,16) &
! = SPREAD([0, 2, 3, 5, 7, 9,11,12,14,15,17,19,21,23], DIM=2, NCOPIES=16)
! Print out as rows (first dimension) by columns (second dimension).
PRINT "(*(15(I3,','),I3,:,/))", TRANSPOSE(scale)
end
[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ian,
Can you add something like this to the documentation? There are no examples that I could find of how to use the implied do on the constant side of the DATA initialization.
thanks,
David
Can you add something like this to the documentation? There are no examples that I could find of how to use the implied do on the constant side of the DATA initialization.
thanks,
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(No more than you can! My ultimate lords and masters sometimes play in the same sandpit as yours (though they like a bit more variety in the colour of their sand...))
The implied do's can only be on the object side.
The implied do's can only be on the object side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry Ian. Somewhere I thought I saw Intel after your name - obviously the wrong Ian :-(
D
D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
DATA is a standard Fortran construct. It is documented, including using implied-DO. Two of the three examples in the Intel Language Reference use implied-DO. What else are you looking for? I will comment that the Intel Language Reference is not intended as a source for learning the language.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
All of the examples in the documentation set all of the elements of the array to the same value. Some examples of more difficult initialisation, like that of the OP problem, could be helpful. I don't really see it as "learning the language", more along the line of helpful tips.
Thanks,
David
All of the examples in the documentation set all of the elements of the array to the same value. Some examples of more difficult initialisation, like that of the OP problem, could be helpful. I don't really see it as "learning the language", more along the line of helpful tips.
Thanks,
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I thought a generalization of the IMPLIED DO LOOP was acceptable.
for example:
integer*1 a(40)
data a/20*3, 10*2, 10*5/
The above DOES compile.
I was trying to avoid something like:
data a/ 10,5,3,6,10,5,3,6, 10, 5, 3, 6, etc. etc. /
for example:
integer*1 a(40)
data a/20*3, 10*2, 10*5/
The above DOES compile.
I was trying to avoid something like:
data a/ 10,5,3,6,10,5,3,6, 10, 5, 3, 6, etc. etc. /
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In DATA, you can repeat single values as you show. But as others have said, what you want isn't currently available in Intel Fortran due to lack of support of transformational intrinsics in initialization expressions. Since these are variables, you could do this in an assignment.
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