dustem_fit_sed.pro 1.49 KB
FUNCTION dustem_fit_sed,tol=tol,Nitermax=Nitermax,func_name=func_name,cf_min=cf_min

disp_str='====================================================='

use_tol=1.e-14   ;Default tolerance value
use_Nitermax=100 ;Default maximum number of iterations
use_func_name='grad_desert' ;FUNCTION NAME TO COMPUTE chi2
use_cfmin=1.e-5

;NUMBER OF FREE PARAMETERS
Nparam=n_elements(*!param_desc)
;INITIALIZE THE OUTPUT PARAMETERS
p_min=fltarr(Nparam)+1.

IF keyword_set(tol) THEN use_tol=tol
IF keyword_set(Nitermax) THEN use_Nitermax=Nitermax
IF keyword_set(func_name) THEN use_func_name=func_name
IF keyword_set(cf_min) THEN use_cfmin=cf_min

;INITIALIZATION OF THE CONJ GRADIENT
print,'Initialization'+disp_str
minf_conj_grad, p_min, f_min, conv_factor, FUNC_NAME=use_func_name,/INITIALIZE,/use_deriv,tolerance=use_tol

message,'pmin:',/info
print,p_min*(*!init_value)
message,'conv_factor='+strtrim(conv_factor,2)+' f_min='+strtrim(f_min,2),/info

;LOOP
iter=1L
WHILE (conv_factor GT use_cfmin AND f_min GT tol AND iter LE use_Nitermax) DO BEGIN
  minf_conj_grad, p_min, f_min, conv_factor, FUNC_NAME=use_func_name, /use_deriv,tolerance=use_tol
  message,'Iter='+strtrim(iter,2)+disp_str,/info
  message,'pmin=',/info
  print,p_min*(*!init_value)
  message,'conv_factor='+strtrim(conv_factor,2)+' f_min='+strtrim(f_min,2),/info
  iter=iter+1
ENDWHILE

;PRINT RESULTS
print,'<°)))><  <°)))><  <°)))><  <°)))><  <°)))><  <°)))><  <°)))><  <°)))><'
print, 'Final parameters : ', p_min*(*!init_value)

RETURN, p_min*(*!init_value)

END