module config_m

  use jumble, only: pi

  implicit none

  real, protected:: min_amp = 0.001
  ! minimum amplitude of ssh, between extremum and outermost contour,
  ! in m

  integer, protected:: max_radius(2) = [20, 20]
  ! maximum radius of an eddy in number of grid points. Beware: run
  ! time is roughly proportional to product(max_radius). If periodic
  ! then max_radius(1) must be < nlon / 4.

  real, protected, save:: min_area ! minimum area of an outermost contour, in m2

  private pi

contains

  subroutine config(leave_trace)

    use, intrinsic:: ISO_FORTRAN_ENV

    ! Libraries:
    use jumble, only: new_unit

    logical, intent(in):: leave_trace

    ! Local:

    integer unit

    real:: min_radius = 25.
    ! minimum radius of the equal-area disk for an outermost contour, in km

    namelist /config_nml/ min_amp, max_radius, min_radius

    !----------------------------------------------------------------------

    print *, "config: Enter config_nml:"
    read(unit = *, nml = config_nml)

    if (leave_trace) then
       call new_unit(unit)
       open(unit, file = "used_config_nml.txt", status = "replace", &
            action = "write")
       write(unit, nml = config_nml)
       close(unit)
    end if

    min_area = pi * (min_radius * 1e3)**2

  end subroutine config

end module config_m
