- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I am new to FORTRAN; I am just trying to learn the basics and so I am trying to implement a simple tridiagonal solver. The tridiagonal solver is a subroutine, and I am just trying to define the input (2 integers, and four 1 dimensional, size 8); this would've worked to do it this way with Python or MATLAB. I've tried to troubleshoot this; I sure there is something simple I am missing.
Here is the script that I call it from:
program TriSolver
print*, "This program solves a tri-diagonal matrix using the Thomas Algorithm"
IL=1
IU=8
CALL SY(IL,IU,[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],[-2.0,-2.0,-2.0,-2.0,-2.0,-2.0,-2.0,-2.0],[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],[-2.0,-2.0,4.0,-2.0,0.0,-5.0,3.0,-2.0])
end
Here is the subroutine:
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
! !
! SUBROUTINE SY SOLVES A TRIDIAGONAL SYSTEM OF !
! EQUATIONS FOLLOWING THE THOMAS ALGORITHM !
! !
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
SUBROUTINE SY(IL,IU,BB,DD,AA,CC)
IMPLICIT NONE
INTEGER, INTENT(IN) :: IL, IU
REAL, DIMENSION(IL:IU), INTENT(IN) :: AA,BB
REAL, DIMENSION(IL:IU), INTENT(INOUT) :: CC,DD
!...
!... IL = SUBSCRIPT OF FIRST EQUATION
!... IU = SUBSCRIPT OF LAST EQUATION
!... BB = COEFFICIENT BEHIND DIAGONAL
!... DD = COEFFICIENT ON DIAGONAL
!... AA = COEFFICIENT AHEAD OF DIAGONAL
!... CC = ELEMENT OF CONSTANT VECTOR
!...
!... ESTABLISH UPPER TRIANGULAR MATRIX
!...
INTEGER :: LP,I,J
REAL :: R
LP = IL + 1
DO I = LP,IU
R = BB(I)/DD(I-1)
DD(I) = DD(I) -R*AA(I-1)
CC(I) = CC(I) - R*CC(I-1)
END DO
!...
!... BACK SUBSTITUTION
!...
CC(IU) = CC(IU)/DD(IU)
DO I=LP, IU
J=IU - I + IL
CC(J) = (CC(J) - AA(J)*CC(J+1))/DD(J)
END DO
!...
!... SOLUTION STORED IN CC
!...
END SUBROUTINE
Here is the error message:
Severity Code Description Project File Line Suppression State
Error error #6638: An actual argument is an expression or constant; this is not valid since the associated dummy argument has the explicit INTENT(OUT) or INTENT(INOUT) attribute. C:\Users\William Lotts\source\repos\Tridiagonal Solver\Tridiagonal Solver\TriDia.f90 11
Thanks for any help!
-Seth
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The CC and DD arguments of SY are INTENT(INOUT), which means that SY is allowed to both read and write to the associated actual argument. You passed array constructors for these arguments, which are constants; constants cannot be written to.
A solution is to declare array variables in the main program, assign the array constructor to the variables, and pass the variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your help!

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page