-
Notifications
You must be signed in to change notification settings - Fork 0
/
opksa2.f
executable file
·1441 lines (1441 loc) · 44.5 KB
/
opksa2.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
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*DECK SGEFA
SUBROUTINE SGEFA (A, LDA, N, IPVT, INFO)
C***BEGIN PROLOGUE SGEFA
C***PURPOSE Factor a matrix using Gaussian elimination.
C***CATEGORY D2A1
C***TYPE SINGLE PRECISION (SGEFA-S, 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 SGEFA factors a real matrix by Gaussian elimination.
C
C SGEFA is usually called by SGECO, but it can be called
C directly with a saving in time if RCOND is not needed.
C (Time for SGECO) = (1 + 9/N)*(Time for SGEFA) .
C
C On Entry
C
C A REAL(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 SGESL or SGEDI will divide by zero
C if called. Use RCOND in SGECO 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 ISAMAX, SAXPY, SSCAL
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 SGEFA
INTEGER LDA,N,IPVT(*),INFO
REAL A(LDA,*)
C
REAL T
INTEGER ISAMAX,J,K,KP1,L,NM1
C
C GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING
C
C***FIRST EXECUTABLE STATEMENT SGEFA
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 = ISAMAX(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.0E0) 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.0E0/A(K,K)
CALL SSCAL(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 SAXPY(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.0E0) INFO = N
RETURN
END
*DECK SGESL
SUBROUTINE SGESL (A, LDA, N, IPVT, B, JOB)
C***BEGIN PROLOGUE SGESL
C***PURPOSE Solve the real system A*X=B or TRANS(A)*X=B using the
C factors of SGECO or SGEFA.
C***CATEGORY D2A1
C***TYPE SINGLE PRECISION (SGESL-S, DGESL-D, CGESL-C)
C***KEYWORDS LINEAR ALGEBRA, LINPACK, MATRIX, SOLVE
C***AUTHOR Moler, C. B., (U. of New Mexico)
C***DESCRIPTION
C
C SGESL solves the real system
C A * X = B or TRANS(A) * X = B
C using the factors computed by SGECO or SGEFA.
C
C On Entry
C
C A REAL(LDA, N)
C the output from SGECO or SGEFA.
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 SGECO or SGEFA.
C
C B REAL(N)
C the right hand side vector.
C
C JOB INTEGER
C = 0 to solve A*X = B ,
C = nonzero to solve TRANS(A)*X = B where
C TRANS(A) is the transpose.
C
C On Return
C
C B the solution vector X .
C
C Error Condition
C
C A division by zero will occur if the input factor contains a
C zero on the diagonal. Technically, this indicates singularity,
C but it is often caused by improper arguments or improper
C setting of LDA . It will not occur if the subroutines are
C called correctly and if SGECO has set RCOND .GT. 0.0
C or SGEFA has set INFO .EQ. 0 .
C
C To compute INVERSE(A) * C where C is a matrix
C with P columns
C CALL SGECO(A,LDA,N,IPVT,RCOND,Z)
C IF (RCOND is too small) GO TO ...
C DO 10 J = 1, P
C CALL SGESL(A,LDA,N,IPVT,C(1,J),0)
C 10 CONTINUE
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 SAXPY, SDOT
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 SGESL
INTEGER LDA,N,IPVT(*),JOB
REAL A(LDA,*),B(*)
C
REAL SDOT,T
INTEGER K,KB,L,NM1
C***FIRST EXECUTABLE STATEMENT SGESL
NM1 = N - 1
IF (JOB .NE. 0) GO TO 50
C
C JOB = 0 , SOLVE A * X = B
C FIRST SOLVE L*Y = B
C
IF (NM1 .LT. 1) GO TO 30
DO 20 K = 1, NM1
L = IPVT(K)
T = B(L)
IF (L .EQ. K) GO TO 10
B(L) = B(K)
B(K) = T
10 CONTINUE
CALL SAXPY(N-K,T,A(K+1,K),1,B(K+1),1)
20 CONTINUE
30 CONTINUE
C
C NOW SOLVE U*X = Y
C
DO 40 KB = 1, N
K = N + 1 - KB
B(K) = B(K)/A(K,K)
T = -B(K)
CALL SAXPY(K-1,T,A(1,K),1,B(1),1)
40 CONTINUE
GO TO 100
50 CONTINUE
C
C JOB = NONZERO, SOLVE TRANS(A) * X = B
C FIRST SOLVE TRANS(U)*Y = B
C
DO 60 K = 1, N
T = SDOT(K-1,A(1,K),1,B(1),1)
B(K) = (B(K) - T)/A(K,K)
60 CONTINUE
C
C NOW SOLVE TRANS(L)*X = Y
C
IF (NM1 .LT. 1) GO TO 90
DO 80 KB = 1, NM1
K = N - KB
B(K) = B(K) + SDOT(N-K,A(K+1,K),1,B(K+1),1)
L = IPVT(K)
IF (L .EQ. K) GO TO 70
T = B(L)
B(L) = B(K)
B(K) = T
70 CONTINUE
80 CONTINUE
90 CONTINUE
100 CONTINUE
RETURN
END
*DECK SGBFA
SUBROUTINE SGBFA (ABD, LDA, N, ML, MU, IPVT, INFO)
C***BEGIN PROLOGUE SGBFA
C***PURPOSE Factor a band matrix using Gaussian elimination.
C***CATEGORY D2A2
C***TYPE SINGLE PRECISION (SGBFA-S, DGBFA-D, CGBFA-C)
C***KEYWORDS BANDED, LINEAR ALGEBRA, LINPACK, MATRIX FACTORIZATION
C***AUTHOR Moler, C. B., (U. of New Mexico)
C***DESCRIPTION
C
C SGBFA factors a real band matrix by elimination.
C
C SGBFA is usually called by SBGCO, but it can be called
C directly with a saving in time if RCOND is not needed.
C
C On Entry
C
C ABD REAL(LDA, N)
C contains the matrix in band storage. The columns
C of the matrix are stored in the columns of ABD and
C the diagonals of the matrix are stored in rows
C ML+1 through 2*ML+MU+1 of ABD .
C See the comments below for details.
C
C LDA INTEGER
C the leading dimension of the array ABD .
C LDA must be .GE. 2*ML + MU + 1 .
C
C N INTEGER
C the order of the original matrix.
C
C ML INTEGER
C number of diagonals below the main diagonal.
C 0 .LE. ML .LT. N .
C
C MU INTEGER
C number of diagonals above the main diagonal.
C 0 .LE. MU .LT. N .
C More efficient if ML .LE. MU .
C On Return
C
C ABD an upper triangular matrix in band storage and
C the multipliers 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 SGBSL will divide by zero if
C called. Use RCOND in SBGCO for a reliable
C indication of singularity.
C
C Band Storage
C
C If A is a band matrix, the following program segment
C will set up the input.
C
C ML = (band width below the diagonal)
C MU = (band width above the diagonal)
C M = ML + MU + 1
C DO 20 J = 1, N
C I1 = MAX(1, J-MU)
C I2 = MIN(N, J+ML)
C DO 10 I = I1, I2
C K = I - J + M
C ABD(K,J) = A(I,J)
C 10 CONTINUE
C 20 CONTINUE
C
C This uses rows ML+1 through 2*ML+MU+1 of ABD .
C In addition, the first ML rows in ABD are used for
C elements generated during the triangularization.
C The total number of rows needed in ABD is 2*ML+MU+1 .
C The ML+MU by ML+MU upper left triangle and the
C ML by ML lower right triangle are not referenced.
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 ISAMAX, SAXPY, SSCAL
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 SGBFA
INTEGER LDA,N,ML,MU,IPVT(*),INFO
REAL ABD(LDA,*)
C
REAL T
INTEGER I,ISAMAX,I0,J,JU,JZ,J0,J1,K,KP1,L,LM,M,MM,NM1
C
C***FIRST EXECUTABLE STATEMENT SGBFA
M = ML + MU + 1
INFO = 0
C
C ZERO INITIAL FILL-IN COLUMNS
C
J0 = MU + 2
J1 = MIN(N,M) - 1
IF (J1 .LT. J0) GO TO 30
DO 20 JZ = J0, J1
I0 = M + 1 - JZ
DO 10 I = I0, ML
ABD(I,JZ) = 0.0E0
10 CONTINUE
20 CONTINUE
30 CONTINUE
JZ = J1
JU = 0
C
C GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING
C
NM1 = N - 1
IF (NM1 .LT. 1) GO TO 130
DO 120 K = 1, NM1
KP1 = K + 1
C
C ZERO NEXT FILL-IN COLUMN
C
JZ = JZ + 1
IF (JZ .GT. N) GO TO 50
IF (ML .LT. 1) GO TO 50
DO 40 I = 1, ML
ABD(I,JZ) = 0.0E0
40 CONTINUE
50 CONTINUE
C
C FIND L = PIVOT INDEX
C
LM = MIN(ML,N-K)
L = ISAMAX(LM+1,ABD(M,K),1) + M - 1
IPVT(K) = L + K - M
C
C ZERO PIVOT IMPLIES THIS COLUMN ALREADY TRIANGULARIZED
C
IF (ABD(L,K) .EQ. 0.0E0) GO TO 100
C
C INTERCHANGE IF NECESSARY
C
IF (L .EQ. M) GO TO 60
T = ABD(L,K)
ABD(L,K) = ABD(M,K)
ABD(M,K) = T
60 CONTINUE
C
C COMPUTE MULTIPLIERS
C
T = -1.0E0/ABD(M,K)
CALL SSCAL(LM,T,ABD(M+1,K),1)
C
C ROW ELIMINATION WITH COLUMN INDEXING
C
JU = MIN(MAX(JU,MU+IPVT(K)),N)
MM = M
IF (JU .LT. KP1) GO TO 90
DO 80 J = KP1, JU
L = L - 1
MM = MM - 1
T = ABD(L,J)
IF (L .EQ. MM) GO TO 70
ABD(L,J) = ABD(MM,J)
ABD(MM,J) = T
70 CONTINUE
CALL SAXPY(LM,T,ABD(M+1,K),1,ABD(MM+1,J),1)
80 CONTINUE
90 CONTINUE
GO TO 110
100 CONTINUE
INFO = K
110 CONTINUE
120 CONTINUE
130 CONTINUE
IPVT(N) = N
IF (ABD(M,N) .EQ. 0.0E0) INFO = N
RETURN
END
*DECK SGBSL
SUBROUTINE SGBSL (ABD, LDA, N, ML, MU, IPVT, B, JOB)
C***BEGIN PROLOGUE SGBSL
C***PURPOSE Solve the real band system A*X=B or TRANS(A)*X=B using
C the factors computed by SGBCO or SGBFA.
C***CATEGORY D2A2
C***TYPE SINGLE PRECISION (SGBSL-S, DGBSL-D, CGBSL-C)
C***KEYWORDS BANDED, LINEAR ALGEBRA, LINPACK, MATRIX, SOLVE
C***AUTHOR Moler, C. B., (U. of New Mexico)
C***DESCRIPTION
C
C SGBSL solves the real band system
C A * X = B or TRANS(A) * X = B
C using the factors computed by SBGCO or SGBFA.
C
C On Entry
C
C ABD REAL(LDA, N)
C the output from SBGCO or SGBFA.
C
C LDA INTEGER
C the leading dimension of the array ABD .
C
C N INTEGER
C the order of the original matrix.
C
C ML INTEGER
C number of diagonals below the main diagonal.
C
C MU INTEGER
C number of diagonals above the main diagonal.
C
C IPVT INTEGER(N)
C the pivot vector from SBGCO or SGBFA.
C
C B REAL(N)
C the right hand side vector.
C
C JOB INTEGER
C = 0 to solve A*X = B ,
C = nonzero to solve TRANS(A)*X = B , where
C TRANS(A) is the transpose.
C
C On Return
C
C B the solution vector X .
C
C Error Condition
C
C A division by zero will occur if the input factor contains a
C zero on the diagonal. Technically, this indicates singularity,
C but it is often caused by improper arguments or improper
C setting of LDA . It will not occur if the subroutines are
C called correctly and if SBGCO has set RCOND .GT. 0.0
C or SGBFA has set INFO .EQ. 0 .
C
C To compute INVERSE(A) * C where C is a matrix
C with P columns
C CALL SBGCO(ABD,LDA,N,ML,MU,IPVT,RCOND,Z)
C If (RCOND is too small) GO TO ...
C DO 10 J = 1, P
C CALL SGBSL(ABD,LDA,N,ML,MU,IPVT,C(1,J),0)
C 10 CONTINUE
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 SAXPY, SDOT
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 SGBSL
INTEGER LDA,N,ML,MU,IPVT(*),JOB
REAL ABD(LDA,*),B(*)
C
REAL SDOT,T
INTEGER K,KB,L,LA,LB,LM,M,NM1
C***FIRST EXECUTABLE STATEMENT SGBSL
M = MU + ML + 1
NM1 = N - 1
IF (JOB .NE. 0) GO TO 50
C
C JOB = 0 , SOLVE A * X = B
C FIRST SOLVE L*Y = B
C
IF (ML .EQ. 0) GO TO 30
IF (NM1 .LT. 1) GO TO 30
DO 20 K = 1, NM1
LM = MIN(ML,N-K)
L = IPVT(K)
T = B(L)
IF (L .EQ. K) GO TO 10
B(L) = B(K)
B(K) = T
10 CONTINUE
CALL SAXPY(LM,T,ABD(M+1,K),1,B(K+1),1)
20 CONTINUE
30 CONTINUE
C
C NOW SOLVE U*X = Y
C
DO 40 KB = 1, N
K = N + 1 - KB
B(K) = B(K)/ABD(M,K)
LM = MIN(K,M) - 1
LA = M - LM
LB = K - LM
T = -B(K)
CALL SAXPY(LM,T,ABD(LA,K),1,B(LB),1)
40 CONTINUE
GO TO 100
50 CONTINUE
C
C JOB = NONZERO, SOLVE TRANS(A) * X = B
C FIRST SOLVE TRANS(U)*Y = B
C
DO 60 K = 1, N
LM = MIN(K,M) - 1
LA = M - LM
LB = K - LM
T = SDOT(LM,ABD(LA,K),1,B(LB),1)
B(K) = (B(K) - T)/ABD(M,K)
60 CONTINUE
C
C NOW SOLVE TRANS(L)*X = Y
C
IF (ML .EQ. 0) GO TO 90
IF (NM1 .LT. 1) GO TO 90
DO 80 KB = 1, NM1
K = N - KB
LM = MIN(ML,N-K)
B(K) = B(K) + SDOT(LM,ABD(M+1,K),1,B(K+1),1)
L = IPVT(K)
IF (L .EQ. K) GO TO 70
T = B(L)
B(L) = B(K)
B(K) = T
70 CONTINUE
80 CONTINUE
90 CONTINUE
100 CONTINUE
RETURN
END
*DECK SAXPY
SUBROUTINE SAXPY (N, SA, SX, INCX, SY, INCY)
C***BEGIN PROLOGUE SAXPY
C***PURPOSE Compute a constant times a vector plus a vector.
C***CATEGORY D1A7
C***TYPE SINGLE PRECISION (SAXPY-S, 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 SA single precision scalar multiplier
C SX single precision vector with N elements
C INCX storage spacing between elements of SX
C SY single precision vector with N elements
C INCY storage spacing between elements of SY
C
C --Output--
C SY single precision result (unchanged if N .LE. 0)
C
C Overwrite single precision SY with single precision SA*SX +SY.
C For I = 0 to N-1, replace SY(LY+I*INCY) with SA*SX(LX+I*INCX) +
C SY(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 SAXPY
REAL SX(*), SY(*), SA
C***FIRST EXECUTABLE STATEMENT SAXPY
IF (N.LE.0 .OR. SA.EQ.0.0E0) 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
SY(IY) = SY(IY) + SA*SX(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
SY(I) = SY(I) + SA*SX(I)
30 CONTINUE
IF (N .LT. 4) RETURN
40 MP1 = M + 1
DO 50 I = MP1,N,4
SY(I) = SY(I) + SA*SX(I)
SY(I+1) = SY(I+1) + SA*SX(I+1)
SY(I+2) = SY(I+2) + SA*SX(I+2)
SY(I+3) = SY(I+3) + SA*SX(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
SY(I) = SA*SX(I) + SY(I)
70 CONTINUE
RETURN
END
*DECK SCOPY
SUBROUTINE SCOPY (N, SX, INCX, SY, INCY)
C***BEGIN PROLOGUE SCOPY
C***PURPOSE Copy a vector.
C***CATEGORY D1A5
C***TYPE SINGLE PRECISION (SCOPY-S, DCOPY-D, CCOPY-C, ICOPY-I)
C***KEYWORDS BLAS, COPY, 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 SX single precision vector with N elements
C INCX storage spacing between elements of SX
C SY single precision vector with N elements
C INCY storage spacing between elements of SY
C
C --Output--
C SY copy of vector SX (unchanged if N .LE. 0)
C
C Copy single precision SX to single precision SY.
C For I = 0 to N-1, copy SX(LX+I*INCX) to SY(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 SCOPY
REAL SX(*), SY(*)
C***FIRST EXECUTABLE STATEMENT SCOPY
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
SY(IY) = SX(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 7.
C
20 M = MOD(N,7)
IF (M .EQ. 0) GO TO 40
DO 30 I = 1,M
SY(I) = SX(I)
30 CONTINUE
IF (N .LT. 7) RETURN
40 MP1 = M + 1
DO 50 I = MP1,N,7
SY(I) = SX(I)
SY(I+1) = SX(I+1)
SY(I+2) = SX(I+2)
SY(I+3) = SX(I+3)
SY(I+4) = SX(I+4)
SY(I+5) = SX(I+5)
SY(I+6) = SX(I+6)
50 CONTINUE
RETURN
C
C Code for equal, positive, non-unit increments.
C
60 NS = N*INCX
DO 70 I = 1,NS,INCX
SY(I) = SX(I)
70 CONTINUE
RETURN
END
*DECK SDOT
REAL FUNCTION SDOT (N, SX, INCX, SY, INCY)
C***BEGIN PROLOGUE SDOT
C***PURPOSE Compute the inner product of two vectors.
C***CATEGORY D1A4
C***TYPE SINGLE PRECISION (SDOT-S, DDOT-D, CDOTU-C)
C***KEYWORDS BLAS, INNER PRODUCT, 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 SX single precision vector with N elements
C INCX storage spacing between elements of SX
C SY single precision vector with N elements
C INCY storage spacing between elements of SY
C
C --Output--
C SDOT single precision dot product (zero if N .LE. 0)
C
C Returns the dot product of single precision SX and SY.
C SDOT = sum for I = 0 to N-1 of SX(LX+I*INCX) * SY(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 SDOT
REAL SX(*), SY(*)
C***FIRST EXECUTABLE STATEMENT SDOT
SDOT = 0.0E0
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
SDOT = SDOT + SX(IX)*SY(IY)
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 5.
C
20 M = MOD(N,5)
IF (M .EQ. 0) GO TO 40
DO 30 I = 1,M
SDOT = SDOT + SX(I)*SY(I)
30 CONTINUE
IF (N .LT. 5) RETURN
40 MP1 = M + 1
DO 50 I = MP1,N,5
SDOT = SDOT + SX(I)*SY(I) + SX(I+1)*SY(I+1) + SX(I+2)*SY(I+2) +
1 SX(I+3)*SY(I+3) + SX(I+4)*SY(I+4)
50 CONTINUE
RETURN
C
C Code for equal, positive, non-unit increments.
C
60 NS = N*INCX
DO 70 I = 1,NS,INCX
SDOT = SDOT + SX(I)*SY(I)
70 CONTINUE
RETURN
END
*DECK SNRM2
REAL FUNCTION SNRM2 (N, SX, INCX)
C***BEGIN PROLOGUE SNRM2
C***PURPOSE Compute the Euclidean length (L2 norm) of a vector.
C***CATEGORY D1A3B
C***TYPE SINGLE PRECISION (SNRM2-S, DNRM2-D, SCNRM2-C)
C***KEYWORDS BLAS, EUCLIDEAN LENGTH, EUCLIDEAN NORM, L2,
C LINEAR ALGEBRA, UNITARY, 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 SX single precision vector with N elements
C INCX storage spacing between elements of SX
C
C --Output--
C SNRM2 single precision result (zero if N .LE. 0)
C
C Euclidean norm of the N-vector stored in SX with storage
C increment INCX .
C If N .LE. 0, return with result = 0.
C If N .GE. 1, then INCX must be .GE. 1
C
C Four Phase Method using two built-in constants that are
C hopefully applicable to all machines.
C CUTLO = maximum of SQRT(U/EPS) over all known machines.
C CUTHI = minimum of SQRT(V) over all known machines.
C where
C EPS = smallest no. such that EPS + 1. .GT. 1.
C U = smallest positive no. (underflow limit)
C V = largest no. (overflow limit)
C
C Brief Outline of Algorithm.
C
C Phase 1 scans zero components.
C Move to phase 2 when a component is nonzero and .LE. CUTLO
C Move to phase 3 when a component is .GT. CUTLO
C Move to phase 4 when a component is .GE. CUTHI/M
C where M = N for X() real and M = 2*N for complex.
C
C Values for CUTLO and CUTHI.
C From the environmental parameters listed in the IMSL converter
C document the limiting values are as follows:
C CUTLO, S.P. U/EPS = 2**(-102) for Honeywell. Close seconds are
C Univac and DEC at 2**(-103)
C Thus CUTLO = 2**(-51) = 4.44089E-16
C CUTHI, S.P. V = 2**127 for Univac, Honeywell, and DEC.
C Thus CUTHI = 2**(63.5) = 1.30438E19
C CUTLO, D.P. U/EPS = 2**(-67) for Honeywell and DEC.
C Thus CUTLO = 2**(-33.5) = 8.23181D-11
C CUTHI, D.P. same as S.P. CUTHI = 1.30438D19
C DATA CUTLO, CUTHI /8.232D-11, 1.304D19/
C DATA CUTLO, CUTHI /4.441E-16, 1.304E19/
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 890831 Modified array declarations. (WRB)
C 890831 REVISION DATE from Version 3.2
C 891214 Prologue converted to Version 4.0 format. (BAB)
C 920501 Reformatted the REFERENCES section. (WRB)
C***END PROLOGUE SNRM2
INTEGER NEXT
REAL SX(*), CUTLO, CUTHI, HITEST, SUM, XMAX, ZERO, ONE
SAVE CUTLO, CUTHI, ZERO, ONE
DATA ZERO, ONE /0.0E0, 1.0E0/
C
DATA CUTLO, CUTHI /4.441E-16, 1.304E19/
C***FIRST EXECUTABLE STATEMENT SNRM2
IF (N .GT. 0) GO TO 10
SNRM2 = ZERO
GO TO 300
C
10 ASSIGN 30 TO NEXT
SUM = ZERO
NN = N * INCX
C
C BEGIN MAIN LOOP
C
I = 1
20 GO TO NEXT,(30, 50, 70, 110)
30 IF (ABS(SX(I)) .GT. CUTLO) GO TO 85
ASSIGN 50 TO NEXT
XMAX = ZERO
C
C PHASE 1. SUM IS ZERO
C
50 IF (SX(I) .EQ. ZERO) GO TO 200
IF (ABS(SX(I)) .GT. CUTLO) GO TO 85
C
C PREPARE FOR PHASE 2.
C
ASSIGN 70 TO NEXT
GO TO 105
C
C PREPARE FOR PHASE 4.
C
100 I = J
ASSIGN 110 TO NEXT
SUM = (SUM / SX(I)) / SX(I)
105 XMAX = ABS(SX(I))
GO TO 115
C
C PHASE 2. SUM IS SMALL.
C SCALE TO AVOID DESTRUCTIVE UNDERFLOW.
C
70 IF (ABS(SX(I)) .GT. CUTLO) GO TO 75
C
C COMMON CODE FOR PHASES 2 AND 4.
C IN PHASE 4 SUM IS LARGE. SCALE TO AVOID OVERFLOW.
C
110 IF (ABS(SX(I)) .LE. XMAX) GO TO 115
SUM = ONE + SUM * (XMAX / SX(I))**2
XMAX = ABS(SX(I))
GO TO 200
C
115 SUM = SUM + (SX(I)/XMAX)**2
GO TO 200
C
C PREPARE FOR PHASE 3.
C
75 SUM = (SUM * XMAX) * XMAX
C
C FOR REAL OR D.P. SET HITEST = CUTHI/N
C FOR COMPLEX SET HITEST = CUTHI/(2*N)
C
85 HITEST = CUTHI / N
C
C PHASE 3. SUM IS MID-RANGE. NO SCALING.
C
DO 95 J = I,NN,INCX
IF (ABS(SX(J)) .GE. HITEST) GO TO 100
95 SUM = SUM + SX(J)**2
SNRM2 = SQRT( SUM )
GO TO 300
C
200 CONTINUE