Fortranのsubroutine可変配列をパラメータとして
864 ワード
Fortranのsubroutine可変配列は、パラメータとしてインタフェースを表示する必要があります.たとえば、subroutineをmoduleに配置してインタフェースを生成することができます.次の方法は正しいです.
インタフェースが表示されない場合は、次のようなエラーがコンパイルされます.
コンパイルエラーが発生しました
module array_over2
contains
subroutine over2(abc)
real,intent(inout) :: abc(:)
abc = abc/2.
end subroutine over2
end module array_over2
program main
use array_over2
implicit none
real :: abc(3) = (/ 1.2 , 3.4 , 5.6/)
call over2(abc)
write(*,*) abc
end program
インタフェースが表示されない場合は、次のようなエラーがコンパイルされます.
subroutine over2(abc)
real,intent(inout) :: abc(:)
abc = abc/2.
end subroutine over2
program main
implicit none
real :: abc(3) = (/ 1.2 , 3.4 , 5.6/)
call over2(abc)
write(*,*) abc
end program
コンパイルエラーが発生しました
$ gfortran 1.f90
1.f90:17:10:
call over2(abc)
1
Error: Explicit interface required for ‘over2’ at (1): assumed-shape argument