program salva_diretto
    implicit none
    integer :: i, j, n, r
    integer, parameter :: Nr=5, Nc=10
    integer, dimension(Nr,Nc) :: mat
    integer, dimension(Nr) :: posiz

    do i = 1, Nc
       do j = 1, Nr
          mat(j,i) = (j-1)*Nc + i
       enddo
    enddo
    WRITE(*,*) "Matrice:"
    do j = 1, Nr
       write(*,100) (mat(j,i),i=1,Nc)
    enddo
    WRITE(*,"(/)")

    OPEN(UNIT = 11, FILE = 'salva.dun', ACCESS='stream', FORM = 'FORMATTED', STATUS="REPLACE")
    do j = 1, Nr
       INQUIRE(11,POS=posiz(j))
       WRITE(11,100,IOSTAT=n) (mat(j,i),i=1,Nc)
       if (n.NE.0) then
          print*,' Errore scrittura record ',j
       end if
    enddo
    CLOSE(UNIT = 11)

   WRITE(*,*) "Riga da leggere?"
   READ*,r
   IF ( r >=1 .AND. r <= Nr ) THEN
     ! Si azzera la matrice per verifica
      mat(:,:) = 0
      OPEN(UNIT = 22, FILE = 'salva.dun', ACCESS='stream', FORM = 'FORMATTED', STATUS="OLD")
      WRITE(*,*) "Riga ",r," in posizione ",posiz,":"
      READ(22,100,IOSTAT=n, POS=posiz(r))  (mat(r,i),i=1,Nc)
      if (n.NE.0) then
          print*,' Errore lettura record ',r
       end if
      WRITE(*,100) (mat(r,i),i=1,Nc)
      CLOSE(UNIT = 22)
100 format(1x,10(i6.2))
   ENDIF
   stop
end
