-1

I have a program that gets a Matrix of Celsius Temperature and Prints The Minimum, Maximum, Averange and Variance of Those Temperatures On The Screen. This Is The Code:

PROGRAM MATRIS
IMPLICIT NONE
INTEGER::M,N,I,J
REAL::AVG,VAR,LEAST,LARGEST,SUM,MIN_A,MAX_A
REAL,DIMENSION(:,:),ALLOCATABLE::A,B
PRINT*,"PLEASE ENTER column,raw"
READ*,M,N
ALLOCATE(A(M,N),B(M,N))
OPEN(10,FILE="C:/TEMP.txt",STATUS="OLD",ACTION="READ")
OPEN(10,FILE="C:/output.txt",STATUS="REPLACE",ACTION="WRITE")
OPEN(10,FILE="C:/output_statistic",STATUS="REPLACE",ACTION="WRITE")
READ*,(10,*)((A(I,J),I=1,M),J=1,N)
DO J=1,N
    DO I=1,M
       B(I,J)=A(I,J)+273.15
    END DO
END DO
WRITE(20,'(2(F6.2,2X))')((A(I,J),I=1,M),J=1,N)
REAL::R1,R2,R3,R4,R5
PRINT*,"PLEASE ENTER YOUR NUMBER"
READ*,R1,R2,R3,R4,R5
CALL REVERSE(R1,R2,R3,R4,R5)
PRINT*,R2,R3,R4,R5
CONTAINS
      SUBROUTINE REVERSE(A,D,E,F,G)
      IMPLICIT NONE
      REAL,INTENT(IN)::A
      REAL,INTENT(OUT)::D,E,F,G
SUM=0.
VAR=0.
LARGEST=0.
LEAST=10000.
DO I=1,N
    READ*,A
    SUM=SUM+A                                       
    MAX_A=MAX(LARGEST,A)
    LARGEST=MAX_A
    MIN_A=MIN(LEAST,A)
    LEAST=MIN_A
    VAR=SQRT(VAR+(A-AVG)**2)
    AVG=SUM/N
    D=MAX_A
    E=MIN_A
    F=VAR
    G=AVG
END DO
RETURN
PRINT*,D/E/F/G
END SUBROUTINE REVERSE
END PROGRAM MATRIS

At Line 19 I get this error: REAL cannot appear after executable statements

And Line 34 I get this Error: A appears on the left hand side of an assignment yet has the INTENT(IN) attribute

How Can I fix These. And Can You See If There Are Other Errors In My Program? I'm new in Fortran And I need your help. Thanks

3
  • Other than the wording of the message, your first problem is that of stackoverflow.com/q/33584501. The second message is slightly unhelpful, but read*,A is presumably what is meant as line 34 (this is a variable definition context which is banned for something with the intent(in) attribute, but it isn't involving the LHS of an assignment). Commented Jan 28, 2016 at 15:01
  • @francescalus Can you help me to fix the errors? I can't get what you mean Commented Jan 28, 2016 at 15:06
  • It's very tricky to answer, as you have two totally different problems. Also, a general "what errors are in this code?" is perhaps not a good fit here as a question. If you can read that linked question and apply the answer to your code that will at least get rid of the line 19 problem. When it does, you can refocus your question on the other one. Commented Jan 28, 2016 at 15:10

1 Answer 1

1

You have to declare all your variables at the beginning of a program or subroutine.

You will have to move your

REAL::R1,R2,R3,R4,R5

up to where you declare the other variables.

As for the second question: You have declared A to be INTENT(IN) in your subroutine. That means that the subroutine can't change its value.

But the READ*,A would do just that. So the compiler tells you that this is inconsistent and can't be compiled.

But please, do me and yourself a favour and get a good book about Fortran programming. Or do some online Fortran courses, if you find some. There are many more errors in your code, and if you try to plough ahead this way, your code will never do what you want it to do.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.