fortran - Can An Allocatable Intent(inout) Argument Be Optional? -
i have problem trying define subroutine, argument contains allocatable, optional, intent(inout) variable shown below. code compiles fine, runtime error of "segmentation fault - invalid memory reference".
subroutine test_routine.f90
subroutine test_routine(a,b) implicit none real,allocatable,intent(in) :: a(:,:) real,allocatable,optional,intent(inout) :: b(:,:) b = b(:,:) = 1 end subroutine
this subroutine packed in module, , called in main.
module test_module.f90
module test_module implicit none interface test_routine module procedure test_routine end interface end module test_module
main test_main.f90
program main use test_module implicit none real,allocatable :: a(:,:),b(:,:) allocate(a(6,6)) allocate(b(6,6)) a(:,:) = 0 call test_routine(a,b) ! works fine call test_routine(a) ! doesn't work! end program main
then tried assign variable op_b, make b, doesn't exist if main routine doesn't pass in. following code still doesn't work.
subroutine test_routine(a,b) implicit none real,allocatable,intent(in) :: a(:,:) real,allocatable,optional,intent(inout) :: b(:,:) real,allocatable :: op_b(:,:) if(.not. present(b)) allocate(op_b(size(a,1),size(a,2))) b = op_b end if b = b(:,:) = 1 end subroutine
by way, tried using fixed size array, still doesn't help. wonder if it's impossible such things?
dummy arguments can optional, allocatable , intent(inout).
but not permitted define or reference optional dummy argument, bar passing present or associating optional argument. if 'b' not present, cannot execute 'b = a'.
Comments
Post a Comment