function uly_ssp_init, cmp, WAVERANGE=lamrange, VELSCALE=velscale, QUIET=quiet
compile_opt idl2
on_error, 2
init_data = *cmp.init_data
template_grid = uly_ssp_read(init_data.model,$
TEMPLATE_GRID=*init_data.template_grid, $
WAVERANGE=lamrange, VELSCALE=velscale, $
LSF=*init_data.lsf_file, $
QUIET=quiet)
if size(template_grid, /TYPE) ne 8 then begin
str=''
if size(init_data.model, /TYPE) eq 7 then str = '('+ init_data.model[0]+') '
message, 'Could not read SSP '+str, /INFO
return, cmp
endif
*init_data.template_grid = template_grid
s1 = size(*template_grid.data)
s4 = size(*template_grid.d2t)
if (s1[0] gt 4) then begin
message, 'Model grid has invalid dimensions', /INFO
cmp.sampling = -1
return, cmp
endif
if not array_equal(s1,s4) then begin
message,$
'The 2nd deriv. of age and templates must have the same size/type' , /INF
cmp.sampling = -1
return, cmp
endif
agemin = min(*template_grid.o_age,max=agemax)
metmin = min(*template_grid.o_metal,max=metmax)
if size(*template_grid.data, /N_DIM) eq 4 then begin
inpmgfe = *template_grid.o_mgfe
(*cmp.para)[2].name = 'Mg/Fe'
(*cmp.para)[2].unit = 'dex'
endif else inpmgfe = [0.,0.]
mgfemin=min(inpmgfe,max=mgfemax)
if total((*cmp.para)[0].limits ne [0d,0d]) eq 0 then $
(*cmp.para)[0].limits = [agemin,agemax] $
else if $
(*cmp.para)[0].limits[0] lt agemin or (*cmp.para)[0].limits[1] gt agemax $
then begin
message, /INFO, $
'The required AGE limits (' + string([agemin,agemax],FOR='(a,1h,,a)')+ $
') are out of the model bounds (' + $
string((*cmp.para)[0].limits,FOR='(a,1h,,a)') + ')'
cmp.sampling = -1
return, cmp
endif
if total((*cmp.para)[1].limits ne [0d,0d]) eq 0 then $
(*cmp.para)[1].limits = [metmin, metmax] $
else if $
(*cmp.para)[1].limits[0] lt metmin or (*cmp.para)[1].limits[1] gt metmax $
then begin
message, /INFO, $
'The required MET limits ('+strtrim((*cmp.para)[1].limits[0],2)+','+strtrim((*cmp.para)[1].limits[1],2)+') are out of the model bounds ('+strtrim(metmin,2)+','+strtrim(metmax,2)+')'
cmp.sampling = -1
return, cmp
endif
if total((*cmp.para)[2].limits ne [0d,0d]) eq 0 then $
(*cmp.para)[2].limits = [mgfemin-0.1, mgfemax+0.3]
cmp.eval_fun = 'SSP'
if ptr_valid(cmp.eval_data) then *cmp.eval_data = template_grid $
else cmp.eval_data = ptr_new(template_grid)
cmp.npix = (size(*template_grid.data,/DIM))[0]
cmp.start = double(template_grid.start)
cmp.step = double(template_grid.step)
cmp.sampling = fix(template_grid.sampling)
if n_elements(*template_grid.goodpix) gt 0 then begin
if ptr_valid(cmp.mask) then *cmp.mask = bytarr(cmp.npix) $
else cmp.mask = ptr_new(bytarr(cmp.npix))
(*cmp.mask)[*template_grid.goodpix] = 1
endif
return, cmp
end
FUNCTION uly_ssp, MODEL_FILE=model_file, DATA=template_grid, $
LSF=lsf_file, $
AL=a_limits, ZL=z_limits, MGFEL=mg_limits, $
AG=a_guess, ZG=z_guess, MGFEG=mg_guess, $
NAME=name, FIXPAR=fixpar, WL=lim_weight
compile_opt idl2
on_error, 2
common uly_path, uly_root
if n_elements(model_file) eq 0 then begin
if n_elements(template_grid) gt 0 then modelf = template_grid.title $
else modelf = uly_root+'/models/PHR_Elodie31.fits'
endif else modelf = model_file
if n_elements(a_guess) eq 0 then a_guess = 8000
if n_elements(z_guess) eq 0 then z_guess = -0.4
if n_elements(mgfe_guess) eq 0 then mgfe_guess = 0.0
s5 = size(a_limits)
if s5[0] gt 0 then $
if not s5[0] eq 2 then $
message, 'The age limits have to be of the type arr(2)'
s6 = size(z_limits)
if s6[0] gt 0 then $
if not s6[0] eq 2 then $
message, 'The metallicity limits have to be of the type arr(2)'
s7 = size(lim_weight)
if s7[0] gt 0 then $
if not s7[0] eq 2 then $
message, 'The weight limits have to be of the type arr(2)'
init_data = {model:modelf, template_grid:ptr_new(template_grid), $
lsf_file:ptr_new(lsf_file)}
descr = ''
if n_elements(modelf) eq 1 then descr += 'model:' + modelf + ' '
if n_elements(lsf_file) eq 1 then descr += 'lsf:' + lsf_file
namec = uly_cmp_name(name)
cmp = {name:namec, $
descr:descr, $
init_fun:'uly_ssp_init', $
init_data:ptr_new(init_data), $
eval_fun:'', $
eval_data:ptr_new(), $
para:ptr_new(/ALLO), $
start:0d, $
step: 0d, $
npix: 0l, $
sampling:-1s, $
mask:ptr_new(), $
weight:0d, $
e_weight:0d, $
l_weight:0d, $
lim_weig:(machar(/DOUBLE)).xmax * [0,1] $
}
*cmp.para = replicate({name:'', unit:'', guess:ptr_new(), step:1D-2, $
limits:[0d,0d], limited:[1,1], fixed:0S, $
value:0D, error:0D, dispf:''}, $
3)
(*cmp.para)[0].name = 'age'
(*cmp.para)[0].unit = 'Myr'
(*cmp.para)[1].name = 'Fe/H'
(*cmp.para)[1].unit = 'dex'
(*cmp.para)[0].dispf = 'exp'
if n_elements(a_limits) gt 0 then (*cmp.para)[0].limits = alog(a_limits)
if n_elements(z_limits) gt 0 then (*cmp.para)[1].limits = z_limits
if n_elements(mg_limits) gt 0 then (*cmp.para)[2].limits = mg_limits
for k=0,2 do (*cmp.para)[k].guess = ptr_new((*cmp.para)[k].limits[0])
if n_elements(a_guess) ge 1 then $
*(*cmp.para)[0].guess = alog(double(string(a_guess)))
if n_elements(z_guess) ge 1 then $
*(*cmp.para)[1].guess = double(string(z_guess))
if n_elements(mg_guess) ge 1 then $
*(*cmp.para)[2].guess = double(string(mg_guess))
(*cmp.para).step = 0.01d
(*cmp.para)[2].fixed = 1s
if n_elements(fixpar) gt 0 then $
(*cmp.para)[0:n_elements(fixpar)-1].fixed = fixpar
if n_elements(lim_weight) gt 0 then $
cmp.lim_weig = double(lim_weight)
return, cmp
end
Part of