Blame view

src/idl/dustem_fit_sed_readme.pro 19.1 KB
5135b194   Jean-Philippe Bernard   cleaned
1
PRO dustem_fit_sed_readme,postcript=postcript,model=model,help=help,png=png,itermax=itermax
427f1205   Jean-Michel Glorian   version 4.2 merged
2

4750086c   Ilyes Choubani   nouvelle philosph...
3

427f1205   Jean-Michel Glorian   version 4.2 merged
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
;This Readme describes how to fit SEDs with dustem
;It runs on the SED stored into the file sample_SED.xcat
;in this directory. Remember that the goal here is not necessarily to
;obtain a good fit in the end, but to illustrate the method.
;The provided SED has only photometric data points from SPITZER
;IRAC and MIPS and IRAS. No spectrum data points.
;SPECTRUM data points can be included and the corresponding filter
;filed must read SPECTRUM. Note that its is note necessary
;to use the .xcat file format, and data SED can be provided
;manually, but the observation structure must have the structure shown below.
;Obviously, the dustem package must have been installed succesfully (see
;dustem_cvs_readme.txt for install instructions).

;+
; NAME:
;    dustem_fit_sed_readme
; PURPOSE:
;    This is an example of how to fit SEDs with the dustem wrapper.
;    It is meant to be an example to follow when writing your own
;    programs using the dustem IDL wrapper.
;    It is not meant to reproduce the result in Compiegne et al 2010
;    The SED used here is in sample_SED.xcat
; CATEGORY:
;    Dustem
; CALLING SEQUENCE:
5135b194   Jean-Philippe Bernard   cleaned
29
;    dustem_fit_sed_readme,postcript=postcript,model=model,help=help
427f1205   Jean-Michel Glorian   version 4.2 merged
30
31
32
33
34
35
36
37
38
; INPUTS:
;    None
; OPTIONAL INPUT PARAMETERS:
;    None
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
5135b194   Jean-Philippe Bernard   cleaned
39
;    model = Selects one of the dust mixture used by dustem
427f1205   Jean-Michel Glorian   version 4.2 merged
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;           'COMPIEGNE_ETAL2010' from Compiegne et al 2010 (default)
;           'DBP90' from Desert et al 1990
;           'DL01' from Draine & Li 2001
;           'DL07' from Draine & Li 2007
;    postcript = if set plot is done in DUSTEM/Docs/Figures/Last_dustem_fit.ps
;    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:
;    None
; EXAMPLES
5135b194   Jean-Philippe Bernard   cleaned
56
;    dustem_fit_sed_readme,model='COMPIEGNE_ETAL2010'
427f1205   Jean-Michel Glorian   version 4.2 merged
57
58
59
60
61
62
; MODIFICATION HISTORY:
;    Written by J.P. Bernard April 1st 2011
;    see evolution details on the dustem cvs maintained at CESR
;    Contact J.-Ph. Bernard (Jean-Philippe.Bernard@cesr.fr) in case of problems.
;-

39afc385   Jean-Philippe Bernard   added 3 empty lin...
63
64
65



427f1205   Jean-Michel Glorian   version 4.2 merged
66
67
68
69
70
IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_fit_sed_readme'
  goto,the_end
ENDIF

5135b194   Jean-Philippe Bernard   cleaned
71
72
IF keyword_set(model) THEN BEGIN
  use_model=strupcase(model)
427f1205   Jean-Michel Glorian   version 4.2 merged
73
ENDIF ELSE BEGIN
607060e5   Ilyes Choubani   test version
74
  use_model='G17_MODELA';'COMPIEGNE_ETAL2010'    ;Default is last dustem model
427f1205   Jean-Michel Glorian   version 4.2 merged
75
76
ENDELSE

e71a7ada   Jean-Philippe Bernard   modified to work ...
77
IF keyword_set(png) THEN BEGIN
3dd007df   Jean-Philippe Bernard   added png plot op...
78
  dir_png=!dustem_dat+'/Figures/'
e71a7ada   Jean-Philippe Bernard   modified to work ...
79
80
81
  force_mkdir,dir_png
ENDIF

7d2d66e7   Ilyes Choubani   replacing polsed,...
82
polarization=0.   ;default is no polarization in models
5c830aef   Jean-Philippe Bernard   removed modificat...
83
;dustem_init,model=use_model,pol=polarization
427f1205   Jean-Michel Glorian   version 4.2 merged
84

