Blame view

src/idl/dustem_run_plugins.pro 8.9 KB
91e991b5   Ilyes Choubani   Applying correcti...
1
PRO dustem_run_plugins, p_dim ,param_descs, param_values, param_func, scopes, st, avoid=avoid, dustem_run=dustem_run
0c25ef54   Ilyes Choubani   Forgotten procedure
2
3
4
5
6
7
8

;HELP ON THE WAY/ 
; 

;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. 

91e991b5   Ilyes Choubani   Applying correcti...
9
10
11
12
13
;Just to be sure 
if not keyword_set(avoid) then avoid=0
if not keyword_set(dustem_run) then dustem_run=0


0c25ef54   Ilyes Choubani   Forgotten procedure
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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

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
	        
	        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
	        
	        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
	        
	        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==============
	        
	        str='toto='+ftn+'(scope=scope)' & str=str(0)        
	        toto=execute(str)            
	        ((*!dustem_plugin).(k).scope)=ptr_new(scope)
	            
91e991b5   Ilyes Choubani   Applying correcti...
64
65
66
67
68
	        str='toto='+ftn+'(paramtag=paramtag)' & str=str(0)        
            toto=execute(str)            
            ((*!dustem_plugin).(k).paramtag)=ptr_new(paramtag)    
	            
	            
0c25ef54   Ilyes Choubani   Forgotten procedure
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	        f=f+1 & i=i+count-1 ; Incrementing the parameter and same-type plugin indices  
	  ENDIF
	ENDFOR
ENDIF


;LOCATING THE PLUGINS THAT SHOULD BE RUN

indices = fltarr(n_tags(*!dustem_plugin),n_elements(scopes));+la_undef() ;


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...
92
93
94
95
96
97
98
99
		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))  
	
	ENDELSE	
	;Now locating the indices of this scope in !dustem_plugin. 
b9013e10   Ilyes Choubani   small fix for fut...
100
    
91e991b5   Ilyes Choubani   Applying correcti...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	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
            if (size(indices))[0] GT 1 then indices[j,i] = 0 ELSE indices[j] = 0
 		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
    		if (size(indices))[0] GT 1 then indices[j,i] = 1 ELSE indices[j] = 1
    		
		ENDIF
0c25ef54   Ilyes Choubani   Forgotten procedure
115
		
91e991b5   Ilyes Choubani   Applying correcti...
116
117
		if ~test and keyword_set(avoid) then begin
            if (size(indices))[0] GT 1 then indices[j,i] = 1 ELSE indices[j] = 1
0c25ef54   Ilyes Choubani   Forgotten procedure
118

91e991b5   Ilyes Choubani   Applying correcti...
119
120
        endif		
	ENDFOR		
0c25ef54   Ilyes Choubani   Forgotten procedure
121

0c25ef54   Ilyes Choubani   Forgotten procedure
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

ENDFOR

;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
	   
	 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
	        
	       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
	        
	       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
	        
	       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)
	        
	       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    
	        
	       ;==============Runnig of the plugins according to their scopes==============
91e991b5   Ilyes Choubani   Applying correcti...
162
	       idd=1
0c25ef54   Ilyes Choubani   Forgotten procedure
163
164
	       
	       FOR j=0L,n_elements(scopes)-1 DO BEGIN
0c25ef54   Ilyes Choubani   Forgotten procedure
165
    	       
b9013e10   Ilyes Choubani   small fix for fut...
166
167
168
169
170
171
172
173
    	       if (size(indices))[0] GT 1 then BEGIN
    	       
        	       if keyword_set(avoid) then idd *= indices(k,j) else idd += indices(k,j) ;the + is for the case when run_plugins is run with a scopes vector containing more than one element and when the avoid keyword isn't set. ( I do not know when this will occur but in the future, maybe the user will want to run 'ONLY' the plugins in the scopes vector)
        	       
    	       ENDIF ELSE idd *= indices(k)
    	       
    	       
    	   ENDFOR  
91e991b5   Ilyes Choubani   Applying correcti...
174
175
176
177
178
179
180
	       
	       IF  idd EQ 1 THEN BEGIN
	           
               str='((*!dustem_plugin).('+strtrim(k,2)+').spec)=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
               
               if keyword_set(dustem_run) then begin
0c25ef54   Ilyes Choubani   Forgotten procedure
181
                   
91e991b5   Ilyes Choubani   Applying correcti...
182
183
                   st = dustem_run(p_dim) 
                   !dustem_current = ptr_new(st)
0c25ef54   Ilyes Choubani   Forgotten procedure
184
                   
91e991b5   Ilyes Choubani   Applying correcti...
185
               endif 
0c25ef54   Ilyes Choubani   Forgotten procedure
186
                   
0c25ef54   Ilyes Choubani   Forgotten procedure
187
	       
91e991b5   Ilyes Choubani   Applying correcti...
188
189
	       
	      ENDIF
0c25ef54   Ilyes Choubani   Forgotten procedure
190
191
192
193
194
195
196
197
    	   
    	     
	          
	       f=f+1 & i=i+count-1 ; Incrementing the parameter and same-type plugin indices  
	  ENDIF
	ENDFOR

END