! Program to show uninitialized partial memory access from using derived type that is sorted by a int16 component.
! I suspect there is not actually a uninitialized partial memory access, but rather the Intel Inspector is having
! a problem with the int16 variable.  Memory error goes away if the integer type of value is changed from int16 to int32.
program problem

use, intrinsic :: iso_fortran_env, only: int16, int32

    implicit none

integer, parameter :: value_kind = int16       ! generates uninitialized partial memory access error with Intel Inspector
!integer, parameter :: value_kind = int32       ! no memory error

type combo
    integer (kind=value_kind) :: value
    integer (kind=int32) :: original_order
end type combo

integer, parameter :: array_size = 5
type(combo), dimension(:), allocatable :: a, left_part
type(combo) :: temp
integer :: i

    allocate(a(array_size))

    do i = 1, array_size
        a(i)%value = int(array_size - i,value_kind)
        a(i)%original_order = i
    end do

    write (*,*) "Original Order"
    do i = 1, array_size
        write (*,*) a(i)%value,a(i)%original_order
    end do

    do i = 1, array_size/2+1
        temp = a(i)
        a(i) = (a(array_size-i+1))
        a(array_size-i+1) = temp
    end do

    write (*,*) "Reverse Order"
    do i = 1, array_size
        write (*,*) a(i)%value,a(i)%original_order
    end do

    deallocate(a)

end program problem
