program test_rrsqrt
 implicit none
  integer, parameter :: m = 5
  integer, parameter :: n = 10  
  real :: H(m,n)
  H = 1
  call testing_local_analysis_covar(H)
contains

 subroutine testing_local_analysis_covar(H)
  implicit none
  real, intent(in) :: H(:,:)
  real :: Pf(size(H,2),size(H,2))
  real :: HPH(2,2)
  integer :: mloc
  real, allocatable :: Hloc(:,:)
  real :: A(n,2), B(2,2)

  Pf = 1

  ! bug is not triggered if one these two lines are commented
  A = matmul(Pf, transpose(H))
  B = matmul(H,matmul(Pf,transpose(H)))

  mloc = 2
  write(6,*) 'size(H,2),n ',size(H,2), n, size(H,2) == n

  allocate(Hloc(mloc,size(H,2))) ! tiggers bug
!  allocate(Hloc(mloc,n))  ! does no trigger bug

  Pf = 1
  Hloc = 1

  HPH = matmul(Hloc,matmul(Pf,transpose(Hloc))) ! -> does not work, unless allocate(Hloc(mloc,n))
!  HPH = matmul(matmul(Hloc,Pf),transpose(Hloc)) ! -> works!
  write(6,*) 'HPH', HPH
  deallocate(Hloc)
 end subroutine testing_local_analysis_covar
end program test_rrsqrt
