PROGRAM QR_test
  IMPLICIT NONE
  INTEGER :: m, n, lwork, i, j, info
  REAL, DIMENSION(:,:), ALLOCATABLE :: a
  REAL, DIMENSION(:), ALLOCATABLE :: tau, work
  CHARACTER*(*), PARAMETER :: form = '(6(2x,f8.6))'

  m = 6; n = 2; lwork = 2*m
  ALLOCATE(a(m,m), tau(MIN(m,n)), work(lwork))
  a = 0.d0
  a(:,1) = (/ 1.d0, 0.d0, 1.d0, 0.d0, 1.d0, 0.d0 /)
  a(:,2) = (/ 0.d0, 1.d0, 0.d0, 1.d0, 0.d0, 1.d0 /)
  CALL sgeqrf(m, n, a, m, tau, work, lwork, info)
  CALL sorgqr(m, m, MIN(m,n), a, m, tau, work, lwork, info)
  WRITE (*,form) a
END PROGRAM QR_test
