1 C 10 NOV 94 - MWS - DNRM2: REMOVE FTNCHECK WARNINGS
2 C 11 JUN 94 - MWS - INCLUDE A COPY OF DGEMV (LEVEL TWO ROUTINE)
3 C 11 AUG 87 - MWS - SANITIZE FLOATING POINT CONSTANTS IN DNRM2
4 C 26 MAR 87 - MWS - USE GENERIC SIGN IN DROTG
5 C 28 NOV 86 - STE - SUPPLY ALL LEVEL ONE BLAS
6 C 7 JUL 86 - JAB - SANITIZE FLOATING POINT CONSTANTS
8 C BASIC LINEAR ALGEBRA SUBPROGRAMS (BLAS) FROM LINPACK (LEVEL 1)
10 C THIS MODULE SHOULD BE COMPILED ONLY IF SPECIALLY CODED
11 C VERSIONS OF THESE ROUTINES ARE NOT AVAILABLE ON THE TARGET MACHINE
13 C*MODULE BLAS1 *DECK DASUM
14 DOUBLE PRECISION FUNCTION DASUM(N,DX,INCX)
16 C TAKES THE SUM OF THE ABSOLUTE VALUES.
17 C JACK DONGARRA, LINPACK, 3/11/78.
19 DOUBLE PRECISION DX(1),DTEMP
20 INTEGER I,INCX,M,MP1,N,NINCX
27 C CODE FOR INCREMENT NOT EQUAL TO 1
30 DO 10 I = 1,NINCX,INCX
31 DTEMP = DTEMP + ABS(DX(I))
36 C CODE FOR INCREMENT EQUAL TO 1
42 IF( M .EQ. 0 ) GO TO 40
44 DTEMP = DTEMP + ABS(DX(I))
46 IF( N .LT. 6 ) GO TO 60
49 DTEMP = DTEMP + ABS(DX(I)) + ABS(DX(I + 1)) + ABS(DX(I + 2))
50 * + ABS(DX(I + 3)) + ABS(DX(I + 4)) + ABS(DX(I + 5))
55 C*MODULE BLAS1 *DECK DAXPY
56 SUBROUTINE DAXPY(N,DA,DX,INCX,DY,INCY)
57 IMPLICIT DOUBLE PRECISION(A-H,O-Z)
60 C CONSTANT TIMES A VECTOR PLUS A VECTOR.
61 C DY(I) = DY(I) + DA * DX(I)
62 C USES UNROLLED LOOPS FOR INCREMENTS EQUAL TO ONE.
63 C JACK DONGARRA, LINPACK, 3/11/78.
66 IF (DA .EQ. 0.0D+00) RETURN
67 IF(INCX.EQ.1.AND.INCY.EQ.1)GO TO 20
69 C CODE FOR UNEQUAL INCREMENTS OR EQUAL INCREMENTS
74 IF(INCX.LT.0)IX = (-N+1)*INCX + 1
75 IF(INCY.LT.0)IY = (-N+1)*INCY + 1
77 DY(IY) = DY(IY) + DA*DX(IX)
83 C CODE FOR BOTH INCREMENTS EQUAL TO 1
89 IF( M .EQ. 0 ) GO TO 40
91 DY(I) = DY(I) + DA*DX(I)
96 DY(I) = DY(I) + DA*DX(I)
97 DY(I + 1) = DY(I + 1) + DA*DX(I + 1)
98 DY(I + 2) = DY(I + 2) + DA*DX(I + 2)
99 DY(I + 3) = DY(I + 3) + DA*DX(I + 3)
103 C*MODULE BLAS1 *DECK DCOPY
104 SUBROUTINE DCOPY(N,DX,INCX,DY,INCY)
105 IMPLICIT DOUBLE PRECISION(A-H,O-Z)
106 DIMENSION DX(*),DY(*)
110 C USES UNROLLED LOOPS FOR INCREMENTS EQUAL TO ONE.
111 C JACK DONGARRA, LINPACK, 3/11/78.
114 IF(INCX.EQ.1.AND.INCY.EQ.1)GO TO 20
116 C CODE FOR UNEQUAL INCREMENTS OR EQUAL INCREMENTS
121 IF(INCX.LT.0)IX = (-N+1)*INCX + 1
122 IF(INCY.LT.0)IY = (-N+1)*INCY + 1
130 C CODE FOR BOTH INCREMENTS EQUAL TO 1
136 IF( M .EQ. 0 ) GO TO 40
140 IF( N .LT. 7 ) RETURN
144 DY(I + 1) = DX(I + 1)
145 DY(I + 2) = DX(I + 2)
146 DY(I + 3) = DX(I + 3)
147 DY(I + 4) = DX(I + 4)
148 DY(I + 5) = DX(I + 5)
149 DY(I + 6) = DX(I + 6)
153 C*MODULE BLAS1 *DECK DDOT
154 DOUBLE PRECISION FUNCTION DDOT(N,DX,INCX,DY,INCY)
155 IMPLICIT DOUBLE PRECISION(A-H,O-Z)
156 DIMENSION DX(1),DY(1)
158 C FORMS THE DOT PRODUCT OF TWO VECTORS.
159 C DOT = DX(I) * DY(I)
160 C USES UNROLLED LOOPS FOR INCREMENTS EQUAL TO ONE.
161 C JACK DONGARRA, LINPACK, 3/11/78.
166 IF(INCX.EQ.1.AND.INCY.EQ.1)GO TO 20
168 C CODE FOR UNEQUAL INCREMENTS OR EQUAL INCREMENTS
173 IF(INCX.LT.0)IX = (-N+1)*INCX + 1
174 IF(INCY.LT.0)IY = (-N+1)*INCY + 1
176 DTEMP = DTEMP + DX(IX)*DY(IY)
183 C CODE FOR BOTH INCREMENTS EQUAL TO 1
189 IF( M .EQ. 0 ) GO TO 40
191 DTEMP = DTEMP + DX(I)*DY(I)
193 IF( N .LT. 5 ) GO TO 60
196 DTEMP = DTEMP + DX(I)*DY(I) + DX(I + 1)*DY(I + 1) +
197 * DX(I + 2)*DY(I + 2) + DX(I + 3)*DY(I + 3) + DX(I + 4)*DY(I + 4)
202 C*MODULE BLAS1 *DECK DNRM2
203 DOUBLE PRECISION FUNCTION DNRM2 ( N, DX, INCX)
205 DOUBLE PRECISION DX(1), CUTLO, CUTHI, HITEST, SUM, XMAX,ZERO,ONE
206 DATA ZERO, ONE /0.0D+00, 1.0D+00/
208 C EUCLIDEAN NORM OF THE N-VECTOR STORED IN DX() WITH STORAGE
210 C IF N .LE. 0 RETURN WITH RESULT = 0.
211 C IF N .GE. 1 THEN INCX MUST BE .GE. 1
213 C C.L.LAWSON, 1978 JAN 08
215 C FOUR PHASE METHOD USING TWO BUILT-IN CONSTANTS THAT ARE
216 C HOPEFULLY APPLICABLE TO ALL MACHINES.
217 C CUTLO = MAXIMUM OF SQRT(U/EPS) OVER ALL KNOWN MACHINES.
218 C CUTHI = MINIMUM OF SQRT(V) OVER ALL KNOWN MACHINES.
220 C EPS = SMALLEST NO. SUCH THAT EPS + 1. .GT. 1.
221 C U = SMALLEST POSITIVE NO. (UNDERFLOW LIMIT)
222 C V = LARGEST NO. (OVERFLOW LIMIT)
224 C BRIEF OUTLINE OF ALGORITHM..
226 C PHASE 1 SCANS ZERO COMPONENTS.
227 C MOVE TO PHASE 2 WHEN A COMPONENT IS NONZERO AND .LE. CUTLO
228 C MOVE TO PHASE 3 WHEN A COMPONENT IS .GT. CUTLO
229 C MOVE TO PHASE 4 WHEN A COMPONENT IS .GE. CUTHI/M
230 C WHERE M = N FOR X() REAL AND M = 2*N FOR COMPLEX.
232 C VALUES FOR CUTLO AND CUTHI..
233 C FROM THE ENVIRONMENTAL PARAMETERS LISTED IN THE IMSL CONVERTER
234 C DOCUMENT THE LIMITING VALUES ARE AS FOLLOWS..
235 C CUTLO, S.P. U/EPS = 2**(-102) FOR HONEYWELL. CLOSE SECONDS ARE
236 C UNIVAC AND DEC AT 2**(-103)
237 C THUS CUTLO = 2**(-51) = 4.44089E-16
238 C CUTHI, S.P. V = 2**127 FOR UNIVAC, HONEYWELL, AND DEC.
239 C THUS CUTHI = 2**(63.5) = 1.30438E19
240 C CUTLO, D.P. U/EPS = 2**(-67) FOR HONEYWELL AND DEC.
241 C THUS CUTLO = 2**(-33.5) = 8.23181D-11
242 C CUTHI, D.P. SAME AS S.P. CUTHI = 1.30438D+19
243 C DATA CUTLO, CUTHI / 8.232D-11, 1.304D+19 /
244 C DATA CUTLO, CUTHI / 4.441E-16, 1.304E19 /
245 DATA CUTLO, CUTHI / 8.232D-11, 1.304D+19 /
248 IF(N .GT. 0) GO TO 10
257 20 GO TO NEXT,(30, 50, 70, 110)
258 30 IF( ABS(DX(I)) .GT. CUTLO) GO TO 85
262 C PHASE 1. SUM IS ZERO
264 50 IF( DX(I) .EQ. ZERO) GO TO 200
265 IF( ABS(DX(I)) .GT. CUTLO) GO TO 85
267 C PREPARE FOR PHASE 2.
271 C PREPARE FOR PHASE 4.
275 SUM = (SUM / DX(I)) / DX(I)
276 105 XMAX = ABS(DX(I))
279 C PHASE 2. SUM IS SMALL.
280 C SCALE TO AVOID DESTRUCTIVE UNDERFLOW.
282 70 IF( ABS(DX(I)) .GT. CUTLO ) GO TO 75
284 C COMMON CODE FOR PHASES 2 AND 4.
285 C IN PHASE 4 SUM IS LARGE. SCALE TO AVOID OVERFLOW.
287 110 IF( ABS(DX(I)) .LE. XMAX ) GO TO 115
288 SUM = ONE + SUM * (XMAX / DX(I))**2
292 115 SUM = SUM + (DX(I)/XMAX)**2
296 C PREPARE FOR PHASE 3.
298 75 SUM = (SUM * XMAX) * XMAX
301 C FOR REAL OR D.P. SET HITEST = CUTHI/N
302 C FOR COMPLEX SET HITEST = CUTHI/(2*N)
306 C PHASE 3. SUM IS MID-RANGE. NO SCALING.
309 IF(ABS(DX(J)) .GE. HITEST) GO TO 100
310 95 SUM = SUM + DX(J)**2
316 IF ( I .LE. NN ) GO TO 20
320 C COMPUTE SQUARE ROOT AND ADJUST FOR SCALING.
322 DNRM2 = XMAX * SQRT(SUM)
326 C*MODULE BLAS1 *DECK DROT
327 SUBROUTINE DROT (N,DX,INCX,DY,INCY,C,S)
328 IMPLICIT DOUBLE PRECISION(A-H,O-Z)
329 DIMENSION DX(1),DY(1)
331 C APPLIES A PLANE ROTATION.
332 C DX(I) = C*DX(I) + S*DY(I)
333 C DY(I) = -S*DX(I) + C*DY(I)
334 C JACK DONGARRA, LINPACK, 3/11/78.
337 IF(INCX.EQ.1.AND.INCY.EQ.1)GO TO 20
339 C CODE FOR UNEQUAL INCREMENTS OR EQUAL INCREMENTS NOT EQUAL
344 IF(INCX.LT.0)IX = (-N+1)*INCX + 1
345 IF(INCY.LT.0)IY = (-N+1)*INCY + 1
347 DTEMP = C*DX(IX) + S*DY(IY)
348 DY(IY) = C*DY(IY) - S*DX(IX)
355 C CODE FOR BOTH INCREMENTS EQUAL TO 1
358 DTEMP = C*DX(I) + S*DY(I)
359 DY(I) = C*DY(I) - S*DX(I)
364 C*MODULE BLAS1 *DECK DROTG
365 SUBROUTINE DROTG(DA,DB,C,S)
367 C CONSTRUCT GIVENS PLANE ROTATION.
368 C JACK DONGARRA, LINPACK, 3/11/78.
370 DOUBLE PRECISION DA,DB,C,S,ROE,SCALE,R,Z
371 DOUBLE PRECISION ZERO, ONE
373 PARAMETER (ZERO=0.0D+00, ONE=1.0D+00)
375 C-----------------------------------------------------------------------
379 IF( ABS(DA) .GT. ABS(DB) ) ROE = DA
380 SCALE = ABS(DA) + ABS(DB)
381 IF( SCALE .NE. ZERO ) GO TO 10
387 10 R = SCALE*SQRT((DA/SCALE)**2 + (DB/SCALE)**2)
392 IF( ABS(DA) .GT. ABS(DB) ) Z = S
393 IF( ABS(DB) .GE. ABS(DA) .AND. C .NE. ZERO ) Z = ONE/C
398 C*MODULE BLAS1 *DECK DSCAL
399 SUBROUTINE DSCAL(N,DA,DX,INCX)
400 IMPLICIT DOUBLE PRECISION(A-H,O-Z)
403 C SCALES A VECTOR BY A CONSTANT.
405 C USES UNROLLED LOOPS FOR INCREMENT EQUAL TO ONE.
406 C JACK DONGARRA, LINPACK, 3/11/78.
409 IF(INCX.EQ.1)GO TO 20
411 C CODE FOR INCREMENT NOT EQUAL TO 1
414 DO 10 I = 1,NINCX,INCX
419 C CODE FOR INCREMENT EQUAL TO 1
425 IF( M .EQ. 0 ) GO TO 40
429 IF( N .LT. 5 ) RETURN
433 DX(I + 1) = DA*DX(I + 1)
434 DX(I + 2) = DA*DX(I + 2)
435 DX(I + 3) = DA*DX(I + 3)
436 DX(I + 4) = DA*DX(I + 4)
440 C*MODULE BLAS1 *DECK DSWAP
441 SUBROUTINE DSWAP (N,DX,INCX,DY,INCY)
442 IMPLICIT DOUBLE PRECISION(A-H,O-Z)
443 DIMENSION DX(1),DY(1)
445 C INTERCHANGES TWO VECTORS.
447 C USES UNROLLED LOOPS FOR INCREMENTS EQUAL ONE.
448 C JACK DONGARRA, LINPACK, 3/11/78.
451 IF(INCX.EQ.1.AND.INCY.EQ.1)GO TO 20
453 C CODE FOR UNEQUAL INCREMENTS OR EQUAL INCREMENTS NOT EQUAL
458 IF(INCX.LT.0)IX = (-N+1)*INCX + 1
459 IF(INCY.LT.0)IY = (-N+1)*INCY + 1
469 C CODE FOR BOTH INCREMENTS EQUAL TO 1
475 IF( M .EQ. 0 ) GO TO 40
481 IF( N .LT. 3 ) RETURN
488 DX(I + 1) = DY(I + 1)
491 DX(I + 2) = DY(I + 2)
496 C*MODULE BLAS1 *DECK IDAMAX
497 INTEGER FUNCTION IDAMAX(N,DX,INCX)
498 IMPLICIT DOUBLE PRECISION(A-H,O-Z)
501 C FINDS THE INDEX OF ELEMENT HAVING MAX. ABSOLUTE VALUE.
502 C JACK DONGARRA, LINPACK, 3/11/78.
505 IF( N .LT. 1 ) RETURN
508 IF(INCX.EQ.1)GO TO 20
510 C CODE FOR INCREMENT NOT EQUAL TO 1
516 IF(ABS(DX(IX)).LE.RMAX) GO TO 5
523 C CODE FOR INCREMENT EQUAL TO 1
527 IF(ABS(DX(I)).LE.RMAX) GO TO 30
533 C*MODULE BLAS *DECK DGEMV
534 SUBROUTINE DGEMV(FORMA,M,N,ALPHA,A,LDA,X,INCX,BETA,Y,INCY)
535 IMPLICIT DOUBLE PRECISION(A-H,O-Z)
537 DIMENSION A(LDA,*),X(*),Y(*)
538 PARAMETER (ZERO=0.0D+00, ONE=1.0D+00)
540 C CLONE OF -DGEMV- WRITTEN BY MIKE SCHMIDT
543 IF(FORMA.EQ.'T') GO TO 200
545 C Y = ALPHA * A * X + BETA * Y
547 IF(ALPHA.EQ.ONE .AND. BETA.EQ.ZERO) THEN
549 Y(LOCY) = DDOT(N,A(I,1),LDA,X,INCX)
554 Y(LOCY) = ALPHA*DDOT(N,A(I,1),LDA,X,INCX) + BETA*Y(LOCY)
560 C Y = ALPHA * A-TRANSPOSE * X + BETA * Y
563 IF(ALPHA.EQ.ONE .AND. BETA.EQ.ZERO) THEN
565 Y(LOCY) = DDOT(M,A(1,I),1,X,INCX)
570 Y(LOCY) = ALPHA*DDOT(M,A(1,I),1,X,INCX) + BETA*Y(LOCY)