dustem_run_plugins.pro 3.32 KB
PRO dustem_run_plugins,p_dim $
                      ,param_descs $
                      ,param_values $
                      ,run_order $
                      ,ask_for_st=ask_for_st $
                      ,st=st $
                      ,N2be_run=N2be_run $
                      ,help=help

;+
; NAME:
;    dustem_run_plugins
;  
; PURPOSE:
;    runs the plugins according to their scopes
;    a N_ELEMENTS(PLUGINS)X N_ELEMENTS(SCOPES) matrix is created to achieve this 
;
; CATEGORY:
;    DustEMWrap, Distributed, Mid-Level, Plugins
;
; CALLING SEQUENCE:
;    dustem_run_plugins,p_dim,param_descs,param_values,run_order,[,/ask_for_st][,st][N2be_run=][,/help] 
;
; INPUTS:
;    p_dim  = parameter values 
;    param_descs = parameter description vector
;    param_values = current parameter values
;    run_order    = run order of the plugins to be run
;
; OPTIONAL INPUT PARAMETERS:
;
; OUTPUTS:
;    None
;
; OPTIONAL OUTPUT PARAMETERS:
;    st         = Dustem output structure
;    N2be_run   = Number of plugins which have been run
; 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:
;
; EXAMPLES
;    dustem_run_plugins, p_min, param_descs, param_values, scopes, st=st
;
; MODIFICATION HISTORY:
;    Written by IC 
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-


dew_prefix='dustem_plugin_' ; we assume that this prefix is at the start of all plugin routines

;=== if no plugins, do nothing
IF (*!dustem_plugin)[0].name EQ 'NONE' THEN BEGIN
	N2be_run=0L
	goto, the_end 
ENDIF


;LOCATING THE PLUGINS THAT SHOULD BE RUN

Nparams=n_elements(param_descs)
Nplugins=n_elements(*!dustem_plugin)
must_be_run=intarr(Nplugins)

FOR i=0L,Nplugins-1 DO BEGIN
		IF (*!dustem_plugin)[i].run_order EQ run_order THEN BEGIN
			must_be_run[i]=1
		ENDIF
ENDFOR

ind2be_run=where(must_be_run EQ 1,count)
N2be_run=count

;=== run plugins that need be run
FOR i=0L,Nplugins-1 DO BEGIN
	IF must_be_run[i] THEN BEGIN
		keys=[0L]
		vals=[0.d0]
		FOR j=0L,Nparams-1 DO BEGIN
			parameter_type=dustem_parameter_description2type(param_descs[j],string_name=string_name,plugin_name=plugin_name,key=key)
			IF parameter_type EQ 'PLUGIN' THEN BEGIN
				IF plugin_name EQ (*!dustem_plugin)[i].name THEN BEGIN
					ind=where(param_descs EQ 'dustem_'+string_name,count)
					IF count NE 0 THEN BEGIN
						keys=[keys,key]
						vals=[vals,param_values[ind[0]]]
					ENDIF
				ENDIF
			ENDIF
		ENDFOR
		keys=keys[1:*]
		vals=vals[1:*]
		IF keyword_set(ask_for_st) THEN BEGIN
			str='spectrum='+(*!dustem_plugin)[i].name+'(key=keys,val=vals,st=st)'
			message,'executing '+str,/info
			toto=execute(str)
		ENDIF ELSE BEGIN
			str='spectrum='+(*!dustem_plugin)[i].name+'(key=keys,val=vals)'
			message,'executing '+str,/info
			toto=execute(str)
		ENDELSE
		(*!dustem_plugin)[i].spec=ptr_new(spectrum)
	ENDIF
ENDFOR


;== JPB: This is now done in dustem_activate_plugins
;IF keyword_set(force_dustem_run) and N2be_run EQ 0 THEN BEGIN
;   st = dustem_run(p_dim,use_previous_fortran=use_previous_fortran)
;   !dustem_current = ptr_new(st)
;ENDIF

;=== JPB: This was initially above the previous test. I moved it below.
the_end:

END