-
Notifications
You must be signed in to change notification settings - Fork 1
/
maths_pda.f
830 lines (829 loc) · 26.5 KB
/
maths_pda.f
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
C Routines from the Starlink PDA library needed by the Maths module in mfit
C Collated by John Young 2009-11-03
C
C 31-MAY-2007 (PWD): Note this routine is not used. See pdaD1mach.c.
C
DOUBLE PRECISION FUNCTION PDA_D1MACH(I)
IMPLICIT NONE
INTEGER I
C
C DOUBLE-PRECISION MACHINE CONSTANTS
C D1MACH( 1) = B**(EMIN-1), THE SMALLEST POSITIVE MAGNITUDE.
C D1MACH( 2) = B**EMAX*(1 - B**(-T)), THE LARGEST MAGNITUDE.
C D1MACH( 3) = B**(-T), THE SMALLEST RELATIVE SPACING.
C D1MACH( 4) = B**(1-T), THE LARGEST RELATIVE SPACING.
C D1MACH( 5) = LOG10(B)
C
INTEGER SMALL(2)
INTEGER LARGE(2)
INTEGER RIGHT(2)
INTEGER DIVER(2)
INTEGER LOG10(2)
INTEGER SC, CRAY1(38), J
COMMON /D9MACH/ CRAY1
SAVE SMALL, LARGE, RIGHT, DIVER, LOG10, SC
DOUBLE PRECISION DMACH(5)
EQUIVALENCE (DMACH(1),SMALL(1))
EQUIVALENCE (DMACH(2),LARGE(1))
EQUIVALENCE (DMACH(3),RIGHT(1))
EQUIVALENCE (DMACH(4),DIVER(1))
EQUIVALENCE (DMACH(5),LOG10(1))
C THIS VERSION ADAPTS AUTOMATICALLY TO MOST CURRENT MACHINES.
C R1MACH CAN HANDLE AUTO-DOUBLE COMPILING, BUT THIS VERSION OF
C D1MACH DOES NOT, BECAUSE WE DO NOT HAVE QUAD CONSTANTS FOR
C MANY MACHINES YET.
C TO COMPILE ON OLDER MACHINES, ADD A C IN COLUMN 1
C ON THE NEXT LINE
DATA SC/0/
C AND REMOVE THE C FROM COLUMN 1 IN ONE OF THE SECTIONS BELOW.
C CONSTANTS FOR EVEN OLDER MACHINES CAN BE OBTAINED BY
C mail [email protected]
C send old1mach from blas
C PLEASE SEND CORRECTIONS TO dmg OR [email protected].
C
C MACHINE CONSTANTS FOR THE HONEYWELL DPS 8/70 SERIES.
C DATA SMALL(1),SMALL(2) / O402400000000, O000000000000 /
C DATA LARGE(1),LARGE(2) / O376777777777, O777777777777 /
C DATA RIGHT(1),RIGHT(2) / O604400000000, O000000000000 /
C DATA DIVER(1),DIVER(2) / O606400000000, O000000000000 /
C DATA LOG10(1),LOG10(2) / O776464202324, O117571775714 /, SC/987/
C
C MACHINE CONSTANTS FOR PDP-11 FORTRANS SUPPORTING
C 32-BIT INTEGERS.
C DATA SMALL(1),SMALL(2) / 8388608, 0 /
C DATA LARGE(1),LARGE(2) / 2147483647, -1 /
C DATA RIGHT(1),RIGHT(2) / 612368384, 0 /
C DATA DIVER(1),DIVER(2) / 620756992, 0 /
C DATA LOG10(1),LOG10(2) / 1067065498, -2063872008 /, SC/987/
C
C MACHINE CONSTANTS FOR THE UNIVAC 1100 SERIES.
C DATA SMALL(1),SMALL(2) / O000040000000, O000000000000 /
C DATA LARGE(1),LARGE(2) / O377777777777, O777777777777 /
C DATA RIGHT(1),RIGHT(2) / O170540000000, O000000000000 /
C DATA DIVER(1),DIVER(2) / O170640000000, O000000000000 /
C DATA LOG10(1),LOG10(2) / O177746420232, O411757177572 /, SC/987/
C
C ON FIRST CALL, IF NO DATA UNCOMMENTED, TEST MACHINE TYPES.
IF (SC .NE. 987) THEN
DMACH(1) = 1.D13
IF ( SMALL(1) .EQ. 1117925532
* .AND. SMALL(2) .EQ. -448790528) THEN
* *** IEEE BIG ENDIAN ***
SMALL(1) = 1048576
SMALL(2) = 0
LARGE(1) = 2146435071
LARGE(2) = -1
RIGHT(1) = 1017118720
RIGHT(2) = 0
DIVER(1) = 1018167296
DIVER(2) = 0
LOG10(1) = 1070810131
LOG10(2) = 1352628735
ELSE IF ( SMALL(2) .EQ. 1117925532
* .AND. SMALL(1) .EQ. -448790528) THEN
* *** IEEE LITTLE ENDIAN ***
SMALL(2) = 1048576
SMALL(1) = 0
LARGE(2) = 2146435071
LARGE(1) = -1
RIGHT(2) = 1017118720
RIGHT(1) = 0
DIVER(2) = 1018167296
DIVER(1) = 0
LOG10(2) = 1070810131
LOG10(1) = 1352628735
ELSE IF ( SMALL(1) .EQ. -2065213935
* .AND. SMALL(2) .EQ. 10752) THEN
* *** VAX WITH D_FLOATING ***
SMALL(1) = 128
SMALL(2) = 0
LARGE(1) = -32769
LARGE(2) = -1
RIGHT(1) = 9344
RIGHT(2) = 0
DIVER(1) = 9472
DIVER(2) = 0
LOG10(1) = 546979738
LOG10(2) = -805796613
ELSE IF ( SMALL(1) .EQ. 1267827943
* .AND. SMALL(2) .EQ. 704643072) THEN
* *** IBM MAINFRAME ***
SMALL(1) = 1048576
SMALL(2) = 0
LARGE(1) = 2147483647
LARGE(2) = -1
RIGHT(1) = 856686592
RIGHT(2) = 0
DIVER(1) = 873463808
DIVER(2) = 0
LOG10(1) = 1091781651
LOG10(2) = 1352628735
ELSE IF ( SMALL(1) .EQ. 1120022684
* .AND. SMALL(2) .EQ. -448790528) THEN
* *** CONVEX C-1 ***
SMALL(1) = 1048576
SMALL(2) = 0
LARGE(1) = 2147483647
LARGE(2) = -1
RIGHT(1) = 1019215872
RIGHT(2) = 0
DIVER(1) = 1020264448
DIVER(2) = 0
LOG10(1) = 1072907283
LOG10(2) = 1352628735
ELSE IF ( SMALL(1) .EQ. 815547074
* .AND. SMALL(2) .EQ. 58688) THEN
* *** VAX G-FLOATING ***
SMALL(1) = 16
SMALL(2) = 0
LARGE(1) = -32769
LARGE(2) = -1
RIGHT(1) = 15552
RIGHT(2) = 0
DIVER(1) = 15568
DIVER(2) = 0
LOG10(1) = 1142112243
LOG10(2) = 2046775455
ELSE
DMACH(2) = 1.D27 + 1
DMACH(3) = 1.D27
LARGE(2) = LARGE(2) - RIGHT(2)
IF (LARGE(2) .EQ. 64 .AND. SMALL(2) .EQ. 0) THEN
CRAY1(1) = 67291416
DO 10 J = 1, 20
CRAY1(J+1) = CRAY1(J) + CRAY1(J)
10 CONTINUE
CRAY1(22) = CRAY1(21) + 321322
DO 20 J = 22, 37
CRAY1(J+1) = CRAY1(J) + CRAY1(J)
20 CONTINUE
IF (CRAY1(38) .EQ. SMALL(1)) THEN
* *** CRAY ***
CALL PDA_I1MCRY(SMALL(1), J, 8285, 8388608, 0)
SMALL(2) = 0
CALL PDA_I1MCRY(LARGE(1), J, 24574, 16777215,16777215)
CALL PDA_I1MCRY(LARGE(2), J, 0, 16777215, 16777214)
CALL PDA_I1MCRY(RIGHT(1), J, 16291, 8388608, 0)
RIGHT(2) = 0
CALL PDA_I1MCRY(DIVER(1), J, 16292, 8388608, 0)
DIVER(2) = 0
CALL PDA_I1MCRY(LOG10(1), J, 16383, 10100890, 8715215)
CALL PDA_I1MCRY(LOG10(2), J, 0, 16226447, 9001388)
ELSE
WRITE(*,9000)
STOP 779
END IF
ELSE
WRITE(*,9000)
STOP 779
END IF
END IF
SC = 987
END IF
* SANITY CHECK
IF (DMACH(4) .GE. 1.0D0) STOP 778
IF (I .LT. 1 .OR. I .GT. 5) THEN
WRITE(*,*) 'D1MACH(I): I =',I,' is out of bounds.'
STOP
END IF
PDA_D1MACH = DMACH(I)
RETURN
9000 FORMAT(/' Adjust D1MACH by uncommenting data statements'/
*' appropriate for your machine.')
* /* Standard C source for D1MACH -- remove the * in column 1 */
*#include <stdio.h>
*#include <float.h>
*#include <math.h>
*double d1mach_(long *i)
*{
* switch(*i){
* case 1: return DBL_MIN;
* case 2: return DBL_MAX;
* case 3: return DBL_EPSILON/FLT_RADIX;
* case 4: return DBL_EPSILON;
* case 5: return log10((double)FLT_RADIX);
* }
* fprintf(stderr, "invalid argument: d1mach(%ld)\n", *i);
* exit(1); return 0; /* some compilers demand return values */
*}
END
SUBROUTINE PDA_I1MCRY(A, A1, B, C, D)
**** SPECIAL COMPUTATION FOR OLD CRAY MACHINES ****
INTEGER A, A1, B, C, D
A1 = 16777216*B + C
A = 16777216*A1 + D
END
*DECK PDA_DAXPY
SUBROUTINE PDA_DAXPY (N, DA, DX, INCX, DY, INCY)
C***BEGIN PROLOGUE PDA_DAXPY
C***PURPOSE Compute a constant times a vector plus a vector.
C***LIBRARY SLATEC (BLAS)
C***CATEGORY D1A7
C***TYPE DOUBLE PRECISION (SAXPY-S, PDA_DAXPY-D, CAXPY-C)
C***KEYWORDS BLAS, LINEAR ALGEBRA, TRIAD, VECTOR
C***AUTHOR Lawson, C. L., (JPL)
C Hanson, R. J., (SNLA)
C Kincaid, D. R., (U. of Texas)
C Krogh, F. T., (JPL)
C***DESCRIPTION
C
C B L A S Subprogram
C Description of Parameters
C
C --Input--
C N number of elements in input vector(s)
C DA double precision scalar multiplier
C DX double precision vector with N elements
C INCX storage spacing between elements of DX
C DY double precision vector with N elements
C INCY storage spacing between elements of DY
C
C --Output--
C DY double precision result (unchanged if N .LE. 0)
C
C Overwrite double precision DY with double precision DA*DX + DY.
C For I = 0 to N-1, replace DY(LY+I*INCY) with DA*DX(LX+I*INCX) +
C DY(LY+I*INCY),
C where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is
C defined in a similar way using INCY.
C
C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T.
C Krogh, Basic linear algebra subprograms for Fortran
C usage, Algorithm No. 539, Transactions on Mathematical
C Software 5, 3 (September 1979), pp. 308-323.
C***ROUTINES CALLED (NONE)
C***REVISION HISTORY (YYMMDD)
C 791001 DATE WRITTEN
C 890831 Modified array declarations. (WRB)
C 890831 REVISION DATE from Version 3.2
C 891214 Prologue converted to Version 4.0 format. (BAB)
C 920310 Corrected definition of LX in DESCRIPTION. (WRB)
C 920501 Reformatted the REFERENCES section. (WRB)
C***END PROLOGUE PDA_DAXPY
DOUBLE PRECISION DX(*), DY(*), DA
C***FIRST EXECUTABLE STATEMENT PDA_DAXPY
IF (N.LE.0 .OR. DA.EQ.0.0D0) RETURN
IF (INCX .EQ. INCY) IF (INCX-1) 5,20,60
C
C Code for unequal or nonpositive increments.
C
5 IX = 1
IY = 1
IF (INCX .LT. 0) IX = (-N+1)*INCX + 1
IF (INCY .LT. 0) IY = (-N+1)*INCY + 1
DO 10 I = 1,N
DY(IY) = DY(IY) + DA*DX(IX)
IX = IX + INCX
IY = IY + INCY
10 CONTINUE
RETURN
C
C Code for both increments equal to 1.
C
C Clean-up loop so remaining vector length is a multiple of 4.
C
20 M = MOD(N,4)
IF (M .EQ. 0) GO TO 40
DO 30 I = 1,M
DY(I) = DY(I) + DA*DX(I)
30 CONTINUE
IF (N .LT. 4) RETURN
40 MP1 = M + 1
DO 50 I = MP1,N,4
DY(I) = DY(I) + DA*DX(I)
DY(I+1) = DY(I+1) + DA*DX(I+1)
DY(I+2) = DY(I+2) + DA*DX(I+2)
DY(I+3) = DY(I+3) + DA*DX(I+3)
50 CONTINUE
RETURN
C
C Code for equal, positive, non-unit increments.
C
60 NS = N*INCX
DO 70 I = 1,NS,INCX
DY(I) = DA*DX(I) + DY(I)
70 CONTINUE
RETURN
END
*DECK PDA_DGEDI
SUBROUTINE PDA_DGEDI (A, LDA, N, IPVT, DET, WORK, JOB)
C***BEGIN PROLOGUE PDA_DGEDI
C***PURPOSE Compute the determinant and inverse of a matrix using the
C factors computed by PDA_DGECO or PDA_DGEFA.
C***LIBRARY SLATEC (LINPACK)
C***CATEGORY D3A1, D2A1
C***TYPE DOUBLE PRECISION (SGEDI-S, PDA_DGEDI-D, CGEDI-C)
C***KEYWORDS DETERMINANT, INVERSE, LINEAR ALGEBRA, LINPACK, MATRIX
C***AUTHOR Moler, C. B., (U. of New Mexico)
C***DESCRIPTION
C
C PDA_DGEDI computes the determinant and inverse of a matrix
C using the factors computed by PDA_DGECO or PDA_DGEFA.
C
C On Entry
C
C A DOUBLE PRECISION(LDA, N)
C the output from PDA_DGECO or PDA_DGEFA.
C
C LDA INTEGER
C the leading dimension of the array A .
C
C N INTEGER
C the order of the matrix A .
C
C IPVT INTEGER(N)
C the pivot vector from PDA_DGECO or PDA_DGEFA.
C
C WORK DOUBLE PRECISION(N)
C work vector. Contents destroyed.
C
C JOB INTEGER
C = 11 both determinant and inverse.
C = 01 inverse only.
C = 10 determinant only.
C
C On Return
C
C A inverse of original matrix if requested.
C Otherwise unchanged.
C
C DET DOUBLE PRECISION(2)
C determinant of original matrix if requested.
C Otherwise not referenced.
C Determinant = DET(1) * 10.0**DET(2)
C with 1.0 .LE. ABS(DET(1)) .LT. 10.0
C or DET(1) .EQ. 0.0 .
C
C Error Condition
C
C A division by zero will occur if the input factor contains
C a zero on the diagonal and the inverse is requested.
C It will not occur if the subroutines are called correctly
C and if PDA_DGECO has set RCOND .GT. 0.0 or PDA_DGEFA has set
C INFO .EQ. 0 .
C
C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
C Stewart, LINPACK Users' Guide, SIAM, 1979.
C***ROUTINES CALLED PDA_DAXPY, PDA_DSCAL, PDA_DSWAP
C***REVISION HISTORY (YYMMDD)
C 780814 DATE WRITTEN
C 890531 Changed all specific intrinsics to generic. (WRB)
C 890831 Modified array declarations. (WRB)
C 890831 REVISION DATE from Version 3.2
C 891214 Prologue converted to Version 4.0 format. (BAB)
C 900326 Removed duplicate information from DESCRIPTION section.
C (WRB)
C 920501 Reformatted the REFERENCES section. (WRB)
C***END PROLOGUE PDA_DGEDI
INTEGER LDA,N,IPVT(*),JOB
DOUBLE PRECISION A(LDA,*),DET(2),WORK(*)
C
DOUBLE PRECISION T
DOUBLE PRECISION TEN
INTEGER I,J,K,KB,KP1,L,NM1
C***FIRST EXECUTABLE STATEMENT PDA_DGEDI
C
C COMPUTE DETERMINANT
C
IF (JOB/10 .EQ. 0) GO TO 70
DET(1) = 1.0D0
DET(2) = 0.0D0
TEN = 10.0D0
DO 50 I = 1, N
IF (IPVT(I) .NE. I) DET(1) = -DET(1)
DET(1) = A(I,I)*DET(1)
IF (DET(1) .EQ. 0.0D0) GO TO 60
10 IF (ABS(DET(1)) .GE. 1.0D0) GO TO 20
DET(1) = TEN*DET(1)
DET(2) = DET(2) - 1.0D0
GO TO 10
20 CONTINUE
30 IF (ABS(DET(1)) .LT. TEN) GO TO 40
DET(1) = DET(1)/TEN
DET(2) = DET(2) + 1.0D0
GO TO 30
40 CONTINUE
50 CONTINUE
60 CONTINUE
70 CONTINUE
C
C COMPUTE INVERSE(U)
C
IF (MOD(JOB,10) .EQ. 0) GO TO 150
DO 100 K = 1, N
A(K,K) = 1.0D0/A(K,K)
T = -A(K,K)
CALL PDA_DSCAL(K-1,T,A(1,K),1)
KP1 = K + 1
IF (N .LT. KP1) GO TO 90
DO 80 J = KP1, N
T = A(K,J)
A(K,J) = 0.0D0
CALL PDA_DAXPY(K,T,A(1,K),1,A(1,J),1)
80 CONTINUE
90 CONTINUE
100 CONTINUE
C
C FORM INVERSE(U)*INVERSE(L)
C
NM1 = N - 1
IF (NM1 .LT. 1) GO TO 140
DO 130 KB = 1, NM1
K = N - KB
KP1 = K + 1
DO 110 I = KP1, N
WORK(I) = A(I,K)
A(I,K) = 0.0D0
110 CONTINUE
DO 120 J = KP1, N
T = WORK(J)
CALL PDA_DAXPY(N,T,A(1,J),1,A(1,K),1)
120 CONTINUE
L = IPVT(K)
IF (L .NE. K) CALL PDA_DSWAP(N,A(1,K),1,A(1,L),1)
130 CONTINUE
140 CONTINUE
150 CONTINUE
RETURN
END
*DECK PDA_DGEFA
SUBROUTINE PDA_DGEFA (A, LDA, N, IPVT, INFO)
C***BEGIN PROLOGUE PDA_DGEFA
C***PURPOSE Factor a matrix using Gaussian elimination.
C***LIBRARY SLATEC (LINPACK)
C***CATEGORY D2A1
C***TYPE DOUBLE PRECISION (SGEFA-S, PDA_DGEFA-D, CGEFA-C)
C***KEYWORDS GENERAL MATRIX, LINEAR ALGEBRA, LINPACK,
C MATRIX FACTORIZATION
C***AUTHOR Moler, C. B., (U. of New Mexico)
C***DESCRIPTION
C
C PDA_DGEFA factors a double precision matrix by Gaussian elimination.
C
C PDA_DGEFA is usually called by PDA_DGECO, but it can be called
C directly with a saving in time if RCOND is not needed.
C (Time for PDA_DGECO) = (1 + 9/N)*(Time for PDA_DGEFA) .
C
C On Entry
C
C A DOUBLE PRECISION(LDA, N)
C the matrix to be factored.
C
C LDA INTEGER
C the leading dimension of the array A .
C
C N INTEGER
C the order of the matrix A .
C
C On Return
C
C A an upper triangular matrix and the multipliers
C which were used to obtain it.
C The factorization can be written A = L*U where
C L is a product of permutation and unit lower
C triangular matrices and U is upper triangular.
C
C IPVT INTEGER(N)
C an integer vector of pivot indices.
C
C INFO INTEGER
C = 0 normal value.
C = K if U(K,K) .EQ. 0.0 . This is not an error
C condition for this subroutine, but it does
C indicate that PDA_DGESL or PDA_DGEDI will divide by zero
C if called. Use RCOND in PDA_DGECO for a reliable
C indication of singularity.
C
C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
C Stewart, LINPACK Users' Guide, SIAM, 1979.
C***ROUTINES CALLED PDA_DAXPY, PDA_DSCAL, PDA_IDAMAX
C***REVISION HISTORY (YYMMDD)
C 780814 DATE WRITTEN
C 890831 Modified array declarations. (WRB)
C 890831 REVISION DATE from Version 3.2
C 891214 Prologue converted to Version 4.0 format. (BAB)
C 900326 Removed duplicate information from DESCRIPTION section.
C (WRB)
C 920501 Reformatted the REFERENCES section. (WRB)
C***END PROLOGUE PDA_DGEFA
INTEGER LDA,N,IPVT(*),INFO
DOUBLE PRECISION A(LDA,*)
C
DOUBLE PRECISION T
INTEGER PDA_IDAMAX,J,K,KP1,L,NM1
C
C GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING
C
C***FIRST EXECUTABLE STATEMENT PDA_DGEFA
INFO = 0
NM1 = N - 1
IF (NM1 .LT. 1) GO TO 70
DO 60 K = 1, NM1
KP1 = K + 1
C
C FIND L = PIVOT INDEX
C
L = PDA_IDAMAX(N-K+1,A(K,K),1) + K - 1
IPVT(K) = L
C
C ZERO PIVOT IMPLIES THIS COLUMN ALREADY TRIANGULARIZED
C
IF (A(L,K) .EQ. 0.0D0) GO TO 40
C
C INTERCHANGE IF NECESSARY
C
IF (L .EQ. K) GO TO 10
T = A(L,K)
A(L,K) = A(K,K)
A(K,K) = T
10 CONTINUE
C
C COMPUTE MULTIPLIERS
C
T = -1.0D0/A(K,K)
CALL PDA_DSCAL(N-K,T,A(K+1,K),1)
C
C ROW ELIMINATION WITH COLUMN INDEXING
C
DO 30 J = KP1, N
T = A(L,J)
IF (L .EQ. K) GO TO 20
A(L,J) = A(K,J)
A(K,J) = T
20 CONTINUE
CALL PDA_DAXPY(N-K,T,A(K+1,K),1,A(K+1,J),1)
30 CONTINUE
GO TO 50
40 CONTINUE
INFO = K
50 CONTINUE
60 CONTINUE
70 CONTINUE
IPVT(N) = N
IF (A(N,N) .EQ. 0.0D0) INFO = N
RETURN
END
*DECK PDA_DSCAL
SUBROUTINE PDA_DSCAL (N, DA, DX, INCX)
C***BEGIN PROLOGUE PDA_DSCAL
C***PURPOSE Multiply a vector by a constant.
C***LIBRARY SLATEC (BLAS)
C***CATEGORY D1A6
C***TYPE DOUBLE PRECISION (SSCAL-S, PDA_DSCAL-D, CSCAL-C)
C***KEYWORDS BLAS, LINEAR ALGEBRA, SCALE, VECTOR
C***AUTHOR Lawson, C. L., (JPL)
C Hanson, R. J., (SNLA)
C Kincaid, D. R., (U. of Texas)
C Krogh, F. T., (JPL)
C***DESCRIPTION
C
C B L A S Subprogram
C Description of Parameters
C
C --Input--
C N number of elements in input vector(s)
C DA double precision scale factor
C DX double precision vector with N elements
C INCX storage spacing between elements of DX
C
C --Output--
C DX double precision result (unchanged if N.LE.0)
C
C Replace double precision DX by double precision DA*DX.
C For I = 0 to N-1, replace DX(IX+I*INCX) with DA * DX(IX+I*INCX),
C where IX = 1 if INCX .GE. 0, else IX = 1+(1-N)*INCX.
C
C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T.
C Krogh, Basic linear algebra subprograms for Fortran
C usage, Algorithm No. 539, Transactions on Mathematical
C Software 5, 3 (September 1979), pp. 308-323.
C***ROUTINES CALLED (NONE)
C***REVISION HISTORY (YYMMDD)
C 791001 DATE WRITTEN
C 890831 Modified array declarations. (WRB)
C 890831 REVISION DATE from Version 3.2
C 891214 Prologue converted to Version 4.0 format. (BAB)
C 900821 Modified to correct problem with a negative increment.
C (WRB)
C 920501 Reformatted the REFERENCES section. (WRB)
C***END PROLOGUE PDA_DSCAL
DOUBLE PRECISION DA, DX(*)
INTEGER I, INCX, IX, M, MP1, N
C***FIRST EXECUTABLE STATEMENT PDA_DSCAL
IF (N .LE. 0) RETURN
IF (INCX .EQ. 1) GOTO 20
C
C Code for increment not equal to 1.
C
IX = 1
IF (INCX .LT. 0) IX = (-N+1)*INCX + 1
DO 10 I = 1,N
DX(IX) = DA*DX(IX)
IX = IX + INCX
10 CONTINUE
RETURN
C
C Code for increment equal to 1.
C
C Clean-up loop so remaining vector length is a multiple of 5.
C
20 M = MOD(N,5)
IF (M .EQ. 0) GOTO 40
DO 30 I = 1,M
DX(I) = DA*DX(I)
30 CONTINUE
IF (N .LT. 5) RETURN
40 MP1 = M + 1
DO 50 I = MP1,N,5
DX(I) = DA*DX(I)
DX(I+1) = DA*DX(I+1)
DX(I+2) = DA*DX(I+2)
DX(I+3) = DA*DX(I+3)
DX(I+4) = DA*DX(I+4)
50 CONTINUE
RETURN
END
*DECK PDA_DSWAP
SUBROUTINE PDA_DSWAP (N, DX, INCX, DY, INCY)
C***BEGIN PROLOGUE PDA_DSWAP
C***PURPOSE Interchange two vectors.
C***LIBRARY SLATEC (BLAS)
C***CATEGORY D1A5
C***TYPE DOUBLE PRECISION (SSWAP-S, PDA_DSWAP-D, CSWAP-C, ISWAP-I)
C***KEYWORDS BLAS, INTERCHANGE, LINEAR ALGEBRA, VECTOR
C***AUTHOR Lawson, C. L., (JPL)
C Hanson, R. J., (SNLA)
C Kincaid, D. R., (U. of Texas)
C Krogh, F. T., (JPL)
C***DESCRIPTION
C
C B L A S Subprogram
C Description of Parameters
C
C --Input--
C N number of elements in input vector(s)
C DX double precision vector with N elements
C INCX storage spacing between elements of DX
C DY double precision vector with N elements
C INCY storage spacing between elements of DY
C
C --Output--
C DX input vector DY (unchanged if N .LE. 0)
C DY input vector DX (unchanged if N .LE. 0)
C
C Interchange double precision DX and double precision DY.
C For I = 0 to N-1, interchange DX(LX+I*INCX) and DY(LY+I*INCY),
C where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is
C defined in a similar way using INCY.
C
C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T.
C Krogh, Basic linear algebra subprograms for Fortran
C usage, Algorithm No. 539, Transactions on Mathematical
C Software 5, 3 (September 1979), pp. 308-323.
C***ROUTINES CALLED (NONE)
C***REVISION HISTORY (YYMMDD)
C 791001 DATE WRITTEN
C 890831 Modified array declarations. (WRB)
C 890831 REVISION DATE from Version 3.2
C 891214 Prologue converted to Version 4.0 format. (BAB)
C 920310 Corrected definition of LX in DESCRIPTION. (WRB)
C 920501 Reformatted the REFERENCES section. (WRB)
C***END PROLOGUE PDA_DSWAP
DOUBLE PRECISION DX(*), DY(*), DTEMP1, DTEMP2, DTEMP3
C***FIRST EXECUTABLE STATEMENT PDA_DSWAP
IF (N .LE. 0) RETURN
IF (INCX .EQ. INCY) IF (INCX-1) 5,20,60
C
C Code for unequal or nonpositive increments.
C
5 IX = 1
IY = 1
IF (INCX .LT. 0) IX = (-N+1)*INCX + 1
IF (INCY .LT. 0) IY = (-N+1)*INCY + 1
DO 10 I = 1,N
DTEMP1 = DX(IX)
DX(IX) = DY(IY)
DY(IY) = DTEMP1
IX = IX + INCX
IY = IY + INCY
10 CONTINUE
RETURN
C
C Code for both increments equal to 1.
C
C Clean-up loop so remaining vector length is a multiple of 3.
C
20 M = MOD(N,3)
IF (M .EQ. 0) GO TO 40
DO 30 I = 1,M
DTEMP1 = DX(I)
DX(I) = DY(I)
DY(I) = DTEMP1
30 CONTINUE
IF (N .LT. 3) RETURN
40 MP1 = M + 1
DO 50 I = MP1,N,3
DTEMP1 = DX(I)
DTEMP2 = DX(I+1)
DTEMP3 = DX(I+2)
DX(I) = DY(I)
DX(I+1) = DY(I+1)
DX(I+2) = DY(I+2)
DY(I) = DTEMP1
DY(I+1) = DTEMP2
DY(I+2) = DTEMP3
50 CONTINUE
RETURN
C
C Code for equal, positive, non-unit increments.
C
60 NS = N*INCX
DO 70 I = 1,NS,INCX
DTEMP1 = DX(I)
DX(I) = DY(I)
DY(I) = DTEMP1
70 CONTINUE
RETURN
END
*DECK PDA_IDAMAX
INTEGER FUNCTION PDA_IDAMAX (N, DX, INCX)
C***BEGIN PROLOGUE PDA_IDAMAX
C***PURPOSE Find the smallest index of that component of a vector
C having the maximum magnitude.
C***LIBRARY SLATEC (BLAS)
C***CATEGORY D1A2
C***TYPE DOUBLE PRECISION (ISAMAX-S, PDA_IDAMAX-D, ICAMAX-C)
C***KEYWORDS BLAS, LINEAR ALGEBRA, MAXIMUM COMPONENT, VECTOR
C***AUTHOR Lawson, C. L., (JPL)
C Hanson, R. J., (SNLA)
C Kincaid, D. R., (U. of Texas)
C Krogh, F. T., (JPL)
C***DESCRIPTION
C
C B L A S Subprogram
C Description of Parameters
C
C --Input--
C N number of elements in input vector(s)
C DX double precision vector with N elements
C INCX storage spacing between elements of DX
C
C --Output--
C PDA_IDAMAX smallest index (zero if N .LE. 0)
C
C Find smallest index of maximum magnitude of double precision DX.
C PDA_IDAMAX = first I, I = 1 to N, to maximize ABS(DX(IX+(I-1)*INCX)),
C where IX = 1 if INCX .GE. 0, else IX = 1+(1-N)*INCX.
C
C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T.
C Krogh, Basic linear algebra subprograms for Fortran
C usage, Algorithm No. 539, Transactions on Mathematical
C Software 5, 3 (September 1979), pp. 308-323.
C***ROUTINES CALLED (NONE)
C***REVISION HISTORY (YYMMDD)
C 791001 DATE WRITTEN
C 890531 Changed all specific intrinsics to generic. (WRB)
C 890531 REVISION DATE from Version 3.2
C 891214 Prologue converted to Version 4.0 format. (BAB)
C 900821 Modified to correct problem with a negative increment.
C (WRB)
C 920501 Reformatted the REFERENCES section. (WRB)
C***END PROLOGUE PDA_IDAMAX
DOUBLE PRECISION DX(*), DMAX, XMAG
INTEGER I, INCX, IX, N
C***FIRST EXECUTABLE STATEMENT PDA_IDAMAX
PDA_IDAMAX = 0
IF (N .LE. 0) RETURN
PDA_IDAMAX = 1
IF (N .EQ. 1) RETURN
C
IF (INCX .EQ. 1) GOTO 20
C
C Code for increments not equal to 1.
C
IX = 1
IF (INCX .LT. 0) IX = (-N+1)*INCX + 1
DMAX = ABS(DX(IX))
IX = IX + INCX
DO 10 I = 2,N
XMAG = ABS(DX(IX))
IF (XMAG .GT. DMAX) THEN
PDA_IDAMAX = I
DMAX = XMAG
ENDIF
IX = IX + INCX
10 CONTINUE
RETURN
C
C Code for increments equal to 1.
C
20 DMAX = ABS(DX(1))
DO 30 I = 2,N
XMAG = ABS(DX(I))
IF (XMAG .GT. DMAX) THEN
PDA_IDAMAX = I
DMAX = XMAG
ENDIF
30 CONTINUE
RETURN
END