dustem_activate_plugins.pro 3.54 KB
PRO dustem_activate_plugins,p_min,help=help,st

;+
; NAME:
;    dustem_activate_plugins
; PURPOSE:
;    activates the plugins present in the parameter description vector (pd) and the fixed parameter description vector (fpd)
; CATEGORY:
;    DUSTEM Wrapper, Distributed, Mid-Level, Plugins
; CALLING SEQUENCE:
;    dustem_activate_plugins,p_min (p_min is the dustem_mpfitfun output)
; INPUTS:
;    parameter desription vector 
; OPTIONAL INPUT PARAMETERS:
;    key  = input parameter number
;    val  = input parameter value
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help                  = if set, print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    None
; RESTRICTIONS:
;    The DustEM fortran code must be installed
;    The DustEMWrap idl code must be installed
; PROCEDURES AND SUBROUTINES USED:
;    *** COMMENT AH --> is this really NONE? ****
;
; EXAMPLES
;    dustem_activate_plugins, p_min (p_min is the output of dustem_mpfitfun)
;
; MODIFICATION HISTORY:
;    Written by IC Apr-2022
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-


IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_activate_plugins'
  goto,the_end
  output=0.
ENDIF

p_dim = p_min * (*(*!dustem_fit).param_init_values)

;JPB: Not sure if calls to dustem_set_func_ind below are still needed. 
;IC: They are needed to accound for the freezing of plugin parameters because I am concatenating the parameter description vector and the fixed one.
;This means that I need dustem_set_func_ind for this composite vector to know which plugins are activated (whether they have frozen parameters or not).
if isa((*!dustem_fit).fixed_param_descs) then begin 
;THIS IS USED TO ACCOUNT FOR THE FREEZING OF PLUGIN PARAMETERS

    ;concatenating the parameter vectors
    param_descs =  [(*(*!dustem_fit).param_descs),(*(*!dustem_fit).fixed_param_descs)]  
    param_values = [p_dim,(*(*!dustem_fit).fixed_param_init_values)]
    param_values = param_values(sort(param_descs)) ;should we put it back to the way it was?
    param_descs = param_descs(sort(param_descs))
        ;Taking care of the param_func vector
    dustem_set_func_ind, param_descs, param_values ; this sets  (*(*!dustem_fit).param_func)
    param_func = (*(*!dustem_fit).param_func)
    dustem_set_func_ind, (*(*!dustem_fit).param_descs), p_dim ;setting the pointers back to their original valyes 
    
endif else begin
    
    param_descs = (*(*!dustem_fit).param_descs)
    param_values = p_dim
    param_func = (*(*!dustem_fit).param_func)

endelse

;PART WHERE THE PLUGINS RUN ACCORDING TO THEIR SCOPES. 

;help section on the way 

;normal (additive) plugins come first as they can be used by other plugins 
;The ISRF plugin is next - we can always change its scope however we please to. DustEm runs here. This is with the /dustem_run keyword. 
;The plugins that use the DustEM output come next - we can always change their 'common' scope 

;IF /avoid is used the specified scopes are avoided. They're considered when /avoid is missing.
;using '**' so not to write the entire scope
dustem_run_plugins, p_dim ,param_descs, param_values, param_func, ['*STELLAR*','*REPLACE*'], avoid=1
dustem_run_plugins, p_dim ,param_descs, param_values, param_func, ['*STELLAR*'] ,dustem_run=1,st ;dustem output is available at this step.

;added this small condition to ensure that dustem is run  
if ~isa(st) then begin
    st=dustem_run(p_dim)
    !dustem_current=ptr_new(st)
endif

dustem_run_plugins, p_dim ,param_descs, param_values, param_func, ['*REPLACE*']


the_end:

END