4750086c   Ilyes Choubani   nouvelle philosph...
85
86
;COMMENT: for some reson polarization=1 doesn't work for ALL of the models except for the two last A and B models

427f1205   Jean-Michel Glorian   version 4.2 merged
87
;=== Set which parameters you want to fit
666cba76   Jean-Philippe Bernard   cleaned the code
88
CASE use_model OF
427f1205   Jean-Michel Glorian   version 4.2 merged
89
90
91
92
93
94
      'DBP90':BEGIN
         pd = [ $
             '(*!dustem_params).G0', $      ;G0
             '(*!dustem_params).grains(0).mdust_o_mh',$  ;PAH0 mass fraction
             '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
             '(*!dustem_params).grains(2).mdust_o_mh', $    ;amCBEx
7d2d66e7   Ilyes Choubani   replacing polsed,...
95
             'dustem_plugin_continuum_2']                ;Intensity of NIR continuum
427f1205   Jean-Michel Glorian   version 4.2 merged
96
        iv =   [1.0, 4.3e-4, 4.7e-4,6.4e-3,0.001]
427f1205   Jean-Michel Glorian   version 4.2 merged
97
98
99
100
        Npar=n_elements(pd)
        ulimed=replicate(0,Npar)
        llimed=replicate(1,Npar)
        llims=replicate(0.,Npar)
427f1205   Jean-Michel Glorian   version 4.2 merged
101
102
103
104
105
106
107
108
109
     END
      'DL01':BEGIN
         pd = [ $
             '(*!dustem_params).G0', $      ;G0
             '(*!dustem_params).grains(0).mdust_o_mh',$  ;PAH0 mass fraction
             '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
             '(*!dustem_params).grains(2).mdust_o_mh', $    ;Gra
             '(*!dustem_params).grains(3).mdust_o_mh', $    ;Gra
             '(*!dustem_params).grains(4).mdust_o_mh', $    ;aSil
7d2d66e7   Ilyes Choubani   replacing polsed,...
110
             'dustem_plugin_continuum_2']                ;Intensity of NIR continuum
427f1205   Jean-Michel Glorian   version 4.2 merged
111
        iv =   [1.0,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001]
427f1205   Jean-Michel Glorian   version 4.2 merged
112
113
114
115
        Npar=n_elements(pd)
        ulimed=replicate(0,Npar)
        llimed=replicate(1,Npar)
        llims=replicate(0.,Npar)
427f1205   Jean-Michel Glorian   version 4.2 merged
116
117
      END
      'DL07':BEGIN
4750086c   Ilyes Choubani   nouvelle philosph...
118
119
120
121
122
123
          pd = [ $
              '(*!dustem_params).G0', $      ;G0
              '(*!dustem_params).grains(0).mdust_o_mh',$  ;PAH0 mass fraction
              '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
              '(*!dustem_params).grains(2).mdust_o_mh', $    ;Gra
              '(*!dustem_params).grains(3).mdust_o_mh', $    ;Gra
7d2d66e7   Ilyes Choubani   replacing polsed,...
124
125
126
              '(*!dustem_params).grains(4).mdust_o_mh', $    ;aSil
              'dustem_plugin_continuum_2']                ;Intensity of NIR continuum
              ;]  
4750086c   Ilyes Choubani   nouvelle philosph...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
        
;         pd = [ $
;             '(*!dustem_params).gas.G0', $      ;G0
;             '(*!dustem_params).grains(0).mdust_o_mh',$  ;PAH0 mass fraction
;             '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
;             '(*!dustem_params).grains(2).mdust_o_mh', $    ;Gra
;             '(*!dustem_params).grains(3).mdust_o_mh', $    ;Gra
;             '(*!dustem_params).grains(4).mdust_o_mh', $    ;aSil
;             'dustem_create_continuum_2', $
;             'dustem_create_stellar_population_O63',$ ; distance to the O3 stellar population
;             'dustem_create_stellar_population_O65',$ ; number of stars of the O3 stellar population
;             'dustem_create_stellar_population_B43',$ ; distance to the B4 stellar population
;             'dustem_create_stellar_population_B45'$ ; number of stars of the B4 stellar population
;             ]
        
