module printmat
contains
subroutine printnice(x,form)
integer :: n,i
real :: x(:,:)
character (128),optional :: form
n=size(x,dim=1)
if(present(form)) then
do i=1,n
write(*,form) x(i,:)
enddo
else
do i=1,n
write(*,'(100g12.5)') x(i,:)
enddo
endif
end subroutine printnice
end module
program assign3
use printmat
implicit none
integer :: n=2
real,allocatable :: a(:,:)
integer,allocatable :: b(:,:)
character (128) :: fmt
allocate(a(n,n),b(n,n))
a=reshape((/1.1234,2.1234,3.1234,5.1234/),(/n,n/))
b=reshape((/1,2,3,5/),(/n,n/))
print*,'Fixed format (g12.5)'
call printnice(a)
print*,'Format for real'
read(*,'(a128)') fmt
call printnice(a,form=fmt)
end program assign3