Blame view

src/idl/dustem_run_plugins.pro 11.1 KB
57cdd991   Ilyes Choubani   updating sections...
1
PRO dustem_run_plugins, p_dim ,$
8768c2c2   Annie Hughes   generalised strin...
2
3
4
5
6
7
8
9
                        param_descs,$
                        param_values,$
                        param_func,$
                        scopes,$
                        st=st,$
                        avoid=avoid,$
                        dustem_run=dustem_run,$
                        help=help
0c25ef54   Ilyes Choubani   Forgotten procedure
10

57cdd991   Ilyes Choubani   updating sections...
11
12
13
;+
; NAME:
;    dustem_run_plugins
8768c2c2   Annie Hughes   generalised strin...
14
;  
57cdd991   Ilyes Choubani   updating sections...
15
; PURPOSE:
2a8e29d5   Ilyes Choubani   small corrections...
16
;    runs the plugins according to their scopes
40cb4765   Ilyes Choubani   Small correction ...
17
;    a N_ELEMENTS(PLUGINS)X N_ELEMENTS(SCOPES) matrix is created to achieve this 
8768c2c2   Annie Hughes   generalised strin...
18
;
57cdd991   Ilyes Choubani   updating sections...
19
; CATEGORY:
8dbb9ca6   Annie Hughes   fix bug with free...
20
;    DustEMWrap, Distributed, Mid-Level, Plugins
8768c2c2   Annie Hughes   generalised strin...
21
;
57cdd991   Ilyes Choubani   updating sections...
22
23
; CALLING SEQUENCE:
;    dustem_run_plugins,p_dim,param_descs,param_values,scopes,[,st][,avoid][,dustem_run][,/help] 
8768c2c2   Annie Hughes   generalised strin...
24
;
57cdd991   Ilyes Choubani   updating sections...
25
26
; INPUTS:
;    p_dim  = parameter values 
87785eb6   Ilyes Choubani   Completing help h...
27
28
29
30
;    param_descs = parameter description vector
;    param_values = current parameter values
;    param-func   = plugin indices array 
;    scopes       = scopes of plugins 
8768c2c2   Annie Hughes   generalised strin...
31
;
57cdd991   Ilyes Choubani   updating sections...
32
33
34
; OPTIONAL INPUT PARAMETERS:
;    avoid      = scopes should be avoided
;    dustem_run = Dustem should be run
8768c2c2   Annie Hughes   generalised strin...
35
;
57cdd991   Ilyes Choubani   updating sections...
36
37
; OUTPUTS:
;    None
8768c2c2   Annie Hughes   generalised strin...
38
;
57cdd991   Ilyes Choubani   updating sections...
39
40
; OPTIONAL OUTPUT PARAMETERS:
;    st         = Dustem output structure
8768c2c2   Annie Hughes   generalised strin...
41
;
57cdd991   Ilyes Choubani   updating sections...
42
43
; ACCEPTED KEY-WORDS:
;    help                  = if set, print this help
8768c2c2   Annie Hughes   generalised strin...
44
;
57cdd991   Ilyes Choubani   updating sections...
45
46
; COMMON BLOCKS:
;    None
8768c2c2   Annie Hughes   generalised strin...
47
;
57cdd991   Ilyes Choubani   updating sections...
48
49
; SIDE EFFECTS:
;    None
8768c2c2   Annie Hughes   generalised strin...
50
;
57cdd991   Ilyes Choubani   updating sections...
51
52
; RESTRICTIONS:
;    The DustEM fortran code must be installed
8dbb9ca6   Annie Hughes   fix bug with free...
53
;    The DustEMWrap IDL code must be installed
8768c2c2   Annie Hughes   generalised strin...
54
;
57cdd991   Ilyes Choubani   updating sections...
55
; PROCEDURES AND SUBROUTINES USED:
8768c2c2   Annie Hughes   generalised strin...
56
;
57cdd991   Ilyes Choubani   updating sections...
57
58
; EXAMPLES
;    dustem_activate_plugins, p_min, pram_descs, param_values, param_func, scopes, st=st, avoid=avoid, dustem_run=dustem_run 
8768c2c2   Annie Hughes   generalised strin...
59
;
57cdd991   Ilyes Choubani   updating sections...
60
61
62
63
64
; MODIFICATION HISTORY:
;    Written by IC 
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-
0c25ef54   Ilyes Choubani   Forgotten procedure
65

