dustem_init_plugins.pro 3.34 KB
PRO dustem_init_plugins,pd,fpd=fpd,help=help

;+
; NAME:
;    dustem_init_plugins
; PURPOSE:
;    initializes variable !dustem_plugin
; CATEGORY:
;    DustEMWrap
; CALLING SEQUENCE:
;    dustem_init_plugins,pd[,fpd]
; INPUTS:
;    pd : variable parameters description
; OPTIONAL INPUT PARAMETERS:
;    fpd : fixed parameters description
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    !dustem_plugin is set
; RESTRICTIONS:
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
; PROCEDURES AND SUBROUTINES USED:
;
; EXAMPLES
;    
; MODIFICATION HISTORY:
;    Written by Ilyes Choubani
;    Evolution details on the DustEMWrap gitlab.
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_init_plugins'
  goto,the_end
END


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(pd(i),0);strmid((*(*!dustem_fit).param_descs)(i),0) ;Try replacing this  ;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
              ftn = strmid(fpd(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+=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


IF Nplugins NE 0 THEN BEGIN
    for i=0L, Nplugins-1 do begin    
        If i EQ 0 then begin ;probably won't need the freezing part.
            strct = create_struct(plugin_names(i),{spec:ptr_new(),scope:ptr_new(),paramtag:ptr_new()});,freeze:{key:ptr_new(),val:ptr_new()}}) 
        endif else begin ;IF i GE 1
            strct = create_struct(strct,plugin_names(i),{spec:ptr_new(),scope:ptr_new(),paramtag:ptr_new()});,freeze:{key:ptr_new(),val:ptr_new()}})
        endelse         
    ENDFOR   
ENDIF



;---------------------------------------------


defsysv, '!dustem_plugin', ptr_new(strct)  ; Need the use of the pointer because dustem_init_plugins is called in dustem_init (avoid conflicting structures error). 

the_end:

END