7d2d66e7   Ilyes Choubani   replacing polsed,...
142
        iv =   [1.0,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001];,10,1.,10.,1.]
4750086c   Ilyes Choubani   nouvelle philosph...
143
144
        
        
427f1205   Jean-Michel Glorian   version 4.2 merged
145
146
147
148
        Npar=n_elements(pd)
        ulimed=replicate(0,Npar)
        llimed=replicate(1,Npar)
        llims=replicate(0.,Npar)
4750086c   Ilyes Choubani   nouvelle philosph...
149
        ;llims =[1e-9  ,0.   ,0.   ,0.    ,0.   ,0.   ,0.   ,1.  ,0.   , 1.   ,0.   ]
427f1205   Jean-Michel Glorian   version 4.2 merged
150
151
      END
      'COMPIEGNE_ETAL2010':BEGIN
4750086c   Ilyes Choubani   nouvelle philosph...
152
153
154
        
        ;ORIGINAL LINES
        
0e608856   Jean-Philippe Bernard   improved
155
        ;parameter description of parameters to be fitted
cf92aab3   Jean-Philippe Bernard   improved
156
157
        pd = [ $
              '(*!dustem_params).gas.G0', $      ;G0
cbf75ef0   Ilyes Choubani   dustem_init_plugi...
158
159
              'dustem_plugin_continuum_2', $      ;intensity of NIR continuum
              'dustem_plugin_synchrotron_2',$
cf92aab3   Jean-Philippe Bernard   improved
160
161
162
163
164
165
166
167
168
              '(*!dustem_params).grains(0).mdust_o_mh',$     ;PAH0 mass fraction
              '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
              '(*!dustem_params).grains(2).mdust_o_mh', $    ;amCBEx
              '(*!dustem_params).grains(3).mdust_o_mh', $    ;amCBEx
              '(*!dustem_params).grains(4).mdust_o_mh' $
              ]
        ;initial parameter values for parameters to be fitted   
        iv =   [ $  
          1.0, $
cbf75ef0   Ilyes Choubani   dustem_init_plugi...
169
          0.002,   $ ;intensity of NIR continuum
7d2d66e7   Ilyes Choubani   replacing polsed,...
170
          0.01,$    
cf92aab3   Jean-Philippe Bernard   improved
171
172
173
174
175
176
          7.8e-4,  $ ;mass fraction of  PAH0  
          7.8e-4,  $ ;mass fraction of  PAH1  
          1.65e-4, $ ;mass fraction of  amCBEx
          1.45e-3, $ ;mass fraction of  amCBEx
          7.8e-3   $   ;mass fraction of  
          ]
4750086c   Ilyes Choubani   nouvelle philosph...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
          
;NEW LINES

;========COMMENTS=======
;amplitudes haven't been used so they're by default set to 1.
;using only the below stellar populations produces amplitudes that exceed 1. I do not understand the physical meaning of this.
         
;         pd = [ $
;               '(*!dustem_params).gas.G0', $      ;G0
;               'dustem_create_continuum_2', $      ;intensity of NIR continuum
;               'dustem_create_stellar_population_O63',$ ; distance to the O3 stellar population
;               ;'dustem_create_stellar_population_O64',$ ; amplitude of the O3 stellar population
;               'dustem_create_stellar_population_O65',$ ; number of stars of the O3 stellar population
;               'dustem_create_stellar_population_B43',$ ; distance to the B4 stellar population
;               ;'dustem_create_stellar_population_B44',$ ; amplitude of the B4 stellar population
;               'dustem_create_stellar_population_B45',$ ; number of stars of the B4 stellar population
;               '(*!dustem_params).grains(0).mdust_o_mh',$     ;PAH0 mass fraction
;               '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
;               '(*!dustem_params).grains(2).mdust_o_mh', $    ;amCBEx
;               '(*!dustem_params).grains(3).mdust_o_mh', $    ;amCBEx
;               '(*!dustem_params).grains(4).mdust_o_mh' $
;               ]  
              
