UPDATE:我修改後的代碼看起來是這樣的:Fortran子例程的輸入參數是否可以在子例程的主體中解除分配和分配?
program run_module_test
use module_test
implicit none
TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:)
call update(xyzArray)
write(6,*)'xyzArray',xyzArray
end program run_module_test
module module_test
implicit none
TYPE :: newXYZ
real(4) :: x, u
real(4) :: y, v
real(4) :: z, w
real(4),dimension(3) :: uvw
END TYPE
integer(4) :: shape = 3
contains
subroutine update(xyzArray)
integer(4) :: i
TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:)
allocate(xyzArray(shape))
do i = 1, shape
xyzArray(i)%x = 0
xyzArray(i)%y = 0
xyzArray(i)%z = 0
xyzArray(i)%u = 0
xyzArray(i)%v = 0
xyzArray(i)%w = 0
xyzArray(i)%uvw = (/0,0,0/)
end do
return
end subroutine update
end module module_test
當他們被編譯,它們產生類似的錯誤:
TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:)
1
Error: ALLOCATABLE attribute conflicts with DUMMY attribute at (1)
當我消除更新()子程序的說法,我收到了矛盾的錯誤:
TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:)
1
Error: Symbol at (1) is not a DUMMY variable
我是否已排除了有用建議中指出的錯誤來源?這可能是一個編譯器相關的錯誤(使用mpi90)?
~~~第一編輯~~~ 我有一個子程序,其輸入參數是用戶定義類型XYZ的數組。我希望取消分配xyzArray,並在子例程的主體中將其分配/修改爲不同的大小。我試圖通過changing array dimensions in fortran建議的方法,但是當我做到以下幾點:當我嘗試
Error: ALLOCATABLE attribute conflicts with DUMMY attribute at (1)
:
subroutine update(xyzArray, ...)
...
deallocate(xyzArray(myshape))
allocate(xyzArray(newshape))
我收到錯誤消息
subroutine update(xyzArray, ...)
...
TYPE (XYZ), allocatable :: xyzArray(:)
我收到一條錯誤消息:
Error: Expression in DEALLOCATE statement at (1) must be ALLOCATABLE or a POINTER
Error: Expression in ALLOCATE statement at (1) must be ALLOCATABLE or a POINTER
我需要做什麼來改變子程序中數組的大小?