/* 
   Attempts to pick a smooth value for a point, according to the
   algorithm implented for "smooth" markers in Soas. See DOI:
   10.1016/j.bioelechem.2009.02.010

   Warning: be wary of this function as it will return a correct
   value only for rather noisy data !
 */
static VALUE function_smooth_pick(int argc, VALUE *argv, VALUE self)
{
  long len = function_sanity_check(self);
  const double *x = Dvector_Data_for_Read(get_x_vector(self),NULL);
  const double *y = Dvector_Data_for_Read(get_y_vector(self),NULL);
  long idx;
  long range;
  switch(argc) {
  case 2:
    range = NUM2LONG(argv[1]);
    break;
  case 1:
    range = len > 500 ? 50 : len/10;
    break;
  default:
    rb_raise(rb_eArgError, "smooth_a=t should have 1 or 2 parameters");
  }
  idx = NUM2LONG(argv[0]);
  if(idx < 0)
    idx = len + idx;
  return rb_float_new(smooth_pick(x,y,len,idx,range));
}