forked from HYCOM/HYCOM-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s8gefs.F90
2338 lines (2338 loc) · 75.3 KB
/
s8gefs.F90
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
!
! --- rename routines to prevent clashes with math libraries
!
SUBROUTINE S8GEFS(A,LDA,N,V,ITASK,IND,WORK,IWORK)
!***BEGIN PROLOGUE SGEFS
!***DATE WRITTEN 800317 (YYMMDD)
!***REVISION DATE 820801 (YYMMDD)
!***CATEGORY NO. D2A1
!***KEYWORDS GENERAL SYSTEM OF LINEAR EQUATIONS,LINEAR EQUATIONS
!***AUTHOR VOORHEES, E., (LANL)
!***PURPOSE SGEFS solves a GENERAL single precision real
! NXN system of linear equations.
!***DESCRIPTION
!
! Subroutine SGEFS solves a general NxN system of single
! precision linear equations using LINPACK subroutines SGECO
! and SGESL. That is, if A is an NxN real matrix and if X
! and B are real N-vectors, then SGEFS solves the equation
!
! A*X=B.
!
! The matrix A is first factored into upper and lower tri-
! angular matrices U and L using partial pivoting. These
! factors and the pivoting information are used to find the
! solution vector X. An approximate condition number is
! calculated to provide a rough estimate of the number of
! digits of accuracy in the computed solution.
!
! If the equation A*X=B is to be solved for more than one vector
! B, the factoring of A does not need to be performed again and
! the option to only solve (ITASK .GT. 1) will be faster for
! the succeeding solutions. In this case, the contents of A,
! LDA, N and IWORK must not have been altered by the user follow-
! ing factorization (ITASK=1). IND will not be changed by SGEFS
! in this case.
!
! Argument Description ***
!
! A REAL(LDA,N)
! on entry, the doubly subscripted array with dimension
! (LDA,N) which contains the coefficient matrix.
! on return, an upper triangular matrix U and the
! multipliers necessary to construct a matrix L
! so that A=L*U.
! LDA INTEGER
! the leading dimension of the array A. LDA must be great-
! er than or equal to N. (terminal error message IND=-1)
! N INTEGER
! the order of the matrix A. The first N elements of
! the array A are the elements of the first column of
! the matrix A. N must be greater than or equal to 1.
! (terminal error message IND=-2)
! V REAL(N)
! on entry, the singly subscripted array(vector) of di-
! mension N which contains the right hand side B of a
! system of simultaneous linear equations A*X=B.
! on return, V contains the solution vector, X .
! ITASK INTEGER
! If ITASK=1, the matrix A is factored and then the
! linear equation is solved.
! If ITASK .GT. 1, the equation is solved using the existing
! factored matrix A and IWORK.
! If ITASK .LT. 1, then terminal error message IND=-3 is
! printed.
! IND INTEGER
! GT. 0 IND is a rough estimate of the number of digits
! of accuracy in the solution, X.
! NOT DONE IN THIS VERSION.
! LT. 0 see error message corresponding to IND below.
! WORK REAL(N)
! a singly subscripted array of dimension at least N.
! IWORK INTEGER(N)
! a singly subscripted array of dimension at least N.
!
! Error Messages Printed ***
!
! IND=-1 terminal N is greater than LDA.
! IND=-2 terminal N is less than 1.
! IND=-3 terminal ITASK is less than 1.
! IND=-4 terminal The matrix A is computationally singular.
! A solution has not been computed.
! IND=-10 warning The solution has no apparent significance.
! The solution may be inaccurate or the matrix
! A may be poorly scaled.
!
! Note- The above terminal(*fatal*) error messages are
! designed to be handled by XERRWV in which
! LEVEL=1 (recoverable) and IFLAG=2 . LEVEL=0
! for warning error messages from XERROR. Unless
! the user provides otherwise, an error message
! will be printed followed by an abort.
!***REFERENCES SUBROUTINE SGEFS WAS DEVELOPED BY GROUP C-3, LOS ALAMOS
! SCIENTIFIC LABORATORY, LOS ALAMOS, NM 87545.
! THE LINPACK SUBROUTINES USED BY SGEFS ARE DESCRIBED IN
! DETAIL IN THE *LINPACK USERS GUIDE* PUBLISHED BY
! THE SOCIETY FOR INDUSTRIAL AND APPLIED MATHEMATICS
! (SIAM) DATED 1979.
!***ROUTINES CALLED SGECO,SGESL,XERROR,XERRWV
!***END PROLOGUE SGEFS
!
INTEGER LDA,N,ITASK,IND,IWORK(N)
REAL A(LDA,N),V(N),WORK(N)
REAL RCOND
!***FIRST EXECUTABLE STATEMENT SGEFS
IF (LDA.LT.N) GO TO 101
IF (N.LE.0) GO TO 102
IF (ITASK.LT.1) GO TO 103
IF (ITASK.GT.1) GO TO 20
!
! FACTOR MATRIX A INTO LU
CALL S8GECO(A,LDA,N,IWORK,RCOND,WORK)
!
! CHECK FOR COMPUTATIONALLY SINGULAR MATRIX
IF (RCOND.EQ.0.0) GO TO 104
!
! COMPUTE IND (ESTIMATE OF NO. OF SIGNIFICANT DIGITS)
! NOT DONE IN THIS VERSION, RETURN 0 INSTEAD
IND=0
!
! SOLVE AFTER FACTORING
20 CALL S8GESL(A,LDA,N,IWORK,V,0)
RETURN
!
! IF LDA.LT.N, IND=-1, TERMINAL XERRWV MESSAGE
101 IND=-1
CALL X8ERRWV( 'SGEFS ERROR (IND=-1) -- LDA=I1 IS LESS THAN N=I2', &
48,-1,1,2,LDA,N,0,0.0,0.0)
RETURN
!
! IF N.LT.1, IND=-2, TERMINAL XERRWV MESSAGE
102 IND=-2
CALL X8ERRWV( 'SGEFS ERROR (IND=-2) -- N=I1 IS LESS THAN 1', &
43,-2,1,1,N,0,0,0.0,0.0)
RETURN
!
! IF ITASK.LT.1, IND=-3, TERMINAL XERRWV MESSAGE
103 IND=-3
CALL X8ERRWV( 'SGEFS ERROR (IND=-3) -- ITASK=I1 IS LESS THAN 1', &
47,-3,1,1,ITASK,0,0,0.0,0.0)
RETURN
!
! IF SINGULAR MATRIX, IND=-4, TERMINAL XERRWV MESSAGE
104 IND=-4
CALL X8ERRWV( 'SGEFS ERROR (IND=-4) -- SINGULAR MATRIX A - NO SOLUT &
&ION',55,-4,1,0,0,0,0,0.0,0.0)
RETURN
!
END
SUBROUTINE S8GECO(A,LDA,N,IPVT,RCOND,Z)
!***BEGIN PROLOGUE SGECO
!***DATE WRITTEN 780814 (YYMMDD)
!***REVISION DATE 820801 (YYMMDD)
!***REVISION HISTORY (YYMMDD)
! 000330 Modified array declarations. (JEC)
!***CATEGORY NO. D2A1
!***KEYWORDS CONDITION,FACTOR,LINEAR ALGEBRA,LINPACK,MATRIX
!***AUTHOR MOLER, C. B., (U. OF NEW MEXICO)
!***PURPOSE Factors a real matrix by Gaussian elimination and estimates
! the condition number of the matrix.
!***DESCRIPTION
!
! SGECO factors a real matrix by Gaussian elimination
! and estimates the condition of the matrix.
!
! If RCOND is not needed, SGEFA is slightly faster.
! To solve A*X = B , follow SGECO by SGESL.
! To compute INVERSE(A)*C , follow SGECO by SGESL.
! To compute DETERMINANT(A) , follow SGECO by SGEDI.
! To compute INVERSE(A) , follow SGECO by SGEDI.
!
! On Entry
!
! A REAL(LDA, N)
! the matrix to be factored.
!
! LDA INTEGER
! the leading dimension of the array A .
!
! N INTEGER
! the order of the matrix A .
!
! On Return
!
! A an upper triangular matrix and the multipliers
! which were used to obtain it.
! The factorization can be written A = L*U , where
! L is a product of permutation and unit lower
! triangular matrices and U is upper triangular.
!
! IPVT INTEGER(N)
! an integer vector of pivot indices.
!
! RCOND REAL
! an estimate of the reciprocal condition of A .
! For the system A*X = B , relative perturbations
! in A and B of size EPSILON may cause
! relative perturbations in X of size EPSILON/RCOND .
! If RCOND is so small that the logical expression
! 1.0 + RCOND .EQ. 1.0
! is true, then A may be singular to working
! precision. In particular, RCOND is zero if
! exact singularity is detected or the estimate
! underflows.
!
! Z REAL(N)
! a work vector whose contents are usually unimportant.
! If A is close to a singular matrix, then Z is
! an approximate null vector in the sense that
! NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .
!
! LINPACK. This version dated 08/14/78 .
! Cleve Moler, University of New Mexico, Argonne National Lab.
!
! Subroutines and Functions
!
! LINPACK SGEFA
! BLAS S8AXPY,S8DOT,S8SCAL,S8ASUM
! Fortran ABS,AMAX1,SIGN
!***REFERENCES DONGARRA J.J., BUNCH J.R., MOLER C.B., STEWART G.W.,
! *LINPACK USERS GUIDE*, SIAM, 1979.
!***ROUTINES CALLED S8ASUM,S8AXPY,S8DOT,SGEFA,S8SCAL
!***END PROLOGUE SGECO
INTEGER LDA,N,IPVT(*)
REAL A(LDA,*),Z(*)
REAL RCOND
!
REAL S8DOT,EK,T,WK,WKM
REAL ANORM,S,S8ASUM,SM,YNORM
INTEGER INFO,J,K,KB,KP1,L
!
! COMPUTE 1-NORM OF A
!
!***FIRST EXECUTABLE STATEMENT SGECO
ANORM = 0.0E0
DO 10 J = 1, N
ANORM = AMAX1(ANORM,S8ASUM(N,A(1,J),1))
10 CONTINUE
!
! FACTOR
!
CALL S8GEFA(A,LDA,N,IPVT,INFO)
!
! RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .
! ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND TRANS(A)*Y = E .
! TRANS(A) IS THE TRANSPOSE OF A . THE COMPONENTS OF E ARE
! CHOSEN TO CAUSE MAXIMUM LOCAL GROWTH IN THE ELEMENTS OF W WHERE
! TRANS(U)*W = E . THE VECTORS ARE FREQUENTLY RESCALED TO AVOID
! OVERFLOW.
!
! SOLVE TRANS(U)*W = E
!
EK = 1.0E0
DO 20 J = 1, N
Z(J) = 0.0E0
20 CONTINUE
DO 100 K = 1, N
IF (Z(K) .NE. 0.0E0) EK = SIGN(EK,-Z(K))
IF (ABS(EK-Z(K)) .LE. ABS(A(K,K))) GO TO 30
S = ABS(A(K,K))/ABS(EK-Z(K))
CALL S8SCAL(N,S,Z,1)
EK = S*EK
30 CONTINUE
WK = EK - Z(K)
WKM = -EK - Z(K)
S = ABS(WK)
SM = ABS(WKM)
IF (A(K,K) .EQ. 0.0E0) GO TO 40
WK = WK/A(K,K)
WKM = WKM/A(K,K)
GO TO 50
40 CONTINUE
WK = 1.0E0
WKM = 1.0E0
50 CONTINUE
KP1 = K + 1
IF (KP1 .GT. N) GO TO 90
DO 60 J = KP1, N
SM = SM + ABS(Z(J)+WKM*A(K,J))
Z(J) = Z(J) + WK*A(K,J)
S = S + ABS(Z(J))
60 CONTINUE
IF (S .GE. SM) GO TO 80
T = WKM - WK
WK = WKM
DO 70 J = KP1, N
Z(J) = Z(J) + T*A(K,J)
70 CONTINUE
80 CONTINUE
90 CONTINUE
Z(K) = WK
100 CONTINUE
S = 1.0E0/S8ASUM(N,Z,1)
CALL S8SCAL(N,S,Z,1)
!
! SOLVE TRANS(L)*Y = W
!
DO 120 KB = 1, N
K = N + 1 - KB
IF (K .LT. N) Z(K) = Z(K) + S8DOT(N-K,A(K+1,K),1,Z(K+1),1)
IF (ABS(Z(K)) .LE. 1.0E0) GO TO 110
S = 1.0E0/ABS(Z(K))
CALL S8SCAL(N,S,Z,1)
110 CONTINUE
L = IPVT(K)
T = Z(L)
Z(L) = Z(K)
Z(K) = T
120 CONTINUE
S = 1.0E0/S8ASUM(N,Z,1)
CALL S8SCAL(N,S,Z,1)
!
YNORM = 1.0E0
!
! SOLVE L*V = Y
!
DO 140 K = 1, N
L = IPVT(K)
T = Z(L)
Z(L) = Z(K)
Z(K) = T
IF (K .LT. N) CALL S8AXPY(N-K,T,A(K+1,K),1,Z(K+1),1)
IF (ABS(Z(K)) .LE. 1.0E0) GO TO 130
S = 1.0E0/ABS(Z(K))
CALL S8SCAL(N,S,Z,1)
YNORM = S*YNORM
130 CONTINUE
140 CONTINUE
S = 1.0E0/S8ASUM(N,Z,1)
CALL S8SCAL(N,S,Z,1)
YNORM = S*YNORM
!
! SOLVE U*Z = V
!
DO 160 KB = 1, N
K = N + 1 - KB
IF (ABS(Z(K)) .LE. ABS(A(K,K))) GO TO 150
S = ABS(A(K,K))/ABS(Z(K))
CALL S8SCAL(N,S,Z,1)
YNORM = S*YNORM
150 CONTINUE
IF (A(K,K) .NE. 0.0E0) Z(K) = Z(K)/A(K,K)
IF (A(K,K) .EQ. 0.0E0) Z(K) = 1.0E0
T = -Z(K)
CALL S8AXPY(K-1,T,A(1,K),1,Z(1),1)
160 CONTINUE
! MAKE ZNORM = 1.0
S = 1.0E0/S8ASUM(N,Z,1)
CALL S8SCAL(N,S,Z,1)
YNORM = S*YNORM
!
IF (ANORM .NE. 0.0E0) RCOND = YNORM/ANORM
IF (ANORM .EQ. 0.0E0) RCOND = 0.0E0
RETURN
END
SUBROUTINE S8GEFA(A,LDA,N,IPVT,INFO)
!***BEGIN PROLOGUE SGEFA
!***DATE WRITTEN 780814 (YYMMDD)
!***REVISION DATE 820801 (YYMMDD)
!***REVISION HISTORY (YYMMDD)
! 000330 Modified array declarations. (JEC)
!***CATEGORY NO. D2A1
!***KEYWORDS FACTOR,LINEAR ALGEBRA,LINPACK,MATRIX
!***AUTHOR MOLER, C. B., (U. OF NEW MEXICO)
!***PURPOSE Factors a real matrix by Gaussian elimination.
!***DESCRIPTION
!
! SGEFA factors a real matrix by Gaussian elimination.
!
! SGEFA is usually called by SGECO, but it can be called
! directly with a saving in time if RCOND is not needed.
! (Time for SGECO) = (1 + 9/N)*(Time for SGEFA) .
!
! On Entry
!
! A REAL(LDA, N)
! the matrix to be factored.
!
! LDA INTEGER
! the leading dimension of the array A .
!
! N INTEGER
! the order of the matrix A .
!
! On Return
!
! A an upper triangular matrix and the multipliers
! which were used to obtain it.
! The factorization can be written A = L*U , where
! L is a product of permutation and unit lower
! triangular matrices and U is upper triangular.
!
! IPVT INTEGER(N)
! an integer vector of pivot indices.
!
! INFO INTEGER
! = 0 normal value.
! = K if U(K,K) .EQ. 0.0 . This is not an error
! condition for this subroutine, but it does
! indicate that SGESL or SGEDI will divide by zero
! if called. Use RCOND in SGECO for a reliable
! indication of singularity.
!
! LINPACK. This version dated 08/14/78 .
! Cleve Moler, University of New Mexico, Argonne National Lab.
!
! Subroutines and Functions
!
! BLAS S8AXPY,S8SCAL,IS8AMAX
!***REFERENCES DONGARRA J.J., BUNCH J.R., MOLER C.B., STEWART G.W.,
! *LINPACK USERS GUIDE*, SIAM, 1979.
!***ROUTINES CALLED IS8AMAX,S8AXPY,S8SCAL
!***END PROLOGUE SGEFA
INTEGER LDA,N,IPVT(*),INFO
REAL A(LDA,*)
!
REAL T
INTEGER IS8AMAX,J,K,KP1,L,NM1
!
! GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING
!
!***FIRST EXECUTABLE STATEMENT SGEFA
INFO = 0
NM1 = N - 1
IF (NM1 .LT. 1) GO TO 70
DO 60 K = 1, NM1
KP1 = K + 1
!
! FIND L = PIVOT INDEX
!
L = IS8AMAX(N-K+1,A(K,K),1) + K - 1
IPVT(K) = L
!
! ZERO PIVOT IMPLIES THIS COLUMN ALREADY TRIANGULARIZED
!
IF (A(L,K) .EQ. 0.0E0) GO TO 40
!
! INTERCHANGE IF NECESSARY
!
IF (L .EQ. K) GO TO 10
T = A(L,K)
A(L,K) = A(K,K)
A(K,K) = T
10 CONTINUE
!
! COMPUTE MULTIPLIERS
!
T = -1.0E0/A(K,K)
CALL S8SCAL(N-K,T,A(K+1,K),1)
!
! ROW ELIMINATION WITH COLUMN INDEXING
!
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 S8AXPY(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
SUBROUTINE S8GESL(A,LDA,N,IPVT,B,JOB)
!***BEGIN PROLOGUE SGESL
!***DATE WRITTEN 780814 (YYMMDD)
!***REVISION DATE 820801 (YYMMDD)
!***REVISION HISTORY (YYMMDD)
! 000330 Modified array declarations. (JEC)
!***CATEGORY NO. D2A1
!***KEYWORDS LINEAR ALGEBRA,LINPACK,MATRIX,SOLVE
!***AUTHOR MOLER, C. B., (U. OF NEW MEXICO)
!***PURPOSE Solves the real system A*X=B or TRANS(A)*X=B
! using the factors of SGECO or SGEFA
!***DESCRIPTION
!
! SGESL solves the real system
! A * X = B or TRANS(A) * X = B
! using the factors computed by SGECO or SGEFA.
!
! On Entry
!
! A REAL(LDA, N)
! the output from SGECO or SGEFA.
!
! LDA INTEGER
! the leading dimension of the array A .
!
! N INTEGER
! the order of the matrix A .
!
! IPVT INTEGER(N)
! the pivot vector from SGECO or SGEFA.
!
! B REAL(N)
! the right hand side vector.
!
! JOB INTEGER
! = 0 to solve A*X = B ,
! = nonzero to solve TRANS(A)*X = B where
! TRANS(A) is the transpose.
!
! On Return
!
! B the solution vector X .
!
! Error Condition
!
! A division by zero will occur if the input factor contains a
! zero on the diagonal. Technically, this indicates singularity,
! but it is often caused by improper arguments or improper
! setting of LDA . It will not occur if the subroutines are
! called correctly and if SGECO has set RCOND .GT. 0.0
! or SGEFA has set INFO .EQ. 0 .
!
! To compute INVERSE(A) * C where C is a matrix
! with P columns
! CALL SGECO(A,LDA,N,IPVT,RCOND,Z)
! IF (RCOND is too small) GO TO ...
! DO 10 J = 1, P
! CALL SGESL(A,LDA,N,IPVT,C(1,J),0)
! 10 CONTINUE
!
! LINPACK. This version dated 08/14/78 .
! Cleve Moler, University of New Mexico, Argonne National Lab.
!
! Subroutines and Functions
!
! BLAS S8AXPY,S8DOT
!***REFERENCES DONGARRA J.J., BUNCH J.R., MOLER C.B., STEWART G.W.,
! *LINPACK USERS GUIDE*, SIAM, 1979.
!***ROUTINES CALLED S8AXPY,S8DOT
!***END PROLOGUE SGESL
INTEGER LDA,N,IPVT(*),JOB
REAL A(LDA,*),B(*)
!
REAL S8DOT,T
INTEGER K,KB,L,NM1
!***FIRST EXECUTABLE STATEMENT SGESL
NM1 = N - 1
IF (JOB .NE. 0) GO TO 50
!
! JOB = 0 , SOLVE A * X = B
! FIRST SOLVE L*Y = B
!
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 S8AXPY(N-K,T,A(K+1,K),1,B(K+1),1)
20 CONTINUE
30 CONTINUE
!
! NOW SOLVE U*X = Y
!
DO 40 KB = 1, N
K = N + 1 - KB
B(K) = B(K)/A(K,K)
T = -B(K)
CALL S8AXPY(K-1,T,A(1,K),1,B(1),1)
40 CONTINUE
GO TO 100
50 CONTINUE
!
! JOB = NONZERO, SOLVE TRANS(A) * X = B
! FIRST SOLVE TRANS(U)*Y = B
!
DO 60 K = 1, N
T = S8DOT(K-1,A(1,K),1,B(1),1)
B(K) = (B(K) - T)/A(K,K)
60 CONTINUE
!
! NOW SOLVE TRANS(L)*X = Y
!
IF (NM1 .LT. 1) GO TO 90
DO 80 KB = 1, NM1
K = N - KB
B(K) = B(K) + S8DOT(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
SUBROUTINE X8ERROR(MESSG,NMESSG,NERR,LEVEL)
!***BEGIN PROLOGUE XERROR
!***DATE WRITTEN 790801 (YYMMDD)
!***REVISION DATE 820801 (YYMMDD)
!***CATEGORY NO. R3C
!***KEYWORDS ERROR,XERROR PACKAGE
!***AUTHOR JONES, R. E., (SNLA)
!***PURPOSE Processes an error (diagnostic) message.
!***DESCRIPTION
! Abstract
! XERROR processes a diagnostic message, in a manner
! determined by the value of LEVEL and the current value
! of the library error control flag, KONTRL.
! (See subroutine XSETF for details.)
!
! Description of Parameters
! --Input--
! MESSG - the Hollerith message to be processed, containing
! no more than 72 characters.
! NMESSG- the actual number of characters in MESSG.
! NERR - the error number associated with this message.
! NERR must not be zero.
! LEVEL - error category.
! =2 means this is an unconditionally fatal error.
! =1 means this is a recoverable error. (I.e., it is
! non-fatal if XSETF has been appropriately called.)
! =0 means this is a warning message only.
! =-1 means this is a warning message which is to be
! printed at most once, regardless of how many
! times this call is executed.
!
! Examples
! CALL XERROR('SMOOTH -- NUM WAS ZERO.',23,1,2)
! CALL XERROR('INTEG -- LESS THAN FULL ACCURACY ACHIEVED.',
! 43,2,1)
! CALL XERROR('ROOTER -- ACTUAL ZERO OF F FOUND BEFORE INTERVAL F
! 1ULLY COLLAPSED.',65,3,0)
! CALL XERROR('EXP -- UNDERFLOWS BEING SET TO ZERO.',39,1,-1)
!
! Latest revision --- 19 MAR 1980
! Written by Ron Jones, with SLATEC Common Math Library Subcommittee
!***REFERENCES JONES R.E., KAHANER D.K., "XERROR, THE SLATEC ERROR-
! HANDLING PACKAGE", SAND82-0800, SANDIA LABORATORIES,
! 1982.
!***ROUTINES CALLED XERRWV
!***END PROLOGUE XERROR
CHARACTER*(*) MESSG
!***FIRST EXECUTABLE STATEMENT XERROR
CALL X8ERRWV(MESSG,NMESSG,NERR,LEVEL,0,0,0,0,0.,0.)
RETURN
END
SUBROUTINE X8ERRWV(MESSG,NMESSG,NERR,LEVEL,NI,I1,I2,NR,R1,R2)
!***BEGIN PROLOGUE XERRWV
!***DATE WRITTEN 800319 (YYMMDD)
!***REVISION DATE 820801 (YYMMDD)
!***CATEGORY NO. R3C
!***KEYWORDS ERROR,XERROR PACKAGE
!***AUTHOR JONES, R. E., (SNLA)
!***PURPOSE Processes error message allowing 2 integer and two real
! values to be included in the message.
!***DESCRIPTION
! Abstract
! XERRWV processes a diagnostic message, in a manner
! determined by the value of LEVEL and the current value
! of the library error control flag, KONTRL.
! (See subroutine XSETF for details.)
! In addition, up to two integer values and two real
! values may be printed along with the message.
!
! Description of Parameters
! --Input--
! MESSG - the Hollerith message to be processed.
! NMESSG- the actual number of characters in MESSG.
! NERR - the error number associated with this message.
! NERR must not be zero.
! LEVEL - error category.
! =2 means this is an unconditionally fatal error.
! =1 means this is a recoverable error. (I.e., it is
! non-fatal if XSETF has been appropriately called.)
! =0 means this is a warning message only.
! =-1 means this is a warning message which is to be
! printed at most once, regardless of how many
! times this call is executed.
! NI - number of integer values to be printed. (0 to 2)
! I1 - first integer value.
! I2 - second integer value.
! NR - number of real values to be printed. (0 to 2)
! R1 - first real value.
! R2 - second real value.
!
! Examples
! CALL X8ERRWV('SMOOTH -- NUM (=I1) WAS ZERO.',29,1,2,
! 1 1,NUM,0,0,0.,0.)
! CALL XERRWV('QUADXY -- REQUESTED ERROR (R1) LESS THAN MINIMUM (
! 1R2).,54,77,1,0,0,0,2,ERRREQ,ERRMIN)
!
! Latest revision --- 19 MAR 1980
! Written by Ron Jones, with SLATEC Common Math Library Subcommittee
!***REFERENCES JONES R.E., KAHANER D.K., "XERROR, THE SLATEC ERROR-
! HANDLING PACKAGE", SAND82-0800, SANDIA LABORATORIES,
! 1982.
!***ROUTINES CALLED F8DUMP,I8MACH,J84SAVE,XERABT,XERCTL,XERPRT,XERSAV,
! XGETUA
!***END PROLOGUE XERRWV
CHARACTER*(*) MESSG
CHARACTER*20 LFIRST
CHARACTER*37 FORM
DIMENSION LUN(5)
! GET FLAGS
!***FIRST EXECUTABLE STATEMENT XERRWV
LKNTRL = J84SAVE(2,0,.FALSE.)
MAXMES = J84SAVE(4,0,.FALSE.)
! CHECK FOR VALID INPUT
IF ((NMESSG.GT.0).AND.(NERR.NE.0).AND. &
(LEVEL.GE.(-1)).AND.(LEVEL.LE.2)) GO TO 10
IF (LKNTRL.GT.0) CALL X8ERPRT('FATAL ERROR IN...',17)
CALL X8ERPRT('XERROR -- INVALID INPUT',23)
IF (LKNTRL.GT.0) CALL F8DUMP
IF (LKNTRL.GT.0) CALL X8ERPRT('JOB ABORT DUE TO FATAL ERROR.', &
29)
IF (LKNTRL.GT.0) CALL X8ERSAV(' ',0,0,0,KDUMMY)
CALL X8ERABT('XERROR -- INVALID INPUT',23)
RETURN
10 CONTINUE
! RECORD MESSAGE
JUNK = J84SAVE(1,NERR,.TRUE.)
CALL X8ERSAV(MESSG,NMESSG,NERR,LEVEL,KOUNT)
! LET USER OVERRIDE
LFIRST = MESSG
LMESSG = NMESSG
LERR = NERR
LLEVEL = LEVEL
CALL X8ERCTL(LFIRST,LMESSG,LERR,LLEVEL,LKNTRL)
! RESET TO ORIGINAL VALUES
LMESSG = NMESSG
LERR = NERR
LLEVEL = LEVEL
LKNTRL = MAX0(-2,MIN0(2,LKNTRL))
MKNTRL = IABS(LKNTRL)
! DECIDE WHETHER TO PRINT MESSAGE
IF ((LLEVEL.LT.2).AND.(LKNTRL.EQ.0)) GO TO 100
IF (((LLEVEL.EQ.(-1)).AND.(KOUNT.GT.MIN0(1,MAXMES))) &
.OR.((LLEVEL.EQ.0) .AND.(KOUNT.GT.MAXMES)) &
.OR.((LLEVEL.EQ.1) .AND.(KOUNT.GT.MAXMES).AND.(MKNTRL.EQ.1)) &
.OR.((LLEVEL.EQ.2) .AND.(KOUNT.GT.MAX0(1,MAXMES)))) GO TO 100
IF (LKNTRL.LE.0) GO TO 20
CALL X8ERPRT(' ',1)
! INTRODUCTION
IF (LLEVEL.EQ.(-1)) CALL X8ERPRT &
('WARNING MESSAGE...THIS MESSAGE WILL ONLY BE PRINTED ONCE.',57)
IF (LLEVEL.EQ.0) CALL X8ERPRT('WARNING IN...',13)
IF (LLEVEL.EQ.1) CALL X8ERPRT &
('RECOVERABLE ERROR IN...',23)
IF (LLEVEL.EQ.2) CALL X8ERPRT('FATAL ERROR IN...',17)
20 CONTINUE
! MESSAGE
CALL X8ERPRT(MESSG,LMESSG)
CALL X8GETUA(LUN,NUNIT)
ISIZEI = LOG10(REAL(I8MACH(9))) + 1.0
ISIZEF = LOG10(REAL(I8MACH(10))**I8MACH(11)) + 1.0
DO 50 KUNIT=1,NUNIT
IUNIT = LUN(KUNIT)
IF (IUNIT.EQ.0) IUNIT = I8MACH(4)
DO 22 I=1,MIN(NI,2)
WRITE (FORM,21) I,ISIZEI
21 FORMAT ('(11X,21HIN ABOVE MESSAGE, I',I1,'=,I',I2,') ')
IF (I.EQ.1) WRITE (IUNIT,FORM) I1
IF (I.EQ.2) WRITE (IUNIT,FORM) I2
22 CONTINUE
DO 24 I=1,MIN(NR,2)
WRITE (FORM,23) I,ISIZEF+10,ISIZEF
23 FORMAT ('(11X,21HIN ABOVE MESSAGE, R',I1,'=,E', &
I2,'.',I2,')')
IF (I.EQ.1) WRITE (IUNIT,FORM) R1
IF (I.EQ.2) WRITE (IUNIT,FORM) R2
24 CONTINUE
IF (LKNTRL.LE.0) GO TO 40
! ERROR NUMBER
WRITE (IUNIT,30) LERR
30 FORMAT (15H ERROR NUMBER =,I10)
40 CONTINUE
50 CONTINUE
! TRACE-BACK
IF (LKNTRL.GT.0) CALL F8DUMP
100 CONTINUE
IFATAL = 0
IF ((LLEVEL.EQ.2).OR.((LLEVEL.EQ.1).AND.(MKNTRL.EQ.2))) &
IFATAL = 1
! QUIT HERE IF MESSAGE IS NOT FATAL
IF (IFATAL.LE.0) RETURN
IF ((LKNTRL.LE.0).OR.(KOUNT.GT.MAX0(1,MAXMES))) GO TO 120
! PRINT REASON FOR ABORT
IF (LLEVEL.EQ.1) CALL X8ERPRT &
('JOB ABORT DUE TO UNRECOVERED ERROR.',35)
IF (LLEVEL.EQ.2) CALL X8ERPRT &
('JOB ABORT DUE TO FATAL ERROR.',29)
! PRINT ERROR SUMMARY
CALL X8ERSAV(' ',-1,0,0,KDUMMY)
120 CONTINUE
! ABORT
IF ((LLEVEL.EQ.2).AND.(KOUNT.GT.MAX0(1,MAXMES))) LMESSG = 0
CALL X8ERABT(MESSG,LMESSG)
RETURN
END
SUBROUTINE X8ERSAV(MESSG,NMESSG,NERR,LEVEL,ICOUNT)
!***BEGIN PROLOGUE XERSAV
!***DATE WRITTEN 800319 (YYMMDD)
!***REVISION DATE 820801 (YYMMDD)
!***CATEGORY NO. Z
!***KEYWORDS ERROR,XERROR PACKAGE
!***AUTHOR JONES, R. E., (SNLA)
!***PURPOSE Records that an error occurred.
!***DESCRIPTION
! Abstract
! Record that this error occurred.
!
! Description of Parameters
! --Input--
! MESSG, NMESSG, NERR, LEVEL are as in XERROR,
! except that when NMESSG=0 the tables will be
! dumped and cleared, and when NMESSG is less than zero the
! tables will be dumped and not cleared.
! --Output--
! ICOUNT will be the number of times this message has
! been seen, or zero if the table has overflowed and
! does not contain this message specifically.
! When NMESSG=0, ICOUNT will not be altered.
!
! Written by Ron Jones, with SLATEC Common Math Library Subcommittee
! Latest revision --- 19 Mar 1980
!***REFERENCES JONES R.E., KAHANER D.K., "XERROR, THE SLATEC ERROR-
! HANDLING PACKAGE", SAND82-0800, SANDIA LABORATORIES,
! 1982.
!***ROUTINES CALLED I8MACH,S88FMT,XGETUA
!***END PROLOGUE XERSAV
INTEGER LUN(5)
CHARACTER*(*) MESSG
CHARACTER*20 MESTAB(10),MES
DIMENSION NERTAB(10),LEVTAB(10),KOUNT(10)
SAVE MESTAB,NERTAB,LEVTAB,KOUNT,KOUNTX
! NEXT TWO DATA STATEMENTS ARE NECESSARY TO PROVIDE A BLANK
! ERROR TABLE INITIALLY
DATA KOUNT(1),KOUNT(2),KOUNT(3),KOUNT(4),KOUNT(5), &
KOUNT(6),KOUNT(7),KOUNT(8),KOUNT(9),KOUNT(10) &
/0,0,0,0,0,0,0,0,0,0/
DATA KOUNTX/0/
!***FIRST EXECUTABLE STATEMENT XERSAV
IF (NMESSG.GT.0) GO TO 80
! DUMP THE TABLE
IF (KOUNT(1).EQ.0) RETURN
! PRINT TO EACH UNIT
CALL X8GETUA(LUN,NUNIT)
DO 60 KUNIT=1,NUNIT
IUNIT = LUN(KUNIT)
IF (IUNIT.EQ.0) IUNIT = I8MACH(4)
! PRINT TABLE HEADER
WRITE (IUNIT,10)
10 FORMAT (32H0 ERROR MESSAGE SUMMARY/ &
51H MESSAGE START NERR LEVEL COUNT)
! PRINT BODY OF TABLE
DO 20 I=1,10
IF (KOUNT(I).EQ.0) GO TO 30
WRITE (IUNIT,15) MESTAB(I),NERTAB(I),LEVTAB(I),KOUNT(I)
15 FORMAT (1X,A20,3I10)
20 CONTINUE
30 CONTINUE
! PRINT NUMBER OF OTHER ERRORS
IF (KOUNTX.NE.0) WRITE (IUNIT,40) KOUNTX
40 FORMAT (41H0OTHER ERRORS NOT INDIVIDUALLY TABULATED=,I10)
WRITE (IUNIT,50)
50 FORMAT (1X)
60 CONTINUE
IF (NMESSG.LT.0) RETURN
! CLEAR THE ERROR TABLES
DO I=1,10
KOUNT(I) = 0
enddo
KOUNTX = 0
RETURN
80 CONTINUE
! PROCESS A MESSAGE...
! SEARCH FOR THIS MESSG, OR ELSE AN EMPTY SLOT FOR THIS MESSG,
! OR ELSE DETERMINE THAT THE ERROR TABLE IS FULL.
MES = MESSG
DO 90 I=1,10
II = I
IF (KOUNT(I).EQ.0) GO TO 110
IF (MES.NE.MESTAB(I)) GO TO 90
IF (NERR.NE.NERTAB(I)) GO TO 90
IF (LEVEL.NE.LEVTAB(I)) GO TO 90
GO TO 100
90 CONTINUE
! THREE POSSIBLE CASES...
! TABLE IS FULL
KOUNTX = KOUNTX+1
ICOUNT = 1
RETURN
! MESSAGE FOUND IN TABLE
100 KOUNT(II) = KOUNT(II) + 1
ICOUNT = KOUNT(II)
RETURN
! EMPTY SLOT FOUND FOR NEW MESSAGE
110 MESTAB(II) = MES
NERTAB(II) = NERR
LEVTAB(II) = LEVEL
KOUNT(II) = 1
ICOUNT = 1
RETURN
END
SUBROUTINE X8GETUA(IUNITA,N)
!***BEGIN PROLOGUE XGETUA
!***DATE WRITTEN 790801 (YYMMDD)
!***REVISION DATE 820801 (YYMMDD)
!***CATEGORY NO. R3C
!***KEYWORDS ERROR,XERROR PACKAGE
!***AUTHOR JONES, R. E., (SNLA)
!***PURPOSE Returns unit number(s) to which error messages are being
! sent.
!***DESCRIPTION
! Abstract
! XGETUA may be called to determine the unit number or numbers
! to which error messages are being sent.
! These unit numbers may have been set by a call to XSETUN,
! or a call to XSETUA, or may be a default value.
!
! Description of Parameters
! --Output--
! IUNIT - an array of one to five unit numbers, depending
! on the value of N. A value of zero refers to the
! default unit, as defined by the I8MACH machine
! constant routine. Only IUNIT(1),...,IUNIT(N) are
! defined by XGETUA. The values of IUNIT(N+1),...,
! IUNIT(5) are not defined (for N .LT. 5) or altered
! in any way by XGETUA.
! N - the number of units to which copies of the
! error messages are being sent. N will be in the
! range from 1 to 5.
!
! Latest revision --- 19 MAR 1980
! Written by Ron Jones, with SLATEC Common Math Library Subcommittee
!***REFERENCES JONES R.E., KAHANER D.K., "XERROR, THE SLATEC ERROR-
! HANDLING PACKAGE", SAND82-0800, SANDIA LABORATORIES,
! 1982.
!***ROUTINES CALLED J84SAVE
!***END PROLOGUE XGETUA
DIMENSION IUNITA(5)
!***FIRST EXECUTABLE STATEMENT XGETUA
N = J84SAVE(5,0,.FALSE.)
DO 30 I=1,N
INDEX = I+4
IF (I.EQ.1) INDEX = 3
IUNITA(I) = J84SAVE(INDEX,0,.FALSE.)
30 CONTINUE
RETURN
END
INTEGER FUNCTION I8MACH(I)
!***BEGIN PROLOGUE I8MACH
!***DATE WRITTEN 750101 (YYMMDD)
!***REVISION DATE 840405 (YYMMDD)
!***CATEGORY NO. R1
!***KEYWORDS MACHINE CONSTANTS
!***AUTHOR FOX, P. A., (BELL LABS)
! HALL, A. D., (BELL LABS)
! SCHRYER, N. L., (BELL LABS)
!***PURPOSE Returns integer machine dependent constants
!***DESCRIPTION
!
! This is the CMLIB version of I8MACH, the integer machine
! constants subroutine originally developed for the PORT library.
!
! I8MACH can be used to obtain machine-dependent parameters
! for the local machine environment. It is a function
! subroutine with one (input) argument, and can be called
! as follows, for example
!
! K = I8MACH(I)
!
! where I=1,...,16. The (output) value of K above is
! determined by the (input) value of I. The results for
! various values of I are discussed below.
!
! I/O unit numbers.
! I8MACH( 1) = the standard input unit.
! I8MACH( 2) = the standard output unit.
! I8MACH( 3) = the standard punch unit.
! I8MACH( 4) = the standard error message unit.
!
! Words.
! I8MACH( 5) = the number of bits per integer storage unit.
! I8MACH( 6) = the number of characters per integer storage unit.
!
! Integers.
! assume integers are represented in the S-digit, base-A form
!
! sign ( X(S-1)*A**(S-1) + ... + X(1)*A + X(0) )
!
! where 0 .LE. X(I) .LT. A for I=0,...,S-1.
! I8MACH( 7) = A, the base.
! I8MACH( 8) = S, the number of base-A digits.
! I8MACH( 9) = A**S - 1, the largest magnitude.
!