Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Why won't this compile?

WSinc
Novo colaborador I
1.086 Visualizações
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.
0 Kudos
8 Respostas
IanH
Colaborador honorário III
1.086 Visualizações
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.

[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]
DavidWhite
Contribuidor valorado II
1.086 Visualizações
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
IanH
Colaborador honorário III
1.086 Visualizações
(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.
DavidWhite
Contribuidor valorado II
1.086 Visualizações
Sorry Ian. Somewhere I thought I saw Intel after your name - obviously the wrong Ian :-(

D
Steven_L_Intel1
Funcionário
1.086 Visualizações
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.
DavidWhite
Contribuidor valorado II
1.086 Visualizações
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
WSinc
Novo colaborador I
1.086 Visualizações
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. /
Steven_L_Intel1
Funcionário
1.086 Visualizações
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.
Responder