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

;+
; NAME:
;    dustem_activate_plugins
; PURPOSE:
;    activates the plugins present in the parameter description vector (pd)
; CATEGORY:
;    DUSTEM Wrapper
; CALLING SEQUENCE:
;    dustem_activate_plugins,pd 
; 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 dustem idl wrapper must be installed
; PROCEDURE:
;    dustem procedure
;-


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)


f=1 ; Initializing the index that is associated to each type of plugin 
FOR i=0L,n_elements(p_min)-1 DO BEGIN
   
   parameter_type=dustem_parameter_description2type((*(*!dustem_fit).param_descs)[i],string_name=string_name) ; Looping over the parameter description vector (here saved in a system variable) to sort out its different elements with repect to their types
   
   IF parameter_type EQ 'PLUGIN' THEN BEGIN   ; Selecting the plugins
        
        ftn = strmid((*(*!dustem_fit).param_descs)(i),0) ; String containing the name of the plugin and the keyword used (ie: dustem_create_continuum_2)    
        ii = strsplit(ftn,'_',count=countx) & ii = ii(countx-1)-1 ; Locating the last underscore to automate the extraction of the plugin's keyword
        ftn = strmid(ftn,0,ii) ; String containing the name of the plugin without the associated keyword
             
        
        tmp = (where(*(*!dustem_fit).param_func eq f, count)) ; Array of indices helping with the sorting out of the different plugins (as a plugin can be called several times with different keywords so as to fit several quantities) 
        PDO_tmp = (*(*!dustem_fit).param_descs)(tmp) ; Array containing the different calls of each plugin at a time
         
        p_dim_tmp = p_dim(tmp) ; Array containing the values of the fitted parameters
        
        
        vari = strmid(PDO_tmp(0),ii+1) ; Test variable to be used to alter the initialization of the index and value arrays below as a keyword can be a scalar or a string
       
        ; Initialization of the index and value arrays. These arrays will be used (below) when calling the plugins (with the default key=key and val=val keywords)
        
        if strlen(strtrim(string(vari),2)) gt 1 then begin
            index = strarr(count) & value = fltarr(count)  
        endif else  begin
            index = fltarr(count) & value = fltarr(count)
        endelse
        
        ; Filling the index and value arrays for one plugin at a time  
        FOR k=0, count-1 DO BEGIN
            
           index[k] = strmid(PDO_tmp[k],ii+1) 
           value[k] = p_dim_tmp[k]           
                      
        ENDFOR    
         
        ;==============Assigning data to the initialized plugin data arrays==============
        
        if strmid(ftn,0,13) eq 'dustem_plugin' then begin
            	    
            
            k=where(strmid(tag_names(*!dustem_scope),0,8) eq strmid(strupcase(strmid(ftn,14)),0,8),counte) ; Selecting a plugin through matching the string name of the plugin form the scope system variable with the one read from the parameter description vector
            
            ;Dry run of the plugins to obtain their scopes and run them accordingly (an advanced user might want to add their own lines here)
            str='toto='+ftn+'(scope=scope)'        
            toto=execute(str)            
            
            (*!dustem_scope).(k)=ptr_new(scope)
            
            
            ;print, 
        
            
            	    
            str='((*!dustem_plugin).('+strtrim(k,2)+'))=ptr_new('+ftn+'(key=index,val=value)'+')' & str=str(0)
            toto=execute(str) & IF !dustem_verbose NE 0 THEN message,strupcase(strmid(ftn,7)),/info
            
        ENDIF  
                     
        f=f+1 & i=i+count-1 ; Incrementing the parameter and same-type plugin indices
  ENDIF
ENDFOR
the_end:

END