program salva_diretto
    implicit none
    integer :: i, j, lunrec, n
    integer, dimension(5,10) :: mat

    do i = 1, 10
       do j = 1, 5
          mat(j,i) = (j-1)*10 + i
       enddo
    enddo
    lunrec=10*4
    OPEN(UNIT = 11, FILE = 'salva.dun', ACCESS='stream', FORM = 'UNFORMATTED', STATUS="REPLACE")
    do j = 1, 5
       WRITE(11,IOSTAT=n) (mat(j,i),i=1,10)
       if (n.NE.0) then
          print*,' Errore scrittura record ',j
       end if
    enddo
    CLOSE(UNIT = 11)
   ! Si azzera la matrice per verifica
   mat(:,:) = 0
   OPEN(UNIT = 22, FILE = 'salva.dun', ACCESS='stream', FORM = 'UNFORMATTED', STATUS="OLD")
    do j = 1, 5
       READ(22,IOSTAT=n)  (mat(j,i),i=1,10)
       if (n.NE.0) then
          print*,' Errore lettura record ',j
       end if
    enddo
    CLOSE(UNIT = 22)
    do j = 1, 5
      write(*,100) (mat(j,i),i=1,10)
    enddo
100 format(1x,10(i6.2))
   stop
end
