1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
      SUBROUTINE ZLATDFIJOBNZLDZRHSRDSUMRDSCALIPIV,
     $                   JPIV )
*
*  -- LAPACK auxiliary routine (version 3.2) --
*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*     November 2006
*
*     .. Scalar Arguments ..
      INTEGER            IJOBLDZN
      DOUBLE PRECISION   RDSCALRDSUM
*     ..
*     .. Array Arguments ..
      INTEGER            IPIV* ), JPIV* )
      COMPLEX*16         RHS* ), ZLDZ* )
*     ..
*
*  Purpose
*  =======
*
*  ZLATDF computes the contribution to the reciprocal Dif-estimate
*  by solving for x in Z * x = b, where b is chosen such that the norm
*  of x is as large as possible. It is assumed that LU decomposition
*  of Z has been computed by ZGETC2. On entry RHS = f holds the
*  contribution from earlier solved sub-systems, and on return RHS = x.
*
*  The factorization of Z returned by ZGETC2 has the form
*  Z = P * L * U * Q, where P and Q are permutation matrices. L is lower
*  triangular with unit diagonal elements and U is upper triangular.
*
*  Arguments
*  =========
*
*  IJOB    (input) INTEGER
*          IJOB = 2: First compute an approximative null-vector e
*              of Z using ZGECON, e is normalized and solve for
*              Zx = +-e - f with the sign giving the greater value of
*              2-norm(x).  About 5 times as expensive as Default.
*          IJOB .ne. 2: Local look ahead strategy where
*              all entries of the r.h.s. b is choosen as either +1 or
*              -1.  Default.
*
*  N       (input) INTEGER
*          The number of columns of the matrix Z.
*
*  Z       (input) DOUBLE PRECISION array, dimension (LDZ, N)
*          On entry, the LU part of the factorization of the n-by-n
*          matrix Z computed by ZGETC2:  Z = P * L * U * Q
*
*  LDZ     (input) INTEGER
*          The leading dimension of the array Z.  LDA >= max(1, N).
*
*  RHS     (input/output) DOUBLE PRECISION array, dimension (N).
*          On entry, RHS contains contributions from other subsystems.
*          On exit, RHS contains the solution of the subsystem with
*          entries according to the value of IJOB (see above).
*
*  RDSUM   (input/output) DOUBLE PRECISION
*          On entry, the sum of squares of computed contributions to
*          the Dif-estimate under computation by ZTGSYL, where the
*          scaling factor RDSCAL (see below) has been factored out.
*          On exit, the corresponding sum of squares updated with the
*          contributions from the current sub-system.
*          If TRANS = 'T' RDSUM is not touched.
*          NOTE: RDSUM only makes sense when ZTGSY2 is called by CTGSYL.
*
*  RDSCAL  (input/output) DOUBLE PRECISION
*          On entry, scaling factor used to prevent overflow in RDSUM.
*          On exit, RDSCAL is updated w.r.t. the current contributions
*          in RDSUM.
*          If TRANS = 'T', RDSCAL is not touched.
*          NOTE: RDSCAL only makes sense when ZTGSY2 is called by
*          ZTGSYL.
*
*  IPIV    (input) INTEGER array, dimension (N).
*          The pivot indices; for 1 <= i <= N, row i of the
*          matrix has been interchanged with row IPIV(i).
*
*  JPIV    (input) INTEGER array, dimension (N).
*          The pivot indices; for 1 <= j <= N, column j of the
*          matrix has been interchanged with column JPIV(j).
*
*  Further Details
*  ===============
*
*  Based on contributions by
*     Bo Kagstrom and Peter Poromaa, Department of Computing Science,
*     Umea University, S-901 87 Umea, Sweden.
*
*  This routine is a further developed implementation of algorithm
*  BSOLVE in [1] using complete pivoting in the LU factorization.
*
*   [1]   Bo Kagstrom and Lars Westin,
*         Generalized Schur Methods with Condition Estimators for
*         Solving the Generalized Sylvester Equation, IEEE Transactions
*         on Automatic Control, Vol. 34, No. 7, July 1989, pp 745-751.
*
*   [2]   Peter Poromaa,
*         On Efficient and Robust Estimators for the Separation
*         between two Regular Matrix Pairs with Applications in
*         Condition Estimation. Report UMINF-95.05, Department of
*         Computing Science, Umea University, S-901 87 Umea, Sweden,
*         1995.
*
*  =====================================================================
*
*     .. Parameters ..
      INTEGER            MAXDIM
      PARAMETER          ( MAXDIM = 2 )
      DOUBLE PRECISION   ZEROONE
      PARAMETER          ( ZERO = 0.0D+0ONE = 1.0D+0 )
      COMPLEX*16         CONE
      PARAMETER          ( CONE = ( 1.0D+00.0D+0 ) )
*     ..
*     .. Local Scalars ..
      INTEGER            IINFOJK
      DOUBLE PRECISION   RTEMPSCALESMINUSPLUS
      COMPLEX*16         BMBPPMONETEMP
