# Error in Fortran: attempt to call a routine with argument number four as a real (kind=1) when a procedure was required

I have never done programming in my life and this is my very first code for a uni assignment, I get no errors in the compiling stage but myh program does not run saying that I have the error in the title, guess the problem is when I call the subroutine. Can anyone help me? It is my first code and it is really frustrating. Thank you.

``````!NUMERICAL COMPUTATION OF INCOMPRESSIBLE COUETTE FLOW USING FINITE DIFFERENCE METHOD

!IMPLICIT APPROACH

!MODEL EQUATION
!PARTIAL(U)/PARTIAL(T)=1/RE*(PARTIAL(U) SQUARE/PARTIAL(Y) SQUARE)

!DEFINE VARIABLES

IMPLICIT NONE

!VELOCITY U AT TIME T, VELOCITY UNEW AT TIME T+1, TIME T
!MAXIMUM 1000 POINTS

REAL V(1000)
REAL VNEW(1000)
REAL T

!GRID SPACING DY, GRID POINTS N+1
REAL DY
INTEGER N

!TIME STEP

REAL DT

!FLOW REYNOLDS NUMBER IN THE MODEL EQUATION

REAL ALPHA

!TOTAL SIMULATION TIME - LOOP NUMBER

INTEGER REP, I, J

!COEFFICIENTS IN LINEAR EQUATION MATRIX, SOURCE TERM K, DIAGONAL B, NON-DIAGONAL A

REAL S(1000), B, A

!INITIALIZATION OF DATA

DATA ALPHA/5000.0/
DATA N/100/
DATA REP/3000/

!CALCULATION OF GRID SPACING

DY=1.0/N

!CALCULATION OF TIME STEP DELTA T, CAN BE LARGER THAN THAT IN AN EXPLICIT METHOD

DT=0.5*RE*DY*DY
DT=ALPHA*DY*DY

!INITIAL CONDITIONS OF VELOCITY PROFILE
!BOTTOM AND INNER POINTS

DO I=1,N
V(I)=0.0
ENDDO

!POINT AT MOVING PLATE

V(N+1)=1.0

!BOUNDARY CONDITIONS AT LOWER AND UPPER POINTS ON PLATE

V(1)=0.0
V(N+1)=1.0

!CALCULATION OF DIAGONAL B AND NON-DIAGONAL A IN LINEAR EQUATION MATRIX

B=1.0+DT/DY/DY/ALPHA
A=-(DT)/2.0/DY/DY/ALPHA

!INITIAL COMPUTATION TIME

T=0.0

!ENTER MAIN LOOP TO MARCH IN TIME DIRECTION

DO I=1,REP
!SIMULATION TIME INCREASE BY DELTA T EACH STEP

T=T+DT

!USE IMPLICIT METHOD TO UPDATE GRID POINT VALUES FOR ALL INTERNAL GRIDS ONLY
!TWO BOUNDARY GRID POINTS VALUES ARE CONSTANT WITHIN THE WHOLE SIMULATION

!CALCULATION OF SOURCE TERM IN LINEAR EQUATION

DO J=2,N
S(J)=(1.0-DT/DY/DY/ALPHA)*V(J)+DT/2.0/DY/DY/ALPHA*V(J+1)+V(J-1)
ENDDO

!INCLUDE BOUNDARY CONDITIONS FOR TWO POINTS NEAR BOUDNARY

S(2)=S(2)-A*V(1)
S(N)=S(N)-A*V(N+1)

!USE SOURCE TERM K, DIAGONAL B, NON-DIAGONAL A, ORDER OF MATRIX N, TO SOLVE LINEAR EQUATION TO GET UPDATED VELOCITY
!CHECK ON INTERNET HOW TO SOLVE THIS BECUASE THIS COMPILER
!DOES NOT SOLVE IT, SOLVE LINEAR EQUATIONS BY A LINEAR SOLVER, FIND AND DOWNLOAD THE MATH LIBRARY FOR THIS COMPILER

CALL SR1(A,B,N,S,VNEW)

!REPLACE OLD VELOCITY VALUES WITH NEW VALUES.
!SINCE UNEW IS FROM UNEW(1), UNEW(2)......., UNEW(N-1), WE SHOULD RE-ARRANGE NUMBERS AS FOLLOWS

DO J=1,N-1
V(J+1)=VNEW(J)
ENDDO

ENDDO

PRINT*,'HERE'

!OUTPUT VELOCITY PROFILES AT THE END OF COMPUTATION
!CREATE OUPUT FILE NAME

!WRITE GRID POINTS AND VELOCITY VALUES

DO I=1,N+1
WRITE(15,10) V(I),(I-1)*DY
10  FORMAT(2F12.3)
ENDDO
CLOSE(15)

!DISPLAY INFORMATION ON SCREEN
!WRITE(*,*) 'THE OUTPUT VELOCITY IS AFTER', ITER, '     TIME STEPS'

