Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Q about repetitive DATA statements

WSinc
New Contributor I
591 Views

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

0 Kudos
4 Replies
Steven_L_Intel1
Employee
591 Views

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]
0 Kudos
WSinc
New Contributor I
591 Views

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

0 Kudos
Steven_L_Intel1
Employee
591 Views

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

0 Kudos
IanH
Honored Contributor III
591 Views

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

0 Kudos
Reply