;Adapt a model function meant for MPFIT to be used by LMFIT. ;The primary two differences are ; 1) LMFIT can't pass any extra parameters. These are stuffed into a common block ; 2) LMFIT requires derivatives. MPFIT functions do not normally calculate derivatives. ; This function calculates numerical derivatives for the function. function lmfitfun_adapt_function,x,a common lm_fit_adapt,function_name,args f=call_function(function_name,x,a,_extra=args) for i=0,n_elements(a)-1 do begin ap=a if abs(ap[i]) lt 1e-6 then ap[i]+=0.01e-6 else ap[i]*=1.001 this_F=call_function(function_name,x,ap,_extra=args) this_dFda=(this_F-f)/(ap[i]-a[i]) if n_elements(dFda) eq 0 then dFda=this_dFda else dFda=[[dFda],[this_dFda]] end return,[[f], [dFda]] end