dustem_init_plugins.pro 3.4 KB
PRO dustem_init_plugins, pd, fpd=fpd


;INITIALIZING THE SCOPES DATA ARRAYS--------------------

varvar=create_struct('varvar',ptr_new())

plugin_names=['']
plugind_detect_string='dustem_plugin'

Nplugins=0L

for i=0L,n_elements(pd)-1 do begin
    fi=strtrim(strmid(pd(i),0,strlen(plugind_detect_string)),2)
    if fi eq plugind_detect_string then begin
        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,14,ii-14) ; String containing the name of the plugin without the associated keyword
        plugin_names=[plugin_names,ftn]
        Nplugins=Nplugins+1
    ENDIF
ENDFOR



IF KEYWORD_SET(fpd) THEN BEGIN
    
    for i=0L,n_elements(fpd)-1 do begin
        fi=strtrim(strmid(fpd(i),0,strlen(plugind_detect_string)),2)
        if fi eq plugind_detect_string then begin
            if isa((*!dustem_fit).fixed_param_descs) then begin
            
                ftn = strmid((*(*!dustem_fit).fixed_param_descs)(i),0) ; String containing the name of the plugin and the keyword used (ie: dustem_create_continuum_2)    
            
            endif else  ftn = strmid((*(*!dustem_fit).param_descs)(i),0) 
            
                
            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,14,ii-14) ; String containing the name of the plugin without the associated keyword
            plugin_names=[plugin_names,ftn]
            Nplugins=Nplugins+1
        ENDIF
    ENDFOR

    
ENDIF


IF Nplugins EQ 0 THEN BEGIN
    plugin_names=['NONE']
    Nplugins=1
ENDIF ELSE BEGIN
    plugin_names=plugin_names[1:*]
    order=sort(plugin_names)
    plugin_names=plugin_names[order]
    un=uniq(plugin_names)
    plugin_names=plugin_names[un]
    Nplugins=n_elements(plugin_names)
ENDELSE

message, 'plugin_names is:',/continue
print, plugin_names

message, 'Nplugins is:',/continue
print, Nplugins


IF Nplugins NE 0 THEN BEGIN
    
    IF Nplugins GT 1 THEN BEGIN ;case of multiple plugins
    
        arr_ptrs=replicate('ptr_new()',Nplugins)
        str_fin=strjoin(("'"+plugin_names+"'"+','+arr_ptrs),',')
                
        str='varvar=create_struct('+str_fin+')'
        toto=execute(str)
        
        message, 'varvar is:',/continue
        print, varvar
        
        defsysv, '!dustem_scope', ptr_new(varvar)
    
   ENDIF ELSE BEGIN ;case of one plugin
   
           varvar=create_struct(plugin_names,ptr_new())
           defsysv, '!dustem_scope', ptr_new(varvar)
    ENDELSE 

ENDIF 

defsysv, '!dustem_scope', ptr_new(varvar)
;---------------------------------------------

                                                                                                         
;INITIALIZING THE PLUGIN DATA ARRAYS----------
tgnms=tag_names(varvar)

for i=0L, n_tags(varvar)-1 do begin

    if i eq 0 then strct= create_struct(tgnms(i),ptr_new())
    if i ge 1 then strct= create_struct(strct, tgnms(i),ptr_new())
endfor

defsysv, '!dustem_plugin', ptr_new(strct)  ; structure that will contain the spectra associated to each plugin ; how do I insert a whole structure as a fucking tag? 
;---------------------------------------------

end