subroutine tagged_result(unit, energy, gradient, sigma, hessian)
!DEC$ ATTRIBUTES DLLEXPORT :: tagged_result
integer, intent(in) :: unit
real(wp), intent(in), optional :: energy
real(wp), intent(in), optional :: gradient(:, :)
real(wp), intent(in), optional :: sigma(:, :)
real(wp), intent(in), optional :: hessian(:, :, :, :)
character(len=*), parameter :: tag_header = &
& '(a,t20,":",a,":",i0,":",*(i0:,","))'
if (present(energy)) then
write(unit, tag_header) "energy", "real", 0
write(unit, '(3es24.16)') energy
end if
if (present(gradient)) then
write(unit, tag_header) "gradient", "real", 2, shape(gradient)
write(unit, '(3es24.16)') gradient
end if
if (present(sigma)) then
write(unit, tag_header) "virial", "real", 2, shape(sigma)
write(unit, '(3es24.16)') sigma
end if
if (present(hessian)) then
write(unit, tag_header) "hessian", "real", 4, shape(hessian)
write(unit, '(3es24.16)') hessian
end if
end subroutine tagged_result