Q about repetitive DATA statements

Q about repetitive DATA statements

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

AttachmentSize
Download test23.f90252 bytes
5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Steve Lionel (Intel)'s picture

You can do it, but it's not pretty:

  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.])
Steve

Yeah, thats more ugly than the DO LOOP, IMHO.

Steve Lionel (Intel)'s picture

But it's compile-time. Up to you.

Steve

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...

Login to leave a comment.