Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

fortran - Unexpected data declaration statement

I'm writing a code for LU decomposition and I don't know how to fix the "unexpected data declaration statement" pointed at line 8 (where I'm declaring an array. See the code fragment). Why is it unexpected?

!Decomposi??o LU
!-----------------------------------------------------------
      PROGRAM LUdecomp
      IMPLICIT INTEGER (I-K,N), REAL (A-H, L-M,O-Z)
      INTEGER, PARAMETER :: N=3
      REAL, DIMENSION (N,N) :: A,L,U    
      A = reshape((/3.,1.,4.,4.,2.,0.,3.,2.,3./),(/3,3/))   !exemplo do Bortoli*******
      REAL, DIMENSION(3) :: B=(/9.,3.,-2./),Z,X     
      OPEN(1,file = 'LUFACTOR.out')
!
!          FORALL (I = 1:N, J = 1:N) A(I,J) = 1.0/REAL(I+J-1)
!-------Fazendo a fatora??o A = LU-----------------------------
        CALL LU(N, A, L, U)
        DO I=1,N
           WRITE(*,10)(L(I,J), J=1,N), (U(I,J), J=1,N)
        END DO
   10   FORMAT(3(F8.4), 7x, 3(F8.4))
!
question from:https://stackoverflow.com/questions/65943476/syntax-error-in-read-statement-in-fortran-while-reading-array

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This statement

  REAL, DIMENSION(3) :: B=(/9.,3.,-2./),Z,X     

is in the wrong place. In a Fortran program-unit (program, subroutine, function) -- certainly one without the new ASSOCIATE and BLOCK constructs -- all declarations have to precede all executable statements.

Move the misplaced statement ahead of the first executable statement.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...