!> @file euler.f90
!> @brief Universal Euler launcher — reads &control dim and dispatches.
!!
!! One command for every dimension: `euler <case.nml>`. Reads the declared
!! dimension via config_dim, then calls the matching driver. File-based only;
!! the cortex/attached mode lives on the `euler_1d`/`euler_2d` targets, not on
!! this universal launcher.
program euler
  use mpi_runtime, only: mpi_runtime_init, mpi_runtime_finalize, parallel_fatal
  use version_info, only: handle_version_flag
  use config_dim, only: read_dim
  use euler_driver, only: run_euler_1d
  use euler_driver_2d, only: run_euler_2d
  implicit none

  character(len=512) :: nml_file, message
  logical :: ok
  integer :: dim

  call handle_version_flag('euler')

  ! Usage check is pre-init (uniform across all images) so it can remain a
  ! plain `error stop` without orphaning ranks.
  if (command_argument_count() < 1) error stop 'usage: euler <input.nml>'

  call mpi_runtime_init()

  call get_command_argument(1, nml_file)

  call read_dim(trim(nml_file), dim, ok, message)
  if (.not. ok) call parallel_fatal(trim(message))

  select case (dim)
  case (1)
    call run_euler_1d(trim(nml_file), ok, message)
  case (2)
    call run_euler_2d(trim(nml_file), ok, message)
  case default
    call parallel_fatal('euler: dim=3 not yet supported (no euler_3d solver)')
  end select
  if (.not. ok) call parallel_fatal(trim(message))

  call mpi_runtime_finalize()

end program euler
