Blame view

src/idl/dustem_activate_plugins.pro 12.6 KB
8bb63b77   Ilyes Choubani   updating actiate ...
1
PRO dustem_activate_plugins,p_min,help=help,st
4750086c   Ilyes Choubani   nouvelle philosph...
2
3
4
5
6
7
8

;+
; NAME:
;    dustem_activate_plugins
; PURPOSE:
;    activates the plugins present in the parameter description vector (pd)
; CATEGORY:
50bb5343   Annie Hughes   minor changes to ...
9
;    DUSTEM Wrapper, Distributed, Mid-Level, Plugins
4750086c   Ilyes Choubani   nouvelle philosph...
10
11
12
; CALLING SEQUENCE:
;    dustem_activate_plugins,pd 
; INPUTS:
4fd64cbb   Ilyes Choubani   dustem_fit_sed_po...
13
;    parameter desription vector 
4750086c   Ilyes Choubani   nouvelle philosph...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
; OPTIONAL INPUT PARAMETERS:
;    key  = input parameter number
;    val  = input parameter value
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help                  = if set, print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    None
; RESTRICTIONS:
50bb5343   Annie Hughes   minor changes to ...
28
29
30
31
32
33
34
35
36
37
38
39
;    The DustEM fortran code must be installed
;    The DustEMWrap idl code must be installed
; PROCEDURES AND SUBROUTINES USED:
;    *** COMMENT AH --> is this really NONE? ****
;
; EXAMPLES
;    dustem_activate_plugins, pd
;
; MODIFICATION HISTORY:
;    Written by IC Apr-2022
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
4750086c   Ilyes Choubani   nouvelle philosph...
40
41
42
43
44
45
46
47
48
;-


IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_activate_plugins'
  goto,the_end
  output=0.
ENDIF

e7938fa3   Ilyes Choubani   Corrected02: Impl...
49
p_dim = p_min * (*(*!dustem_fit).param_init_values)
0068116a   Ilyes Choubani   General update + ...
50
st=dustem_run(p_dim)    
afde94a3   Ilyes Choubani   general update
51
!dustem_current = ptr_new(st)
e7938fa3   Ilyes Choubani   Corrected02: Impl...
52

3c479f24   Ilyes Choubani   Allowing to fix p...
53
54
55
56
if isa((*!dustem_fit).fixed_param_descs) then begin

    ;concatenating the parameter vectors
    param_descs =  [(*(*!dustem_fit).param_descs),(*(*!dustem_fit).fixed_param_descs)]  
3c479f24   Ilyes Choubani   Allowing to fix p...
57
58
    param_values = [p_dim,(*(*!dustem_fit).fixed_param_init_values)]
    param_values = param_values(sort(param_descs)) ;should we put it back to the way it was?
1bc09467   Ilyes Choubani   fixed issue with ...
59
    param_descs = param_descs(sort(param_descs))
3c479f24   Ilyes Choubani   Allowing to fix p...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        ;Taking care of the param_func vector
    dustem_set_func_ind, param_descs, param_values ; this sets  (*(*!dustem_fit).param_func)
    param_func = (*(*!dustem_fit).param_func)
    dustem_set_func_ind, (*(*!dustem_fit).param_descs), p_dim ;setting the pointers back to their original valyes 
    
endif else begin
    
    param_descs = (*(*!dustem_fit).param_descs)
    param_values = p_dim
    param_func = (*(*!dustem_fit).param_func)

endelse


f=1 ; Initializing the index that is associated to each plugin 
FOR i=0L,n_elements(param_descs)-1 DO BEGIN
4750086c   Ilyes Choubani   nouvelle philosph...
76
   
3c479f24   Ilyes Choubani   Allowing to fix p...
77
   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
4750086c   Ilyes Choubani   nouvelle philosph...
78
79
   
   IF parameter_type EQ 'PLUGIN' THEN BEGIN   ; Selecting the plugins
e7938fa3   Ilyes Choubani   Corrected02: Impl...
80
        
3c479f24   Ilyes Choubani   Allowing to fix p...
81
        ftn = strmid(param_descs(i),0) ; String containing the name of the plugin and the keyword used (ie: dustem_create_continuum_2)    
4750086c   Ilyes Choubani   nouvelle philosph...
82
83
        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
e7938fa3   Ilyes Choubani   Corrected02: Impl...
84
        
3c479f24   Ilyes Choubani   Allowing to fix p...
85
86
87
88
        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
2e2611d1   Ilyes Choubani   fixing counter in...
89
         
3c479f24   Ilyes Choubani   Allowing to fix p...
90
        p_dim_tmp = param_values(tmp) ; Array containing the values of the fitted parameters
e7938fa3   Ilyes Choubani   Corrected02: Impl...
91
        