cf92aab3   Jean-Philippe Bernard   improved
200
201
202
203
204
205
206
207
208
        ; pd = [ $
        ;       ;'(*!dustem_params).G0', $      ;G0
        ;       '(*!dustem_params).grains(0).mdust_o_mh',$     ;PAH0 mass fraction
        ;       '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
        ;       '(*!dustem_params).grains(2).mdust_o_mh', $    ;amCBEx
        ;       '(*!dustem_params).grains(3).mdust_o_mh', $    ;amCBEx
        ;       '(*!dustem_params).grains(4).mdust_o_mh', $
        ;       ;'dustem_create_continuum_2', $      ;intensity of NIR continuum
        ;       'dustem_create_stellar_population_O63',$ ; distance to the O6 stellar population
4750086c   Ilyes Choubani   nouvelle philosph...
209
              
cf92aab3   Jean-Philippe Bernard   improved
210
        ;       ;'dustem_create_stellar_population_O64',$ ; amplitude of the O6 stellar population
4750086c   Ilyes Choubani   nouvelle philosph...
211
              
cf92aab3   Jean-Philippe Bernard   improved
212
213
        ;       ;'dustem_create_stellar_population_O65',$ ; number of stars of the O6 stellar population
        ;       'dustem_create_stellar_population_B43'$ ; distance to the B4 stellar population
4750086c   Ilyes Choubani   nouvelle philosph...
214
              
cf92aab3   Jean-Philippe Bernard   improved
215
        ;       ;;'dustem_create_stellar_population_B44',$ ; amplitude of the B4 stellar population
4750086c   Ilyes Choubani   nouvelle philosph...
216
              
cf92aab3   Jean-Philippe Bernard   improved
217
218
        ;       ;'dustem_create_stellar_population_B45'$ ; number of stars of the B4 stellar population
        ;       ]        
4750086c   Ilyes Choubani   nouvelle philosph...
219
220
 
          
0e608856   Jean-Philippe Bernard   improved
221
        ;initial parameter values for parameters to be fitted   
cf92aab3   Jean-Philippe Bernard   improved
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
        ; iv =   [ $  
        ;   1.,     $ ;G0
        ;   7.8e-4,  $ ;mass fraction of  PAH0  
        ;   7.8e-4,  $ ;mass fraction of  PAH1  
        ;   1.65e-4, $ ;mass fraction of  amCBEx
        ;   1.45e-3, $ ;mass fraction of  amCBEx
        ;   7.8e-3,   $   ;mass fraction of big grains?
        ;   0.002,   $ ;intensity of NIR continuum    
        ;   10.,$
        ;   ;;1.,$
        ;   1.,$
        ;   10.,$
        ;   ;;1.,$
        ;   1.$  
        ;   ]          
4750086c   Ilyes Choubani   nouvelle philosph...
237
238
;           
        
cf92aab3   Jean-Philippe Bernard   improved
239
240
241
242
243
244
245
246
247
248
249
250
251
252
        ; iv =   [ $  
        ;   7.8e-4,  $ ;mass fraction of  PAH0  
        ;   7.8e-4,  $ ;mass fraction of  PAH1  
        ;   1.65e-4, $ ;mass fraction of  amCBEx
        ;   1.45e-3, $ ;mass fraction of  amCBEx
        ;   7.8e-3,   $   ;mass fraction of big grains?
        ;   ;0.002,   $ ;intensity of NIR continuum    
        ;   10.,$
        ;   ;;1.,$
        ;   ;1.,$
        ;   10.$
        ;   ;;1.,$
        ;   ;1.$  
        ;   ]          
4750086c   Ilyes Choubani   nouvelle philosph...
253
254
255
256
        
        
            
     
427f1205   Jean-Michel Glorian   version 4.2 merged
257
        Npar=n_elements(pd)
