!> @file euler_driver.f90
!> @brief 1D Euler file-based solve driver (extracted from app/euler_1d).
!!
!! Wraps the solver_session lifecycle for a namelist-driven 1D run. Assumes the
!! MPI runtime is already initialized by the caller. The cortex/attached mode is
!! deliberately NOT here — it stays in app/euler_1d.f90, which shares the
!! dim-aware cortex_run_attached with app/euler_2d.f90 (IPC is not 1D-only;
!! only the universal euler launcher omits attached mode).
module euler_driver
  use solver_session, only: solver_session_t, solver_session_create, &
                            solver_session_load_namelist, solver_session_initialize, &
                            solver_session_run_to_end, solver_session_write_result, &
                            solver_session_destroy, solver_status_ok
  implicit none
  private
  public :: run_euler_1d

contains

  !> Run a 1D Euler case from `nml_file`. MPI must already be initialized.
  subroutine run_euler_1d(nml_file, ok, message)
    character(len=*), intent(in) :: nml_file
    logical, intent(out) :: ok
    character(len=*), intent(out) :: message

    type(solver_session_t) :: session
    integer :: status

    ok = .false.
    message = ''

    call solver_session_create(session)
    call solver_session_load_namelist(session, trim(nml_file), status, message)
    if (status == solver_status_ok) call solver_session_initialize(session, status, message)
    if (status == solver_status_ok) call solver_session_run_to_end(session, status, message)
    if (status == solver_status_ok) call solver_session_write_result(session, status=status, message=message)
    ok = (status == solver_status_ok)
    call solver_session_destroy(session)
  end subroutine run_euler_1d

end module euler_driver
