function get_compiler_id(compiler) result(id)
character(len=*), intent(in) :: compiler
integer(kind=compiler_enum) :: id
character(len=:), allocatable :: full_command, full_command_parts(:), command, output
integer :: stat, io
! Check whether we are dealing with an MPI compiler wrapper first
if (check_compiler(compiler, "mpifort") &
& .or. check_compiler(compiler, "mpif90") &
& .or. check_compiler(compiler, "mpif77")) then
output = get_temp_filename()
call run(compiler//" -show > "//output//" 2>&1", &
& echo=.false., exitstat=stat)
if (stat == 0) then
open(file=output, newunit=io, iostat=stat)
if (stat == 0) call getline(io, full_command, stat)
close(io, iostat=stat)
! If we get a command from the wrapper, we will try to identify it
call split(full_command, full_command_parts, delimiters=' ')
if(size(full_command_parts) > 0)then
command = trim(full_command_parts(1))
endif
if (allocated(command)) then
id = get_id(command)
if (id /= id_unknown) return
end if
end if
end if
id = get_id(compiler)
end function get_compiler_id