Blame view

src/idl/dustem_activate_plugins.pro 7.55 KB
4750086c   Ilyes Choubani   nouvelle philosph...
1
2
3
4
5
6
7
8
9
10
11
12
13
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
PRO dustem_activate_plugins,p_min,res=res,st,help=help

;+
; NAME:
;    dustem_activate_plugins
; PURPOSE:
;    activates the plugins present in the parameter description vector (pd)
; CATEGORY:
;    DUSTEM Wrapper
; CALLING SEQUENCE:
;    dustem_activate_plugins,pd 
; INPUTS:
;    parameter desription vector (pd) or an array of the same size (ie: the array of fitted parameters p_min or p_dim)
; 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:
;    The dustem fortran code must be installed
;    The dustem idl wrapper must be installed
; PROCEDURE:
;    dustem procedure
;-


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

e7938fa3   Ilyes Choubani   Corrected02: Impl...
41
42
43

p_dim = p_min * (*(*!dustem_fit).param_init_values)

e7938fa3   Ilyes Choubani   Corrected02: Impl...
44

4750086c   Ilyes Choubani   nouvelle philosph...
45
f=1 ; Initializing the index that is associated to each type of plugin 
e7938fa3   Ilyes Choubani   Corrected02: Impl...
46
FOR i=0L,n_elements(p_min)-1 DO BEGIN
4750086c   Ilyes Choubani   nouvelle philosph...
47
48
49
50
   
   parameter_type=dustem_parameter_description2type((*(*!dustem_fit).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
e7938fa3   Ilyes Choubani   Corrected02: Impl...
51
        
4750086c   Ilyes Choubani   nouvelle philosph...
52
53
54
        ftn = strmid((*(*!dustem_fit).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
2e2611d1   Ilyes Choubani   fixing counter in...
55
             
e7938fa3   Ilyes Choubani   Corrected02: Impl...
56
        
4750086c   Ilyes Choubani   nouvelle philosph...
57
58
        tmp = (where(*(*!dustem_fit).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 = (*(*!dustem_fit).param_descs)(tmp) ; Array containing the different calls of each plugin at a time
2e2611d1   Ilyes Choubani   fixing counter in...
59
         
4750086c   Ilyes Choubani   nouvelle philosph...
60
        p_dim_tmp = p_dim(tmp) ; Array containing the values of the fitted parameters
e7938fa3   Ilyes Choubani   Corrected02: Impl...
61
        
e7938fa3   Ilyes Choubani   Corrected02: Impl...
62
        
d66feb17   Ilyes Choubani   Fix to some routines
63
        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
8b12fe66   Ilyes Choubani   restoring activat...
64
       
4750086c   Ilyes Choubani   nouvelle philosph...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        ; 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 k=0, count-1 DO BEGIN
            
           index[k] = strmid(PDO_tmp[k],ii+1) 
           value[k] = p_dim_tmp[k]           
                      
        ENDFOR    
d66feb17   Ilyes Choubani   Fix to some routines
80
       
d66feb17   Ilyes Choubani   Fix to some routines
81
 
4750086c   Ilyes Choubani   nouvelle philosph...
82
83
        ;==============Assigning data to the initialized plugin data arrays==============
        
cbf75ef0   Ilyes Choubani   dustem_init_plugi...
84
        if strmid(ftn,0,13) eq 'dustem_plugin' then begin
2e2611d1   Ilyes Choubani   fixing counter in...
85
86
            	    
            k=where(strmid(tag_names(*!dustem_scope),0,4) eq strmid(strupcase(strmid(ftn,14)),0,4),counte) ; Selecting a plugin through matching the string name of the plugin form the scope system variable with the one read from the parameter description vector 
4750086c   Ilyes Choubani   nouvelle philosph...
87
           
8b12fe66   Ilyes Choubani   restoring activat...
88
        
4750086c   Ilyes Choubani   nouvelle philosph...
89
            ;Dry run of the plugins to obtain their scopes and run them accordingly (an advanced user might want to add their own lines here)
8b12fe66   Ilyes Choubani   restoring activat...
90
91
            str='toto='+ftn+'(scope=scope)'        
            toto=execute(str)
4750086c   Ilyes Choubani   nouvelle philosph...
92
            
7f2b2149   Jean-Philippe Bernard   a Ilyes
93
            (*!dustem_scope).(k)=ptr_new(scope)
8b12fe66   Ilyes Choubani   restoring activat...
94
            
7f2b2149   Jean-Philippe Bernard   a Ilyes
95
            IF !dustem_verbose NE 0 THEN message,strupcase(strmid(ftn,7)),/info
4750086c   Ilyes Choubani   nouvelle philosph...
96
97
98
99
100
            
      
            ;===========================Activating (running) the plugins that have the 'ADD_SED' and 'ADD_POLSED' scopes=======================================
            
            if total(strsplit((*(*!dustem_scope).(k)),'+',/extract) eq 'ADD_SED') or total(strsplit((*(*!dustem_scope).(k)),'+',/extract) eq 'ADD_POLSED') then begin
4750086c   Ilyes Choubani   nouvelle philosph...
101
102
103
104
		        str='((*!dustem_plugin).('+strtrim(k,2)+'))=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 else begin 
e7938fa3   Ilyes Choubani   Corrected02: Impl...
105
          
4750086c   Ilyes Choubani   nouvelle philosph...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
            ;=========================================================================================================================================================================================================================
            ;If the user needs to run a block that has different criteria (a plugin that uses different keywords) than the one above, they will have to write a new block (if clause such as the (.. eq 'DEFINE_ISRF') one)
            ;=========================================================================================================================================================================================================================
                
                ;===========================Activating the plugins that have all the remaning scopes. Examples are  'ADD_EXT', 'ADD_POLEXT' etc...=======================================    
                
                if total(strsplit((*(*!dustem_scope).(k)),'+',/extract) ne 'DEFINE_ISRF') then begin ; This condition is because the 'DEFINE_ISRF' scope has a specific treatment
            
                    str='((*!dustem_plugin).('+strtrim(k,2)+'))=ptr_new('+ftn+'(st,key=index,val=value)'+')' & str=str(0)
                    toto=execute(str) & IF !dustem_verbose NE 0 THEN message,strupcase(strmid(ftn,7)),/info
                endif
                ;=========================================================================================================================================================================
                
                
                ;===========================Activating the more customized plugin with the 'DEFINE_ISRF' scope=======================================
                if total(strsplit((*(*!dustem_scope).(k)),'+',/extract) eq 'DEFINE_ISRF') then begin 
               
cbf75ef0   Ilyes Choubani   dustem_init_plugi...
123
                    toto=dustem_plugin_stellar_population(key=index,val=value)
4750086c   Ilyes Choubani   nouvelle philosph...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
              
                    str='((*!dustem_plugin).('+strtrim(k,2)+'))=ptr_new('+'(!dustem_composite_stellar_population)'+')' & str=str(0)
                    toto=execute(str) & IF !dustem_verbose NE 0 THEN message,strupcase(strmid(ftn,7)),/info
                endif
                ;===================================================================================================================== 
                        
            endelse
                
        ;This block isn't reated to the computation of the isrf nor the computation of the greybody case. It has to be investigated 
        endif else begin
            str='res='+ftn+'(key=index,val=value)'
            toto=execute(str) & IF !dustem_verbose NE 0 THEN message,strupcase(strmid(ftn,7)),/info
        endelse 
        ;====================================================================================
         
2e2611d1   Ilyes Choubani   fixing counter in...
139
        f=f+1 & i=i+count-1 ; Incrementing the parameter and same-type plugin indices
e7938fa3   Ilyes Choubani   Corrected02: Impl...
140
141
  ENDIF
ENDFOR
4750086c   Ilyes Choubani   nouvelle philosph...
142
the_end:
e7938fa3   Ilyes Choubani   Corrected02: Impl...
143

4750086c   Ilyes Choubani   nouvelle philosph...
144
END