context: #region Translated by Jose Antonio De Santiago-Castillo.
  
  //Translated by Jose Antonio De Santiago-Castillo.
  //E-mail:JAntonioDeSantiago@gmail.com
  //Website: www.DotNumerics.com
  //
  //Fortran to C# Translation.
  //Translated by:
  //F2CSharp Version 0.72 (Dicember 7, 2009)
  //Code Optimizations: , assignment operator, for-loop: array indexes
  //
  #endregion
  
  using System;
  using DotNumerics.FortranLibrary;
  
  namespace DotNumerics.LinearAlgebra.CSLapack
  {
      /// <summary>
      /// -- LAPACK auxiliary routine (version 3.1) --
      /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
      /// November 2006
      /// Purpose
      /// =======
      /// 
      /// DLAHQR is an auxiliary routine called by DHSEQR to update the
      /// eigenvalues and Schur decomposition already computed by DHSEQR, by
      /// dealing with the Hessenberg submatrix in rows and columns ILO to
      /// IHI.
      /// 
      ///</summary>
      public class DLAHQR
      {
      
  
          #region Dependencies
          
          DLAMCH _dlamch; DCOPY _dcopy; DLABAD _dlabad; DLANV2 _dlanv2; DLARFG _dlarfg; DROT _drot; 
  
          #endregion
  
  
          #region Variables
          
          const int ITMAX = 30; const double ZERO = 0.0E0; const double ONE = 1.0E0; const double TWO = 2.0E0; 
          const double DAT1 = 3.0E0 / 4.0E0;const double DAT2 =  - 0.4375E0; double[] V = new double[3]; 
  
          #endregion
  
          public DLAHQR(DLAMCH dlamch, DCOPY dcopy, DLABAD dlabad, DLANV2 dlanv2, DLARFG dlarfg, DROT drot)
          {
      
  
              #region Set Dependencies
              
              this._dlamch = dlamch; this._dcopy = dcopy; this._dlabad = dlabad; this._dlanv2 = dlanv2; this._dlarfg = dlarfg; 
              this._drot = drot;
  
              #endregion
  
          }
      
          public DLAHQR()
          {
      
  
              #region Dependencies (Initialization)
              
              LSAME lsame = new LSAME();
              DLAMC3 dlamc3 = new DLAMC3();
              DCOPY dcopy = new DCOPY();
              DLABAD dlabad = new DLABAD();
              DLAPY2 dlapy2 = new DLAPY2();
              DNRM2 dnrm2 = new DNRM2();
              DSCAL dscal = new DSCAL();
              DROT drot = new DROT();
              DLAMC1 dlamc1 = new DLAMC1(dlamc3);
              DLAMC4 dlamc4 = new DLAMC4(dlamc3);
              DLAMC5 dlamc5 = new DLAMC5(dlamc3);
              DLAMC2 dlamc2 = new DLAMC2(dlamc3, dlamc1, dlamc4, dlamc5);
              DLAMCH dlamch = new DLAMCH(lsame, dlamc2);
              DLANV2 dlanv2 = new DLANV2(dlamch, dlapy2);
              DLARFG dlarfg = new DLARFG(dlamch, dlapy2, dnrm2, dscal);
  
              #endregion
  
  
              #region Set Dependencies
              
              this._dlamch = dlamch; this._dcopy = dcopy; this._dlabad = dlabad; this._dlanv2 = dlanv2; this._dlarfg = dlarfg; 
              this._drot = drot;
  
              #endregion
  
          }
          /// <summary>
          /// Purpose
          /// =======
          /// 
          /// DLAHQR is an auxiliary routine called by DHSEQR to update the
          /// eigenvalues and Schur decomposition already computed by DHSEQR, by
          /// dealing with the Hessenberg submatrix in rows and columns ILO to
          /// IHI.
          /// 
          ///</summary>
          /// <param name="WANTT">
          /// (input) LOGICAL
          /// = .TRUE. : the full Schur form T is required;
          /// = .FALSE.: only eigenvalues are required.
          ///</param>
          /// <param name="WANTZ">
          /// (input) LOGICAL
          /// = .TRUE. : the matrix of Schur vectors Z is required;
          /// = .FALSE.: Schur vectors are not required.
          ///</param>
          /// <param name="N">
          /// (input) INTEGER
          /// The order of the matrix H.  N .GE. 0.
          ///</param>
          /// <param name="ILO">
          /// (input) INTEGER
          ///</param>
          /// <param name="IHI">
          /// (input) INTEGER
          /// It is assumed that H is already upper quasi-triangular in
          /// rows and columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless
          /// ILO = 1). DLAHQR works primarily with the Hessenberg
          /// submatrix in rows and columns ILO to IHI, but applies
          /// transformations to all of H if WANTT is .TRUE..
          /// 1 .LE. ILO .LE. max(1,IHI); IHI .LE. N.
          ///</param>
          /// <param name="H">
          /// (input/output) DOUBLE PRECISION array, dimension (LDH,N)
          /// On entry, the upper Hessenberg matrix H.
          /// On exit, if INFO is zero and if WANTT is .TRUE., H is upper
          /// quasi-triangular in rows and columns ILO:IHI, with any
          /// 2-by-2 diagonal blocks in standard form. If INFO is zero
          /// and WANTT is .FALSE., the contents of H are unspecified on
          /// exit.  The output state of H if INFO is nonzero is given
          /// below under the description of INFO.
          ///</param>
          /// <param name="LDH">
          /// (input) INTEGER
          /// The leading dimension of the array H. LDH .GE. max(1,N).
          ///</param>
          /// <param name="WR">
          /// (output) DOUBLE PRECISION array, dimension (N)
          ///</param>
          /// <param name="WI">
          /// (output) DOUBLE PRECISION array, dimension (N)
          /// The real and imaginary parts, respectively, of the computed
          /// eigenvalues ILO to IHI are stored in the corresponding
          /// elements of WR and WI. If two eigenvalues are computed as a
          /// complex conjugate pair, they are stored in consecutive
          /// elements of WR and WI, say the i-th and (i+1)th, with
          /// WI(i) .GT. 0 and WI(i+1) .LT. 0. If WANTT is .TRUE., the
          /// eigenvalues are stored in the same order as on the diagonal
          /// of the Schur form returned in H, with WR(i) = H(i,i), and, if
          /// H(i:i+1,i:i+1) is a 2-by-2 diagonal block,
          /// WI(i) = sqrt(H(i+1,i)*H(i,i+1)) and WI(i+1) = -WI(i).
          ///</param>
          /// <param name="ILOZ">
          /// (input) INTEGER
          ///</param>
          /// <param name="IHIZ">
          /// (input) INTEGER
          /// Specify the rows of Z to which transformations must be
          /// applied if WANTZ is .TRUE..
          /// 1 .LE. ILOZ .LE. ILO; IHI .LE. IHIZ .LE. N.
          ///</param>
          /// <param name="Z">
          /// (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
          /// If WANTZ is .TRUE., on entry Z must contain the current
          /// matrix Z of transformations accumulated by DHSEQR, and on
          /// exit Z has been updated; transformations are applied only to
          /// the submatrix Z(ILOZ:IHIZ,ILO:IHI).
          /// If WANTZ is .FALSE., Z is not referenced.
          ///</param>
          /// <param name="LDZ">
          /// (input) INTEGER
          /// The leading dimension of the array Z. LDZ .GE. max(1,N).
          ///</param>
          /// <param name="INFO">
          /// (output) INTEGER
          /// =   0: successful exit
          /// .GT. 0: If INFO = i, DLAHQR failed to compute all the
          /// eigenvalues ILO to IHI in a total of 30 iterations
          /// per eigenvalue; elements i+1:ihi of WR and WI
          /// contain those eigenvalues which have been
          /// successfully computed.
          /// 
          /// If INFO .GT. 0 and WANTT is .FALSE., then on exit,
          /// the remaining unconverged eigenvalues are the
          /// eigenvalues of the upper Hessenberg matrix rows
          /// and columns ILO thorugh INFO of the final, output
          /// value of H.
          /// 
          /// If INFO .GT. 0 and WANTT is .TRUE., then on exit
          /// (*)       (initial value of H)*U  = U*(final value of H)
          /// where U is an orthognal matrix.    The final
          /// value of H is upper Hessenberg and triangular in
          /// rows and columns INFO+1 through IHI.
          /// 
          /// If INFO .GT. 0 and WANTZ is .TRUE., then on exit
          /// (final value of Z)  = (initial value of Z)*U
          /// where U is the orthogonal matrix in (*)
          /// (regardless of the value of WANTT.)
          ///</param>
          public void Run(bool WANTT, bool WANTZ, int N, int ILO, int IHI, ref double[] H, int offset_h
                           , int LDH, ref double[] WR, int offset_wr, ref double[] WI, int offset_wi, int ILOZ, int IHIZ, ref double[] Z, int offset_z
                           , int LDZ, ref int INFO)
          {
  
              #region Variables
              
              double AA = 0; double AB = 0; double BA = 0; double BB = 0; double CS = 0; double DET = 0; double H11 = 0; 
              double H12 = 0;double H21 = 0; double H21S = 0; double H22 = 0; double RT1I = 0; double RT1R = 0; double RT2I = 0; 
              double RT2R = 0;double RTDISC = 0; double S = 0; double SAFMAX = 0; double SAFMIN = 0; double SMLNUM = 0; 
              double SN = 0;double SUM = 0; double T1 = 0; double T2 = 0; double T3 = 0; double TR = 0; double TST = 0; 
              double ULP = 0;double V2 = 0; double V3 = 0; int I = 0; int I1 = 0; int I2 = 0; int ITS = 0; int J = 0; int K = 0; 
              int L = 0;int M = 0; int NH = 0; int NR = 0; int NZ = 0; int offset_v = 0; int o_v = -1; 
  
              #endregion
  
  
              #region Implicit Variables
              
              int H_K = 0; int H_0 = 0; int H_1 = 0; int H_2 = 0; int H_3 = 0; int Z_K = 0; int Z_0 = 0; int Z_1 = 0; int Z_2 = 0; 
              int Z_3 = 0;int H_4 = 0; int H_5 = 0; int Z_4 = 0; int Z_5 = 0; 
  
              #endregion
  
  
              #region Array Index Correction
              
               int o_h = -1 - LDH + offset_h;  int o_wr = -1 + offset_wr;  int o_wi = -1 + offset_wi; 
  
gt:              int o_z = -1 - LDZ + offset_z;