Fortran 90中出现了一个奇怪的错误

时间:2016-01-28 13:22:22

标签: fortran fortran90

我正在Fortran中编写程序,我在程序中有这一行:

READ*,(10,*)((A(I,J),I=1,M),J=1,N)

我在编译器中遇到了这个错误:

*** '*' must be preceded with an operand
*** '(' found where not expected
*** Compilation abandoned

当我输入数字而不是*时,第一个错误就消失了

如何修复这些错误?

修改

这是我的完整代码:

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

这应该得到温度矩阵Celsius并打印Kelvin中的最小值,最大值,平均值和方差。

1 个答案:

答案 0 :(得分:0)

我会发布我的(和@ innoSPG)评论作为答案,所以可以勾选这个问题。

这一行

READ*,(10,*)((A(I,J),I=1,M),J=1,N)

包含一个简单的语法错误,*,之后不允许read并且编译器放弃。只需删除它们:

READ (10,*)((A(I,J),I=1,M),J=1,N)