' ******************************************************************
' Save transformations used by ElmHes
' ******************************************************************

SUB Eltran(A()     AS DOUBLE,  _
           Lo      AS INTEGER, _
           Hi      AS INTEGER, _
           Inter() AS INTEGER, _
           Z()     AS DOUBLE)
' ------------------------------------------------------------------
' This subroutine is a translation of the EISPACK subroutine Eltran.
'
' This subroutine accumulates the stabilized elementary similarity
' transformations used in the reduction of a real general matrix
' to upper Hessenberg form by Elmhes.
'
' On input:
'
'   A contains the multipliers which were used in the reduction
'   by Elmhes in its lower triangle below the subdiagonal.
'
'   Lo and Hi are integers determined by the balancing procedure
'   Balance. If Balance has not been used, set Lo=Lbound(A),
'   Hi=Ubound(A).
'
'   Inter contains information on the rows and columns interchanged
'   in the reduction by Elmhes. Only elements Lo through Hi are used
'
' On output:
'
'   Z contains the transformation matrix produced in the reduction
'   by Elmhes.
' ------------------------------------------------------------------

  DIM AS INTEGER Lb, Ub, I, J, M, M1

  Lb = LBOUND(A, 1)
  Ub = UBOUND(A, 1)

  ' Initialize Z to identity matrix
  FOR I = Lb TO Ub
    FOR J = Lb TO Ub
      IF I = J THEN Z(I, J) = 1 ELSE Z(I, J) = 0
    NEXT J
  NEXT I

  IF Hi < Lo THEN EXIT SUB

  FOR M = Hi - 1 TO Lo + 1 STEP -1
    M1 = M - 1
    FOR I = M + 1 TO Hi
      Z(I, M) = A(I, M1)
    NEXT I
    I = Inter(M)
    IF I <> M THEN
      FOR J = M TO Hi
        Z(M, J) = Z(I, J)
        Z(I, J) = 0
      NEXT J
      Z(I, M) = 1
    END IF
  NEXT M
END SUB
