I need help understanding how this code flows. Back when I was in school, we had an assignment to create a 3-d truss structural analysis program. It became a colaborative effort as most of us had little programming experience. We came across this subroutine which I believe performs a Gauss elimination and back substitution. I am currently trying to teach myself how to program in Python and I'm attempting to translate the old Fortran code into Python 3.x. Here is the subroutine.
BGK is the structure stiffness matrix, Q is the applies loads, NDIS is the number of degrees of freedom and MB is the bandwidth of BGK. As I understand this, these four variables are passed to the subroutine and BGK and Q is passed back. I believe the code up to line 700 is the elimination portion of the routine and from 700 on is the back substitution. Please correct me if I'm wrong. How I understand the code is that it begins, increments N to 1 and divides the applied load in row 1 by the pivot value. It then checks to see if N-NDIS is non-zero. if it isn't it runs a do loop to 600 creating the vector F from BGK and dividing the rest of row 1 by the pivot value. The next do loop to 660 begins by performing another check. If the check is >= to 0 then it runs another do loop to 650 or breaks out of the do loop if the number is negative. Once the nested do loop to 650 finishes and the do loop to 660 completes, the routine returns to line 500 and increments N and the loops restart. The go to 500 line seems to function like a for statement. Lines 700 to 900 operate similar to the first part of the routine except it increments N by -1. Have I correctly interpreted the subroutine? I appreciate any help I can get.
Code:
SUBROUTINE BNDSOL(BGK,Q,NDIS,MB)
DIMENSION BGK(100,30),Q(100),F(30)
N=0
500 N=N+1
Q(N)=Q(N)/BGK(N,1)
IF(N-NDIS)550,700,550
550 DO 600 K=2,MB
F(K)=BGK(N,K)
600 BGK(N,K)=BGK(N,K)/BGK(N,1)
DO 660 L=2,MB
I=N+L-1
IF(NDIS-I)660,640,640
640 J=0
DO 650 K=L,MB
J=J+1
650 BGK(I,J)=BGK(I,J)-F(L)*BGK(N,K)
Q(I)=Q(I)-F(L)*Q(N)
660 CONTINUE
GO TO 500
700 N=N-1
IF(N)750,900,750
750 DO 800 K=2,MB
L=N+K-1
IF(NDIS-L)800,770,770
770 Q(N)=Q(N)-BGK(N,K)*Q(L)
800 CONTINUE
GO TO 700
900 RETURN
END
BGK is the structure stiffness matrix, Q is the applies loads, NDIS is the number of degrees of freedom and MB is the bandwidth of BGK. As I understand this, these four variables are passed to the subroutine and BGK and Q is passed back. I believe the code up to line 700 is the elimination portion of the routine and from 700 on is the back substitution. Please correct me if I'm wrong. How I understand the code is that it begins, increments N to 1 and divides the applied load in row 1 by the pivot value. It then checks to see if N-NDIS is non-zero. if it isn't it runs a do loop to 600 creating the vector F from BGK and dividing the rest of row 1 by the pivot value. The next do loop to 660 begins by performing another check. If the check is >= to 0 then it runs another do loop to 650 or breaks out of the do loop if the number is negative. Once the nested do loop to 650 finishes and the do loop to 660 completes, the routine returns to line 500 and increments N and the loops restart. The go to 500 line seems to function like a for statement. Lines 700 to 900 operate similar to the first part of the routine except it increments N by -1. Have I correctly interpreted the subroutine? I appreciate any help I can get.