- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Is there a method to resize AN EXISTING dynamic array without trashing the existing contents? i.e. similar to "REDIM PRESERVE" in Visual Basic. The only way that I can think of is to copy the contenst into a temporary array of the same dimensions / size, deallocate the original array, allocate it again and then copy the contents of the tempoary array back. Seems somewhat ineligant!
링크가 복사됨
3 응답
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
No -- but CVF now supports ALLOCATABLE arguments (which is a feature from Fortran 2000 draft), so you can solve it more elegantly and generally:
Now you can reallocate any array in a single subroutine call.
Jugoslav
SUBROUTINE ReAlloc(A, n) REAL, ALLOCATABLE:: A(:) INTEGER:: n, nOld REAL, ALLOCATABLE:: Temp(:) nOld = SIZE(Temp) IF (nOld > n) RETURN ALLOCATE(Temp(nOld)) Temp=A DEALLOCATE(A) ALLOCATE(A(n)) A(1:nOld) = Temp END SUBROUTINE Realloc
Now you can reallocate any array in a single subroutine call.
Jugoslav
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Shouldn't it be nOld=SIZE(A), not
> nOld = SIZE(Temp)
Eddie
> nOld = SIZE(Temp)
Eddie
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Thanks - I arrived at almost the same solution but at least I know that I wasn't missing something. CJH
