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

Downloadapplication/octet-stream test23.f90252 bytes
5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.])
Retired 12/31/2016

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

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

Retired 12/31/2016

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today