4750086c   Ilyes Choubani   nouvelle philosph...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
        
        ;ulimed=[0   ,0   ,0   ,0   ,0   ,0   , 0   ,0   ,0   ,0   ,0   ,0   ,0] 
        ;ulimed=[0   ,0   ,0   ,0   ,0   ,0   , 0   ,0   ,0   ,0] 

        
        ;llimed=[1   , 1   ,1   ,1   ,1   ,1   ,1   ,1   ,1   ,1   ,1   ,1   ,1]
        ;llimed=[1   , 1   ,1   ,1   ,1   ,1   ,1   ,1   ,1   ,1]
        
        ;llims =[0.  ,0.   ,0.  ,0.   , 0.   ,0.   ,0.   ,0.   ,0.   ,0.   ,0.    ,0.   ,0.   ,0.]
        ;llims =[1.  ,0.   ,10.  ,0.   , 0.   ,0.   ,0.   ,0.   ,0.    ,0.   ,0.]
        
        ;lower limiting the stellar distances to 1pc avoid singularities
        ;[1e-9  ,
        ;llims =[1e-5  ,0.   ,0.    ,0.   ,0.   ,0.   ,0.   ,1.  ,0.     , 1.   ,0.   ]  
        
        ;llims =[0.   ,0.    ,0.   ,0.   ,0.   ,0.   ,1.  ,0.     , 1.   ,0.   ]
cf92aab3   Jean-Philippe Bernard   improved
274
        ;llims =[0.    ,0.   ,0.   ,0.   ,0.   ,1.  , 1.   ]
4750086c   Ilyes Choubani   nouvelle philosph...
275
        
427f1205   Jean-Michel Glorian   version 4.2 merged
276
277
        ulimed=replicate(0,Npar)
        llimed=replicate(1,Npar)
cf92aab3   Jean-Philippe Bernard   improved
278
        llims=replicate(0.,Npar)
4750086c   Ilyes Choubani   nouvelle philosph...
279
280
        
        
427f1205   Jean-Michel Glorian   version 4.2 merged
281
        ;=== Fixed parameters
0e608856   Jean-Philippe Bernard   improved
282
        ;parameter description of parameters to be set to a non-default value
4750086c   Ilyes Choubani   nouvelle philosph...
283
        ;fpd=[ $
0e608856   Jean-Philippe Bernard   improved
284
285
          ;'!dustem_isrf_star_add[0].amplitude', $        ;amplitiude of first stellar contribution to ISRF
          ;'!dustem_isrf_star_add[0].distance', $        ;amplitiude of first stellar contribution to ISRF
4750086c   Ilyes Choubani   nouvelle philosph...
286
          ;'(*!dustem_params).gas.G0' $     ;multiplicative factor to total ISRF
0e608856   Jean-Philippe Bernard   improved
287
          ;'dustem_create_continuum_2' $     ;intensity of NIR continuum
4750086c   Ilyes Choubani   nouvelle philosph...
288
          ;  ]
0e608856   Jean-Philippe Bernard   improved
289
        ;initial parameter values for fixed parameters
4750086c   Ilyes Choubani   nouvelle philosph...
290
        ;fiv=[ $
0e608856   Jean-Philippe Bernard   improved
291
292
          ;1.0, $      ;amplitiude of first stellar contribution to ISRF
          ;1.0, $      ;distance of first stellar contribution to ISRF
4750086c   Ilyes Choubani   nouvelle philosph...
293
        ;  1. $        ;multiplicative factor to total ISRF
0e608856   Jean-Philippe Bernard   improved
294
          ;1.e-6 $      ;intensity of NIR continuum
4750086c   Ilyes Choubani   nouvelle philosph...
295
         ;   ]
427f1205   Jean-Michel Glorian   version 4.2 merged
296
      END
4750086c   Ilyes Choubani   nouvelle philosph...
297
     
5135b194   Jean-Philippe Bernard   cleaned
298
299
300
301
302
303
304
305
     'AJ13':BEGIN
        pd = [ $
             '(*!dustem_params).G0', $      ;G0
             '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
             '(*!dustem_params).grains(0).mdust_o_mh',$  ;PAH0 mass fraction
             '(*!dustem_params).grains(2).mdust_o_mh', $    ;amCBEx
             '(*!dustem_params).grains(3).mdust_o_mh', $    ;amCBEx
             '(*!dustem_params).grains(4).mdust_o_mh', $      ;aSil
7d2d66e7   Ilyes Choubani   replacing polsed,...
306
             'dustem_plugin_continuum_2']                ;Intensity of NIR continuum
5135b194   Jean-Philippe Bernard   cleaned
307
308
309
310
311
        iv =   [1.0, 7.8e-4, 7.8e-4,1.65e-4,1.45e-3,7.8e-3,0.001]
        Npar=n_elements(pd)
        ulimed=replicate(0,Npar)
        llimed=replicate(1,Npar)
        llims=replicate(0.,Npar)
5135b194   Jean-Philippe Bernard   cleaned
312
      END
666cba76   Jean-Philippe Bernard   cleaned the code
313
      'G17_MODELA':BEGIN
4750086c   Ilyes Choubani   nouvelle philosph...
314
        ;dustem_init,model=use_model,/pol
666cba76   Jean-Philippe Bernard   cleaned the code
315
316
317
318
319
320
321
322

         pd = [ $
             '(*!dustem_params).G0', $      ;G0
             '(*!dustem_params).grains(0).mdust_o_mh',$  ;PAH0 mass fraction
             '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
             '(*!dustem_params).grains(2).mdust_o_mh', $    ;Gra
             '(*!dustem_params).grains(3).mdust_o_mh', $    ;Gra
             '(*!dustem_params).grains(4).mdust_o_mh', $    ;aSil
7d2d66e7   Ilyes Choubani   replacing polsed,...
323
             'dustem_plugin_continuum_2']                ;Intensity of NIR continuum
666cba76   Jean-Philippe Bernard   cleaned the code
324
325
326
327
328
        iv =   [1.0,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001]
        Npar=n_elements(pd)
        ulimed=replicate(0,Npar)
        llimed=replicate(1,Npar)
        llims=replicate(0.,Npar)
476507cb   Jean-Philippe Bernard   modified
329
        polarization=1
666cba76   Jean-Philippe Bernard   cleaned the code
330
331
332
333
334
335
336
337
338
      END
      'G17_MODELB':BEGIN
         pd = [ $
             '(*!dustem_params).G0', $      ;G0
             '(*!dustem_params).grains(0).mdust_o_mh',$  ;PAH0 mass fraction
             '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
             '(*!dustem_params).grains(2).mdust_o_mh', $    ;Gra
             '(*!dustem_params).grains(3).mdust_o_mh', $    ;Gra
             '(*!dustem_params).grains(4).mdust_o_mh', $    ;aSil
7d2d66e7   Ilyes Choubani   replacing polsed,...
339
             'dustem_plugin_continuum_2']                ;Intensity of NIR continuum
2399e73e   Jean-Philippe Bernard   imprved towards r...
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
        iv =   [1.0,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001]
        Npar=n_elements(pd)
        ulimed=replicate(0,Npar)
        llimed=replicate(1,Npar)
        llims=replicate(0.,Npar)
        polarization=1
      END
      'THEMIS':BEGIN
         pd = [ $
             '(*!dustem_params).G0', $      ;G0
             '(*!dustem_params).grains(0).mdust_o_mh',$  ;PAH0 mass fraction
             '(*!dustem_params).grains(1).mdust_o_mh',$     ;PAH1 mass fraction
             '(*!dustem_params).grains(2).mdust_o_mh', $    ;Gra
             '(*!dustem_params).grains(3).mdust_o_mh', $    ;Gra
             '(*!dustem_params).grains(4).mdust_o_mh', $    ;aSil
             'dustem_plugin_continuum_2']                ;Intensity of NIR continuum
666cba76   Jean-Philippe Bernard   cleaned the code
356
357
358
359
360
361
362
363
        iv =   [1.0,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001]
        Npar=n_elements(pd)
        ulimed=replicate(0,Npar)
        llimed=replicate(1,Npar)
        llims=replicate(0.,Npar)
        polarization=1
      END

427f1205   Jean-Michel Glorian   version 4.2 merged
364
365
ENDCASE

5c830aef   Jean-Philippe Bernard   removed modificat...
366
367
368
dustem_init,model=use_model,pol=polarization
!dustem_nocatch=1

4750086c   Ilyes Choubani   nouvelle philosph...
369
;dustem_init,model=use_model,pol=polarization
452c334e   Ilyes Choubani   Implementation Of...
370

666cba76   Jean-Philippe Bernard   cleaned the code
371
372
!dustem_verbose=1
!dustem_show_plot=1
427f1205   Jean-Michel Glorian   version 4.2 merged
373

452c334e   Ilyes Choubani   Implementation Of...
374

666cba76   Jean-Philippe Bernard   cleaned the code
375
376
377
378
;=== Read sample SED
;=== Composite SED from Compiegne et al 2010, gathered by C. Bot
dir=!dustem_wrap_soft_dir+'/Data/SEDs/'
file=dir+'Gal_composite_spectrum.xcat'
5a7a4415   Jean-Philippe Bernard   adapted to new fi...
379
;file=dir+'Gal_composite_spectrum.xcat.old'
427f1205   Jean-Michel Glorian   version 4.2 merged
380

666cba76   Jean-Philippe Bernard   cleaned the code
381
spec=read_xcat(file,/silent)
476507cb   Jean-Philippe Bernard   modified
382

5a7a4415   Jean-Philippe Bernard   adapted to new fi...
383
384
385
386
;ind=where(spec.error EQ 0.,count)
;IF count NE 0 THEN spec(ind).error=0.2*spec(ind).spec
ind=where(spec.sigmaII EQ 0.,count)
IF count NE 0 THEN spec(ind).sigmaII=(0.2*spec(ind).StokesI)^2
666cba76   Jean-Philippe Bernard   cleaned the code
387
ind=where(spec.instru EQ 'FIRAS',count)
5a7a4415   Jean-Philippe Bernard   adapted to new fi...
388
389
;IF count NE 0 THEN spec(ind).error=0.2*spec(ind).spec
IF count NE 0 THEN spec(ind).sigmaII=(0.2*spec(ind).StokesI)^2
452c334e   Ilyes Choubani   Implementation Of...
390

666cba76   Jean-Philippe Bernard   cleaned the code
391
;=== SET THE OBSERVATION STRUCTURE
427f1205   Jean-Michel Glorian   version 4.2 merged
392
393
st=dustem_set_data(sed=spec)

427f1205   Jean-Michel Glorian   version 4.2 merged
394
395
;== SET THE FITTED PARAMETERS
dustem_init_parinfo,pd,iv,up_limited=ulimed,lo_limited=llimed,up_limits=ulims,lo_limits=llims
5135b194   Jean-Philippe Bernard   cleaned
396

f882e687   Ilyes Choubani   improved
397

4750086c   Ilyes Choubani   nouvelle philosph...
398
;dustem_init_fixed_params,fpd,fiv
0e608856   Jean-Philippe Bernard   improved
399

452c334e   Ilyes Choubani   Implementation Of...
400
401
402
403
dustem_init_plugins, pd ;initializing the scopes of the plugins to be read later



427f1205   Jean-Michel Glorian   version 4.2 merged
404
;=== RUN fit
4750086c   Ilyes Choubani   nouvelle philosph...
405
tol=1.e-16
cf92aab3   Jean-Philippe Bernard   improved
406
407
;use_Nitermax=50 ;maximum number of iteration. This is the criterium which will stop the fit procedure , NOTA BENE: 3 iterations aren't enough to fit the entirety of the newly added stellar population parameters.
use_Nitermax=5 ;maximum number of iteration. This is the criterium which will stop the fit procedure , NOTA BENE: 3 iterations aren't enough to fit the entirety of the newly added stellar population parameters.
5135b194   Jean-Philippe Bernard   cleaned
408
IF keyword_set(itermax) THEN use_Nitermax=itermax
427f1205   Jean-Michel Glorian   version 4.2 merged
409

427f1205   Jean-Michel Glorian   version 4.2 merged
410
t1=systime(0,/sec)
4750086c   Ilyes Choubani   nouvelle philosph...
411
412
413
414
415
yr=[1e-4,100]
xr=[1,6e4]
;legend_xpos=0.6
;legend_ypos=0.8
tit='Spectral Energy Distribution (Running)'
9be94157   Jean-Philippe Bernard   improved
416
417
418
419
ytit=textoidl('I_\nu (MJy/sr) for N_H=10^{20} H/cm^2')
xtit=textoidl('\lambda (\mum)')
res=dustem_mpfit_data(tol=tol,Nitermax=use_Nitermax,gtol=gtol,/xlog,/ylog,xr=xr,yr=yr,xtit=xtit,ytit=ytit,title=tit,legend_xpos=legend_xpos,legend_ypos=legend_ypos,errors=errors,chi2=chi2,rchi2=rchi2)

427f1205   Jean-Michel Glorian   version 4.2 merged
420
421
t2=systime(0,/sec)

427f1205   Jean-Michel Glorian   version 4.2 merged
422
;=== SAVE FIT RESULTS
66aff855   Jean-Philippe Bernard   modified to impro...
423
file_out='/tmp/DUSTEM_fit_example.sav'
66aff855   Jean-Philippe Bernard   modified to impro...
424
425
426
dustem_save_system_variables,file_out
message,'Saved '+file_out,/continue

e71a7ada   Jean-Philippe Bernard   modified to work ...
427
;stop
66aff855   Jean-Philippe Bernard   modified to impro...
428
429
430
431
432
433
434
435

;======================================
;====You can exit IDL here and re-enter
;======================================

file='/tmp/DUSTEM_fit_example.sav'
dustem_restore_system_variables,file

427f1205   Jean-Michel Glorian   version 4.2 merged
436
;=== Plot best fit
4750086c   Ilyes Choubani   nouvelle philosph...
437
tit='Spectral Energy Distribution (Saved)'
427f1205   Jean-Michel Glorian   version 4.2 merged
438
439
440
441
442
443
ytit=textoidl('I_\nu (MJy/sr) for N_H=10^{20} H/cm^2')
xtit=textoidl('\lambda (\mum)')
errors=(*(*!dustem_fit).current_param_errors)*(*(*!dustem_fit).param_init_values)
chi2=(*!dustem_fit).chi2
rchi2=(*!dustem_fit).rchi2

68d2f391   Jean-Philippe Bernard   modified to cope ...
444
window,2
427f1205   Jean-Michel Glorian   version 4.2 merged
445
446

;=== RESTORE FIT RESULTS
427f1205   Jean-Michel Glorian   version 4.2 merged
447
448
449
res=*(*!dustem_fit).current_param_values
chi2=(*!dustem_fit).chi2
rchi2=(*!dustem_fit).rchi2
66aff855   Jean-Philippe Bernard   modified to impro...
450
errors=(*(*!dustem_fit).current_param_errors)*(*(*!dustem_fit).param_init_values)
427f1205   Jean-Michel Glorian   version 4.2 merged
451
452

;=== Plot best fit
427f1205   Jean-Michel Glorian   version 4.2 merged
453
454
455
456
loadct,13
IF keyword_set(postcript) THEN BEGIN
  set_plot,'PS'
;  ps_file=getenv('DUSTEM_SOFT_DIR')+'/Docs/Figures/'+'Last_dustem_fit.ps'
4750086c   Ilyes Choubani   nouvelle philosph...
457
  ps_file=!dustem_wrap_soft_dir+'Docs/Figures/'+'Last_dustem_fit.ps'
427f1205   Jean-Michel Glorian   version 4.2 merged
458
459
  device,filename=ps_file,/color
ENDIF
e71a7ada   Jean-Philippe Bernard   modified to work ...
460

427f1205   Jean-Michel Glorian   version 4.2 merged
461
;dustem_sed_plot,(*!dustem_fit_params),ytit=ytit,xtit=xtit,title=tit,yr=yr,xr=xr,/ysty,/xsty,res=res,errors=errors,chi2=chi2,rchi2=rchi2
e71a7ada   Jean-Philippe Bernard   modified to work ...
462
dustem_sed_plot,*(*!dustem_fit).current_param_values,ytit=ytit,xtit=xtit,title=tit,yr=yr,xr=xr,/ysty,/xsty,res=res,errors=errors,chi2=chi2,rchi2=rchi2,/xlog,/ylog,legend_xpos=legend_xpos,legend_ypos=legend_ypos
427f1205   Jean-Michel Glorian   version 4.2 merged
463
464
465
466
467
IF keyword_set(postcript) THEN BEGIN
  device,/close
  set_plot,'X'
  message,'wrote '+ps_file,/info
ENDIF
e71a7ada   Jean-Philippe Bernard   modified to work ...
468
469
470
471
472
473
IF keyword_set(png) THEN BEGIN
  ;file_png=!dustem_wrap_soft_dir+'/Docs/Figures/'+'Last_dustem_fit.png'
  file_png=dir_png+'Last_dustem_fit_sed_readme.png'
  write_png,file_png,tvrd(/true)
  message,'Wrote '+file_png,/info
ENDIF
427f1205   Jean-Michel Glorian   version 4.2 merged
474
475
476
477
478
479

message,'dustem_mpfit_sed executed in '+strtrim(t2-t1,2)+' sec',/info

the_end:

END