!TERMINATION OF COMPUTER PROGRAM

STOP

END

!!!!!!!!
!!!!!!!!!!!!
!!!!!!!!!

SUBROUTINE SR1(A,B,N,S,VNEW)
REAL DIAGM(N), DIAGU(N), DIAGL(N)
REAL SS(N)
DO J=1,N-1
SS(J)=S(J+1)
ENDDO

DO I=1,N
DIAGM(i)=B

!Sets main diagonal as B for every value of i

IF (I==0) then
DIAGU(I)=A
DIAGL(I)=0

! No lower diagonal coefficient when i = 0

ELSE IF (I==N) THEN
DIAGU(I)=0

! No upper diagonal coefficient when i = Num

DIAGL(I)=A
ELSE
DIAGU(I)=A

! For all other points there is an upper diagonal coefficient

DIAGL(I)=A

! For all other points there is a lower diagonal coefficient

ENDIF

ENDDO

!CALL STANDARD FORTRAN MATH LIBRARY TO SOLVE LINEAR EQUATION AND GET SOLUTION VECTOR X(N-1)

CALL SR2 (DIAGL,DIAGM,DIAGU,SS,VNEW,N-2)

RETURN
END SUBROUTINE

!!!!!!!!!!!!!!!
!!!!!!!!!!!
!!!!!!!!!!!

SUBROUTINE SR2 (A,B,C,D,Z,N)

!a - sub-diagonal (means it is the diagonal below the main diagonal)
!b - the main diagonal
!c - sup-diagonal (means it is the diagonal above the main diagonal)
!K - right part
!E - number of equations

INTEGER N
REAL A(N), B(N), C(N), D(N)
REAL CP(N), DP(N), Z(N)
REAL M
INTEGER I
DATA M/1/

!initialize c-prime and d-prime

CP(1) = C(1)/B(1)
DP(1) = D(1)/B(1)
!solve for vectors c-prime and d-prime

DO I=2,N
M=b(i)-CP(I-1)*(A(I))
CP(I)=C(I)/M
DP(I)=(D(I)-DP(I-1)*A(I))/M
ENDDO

!initialize UNEW

Z(N)=DP(N)

!solve for x from the vectors c-prime and d-prime

DO I=N-1, 1, -1
Z(I)=DP(I)-CP(I)*Z(I+1)
ENDDO

END SUBROUTINE
``````
• you reference `S(J+1)` without declaring `S` to be an array. – agentp Mar 30 '14 at 12:59
• @george That's surely expandable to an answer? – francescalus Mar 30 '14 at 13:26

As george says in a comment, the problem is with the subroutine `SR1`. So that this isn't just a CW-stealing-a-comment answer I'll also expand a bit.
The way things are structured `SR1` is a different scope from the main program. The `IMPLICIT NONE` in the main program doesn't apply to the subroutine, so `A`, `B`, `N`, `S` and `VNEW` are all implicitly typed. Apart from `N`,which is an integer, they are (scalar) reals.
The reference to `S(J+1)`, as george says, means that `S` is not only a scalar real, but also a function. Remember that `SR1` is a different scope and no information is passed from the caller to the callee about types, shapes, etc.. Further, that the dummy argument in `SR1` called `A` happens to be same name as the actual argument in the call doesn't mean that the callee "knows" things. Your call to `SR2` with the `VNEW` is also a problem for the same reason.
The question is tagged as "fortran77" so there isn't too much you can do to ensure there is a lot of checking going on, but there may well be compiler options and as you can use `IMPLICIT NONE` (not Fortran 77) that would detect your problems.
{"ft_lang_label":"__label__en","ft_lang_prob":0.58650005,"math_prob":0.91669136,"size":4402,"snap":"2019-51-2020-05","text_gpt3_token_len":1581,"char_repetition_ratio":0.11118691,"word_repetition_ratio":0.024242423,"special_character_ratio":0.3050886,"punctuation_ratio":0.1931097,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9963371,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-26T18:38:19Z\",\"WARC-Record-ID\":\"<urn:uuid:0b66d23c-7573-45c6-b514-01b87b57f48d>\",\"Content-Length\":\"145936\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bd053ed2-16df-4728-a3d8-d722bcdb68bf>\",\"WARC-Concurrent-To\":\"<urn:uuid:58b904b7-1bd9-4468-88d8-0ca261f58a98>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://stackoverflow.com/questions/22744193/error-in-fortran-attempt-to-call-a-routine-with-argument-number-four-as-a-real\",\"WARC-Payload-Digest\":\"sha1:VM5WE2ZI2HRGURQVOUVN6JKQMJSIRTNV\",\"WARC-Block-Digest\":\"sha1:MWWMZK4QCBR73KBPVL2MUY7OO7CQ7VXK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579251690095.81_warc_CC-MAIN-20200126165718-20200126195718-00146.warc.gz\"}"}