How to write using subroutine?
program main
implicit none
! compile : ifort /assume:realloc_lhs main.f90
integer,allocatable :: a(:), b(..)
integer :: val = 20
integer :: pos = 2
integer :: i,j
a = [a,[10, 20, 40, 50]]
write(*,* ) “a array:”, a,size(a)
!----------------------------------
do i = 1, size(a)
if (i /= pos .and. a(i) /= val) then
!write(*, *) a(i)
b=[b,a(i)]
end if
end do
!------------------------------------
write(*,* ) “b array:”, b
end program main
this program is working , but if I use subroutine , do not work
program main
implicit none
integer,allocatable :: a(:),b(:)
integer :: val = 20
integer :: pos = 2
integer :: i,j
a = [a,[10, 20, 40, 50]]
write(*,* ) “a dizisi:”, a,size(a)
call extract(a,b,val,pos)
write(*,* ) “b dizisi:”, b
end program main
subroutine extract(a,b,val,pos)
implicit none
integer,allocatable :: a(:),b(..)
integer::val,pos
integer::i
write(*,*) a
do i = 1, size(a)
if (i /= pos .and. a(i) /= val) then
write(*,* ) a(i)
b=[b,a(i)]
end if
end do
end subroutine extract
Create TopicClose