0068116a   Ilyes Choubani   General update + ...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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
        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    
        
        ;==============Assigning data to the plugin data structure==============
        
        ;Dry run of the plugins to obtain their scopes and run them accordingly (an advanced user might want to add their own lines here)
        str='toto='+ftn+'(scope=scope)' & str=str(0)        
        toto=execute(str)            
        ((*!dustem_plugin).(k).scope)=ptr_new(scope)
        
        
        ;we first need to run the isrf plugin
        ;should we adjust the list of plugins with given priority?
        
        
        if (*(*!dustem_plugin).(k).scope) NE 'STELLAR_POPULATION' and strmid((*(*!dustem_plugin).(k).scope),0,7) NE 'REPLACE'  THEN BEGIN
            
            str='toto='+ftn+'(paramtag=paramtag)' & str=str(0)        
            toto=execute(str)            
            ((*!dustem_plugin).(k).paramtag)=ptr_new(paramtag)
            
            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
        
        ENDIF
            
        f=f+1 & i=i+count-1 ; Incrementing the parameter and same-type plugin indices  
  ENDIF
ENDFOR


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
e7938fa3   Ilyes Choubani   Corrected02: Impl...
154
        
d66feb17   Ilyes Choubani   Fix to some routines
155
        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
3c479f24   Ilyes Choubani   Allowing to fix p...
156
        
4750086c   Ilyes Choubani   nouvelle philosph...
157
158
159
160
161
162
163
164
165
        ; 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  
3c479f24   Ilyes Choubani   Allowing to fix p...
166
167
168
        FOR l=0, count-1 DO BEGIN
           index[l] = strmid(PDO_tmp[l],ii+1) 
           value[l] = p_dim_tmp[l]                      
4750086c   Ilyes Choubani   nouvelle philosph...
169
        ENDFOR    
4750086c   Ilyes Choubani   nouvelle philosph...
170
        
3c479f24   Ilyes Choubani   Allowing to fix p...
171
172
        ;==============Assigning data to the plugin data structure==============
        
0068116a   Ilyes Choubani   General update + ...
173
        ;Dry run of the plugins to obtain their scopes and run them accordingly (an advanced user might want to add their own lines here)
3c479f24   Ilyes Choubani   Allowing to fix p...
174
175
176
177
        str='toto='+ftn+'(scope=scope)' & str=str(0)        
        toto=execute(str)            
        ((*!dustem_plugin).(k).scope)=ptr_new(scope)
        
0068116a   Ilyes Choubani   General update + ...
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
        
        ;we first need to run the isrf plugin
        ;should we adjust the list of plugins with given priority?
        
        
        if (*(*!dustem_plugin).(k).scope) EQ 'STELLAR_POPULATION' THEN BEGIN
            
            str='toto='+ftn+'(paramtag=paramtag)' & str=str(0)        
            toto=execute(str)            
            ((*!dustem_plugin).(k).paramtag)=ptr_new(paramtag)
            
            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
            st = dustem_run(p_dim) ;run with changed isrf
            !dustem_current = ptr_new(st)
        ENDIF
            
        f=f+1 & i=i+count-1 ; Incrementing the parameter and same-type plugin indices  
  ENDIF
ENDFOR




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    
        
        ;==============Assigning data to the plugin data structure==============
        
        ;Dry run of the plugins to obtain their scopes and run them accordingly (an advanced user might want to add their own lines here)
        str='toto='+ftn+'(scope=scope)' & str=str(0)        
3c479f24   Ilyes Choubani   Allowing to fix p...
241
        toto=execute(str)            
0068116a   Ilyes Choubani   General update + ...
242
243
        ((*!dustem_plugin).(k).scope)=ptr_new(scope)
        
3c479f24   Ilyes Choubani   Allowing to fix p...
244
        
0068116a   Ilyes Choubani   General update + ...
245
246
        ;we first need to run the isrf plugin
        ;should we adjust the list of plugins with given priority?
e6ef3674   Ilyes Choubani   removed st keywor...
247
        
3c479f24   Ilyes Choubani   Allowing to fix p...
248
        
0068116a   Ilyes Choubani   General update + ...
249
250
251
252
253
254
255
256
257
258
259
260
261
        if strmid((*(*!dustem_plugin).(k).scope),0,7) EQ 'REPLACE' THEN BEGIN
            
            str='toto='+ftn+'(paramtag=paramtag)' & str=str(0)        
            toto=execute(str)            
            ((*!dustem_plugin).(k).paramtag)=ptr_new(paramtag)
            
            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
            st = dustem_run(p_dim) ;run with changed isrf
            !dustem_current = ptr_new(st)
        ENDIF
            
607060e5   Ilyes Choubani   test version
262
        f=f+1 & i=i+count-1 ; Incrementing the parameter and same-type plugin indices  
e7938fa3   Ilyes Choubani   Corrected02: Impl...
263
264
  ENDIF
ENDFOR
0068116a   Ilyes Choubani   General update + ...
265
266
267



4750086c   Ilyes Choubani   nouvelle philosph...
268
the_end:
e7938fa3   Ilyes Choubani   Corrected02: Impl...
269

4750086c   Ilyes Choubani   nouvelle philosph...
270
END