*     ..
*     .. Local Arrays ..
      DOUBLE PRECISION   RWORKMAXDIM )
      COMPLEX*16         WORK4*MAXDIM ), XMMAXDIM ), XPMAXDIM )
*     ..
*     .. External Subroutines ..
      EXTERNAL           ZAXPYZCOPYZGECONZGESC2ZLASSQZLASWP,
     $                   ZSCAL
*     ..
*     .. External Functions ..
      DOUBLE PRECISION   DZASUM
      COMPLEX*16         ZDOTC
      EXTERNAL           DZASUMZDOTC
*     ..
*     .. Intrinsic Functions ..
      INTRINSIC          ABSDBLESQRT
*     ..
*     .. Executable Statements ..
*
      IFIJOB.NE.2 ) THEN
*
*        Apply permutations IPIV to RHS
*
         CALL ZLASWP1RHSLDZ1N-1IPIV1 )
*
*        Solve for L-part choosing RHS either to +1 or -1.
*
         PMONE = -CONE
         DO 10 J = 1N - 1
            BP = RHSJ ) + CONE
            BM = RHSJ ) - CONE
            SPLUS = ONE
*
*           Lockahead for L- part RHS(1:N-1) = +-1
*           SPLUS and SMIN computed more efficiently than in BSOLVE[1].
*
            SPLUS = SPLUS + DBLEZDOTCN-JZJ+1J ), 1ZJ+1,
     $              J ), 1 ) )
            SMINU = DBLEZDOTCN-JZJ+1J ), 1RHSJ+1 ), 1 ) )
            SPLUS = SPLUS*DBLERHSJ ) )
            IFSPLUS.GT.SMINU ) THEN
               RHSJ ) = BP
            ELSE IFSMINU.GT.SPLUS ) THEN
               RHSJ ) = BM
            ELSE
*
*              In this case the updating sums are equal and we can
*              choose RHS(J) +1 or -1. The first time this happens we
*              choose -1, thereafter +1. This is a simple way to get
*              good estimates of matrices like Byers well-known example
*              (see [1]). (Not done in BSOLVE.)
*
               RHSJ ) = RHSJ ) + PMONE
               PMONE = CONE
            END IF
*
*           Compute the remaining r.h.s.
*
            TEMP = -RHSJ )
            CALL ZAXPYN-JTEMPZJ+1J ), 1RHSJ+1 ), 1 )
   10    CONTINUE
*
*        Solve for U- part, lockahead for RHS(N) = +-1. This is not done
*        In BSOLVE and will hopefully give us a better estimate because
*        any ill-conditioning of the original matrix is transfered to U
*        and not to L. U(N, N) is an approximation to sigma_min(LU).
*
         CALL ZCOPYN-1RHS1WORK1 )
         WORKN ) = RHSN ) + CONE
         RHSN ) = RHSN ) - CONE
         SPLUS = ZERO
         SMINU = ZERO
         DO 30 I = N1-1
            TEMP = CONE / ZII )
            WORKI ) = WORKI )*TEMP
            RHSI ) = RHSI )*TEMP
            DO 20 K = I + 1N
               WORKI ) = WORKI ) - WORKK )*ZIK )*TEMP )
               RHSI ) = RHSI ) - RHSK )*ZIK )*TEMP )
   20       CONTINUE
            SPLUS = SPLUS + ABSWORKI ) )
            SMINU = SMINU + ABSRHSI ) )
   30    CONTINUE
         IFSPLUS.GT.SMINU )
     $      CALL ZCOPYNWORK1RHS1 )
*
*        Apply the permutations JPIV to the computed solution (RHS)
*
         CALL ZLASWP1RHSLDZ1N-1JPIV-1 )
*
*        Compute the sum of squares
*
         CALL ZLASSQNRHS1RDSCALRDSUM )
         RETURN
      END IF
*
*     ENTRY IJOB = 2
*
*     Compute approximate nullvector XM of Z
*
      CALL ZGECON'I'NZLDZONERTEMPWORKRWORKINFO )
      CALL ZCOPYNWORKN+1 ), 1XM1 )
*
*     Compute RHS
*
      CALL ZLASWP1XMLDZ1N-1IPIV-1 )
      TEMP = CONE / SQRTZDOTCNXM1XM1 ) )
      CALL ZSCALNTEMPXM1 )
      CALL ZCOPYNXM1XP1 )
      CALL ZAXPYNCONERHS1XP1 )
      CALL ZAXPYN-CONEXM1RHS1 )
      CALL ZGESC2NZLDZRHSIPIVJPIVSCALE )
      CALL ZGESC2NZLDZXPIPIVJPIVSCALE )
      IFDZASUMNXP1 ).GT.DZASUMNRHS1 ) )
     $   CALL ZCOPYNXP1RHS1 )
*
*     Compute the sum of squares
*
      CALL ZLASSQNRHS1RDSCALRDSUM )
      RETURN
*
*     End of ZLATDF
*
      END