The distilled program
program tst
implicit none
!
integer, parameter :: k_wp = kind(1.d0)
type :: sta
integer :: n
real(k_wp),pointer :: a(:)
end type sta
type(sta), allocatable :: zd(:),zu(:)
!
allocate(zd(1))
zd(1)%n = 2
allocate(zd(1)%a(zd(1)%n))
!
allocate(zu(1))
zu(1)%n = 4
allocate(zu(1)%a(zu(1)%n))
!
zd(1)%a = (/ -4d0,-3d0 /)
zu(1)%a = (/ 1d0,2d0,3d0,4d0 /)
call sub(zd,zu)
deallocate(zd(1)%a, zu(1)%a)
deallocate(zd, zu)
contains
subroutine sub(zd,zu)
type(sta) :: zd(:),zu(:)
real(k_wp) :: z(zd(1)%n + zu(1)%n)
character(len = 20),save :: fmt='(1x,A6,1p,6D13.4)'
z = (/ zd(1)%a , zu(1)%a /)
write(*,fmt)' zd = ',zd(1)%a
write(*,fmt)' zu = ',zu(1)%a
write(*,fmt)' z = ',z
return
end subroutine sub
end program tst
produces the erroneous output
zd = -4.0000D+00 -3.0000D+00
zu = 1.0000D+00 2.0000D+00 3.0000D+00 4.0000D+00
z = 0.0000D+00 0.0000D+00 0.0000D+00 0.0000D+00 0.0000D+00 0.0000D+00
instead of the correct result
zd = -4.0000D+00 -3.0000D+00
zu = 1.0000D+00 2.0000D+00 3.0000D+00 4.0000D+00
z = -4.0000D+00 -3.0000D+00 1.0000D+00 2.0000D+00 3.0000D+00 4.0000D+00
The compiler default options were used (f95 tst.f90).