639e87fb   Ilyes Choubani   Allowing run with...
66
67


0c25ef54   Ilyes Choubani   Forgotten procedure
68
69
70
;Because I don't want to run this block each time the procedure is run I will test on the presence of all the scope tags in !dustem_plugin
;if all of them are present then this block has been run. 

2bbb56cf   Jean-Philippe Bernard   modified to fix b...
71
72
;stop 

8768c2c2   Annie Hughes   generalised strin...
73
74
dew_prefix='dustem_plugin_' ; we assume that this prefix is at the start of all plugin routines

639e87fb   Ilyes Choubani   Allowing run with...
75
76
IF (tag_names(*!dustem_plugin))(0) EQ 'NONE' THEN goto, the_end 

91e991b5   Ilyes Choubani   Applying correcti...
77
78
79
80
;Just to be sure 
if not keyword_set(avoid) then avoid=0
if not keyword_set(dustem_run) then dustem_run=0

2bbb56cf   Jean-Philippe Bernard   modified to fix b...
81
;stop
91e991b5   Ilyes Choubani   Applying correcti...
82

0c25ef54   Ilyes Choubani   Forgotten procedure
83
84
85
86
87
88
89
90
test_all_scopes = 1. 
FOR i=0L,n_tags(*!dustem_plugin)-1 DO BEGIN

	IF isa(((*!dustem_plugin).(i).scope)) then test=1 else test=0
	test_all_scopes*=test 

ENDFOR

2bbb56cf   Jean-Philippe Bernard   modified to fix b...
91
92
;stop

