# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
module irls
  use quantile_mod
  implicit none
  contains
  integer function l1 (res, weight)
    real, dimension (:) :: res, weight
    real :: rbar
    rbar = quantile( int( 0.5*size(res)), abs (res))
    ! median
    weight = 1. / sqrt( sqrt (1. + (res/rbar)**2))
    l1 = 0
  end function
  integer function cauchy (res, weight)
    real, dimension (:) :: res, weight
    real :: rbar
    rbar = quantile( int( 0.5*size(res)), abs (res))
    ! median
    weight = 1. / sqrt (1. + (res/rbar)**2)
    cauchy = 0
  end function
end module
