I got a compiler error when trying to initialize an array with the following form:
real*8, dimension(25,11), parameter :: p=&
(/ 4.8610170D+00, 2.4603311D+00, 4.2003577D+01, 1.1525126D-02,&
… /)
The size of the comma-separated list is 275 elements (matching the dimension).
For this code I got the error: “Shape of initializer does not match the shape of p”
This code compiles under Intel Fortran.
I changed to:
real*8, dimension(25,11) :: p
data p/ << the same comma separated list of data >> /
and this worked.
Can someone explain why the PGI compiler won’t allow the ‘parameter’ syntax but it does allow the ‘data’ syntax?
Thank you.
Hi Jason,
I’ve created a simple test case which should reproduce the behavior you reported:
program arraytest
real*8, dimension(3,2), parameter :: p = &
(/ 1, 2, 3, 4, 5, 6 /)
end program arraytest
And I do see the error with PGI 14.3. I’ll file a report on it.
Best regards,
+chris
Here is a work-around:
Replace
real*8, dimension(25,11), parameter :: p=&
(/ 4.8610170D+00, 2.4603311D+00, 4.2003577D+01, 1.1525126D-02,&
... /)
by
real*8, dimension(25,11), parameter :: p=&
reshape( (/ 4.8610170D+00, 2.4603311D+00, 4.2003577D+01, 1.1525126D-02,&
... /), (/ 25, 11 )/ )/
[/quote]
Thanks cparrot and mecej4.
The ‘reshape’ work-around is what we are using.