SpectraRust/synspec/extracted/lineqs.f
2026-03-19 14:05:33 +08:00

64 lines
1.6 KiB
Fortran

SUBROUTINE LINEQS(A,B,X,N,NR)
C =============================
C
C Solution of the linear system A*X=B
C by Gaussian elimination with partial pivoting
C
C Input: A - matrix of the linear system, with actual size (N x N),
C and maximum size (NR x NR)
C B - the rhs vector
C Output: X - solution vector
C Note that matrix A and vector B are destroyed here !
C
INCLUDE 'PARAMS.FOR'
DIMENSION A(NR,NR),B(NR),X(NR),D(MLEVEL)
DIMENSION IP(MLEVEL)
DO 70 I=1,N
DO 10 J=1,N
10 D(J)=A(J,I)
IM1=I-1
IF(IM1.LT.1) GO TO 40
DO 30 J=1,IM1
IT=IP(J)
A(J,I)=D(IT)
D(IT)=D(J)
JP1=J+1
DO 20 K=JP1,N
20 D(K)=D(K)-A(K,J)*A(J,I)
30 CONTINUE
40 AM=ABS(D(I))
IP(I)=I
DO 50 K=I,N
IF(AM.GE.ABS(D(K))) GO TO 50
IP(I)=K
AM=ABS(D(K))
50 CONTINUE
IT=IP(I)
A(I,I)=D(IT)
D(IT)=D(I)
IP1=I+1
IF(IP1.GT.N) GO TO 80
DO 60 K=IP1,N
60 A(K,I)=D(K)/A(I,I)
70 CONTINUE
80 DO 100 I=1,N
IT=IP(I)
X(I)=B(IT)
B(IT)=B(I)
IP1=I+1
IF(IP1.GT.N) GO TO 110
DO 90 J=IP1,N
90 B(J)=B(J)-A(J,I)*X(I)
100 CONTINUE
110 DO 140 I=1,N
K=N-I+1
SUM=0.
KP1=K+1
IF(KP1.GT.N) GO TO 130
DO 120 J=KP1,N
120 SUM=SUM+A(K,J)*X(J)
130 X(K)=(X(K)-SUM)/A(K,K)
140 CONTINUE
RETURN
END