0c25ef54   Ilyes Choubani   Forgotten procedure
93
94
95
96
97
98
99
100
101
IF ~test_all_scopes THEN BEGIN
	;FIRST LOOP TO RETRIEVE THE SCOPES OF ALL THE PLUGINS
	f=1 ; Initializing the index that is associated to each plugin 
	FOR i=0L,n_elements(param_descs)-1 DO BEGIN
	   
	   parameter_type=dustem_parameter_description2type(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
	        
8768c2c2   Annie Hughes   generalised strin...
102
103
	        ftn = strmid(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
0c25ef54   Ilyes Choubani   Forgotten procedure
104
	        ftn = strmid(ftn,0,ii) ; String containing the name of the plugin without the associated keyword
8768c2c2   Annie Hughes   generalised strin...
105
106
107
108
109
110
                this_plugin = strupcase(strmid(ftn,strlen(dew_prefix)))

;                end_char=strlen(this_plugin)
;	        k=where(tag_names(*!dustem_plugin) eq strmid(this_plugin,0,end_char),counte) ; Selecting a plugin through matching the string name of the plugin from the scope system variable with the one read from the parameter description vector
	        k=where(tag_names(*!dustem_plugin) eq this_plugin,counte) ; Selecting a plugin through matching the string name of the plugin from the scope system variable with the one read from the parameter description vector
                
0c25ef54   Ilyes Choubani   Forgotten procedure
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
	        tmp = where(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 = param_descs(tmp) ; Array containing the different calls of each plugin at a time
	         
	        p_dim_tmp = param_values(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 l=0, count-1 DO BEGIN
	           index[l] = strmid(PDO_tmp[l],ii+1) 
	           value[l] = p_dim_tmp[l]                      
	        ENDFOR    
	        
	        ;==============Dry run of the plugins to obtain their scopes and run them accordingly==============
8768c2c2   Annie Hughes   generalised strin...
133
                
0c25ef54   Ilyes Choubani   Forgotten procedure
134
	        str='toto='+ftn+'(scope=scope)' & str=str(0)        
8768c2c2   Annie Hughes   generalised strin...
135
                toto=execute(str)
0c25ef54   Ilyes Choubani   Forgotten procedure
136
	        ((*!dustem_plugin).(k).scope)=ptr_new(scope)
f9089dc2   Ilyes Choubani   implementing the ...
137
	           
8768c2c2   Annie Hughes   generalised strin...
138
139
140
                str='toto='+ftn+'(paramtag=paramtag)' & str=str(0)        
                toto=execute(str)            
                ((*!dustem_plugin).(k).paramtag)=ptr_new(paramtag)    
91e991b5   Ilyes Choubani   Applying correcti...
141
	            
0c25ef54   Ilyes Choubani   Forgotten procedure
142
143
144
145
146
	        f=f+1 & i=i+count-1 ; Incrementing the parameter and same-type plugin indices  
	  ENDIF
	ENDFOR
ENDIF

2bbb56cf   Jean-Philippe Bernard   modified to fix b...
147
;stop
0c25ef54   Ilyes Choubani   Forgotten procedure
148
149
150

;LOCATING THE PLUGINS THAT SHOULD BE RUN

2a8e29d5   Ilyes Choubani   small corrections...
151
indices = fltarr(n_tags(*!dustem_plugin),n_elements(scopes)) ;
0c25ef54   Ilyes Choubani   Forgotten procedure
152
153
154
155
156
157
158
159
160
161
162
163
164
165


FOR i=0L,n_elements(scopes)-1 DO BEGIN

	;test if there is a '*' string. This means that all scopes containing that string will be either avoided or chosen.
	;this means that we need the index of the scope corresponding to this string.
		
	;first we need to extract the string between the two '*' and then match it with the existing plugin 
	; this enables us to get the indices of the plugins to run...

	IF strmid(scopes(i),0,1) EQ '*' THEN BEGIN

		;Now I need to locate the second '*': 
		ind_ast = STRPOS(scopes(i), '*', /REVERSE_SEARCH)
91e991b5   Ilyes Choubani   Applying correcti...
166
167
168
169
170
		scope_to_match = strmid(scopes(i),1,ind_ast-1) 
		;
	ENDIF ELSE BEGIN ;assuming the string is identical to the plugin's scope
	
    	scope_to_match = strupcase(scopes(i))  
8768c2c2   Annie Hughes   generalised strin...
171
        
91e991b5   Ilyes Choubani   Applying correcti...
172
173
	ENDELSE	
	;Now locating the indices of this scope in !dustem_plugin. 
91934f7c   Annie Hughes   not sure
174
        
91e991b5   Ilyes Choubani   Applying correcti...
175
176
177
178
179
	FOR j=0L,n_tags(*!dustem_plugin)-1 DO BEGIN
        
        test = strcmp((*((*!dustem_plugin).(j).scope)),scope_to_match,strlen(scope_to_match),/FOLD_CASE) EQ 1
        
        IF test and keyword_set(avoid) THEN BEGIN
2a8e29d5   Ilyes Choubani   small corrections...
180
            if (size(indices))[0] GT 1 then indices[j,i] *= 0 ELSE indices[j] *= 0
91e991b5   Ilyes Choubani   Applying correcti...
181
182
183
184
185
 		ENDIF ;ELSE BEGIN
;     		if (size(indices))[0] GT 1 then indices[j,i] = 1 ELSE indices[j] = 1
; 		ENDELSE 
; 		
		IF test and not keyword_set(avoid)then  BEGIN
2a8e29d5   Ilyes Choubani   small corrections...
186
    		if (size(indices))[0] GT 1 then indices[j,i] += 1 ELSE indices[j] += 1
91e991b5   Ilyes Choubani   Applying correcti...
187
188
    		
		ENDIF
0c25ef54   Ilyes Choubani   Forgotten procedure
189
		
91e991b5   Ilyes Choubani   Applying correcti...
190
		if ~test and keyword_set(avoid) then begin
2a8e29d5   Ilyes Choubani   small corrections...
191
            if (size(indices))[0] GT 1 then indices[j,i] += 1 ELSE indices[j] += 1
0c25ef54   Ilyes Choubani   Forgotten procedure
192

2a8e29d5   Ilyes Choubani   small corrections...
193
194
        endif
        		
91e991b5   Ilyes Choubani   Applying correcti...
195
	ENDFOR		
0c25ef54   Ilyes Choubani   Forgotten procedure
196

0c25ef54   Ilyes Choubani   Forgotten procedure
197
198
ENDFOR

2bbb56cf   Jean-Philippe Bernard   modified to fix b...
199
;stop
0c25ef54   Ilyes Choubani   Forgotten procedure
200
201
202
203
204
;RUNNING THE PLUGINS ACCORDING TO THEIR SCOPES

f=1 ; Initializing the index that is associated to each plugin 
FOR i=0L,n_elements(param_descs)-1 DO BEGIN
	   
2bbb56cf   Jean-Philippe Bernard   modified to fix b...
205
206
207
208
209
210
211
	parameter_type=dustem_parameter_description2type(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
	    ;stop
       ftn = strmid(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
8768c2c2   Annie Hughes   generalised strin...
212
213
214
215
216
217
218
219
       this_plugin = strupcase(strmid(ftn,strlen(dew_prefix)))

;                end_char=strlen(this_plugin)
;	        k=where(tag_names(*!dustem_plugin) eq strmid(this_plugin,0,end_char),counte) ; Selecting a plugin through matching the string name of the plugin from the scope system variable with the one read from the parameter description vector
	        k=where(tag_names(*!dustem_plugin) eq this_plugin,counte) ; Selecting a plugin through matching the string name of the plugin from the scope system variable with the o

       
;       k=where(strmid(tag_names(*!dustem_plugin),0,8) eq strmid(strupcase(strmid(ftn,14)),0,8),counte) ; Selecting a plugin through matching the string name of the plugin from the scope system variable with the one read from the parameter description vector
2bbb56cf   Jean-Philippe Bernard   modified to fix b...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
       ;help,f
       ;stop
       tmp = where(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 = param_descs(tmp) ; Array containing the different calls of each plugin at a time
         
       p_dim_tmp = param_values(tmp) ; Array containing the values of the parameters used for the run
        
       vari = strmid(PDO_tmp(0),ii+1) ; Test variable to be used to alter the initialization of the index and value arrays below for 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)
       ;print,ftn,ii,ftn,counte
       ;print,PDO_tmp,p_dim_tmp,vari
       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
       ;help,'<<<<',index,count

        ; Filling the index and value arrays for one plugin at a time  
       FOR l=0, count-1 DO BEGIN
          index[l] = strmid(PDO_tmp[l],ii+1) 
          value[l] = p_dim_tmp[l]                      
       ENDFOR    
        
       ;==============Running of the plugins according to their scopes==============
   
       
       if keyword_set(avoid) then idd=product(indices[k,*]) else idd=total(indices[k,*])
        	   
       IF  idd GE 1 THEN BEGIN
           str='((*!dustem_plugin).('+strtrim(k,2)+').spec)=ptr_new('+ftn+'(key=index,val=value)'+')' & str=str(0)
           ;print,'>>>>>',str
           ;stop
           ;plante fawlty quand
           ;((*!dustem_plugin).(1).spec)=ptr_new(dustem_plugin_stellar_population(key=index,val=value))
           toto=execute(str)
           ;stop
           IF !dustem_verbose NE 0 THEN message,strupcase(strmid(ftn,7)),/info
       ENDIF
40cb4765   Ilyes Choubani   Small correction ...
260
	   
2bbb56cf   Jean-Philippe Bernard   modified to fix b...
261
262
263
	     
          
      f=f+1 & i=i+count-1 ; Incrementing the parameter and same-type plugin indices  
a73f6031   Ilyes Choubani   small corrections...
264
    	  
2bbb56cf   Jean-Philippe Bernard   modified to fix b...
265
266
267
268
269
	ENDIF
ENDFOR

;stop

ab4dc92e   Ilyes Choubani   Slight modificati...
270
271
272
273
274
275
if keyword_set(dustem_run) then begin
    
    st = dustem_run(p_dim) 
    !dustem_current = ptr_new(st)
    
endif 
2bbb56cf   Jean-Philippe Bernard   modified to fix b...
276
277
278

;stop

639e87fb   Ilyes Choubani   Allowing run with...
279
the_end:
8768c2c2   Annie Hughes   generalised strin...
280
END