h12.f 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. *DECK H12
  2. SUBROUTINE H12 (MODE, LPIVOT, L1, M, U, IUE, UP, C, ICE, ICV, NCV)
  3. C***BEGIN PROLOGUE H12
  4. C***SUBSIDIARY
  5. C***PURPOSE Subsidiary to HFTI, LSEI and WNNLS
  6. C***LIBRARY SLATEC
  7. C***TYPE SINGLE PRECISION (H12-S, DH12-D)
  8. C***AUTHOR (UNKNOWN)
  9. C***DESCRIPTION
  10. C
  11. C C.L.Lawson and R.J.Hanson, Jet Propulsion Laboratory, 1973 Jun 12
  12. C to appear in 'Solving Least Squares Problems', Prentice-Hall, 1974
  13. C
  14. C Construction and/or application of a single
  15. C Householder transformation.. Q = I + U*(U**T)/B
  16. C
  17. C MODE = 1 or 2 to select algorithm H1 or H2 .
  18. C LPIVOT is the index of the pivot element.
  19. C L1,M If L1 .LE. M the transformation will be constructed to
  20. C zero elements indexed from L1 through M. If L1 GT. M
  21. C THE SUBROUTINE DOES AN IDENTITY TRANSFORMATION.
  22. C U(),IUE,UP On entry to H1 U() contains the pivot vector.
  23. C IUE is the storage increment between elements.
  24. C On exit from H1 U() and UP
  25. C contain quantities defining the vector U of the
  26. C Householder transformation. On entry to H2 U()
  27. C and UP should contain quantities previously computed
  28. C by H1. These will not be modified by H2.
  29. C C() On entry to H1 or H2 C() contains a matrix which will be
  30. C regarded as a set of vectors to which the Householder
  31. C transformation is to be applied. On exit C() contains the
  32. C set of transformed vectors.
  33. C ICE Storage increment between elements of vectors in C().
  34. C ICV Storage increment between vectors in C().
  35. C NCV Number of vectors in C() to be transformed. If NCV .LE. 0
  36. C no operations will be done on C().
  37. C
  38. C***SEE ALSO HFTI, LSEI, WNNLS
  39. C***ROUTINES CALLED SAXPY, SDOT, SSWAP
  40. C***REVISION HISTORY (YYMMDD)
  41. C 790101 DATE WRITTEN
  42. C 890531 Changed all specific intrinsics to generic. (WRB)
  43. C 890831 Modified array declarations. (WRB)
  44. C 891214 Prologue converted to Version 4.0 format. (BAB)
  45. C 900328 Added TYPE section. (WRB)
  46. C***END PROLOGUE H12
  47. DIMENSION U(IUE,*), C(*)
  48. C***FIRST EXECUTABLE STATEMENT H12
  49. ONE=1.
  50. C
  51. IF (0.GE.LPIVOT.OR.LPIVOT.GE.L1.OR.L1.GT.M) RETURN
  52. CL=ABS(U(1,LPIVOT))
  53. IF (MODE.EQ.2) GO TO 60
  54. C ****** CONSTRUCT THE TRANSFORMATION. ******
  55. DO 10 J=L1,M
  56. 10 CL=MAX(ABS(U(1,J)),CL)
  57. IF (CL) 130,130,20
  58. 20 CLINV=ONE/CL
  59. SM=(U(1,LPIVOT)*CLINV)**2
  60. DO 30 J=L1,M
  61. 30 SM=SM+(U(1,J)*CLINV)**2
  62. CL=CL*SQRT(SM)
  63. IF (U(1,LPIVOT)) 50,50,40
  64. 40 CL=-CL
  65. 50 UP=U(1,LPIVOT)-CL
  66. U(1,LPIVOT)=CL
  67. GO TO 70
  68. C ****** APPLY THE TRANSFORMATION I+U*(U**T)/B TO C. ******
  69. C
  70. 60 IF (CL) 130,130,70
  71. 70 IF (NCV.LE.0) RETURN
  72. B=UP*U(1,LPIVOT)
  73. C B MUST BE NONPOSITIVE HERE. IF B = 0., RETURN.
  74. C
  75. IF (B) 80,130,130
  76. 80 B=ONE/B
  77. MML1P2=M-L1+2
  78. IF (MML1P2.GT.20) GO TO 140
  79. I2=1-ICV+ICE*(LPIVOT-1)
  80. INCR=ICE*(L1-LPIVOT)
  81. DO 120 J=1,NCV
  82. I2=I2+ICV
  83. I3=I2+INCR
  84. I4=I3
  85. SM=C(I2)*UP
  86. DO 90 I=L1,M
  87. SM=SM+C(I3)*U(1,I)
  88. 90 I3=I3+ICE
  89. IF (SM) 100,120,100
  90. 100 SM=SM*B
  91. C(I2)=C(I2)+SM*UP
  92. DO 110 I=L1,M
  93. C(I4)=C(I4)+SM*U(1,I)
  94. 110 I4=I4+ICE
  95. 120 CONTINUE
  96. 130 RETURN
  97. 140 CONTINUE
  98. L1M1=L1-1
  99. KL1=1+(L1M1-1)*ICE
  100. KL2=KL1
  101. KLP=1+(LPIVOT-1)*ICE
  102. UL1M1=U(1,L1M1)
  103. U(1,L1M1)=UP
  104. IF (LPIVOT.EQ.L1M1) GO TO 150
  105. CALL SSWAP(NCV,C(KL1),ICV,C(KLP),ICV)
  106. 150 CONTINUE
  107. DO 160 J=1,NCV
  108. SM=SDOT(MML1P2,U(1,L1M1),IUE,C(KL1),ICE)
  109. SM=SM*B
  110. CALL SAXPY (MML1P2,SM,U(1,L1M1),IUE,C(KL1),ICE)
  111. KL1=KL1+ICV
  112. 160 CONTINUE
  113. U(1,L1M1)=UL1M1
  114. IF (LPIVOT.EQ.L1M1) RETURN
  115. KL1=KL2
  116. CALL SSWAP(NCV,C(KL1),ICV,C(KLP),ICV)
  117. RETURN
  118. END