Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help calling in function

Status
Not open for further replies.

jecstir2112

Instructor
Mar 25, 2010
3
US
Hey, Im trying to call the function into the matrix in order to multiply it by another matrices. I am having trouble with the reals and basics. I have the formats down ( i think )....


PROGRAM MATRIXMAKER
integer n, W, icount
real(2) Sig_tr, Sig_a, Lambda_tr, D, dx, S_o
real(2), allocatable :: A:),:), B:)), Y:),:), Z:))

write(*,*) 'Input the number of nodes (n)'
read(*,*) n
write(*,*) 'Input the length of the slab(W)'
read(*,*) W

Sig_tr = 0.0362;
Sig_a = 0.1532;
S_o = 10e8;
Lambda_tr = 1/Sig_tr ;
D = Lambda_tr/3;
dx = W / (n-1);


allocate(A(n-1,n-1))
allocate(B(n-1))
allocate(Z(n-1))
allocate(Y(n,n))
Y = 0
Z = 0
Y(1,1) = ((D/dx)+(Sig_a*dx/2));
Y(1,2) = -D/dx;
Z(1) = S_o/2;

do icount = 2,n-1
Y(icount,icount) = (2*D)/dx+Sig_a*dx;
Y(icount,icount+1) = -D/dx;
Y(icount,icount-1) = -D/dx;
Z(icount) = 0;
enddo

call FINDInv(matrix, inverse, n, errorflag)


END PROGRAM MATRIXMAKER


SUBROUTINE FINDInv(matrix, inverse, n, errorflag)
IMPLICIT NONE
!Declarations

INTEGER, INTENT(IN) :: n
INTEGER, INTENT(OUT) :: errorflag !Return error status. -1 for error, 0 for normal
REAL, INTENT(IN), DIMENSION(n,n) :: matrix !Input matrix
REAL, INTENT(OUT), DIMENSION(n,n) :: inverse !Inverted matrix

LOGICAL :: FLAG = .TRUE.
INTEGER :: i, j, k
REAL :: m
REAL, DIMENSION(n,2*n) :: augmatrix !augmented matrix


!Augment input matrix with an identity matrix
DO i = 1, n
DO j = 1, 2*n
IF (j <= n ) THEN
augmatrix(i,j) = matrix(i,j)
ELSE IF ((i+n) == j) THEN
augmatrix(i,j) = 1
Else
augmatrix(i,j) = 0
ENDIF
END DO
END DO

!Reduce augmented matrix to upper traingular form
DO k =1, n-1
IF (augmatrix(k,k) == 0) THEN
FLAG = .FALSE.
DO i = k+1, n
IF (augmatrix(i,k) /= 0) THEN
DO j = 1,2*n
augmatrix(k,j) = augmatrix(k,j)+augmatrix(i,j)
END DO
FLAG = .TRUE.
EXIT
ENDIF
IF (FLAG .EQV. .FALSE.) THEN
PRINT*, "Matrix is non - invertible"
inverse = 0
errorflag = -1
return

ENDIF
END DO
ENDIF
DO j = k+1, n
m = augmatrix(j,k)/augmatrix(k,k)
DO i = k, 2*n
augmatrix(j,i) = augmatrix(j,i) - m*augmatrix(k,i)
END DO
END DO
END DO

!Test for invertibility
DO i = 1, n
IF (augmatrix(i,i) == 0) THEN
PRINT*, "Matrix is non - invertible"
inverse = 0
errorflag = -1
return
ENDIF
END DO


!Make diagonal elements as 1
DO i = 1 , n
m = augmatrix(i,i)
DO j = i , (2 * n)
augmatrix(i,j) = (augmatrix(i,j) / m)
END DO
END DO

!Reduced right side half of augmented matrix to identity matrix
DO k = n-1, 1, -1
DO i =1, k
m = augmatrix(i,k+1)
DO j = k, (2*n)
augmatrix(i,j) = augmatrix(i,j) -augmatrix(k+1,j) * m
END DO
END DO
END DO

!store answer
DO i =1, n
DO j = 1, n
inverse(i,j) = augmatrix(i,j+n)
END DO
END DO
errorflag = 0

END SUBROUTINE FINDINV

 
1) Fortran arrays begin at 1: not 0 so your allocates should be allocate(A(n,n)) not n-1

2) Parameter declarations for arrays should be
REAL, INTENT(IN), DIMENSION:),:) :: matrix !Input matrix

Try that first. If it still doesn't work, tell us what the compiler/linker is moaning about.
 
Error 4 SUBROUTINE 'FINDINV' called with argument no 1 as a INTEGER(KIND=3) when a REAL(KIND=1) was expected (from the main program) LINK
 
You need to declare error flag as an integer otherwise it takes it as a real. Also, I think this is what you meant

call findinv (a, y, n, errorflag)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top