!---------------------------------------------------------------------- ! !Problem with shape in reshape ! ! ------------------------------------------------------------------------ module lina2 use iso_fortran_env implicit none ! matrix type matrix (r,c,k) integer(int64),len::r,c=r integer,kind:: k=real32 real(k), dimension(1:r,1:c)::x contains private generic,public :: assignment(=) => copy_matrix2 generic,public :: print => print_matrix procedure :: copy_matrix2 procedure :: print_matrix end type matrix contains ! ! copy_matrix: assignment of an array to a matrix ! gives problem ! subroutine copy_matrix2(me,a) implicit none type(matrix(r=*,c=*)), intent(inout) :: me real, dimension(:), intent(in) :: a integer(int64) :: i if(me%r*me%c /= size(a)) then stop 'dimension mismatch' end if me%x=transpose(reshape(a,shape(me%x))) ! need to put shape between () otherwise unexpected behavior end subroutine copy_matrix2 subroutine write_matrix(a) implicit none real, dimension(:,:) :: a integer :: i,j write(*,*) do i = lbound(a,1), ubound(a,1) write(*,*) (a(i,j), j = lbound(a,2), ubound(a,2)) end do end subroutine write_matrix subroutine print_matrix(me) type(matrix(*,*)), intent(in) :: me call write_matrix(me%x) end subroutine print_matrix end module lina2