Although it seems like it should be standard, I am pretty sure that the shape of the LHS has to match the RHS in a declaration. I think it is a good extension as that seems silly when the shape of the LHS is fixed; and because there is no such limitation with a DATA statement; but I think if I am
using “ifx -stand f18 xx.F90” I should be getting a warning about line #8.
program demo_clip
implicit none
integer :: ii(2,3)
! everyone takes a DATA statement
data ii/10,20,30,40,50,60/
#ifdef __INTEL_COMPILER
! ifort -stand f18 xx.f90 does not produce warning
integer :: jj(3,4)=[1,2,3,4,5,6,7,8,9,10,11,12]
#elif __GFORTRAN__
! gfortran requires a reshape
integer :: jj(3,4)=reshape([1,2,3,4,5,6,7,8,9,10,11,12],shape(jj))
#endif
call printi('ii=',ii)
call printi('jj=',jj)
contains
subroutine printi(title,a)
implicit none
! print small 2d integer scalar, vector, matrix in row-column format
character(len=*),intent(in) :: title
integer,intent(in) :: a(..)
character(len=*),parameter :: all='(" ",*(g0,1x))'
character(len=20) :: row
integer,allocatable :: b(:,:)
integer :: i
write(*,all,advance='no')trim(title)
! copy everything to a matrix to keep code simple
select rank(a)
rank (0); write(*,'(a)')' (a scalar)'; b=reshape([a],[1,1])
rank (1); write(*,'(a)')' (a vector)'; b=reshape(a,[size(a),1])
rank (2); write(*,'(a)')' (a matrix)'; b=a
rank default; stop '*printi* unexpected rank'
end select
! find how many characters to use for integers
write(row,'(i0)')ceiling(log10(real(maxval(abs(b)))))+2
row='(" > [",*(i'//trim(row)//':,","))' ! use this format to write a row
do i=1,size(b,dim=1)
write(*,fmt=row,advance='no')b(i,:)
write(*,'(" ]")')
enddo
write(*,all) '> shape=',shape(a),',rank=',rank(a),',size=',size(a)
write(*,*)
end subroutine printi
end program demo_clip