The following program P1 runs as expected, returning the output shown.
program p1
use iso_fortran_env
implicit none
real, allocatable :: a(:), temp(:)
print*, compiler_version()
print*
allocate(a(2))
a = [1.0,2.0]
print*, 'a after allocate and assignment'
print*, a
print*
allocate(temp(4))
temp(1:2) = a
temp(3) = 3.0
temp(4) = 4.0
print*, 'temp after allocate and assignment'
print*, temp
print*
call move_alloc(temp,a)
print*, 'after move_alloc'
print*, 'allocated(temp) = ', allocated(temp)
print*, 'allocated(a) = ', allocated(a)
print*
print*, 'a after move_alloc'
print*, a
end program p1
FTN95 v9.06.0
a after allocate and assignment
1.00000 2.00000
temp after allocate and assignment
1.00000 2.00000 3.00000 4.00000
after move_alloc
allocated(temp) = F
allocated(a) = T
a after move_alloc
1.00000 2.00000 3.00000 4.00000
The second program P2 below has the declaration of a and temp in a module, which is used by the main program, otherwise all other executable statements in P2 are the same as P1.
module data_mod
real, allocatable :: a(:), temp(:)
end module data_mod
program p2
use data_mod
use iso_fortran_env
implicit none
print*, compiler_version()
print*
allocate(a(2))
a = [1.0,2.0]
print*, 'a after allocate and assignment'
print*, a
print*
allocate(temp(4))
temp(1:2) = a
temp(3) = 3.0
temp(4) = 4.0
print*, 'temp after allocate and assignment'
print*, temp
print*
call move_alloc(temp,a) ! ### error 984
print*, 'after move_alloc'
print*, 'allocated(temp) = ', allocated(temp)
print*, 'allocated(a) = ', allocated(a)
print*
print*, 'a after move_alloc'
print*, a
end program p2
When compiled, the following error is generated error 984 - DATA_MOD cannot appear here as it has been used in a USE statement as a MODULE name
The error message does not seem to be sensible in the context of the code, and I cannot see anything wrong with the code.
Adding IMPLICIT NONE to the module changes the error message at the same line to error 174 - Unexpected '!' in expression
I recall that we discussed various ways of extending an array in a pervious post:
https://forums.silverfrost.com/Forum/Topic/4384&postdays=0&postorder=asc&highlight=movealloc&start=0
John's program from Wed Jan 31, 2024 no longer runs with the present 9.06 FTN - which is a change. error 84 - Name of END SUBROUTINE is not the same as the name of the matching SUBROUTINE ('END SUBROUTINE EXTEND_ALLOC_AUTO' instead of 'EXTEND_ALLOC_AUTO') Compilation or linking failed.