0

単純な Fortran コードを使用していますが、解決策が見つからないエラーが発生します。これを修正する方法を知っている人はいますか?

subroutine sort(A,A_done,N,P)
! Sort a real array by algebraically increasing value and return the permutation that 
! rearranges the array
  implicit none

  Integer N, TEMP1, K, L, P(N), TEMP2
  real(8), dimension(:) ::  A_done
  real(8), dimension(:) ::  A

  DO K=1, N-1
    DO L=K+1, N
        if A(K)>A(L)
                TEMP1=A(K)
            TEMP2=P(K)
            A(K)=A(L)
                P(K)=P(L)
        A(L)=TEMP1
            P(L)=TEMP2
    end if

    END DO
  END DO
  A_done=A
  RETURN
  END

gfortran -Wall -Werror -fbounds-check -w -L -lm -o シミュレーション readinput.for nooutfile.for mean.for covariance.for correlation.for rperm.for simmain.for sort.for ファイル内 sort.for:13

     if A(K)>A(L)
    1

Error: Unclassifiable statement at (1) ファイル sort.for:20

    end if
      1

Error: Expecting END DO statement at (1) make: * [Simulation] Error 1

助けてくれてありがとう

4

1 に答える 1

1

かっこのペアと「then」を忘れました。

if A(K)>A(L)入力する必要がありますif (A(K)>A(L)) then

それ以外に、コードには複数の問題があります。

  1. atTEMP1=A(K)および同様の式では、real(8) 値を整数変数に渡します。
  2. 変数が何をするのか理解Pできません (説明していただけますか?) が、real(8) と整数も混在しています。
  3. サブルーチンで配列の次元を指定する必要があります。(モジュールを使ってそうしない方法もあると思います)
  4. A を変更してから A_done にコピーすることに注意してください。なぜそうするのですか?元の値が失われ、より多くのメモリが消費されます。

私はいくつかの修正を加えましたが、それは残しておきたいと思うかもしれません。このコードは正常にコンパイルおよび実行されます。

Program test

    implicit none
    integer N
    real(8), allocatable :: A(:), A_done(:), P(:)

    N=5
    Allocate (A(N), A_done(N), P(N))

    A=(/5,3,6,1,9/)
    call sort(A, A_done, N, P)

    Write (*,*) A_done

End

subroutine sort(A,A_done,N,P)
! Sort a real array by algebraically increasing value and return the permutation that 
! rearranges the array
    implicit none

    Integer N, K, L
    real(8), dimension(N) ::  A, A_done, P
    real(8) :: TEMP1, TEMP2

    DO K=1, N-1
            DO L=K+1, N
                    if (A(K)>A(L)) then
                            TEMP1=A(K)
                            TEMP2=P(K)

                            A(K)=A(L)
                            P(K)=P(L)

                            A(L)=TEMP1
                            P(L)=TEMP2
                    end if
            END DO
    END DO
    A_done=A
    RETURN
END 
于 2013-04-07T13:09:55.330 に答える