Commit fe2ab57b99f255938eaad551b8202d995a732c27

Authored by Annie Hughes
1 parent 79bbc7a3
Exists in master

improved comments and removed unimplemented keywords

Showing 1 changed file with 103 additions and 110 deletions   Show diff stats
src/idl/dustem_fit_intensity_example.pro
1 PRO dustem_fit_intensity_example,model=model $ 1 PRO dustem_fit_intensity_example,model=model $
2 ,sed_file=sed_file $ 2 ,sed_file=sed_file $
3 ,Nitermax=Nitermax $ 3 ,Nitermax=Nitermax $
4 - ,postscript=postscript $  
5 ,fits_save=fits_save $ 4 ,fits_save=fits_save $
6 ,help=help $ 5 ,help=help $
7 ,wait=wait $ 6 ,wait=wait $
@@ -31,7 +30,7 @@ PRO dustem_fit_intensity_example,model=model $ @@ -31,7 +30,7 @@ PRO dustem_fit_intensity_example,model=model $
31 ; DustEMWrap, Distributed, High-Level, User Example 30 ; DustEMWrap, Distributed, High-Level, User Example
32 ; 31 ;
33 ; CALLING SEQUENCE: 32 ; CALLING SEQUENCE:
34 -; dustem_fit_intensity_example[,model=][sed_file=][,postscript=][,Nitermax=][,fits_save=][,/help,/wait,/verbose] 33 +; dustem_fit_intensity_example[,model=][sed_file=][,Nitermax=][,fits_save=][,/help,/wait,/verbose]
35 ; 34 ;
36 ; INPUTS: 35 ; INPUTS:
37 ; None 36 ; None
@@ -45,16 +44,15 @@ PRO dustem_fit_intensity_example,model=model $ @@ -45,16 +44,15 @@ PRO dustem_fit_intensity_example,model=model $
45 ; OPTIONAL OUTPUT PARAMETERS: 44 ; OPTIONAL OUTPUT PARAMETERS:
46 ; Plots, results structure in binary FITS table format 45 ; Plots, results structure in binary FITS table format
47 ; 46 ;
48 -; ACCEPTED KEY-WORDS: 47 +; ACCEPTED KEY-WORDS
49 ; model = specifies the interstellar dust mixture used by 48 ; model = specifies the interstellar dust mixture used by
50 ; DustEM. See userguide or dustem_test_model_exists.pro 49 ; DustEM. See userguide or dustem_test_model_exists.pro
51 ; for more details about available models in current release. 50 ; for more details about available models in current release.
52 ; sed_file = string naming the path to text file in .xcat format that 51 ; sed_file = string naming the path to text file in .xcat format that
53 ; describes the observational SED. If not set, the file 52 ; describes the observational SED. If not set, the file
54 ; 'Data/EXAMPLE_OBSDATA/example_SED_1.xcat' is used. 53 ; 'Data/EXAMPLE_OBSDATA/example_SED_1.xcat' is used.
55 -; postscript = if set, final plot is saved as postscript file  
56 ; Nitermax = maximum number of fit iterations. Default is 5. 54 ; Nitermax = maximum number of fit iterations. Default is 5.
57 -; fits_save = if set, save the fit results in a binary 55 +; fits_save = if set, save the DustEMWrap fitting results in a binary
58 ; FITS file. 56 ; FITS file.
59 ; help = if set, print this help 57 ; help = if set, print this help
60 ; wait = if set, wait this many seconds between each step of 58 ; wait = if set, wait this many seconds between each step of
@@ -90,23 +88,27 @@ IF keyword_set(help) THEN BEGIN @@ -90,23 +88,27 @@ IF keyword_set(help) THEN BEGIN
90 goto,the_end 88 goto,the_end
91 END 89 END
92 90
  91 +;; ;===================================
  92 +;; ;=== SET THE DUST MODEL HERE
  93 +;; ;===================================
93 IF keyword_set(model) THEN BEGIN 94 IF keyword_set(model) THEN BEGIN
94 use_model=strupcase(model) 95 use_model=strupcase(model)
95 ENDIF ELSE BEGIN 96 ENDIF ELSE BEGIN
96 use_model='DBP90' ;Example with default keywords uses the DBP90 model 97 use_model='DBP90' ;Example with default keywords uses the DBP90 model
97 ENDELSE 98 ENDELSE
98 -  
99 -exists=dustem_test_model_exists(use_model) 99 +use_polarization=0 ; here we initialize DustEMWrap in no polarization mode since we are only fitting Stokes I
  100 +exists=dustem_test_model_exists(use_model,/silent)
100 if exists ne 1 then $ 101 if exists ne 1 then $
101 message,'Unknown dust model' 102 message,'Unknown dust model'
102 103
103 -use_polarization=0 ; initialize Dustemwrap in no polarization mode  
104 -use_window=2 ; default graphics window number to use for plotting the results 104 +;; ;===================================
  105 +;; ;=== PARSE OTHER INPUTS AND SET SOME BASIC RUN PARAMETERS
  106 +;; ;===================================
105 use_verbose=0 107 use_verbose=0
106 if keyword_set(verbose) then use_verbose=1 108 if keyword_set(verbose) then use_verbose=1
107 use_Nitermax=5 ; maximum number of iterations for the fit 109 use_Nitermax=5 ; maximum number of iterations for the fit
108 IF keyword_set(Nitermax) THEN use_Nitermax=Nitermax 110 IF keyword_set(Nitermax) THEN use_Nitermax=Nitermax
109 - 111 +use_window=0 ; default graphics window number to use for plotting the results
110 dustem_define_la_common 112 dustem_define_la_common
111 113
112 ;=== Set the (model-dependent) parameters that you want to fit (pd), 114 ;=== Set the (model-dependent) parameters that you want to fit (pd),
@@ -120,22 +122,27 @@ dustem_define_la_common @@ -120,22 +122,27 @@ dustem_define_la_common
120 ;=== Examples are provided for some of the dust models. 122 ;=== Examples are provided for some of the dust models.
121 ;=== To try them, uncomment the model that you want to try and re-run 123 ;=== To try them, uncomment the model that you want to try and re-run
122 124
123 -;=== AN EXAMPLE FOR DBP90 125 +;; ;===================================
  126 +;; ;=== AN EXAMPLE FOR DBP90
  127 +;; ;===================================
124 ;=== Here we fit the dust abundances of the DBP90 model, the 128 ;=== Here we fit the dust abundances of the DBP90 model, the
125 -;=== intensity of the dust-heating radiation field, as well as a plug-in  
126 -;=== for synchrotron emission 129 +;=== intensity of the dust-heating radiation field. We also invoke a plug-in
  130 +;=== for that fits parameters of synchrotron emission
127 ;=== The free parameters are all lower-bounded at zero. 131 ;=== The free parameters are all lower-bounded at zero.
128 -;=== use_model='DBP90' ; you should specify this above! 132 +;=== use_model='DBP90' ; you should specify this above (line 93)
  133 +
  134 +;=== pd is the structure of free parameters
129 pd = [ $ 135 pd = [ $
130 '(*!dustem_params).G0', $ ;G0 136 '(*!dustem_params).G0', $ ;G0
131 '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction 137 '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction
132 '(*!dustem_params).grains(1).mdust_o_mh',$ ;VSG mass fraction 138 '(*!dustem_params).grains(1).mdust_o_mh',$ ;VSG mass fraction
133 - '(*!dustem_params).grains(2).mdust_o_mh'];,$ ;BG mass fraction  
134 -; 'dustem_plugin_synchrotron_1', $ ;Spectral index of CREs  
135 -; 'dustem_plugin_synchrotron_2'] ;Synchrotron amplitude at 10 mm 139 + '(*!dustem_params).grains(2).mdust_o_mh'];,$ ;BG mass fraction
  140 +; 'dustem_plugin_synchrotron_1', $ ;Spectral index of CREs
  141 +; 'dustem_plugin_synchrotron_2'] ;Synchrotron amplitude at 10 mm
136 142
137 -; initial values vector for run without synchrotron plugin  
138 -; [G0,PAH0,VSG,BG] 143 +;=== iv is the vector of initial values for the free parameters
  144 +;=== following lines are for a run without fitting the synchrotron
  145 +;=== i.e. [ initial values for G0,PAH0,VSG,BG]
139 iv = [1.6, 2.2e-4, 5.7e-4, 3.4e-3] 146 iv = [1.6, 2.2e-4, 5.7e-4, 3.4e-3]
140 147
141 ; initial values vector for run including the synchrotron plugin 148 ; initial values vector for run including the synchrotron plugin
@@ -143,13 +150,15 @@ iv = [1.6, 2.2e-4, 5.7e-4, 3.4e-3] @@ -143,13 +150,15 @@ iv = [1.6, 2.2e-4, 5.7e-4, 3.4e-3]
143 ;iv = [1.6, 2.2e-4, 5.7e-4, 3.4e-3, 2.7,0.01] 150 ;iv = [1.6, 2.2e-4, 5.7e-4, 3.4e-3, 2.7,0.01]
144 151
145 ; initial values vector for run including the synchrotron plugin and 152 ; initial values vector for run including the synchrotron plugin and
146 -; fixing the G0 and BB continuum parameters 153 +; fixing the G0 and BB continuum parameters (see below)
  154 +; [PAH0,VSG,BG,alpha_CR,Amp_syn]
147 ;iv = [2.2e-4, 5.7e-4, 3.4e-3, 2.7,0.01] 155 ;iv = [2.2e-4, 5.7e-4, 3.4e-3, 2.7,0.01]
148 156
149 Npar=n_elements(pd) 157 Npar=n_elements(pd)
150 -ulimed=replicate(0,Npar)  
151 -llimed=replicate(1,Npar)  
152 -llims=replicate(1.e-15,Npar) 158 +ulimed=replicate(0,Npar) ; flag ON=1, OFF=0
  159 +llimed=replicate(1,Npar) ; flag ON=1, OFF=0
  160 +llims=replicate(1.e-15,Npar) ; lower limit value for each free parameter
  161 +; ulims=replicate(1.e15,Npar) ; upper limit value for each free parameter
153 fpd=[] & fiv=[] 162 fpd=[] & fiv=[]
154 163
155 ; example using fixed parameters (ISRF and a NIR continuum) 164 ; example using fixed parameters (ISRF and a NIR continuum)
@@ -164,40 +173,51 @@ fpd=[] & fiv=[] @@ -164,40 +173,51 @@ fpd=[] & fiv=[]
164 ;fiv=[0.5,750,1.e-2] 173 ;fiv=[0.5,750,1.e-2]
165 174
166 ;; ;================================== 175 ;; ;==================================
167 -;; ;=== EXAMPLES FOR OTHER DUST MODELS 176 +;; ;=== EXAMPLES FOR OTHER PHYSICAL DUST MODELS
168 ;; ;=== START BELOW HERE 177 ;; ;=== START BELOW HERE
169 ;; ;================================== 178 ;; ;==================================
170 179
171 - 180 +;; ;===================================
172 ;; ;=== AN EXAMPLE FOR DL07 181 ;; ;=== AN EXAMPLE FOR DL07
  182 +;; ;===================================
173 ;; ;=== Here we fit the dust abundances of the model and the 183 ;; ;=== Here we fit the dust abundances of the model and the
174 ;; ;=== intensity of the ISRF (via gas.G0 since the model 184 ;; ;=== intensity of the ISRF (via gas.G0 since the model
175 ;; ;=== includes spinning dust) 185 ;; ;=== includes spinning dust)
176 ;; ;=== The free parameters are all lower-bounded at zero. 186 ;; ;=== The free parameters are all lower-bounded at zero.
177 -;; use_model='DL07' ; you should specify this above, or in the command line  
178 -;; pd = [ '(*!dustem_params).gas.G0'], $ 187 +;; ;=== use_model='DL07' ; you should specify this above (line 93), or in the command line when you run the example
  188 +;; pd = [ '(*!dustem_params).gas.G0'], $ ;G0
179 ;; '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction 189 ;; '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction
180 ;; '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction 190 ;; '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction
181 ;; '(*!dustem_params).grains(2).mdust_o_mh', $ ;Gra 191 ;; '(*!dustem_params).grains(2).mdust_o_mh', $ ;Gra
182 ;; '(*!dustem_params).grains(3).mdust_o_mh', $ ;Gra 192 ;; '(*!dustem_params).grains(3).mdust_o_mh', $ ;Gra
183 ;; '(*!dustem_params).grains(4).mdust_o_mh'] ;aSil 193 ;; '(*!dustem_params).grains(4).mdust_o_mh'] ;aSil
184 -;; iv = [1.5 ,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3]  
185 -;; Npar=n_elements(pd)  
186 -;; ulimed=replicate(0,Npar)  
187 -;; llimed=replicate(1,Npar)  
188 -;; llims=replicate(1.e-15,Npar)  
189 -;; ; fpd=['(*!dustem_params).gas.G0']  
190 -;; ; fiv=[2.]  
191 -  
192 -  
193 -;; ;; ;=== AN EXAMPLE FOR MC10 194 +;; iv = [1.5 ,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3]
  195 +;;
  196 +;; ;=== Uncomment the following lines if you want to fix the ISRF instead of leaving it as a free parameter
  197 +;; ;pd = ['(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction
  198 +;; ; '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction
  199 +;; ; '(*!dustem_params).grains(2).mdust_o_mh', $ ;Gra
  200 +;; ; '(*!dustem_params).grains(3).mdust_o_mh', $ ;Gra
  201 +;; ; '(*!dustem_params).grains(4).mdust_o_mh'] ;aSil
  202 +;; ;iv = [5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3]
  203 +;; ;fpd=['(*!dustem_params).gas.G0']
  204 +;; ;fiv=[2.]
  205 +;;
  206 +;; Npar=n_elements(pd)
  207 +;; ulimed=replicate(0,Npar)
  208 +;; llimed=replicate(1,Npar)
  209 +;; llims=replicate(1.e-15,Npar)
  210 +
  211 +;; ;===================================
  212 +;; ;=== AN EXAMPLE FOR MC10
  213 +;; ;===================================
194 ;; ;; ;=== Here we fit the dust abundances of the MC10 model, the 214 ;; ;; ;=== Here we fit the dust abundances of the MC10 model, the
195 ;; ;; ;=== intensity of the dust-heating radiation field as well as a plug-in: 215 ;; ;; ;=== intensity of the dust-heating radiation field as well as a plug-in:
196 ;; ;; ;=== (i) continuum due to a blackbody 216 ;; ;; ;=== (i) continuum due to a blackbody
197 ;; ;; ;=== The intensity of the dust-heating radiation field is fixed to 217 ;; ;; ;=== The intensity of the dust-heating radiation field is fixed to
198 ;; ;; ;=== 1.5*G0 and the tmperature of the blackbody is fixed to 1200K 218 ;; ;; ;=== 1.5*G0 and the tmperature of the blackbody is fixed to 1200K
199 ;; ;; ;=== The free parameters in the fit are lower-bounded at zero. 219 ;; ;; ;=== The free parameters in the fit are lower-bounded at zero.
200 -;; use_model='MC10' ; you should specify this above, or in the command line 220 +;; ;; ;=== use_model='MC10' ; you should specify this above, or in the command line
201 ;; pd = [ $ 221 ;; pd = [ $
202 ;; '(*!dustem_params).grains(0).mdust_o_mh'$ ;PAH0 mass fraction 222 ;; '(*!dustem_params).grains(0).mdust_o_mh'$ ;PAH0 mass fraction
203 ;; ,'(*!dustem_params).grains(1).mdust_o_mh' $ ;PAH1 mass fraction 223 ;; ,'(*!dustem_params).grains(1).mdust_o_mh' $ ;PAH1 mass fraction
@@ -217,16 +237,17 @@ fpd=[] & fiv=[] @@ -217,16 +237,17 @@ fpd=[] & fiv=[]
217 ;; ] 237 ;; ]
218 ;; fiv=[1.5, 1200.] 238 ;; fiv=[1.5, 1200.]
219 239
220 -  
221 - 240 +;; ;===================================
222 ;; ;=== AN EXAMPLE FOR J13 241 ;; ;=== AN EXAMPLE FOR J13
  242 +;; ;===================================
223 ;; ;=== Here we fit the dust abundances of the J13 model, the 243 ;; ;=== Here we fit the dust abundances of the J13 model, the
224 -;; ;=== intensity of the dust-heating radiation field as well as two plug-ins: 244 +;; ;=== intensity of the dust-heating radiation field as well as the free
  245 +;; ;=== parameters of two plug-ins:
225 ;; ;=== (i) free-free emission 246 ;; ;=== (i) free-free emission
226 ;; ;=== (ii)continuum due to a blackbody 247 ;; ;=== (ii)continuum due to a blackbody
227 ;; ;=== The temperature of the blackbody is fixed to 1000K 248 ;; ;=== The temperature of the blackbody is fixed to 1000K
228 ;; ;=== The free parameters in the fit are all lower-bounded at zero. 249 ;; ;=== The free parameters in the fit are all lower-bounded at zero.
229 -;; use_model='J13' ; you should specify this above, or in the command line 250 +;; ;=== use_model='J13' ; you should specify this above, or in the command line
230 ;; pd = [ $ 251 ;; pd = [ $
231 ;; '(*!dustem_params).G0' $ ;G0 252 ;; '(*!dustem_params).G0' $ ;G0
232 ;; ,'(*!dustem_params).grains(0).mdust_o_mh'$ ;CM20 -- power law size distribution 253 ;; ,'(*!dustem_params).grains(0).mdust_o_mh'$ ;CM20 -- power law size distribution
@@ -235,36 +256,27 @@ fpd=[] & fiv=[] @@ -235,36 +256,27 @@ fpd=[] & fiv=[]
235 ;; ,'(*!dustem_params).grains(3).mdust_o_mh' $ ;aOlM5 256 ;; ,'(*!dustem_params).grains(3).mdust_o_mh' $ ;aOlM5
236 ;; ,'dustem_plugin_freefree_1' $ ;ionized gas temperature 257 ;; ,'dustem_plugin_freefree_1' $ ;ionized gas temperature
237 ;; ,'dustem_plugin_freefree_2' $ ;free-free amplitude 258 ;; ,'dustem_plugin_freefree_2' $ ;free-free amplitude
238 -;; ,'dustem_plugin_continuum_2'] ;Intensity at peak of the BB continuum 259 +;; ,'dustem_plugin_continuum_2'] ;intensity at peak of the BB continuum
239 ;; iv = [1.2,1.7e-3, 6.3e-4, 2.55e-3, 2.55e-3, 7500., 0.4, 0.001] 260 ;; iv = [1.2,1.7e-3, 6.3e-4, 2.55e-3, 2.55e-3, 7500., 0.4, 0.001]
  261 +;; fpd=[ 'dustem_plugin_continuum_1'] ; Temperature of the BB
  262 +;; fiv=[1000.]
240 ;; Npar=n_elements(pd) 263 ;; Npar=n_elements(pd)
241 ;; ulimed=replicate(0,Npar) 264 ;; ulimed=replicate(0,Npar)
242 ;; llimed=replicate(1,Npar) 265 ;; llimed=replicate(1,Npar)
243 ;; llims=replicate(1.e-15,Npar) 266 ;; llims=replicate(1.e-15,Npar)
244 -;; fpd=[ 'dustem_plugin_continuum_1'] ; Temperature of the BB  
245 -;; fiv=[1000.]  
246 -  
247 -  
248 -;;Nfix=n_elements(fpd)  
249 -;;if n_elements(fiv) ne Nfix then begin  
250 -;; message,'Number of fixed parameters (fpd) does not equal number of initial values of fixed parameters (fiv)',/info  
251 -;; stop  
252 -;;end  
253 -  
254 -if keyword_set(wait) then begin  
255 - message,'Finished setting dust model and plug-in parameters: '+use_model,/info  
256 - wait,wait  
257 -end  
258 267
259 -;== INITIALISE DUSTEM  
260 -dustem_init,model=use_model,polarization=use_polarization,/show_plot  
261 -;stop 268 +;;===================================
  269 +;;=== INITIALISE DUSTEM
  270 +;;===================================
  271 +dustem_init,model=use_model,polarization=use_polarization
262 !dustem_nocatch=1 272 !dustem_nocatch=1
263 !dustem_verbose=use_verbose 273 !dustem_verbose=use_verbose
264 IF keyword_set(noobj) THEN !dustem_noobj=1 274 IF keyword_set(noobj) THEN !dustem_noobj=1
265 !EXCEPT=2 ; for debugging 275 !EXCEPT=2 ; for debugging
266 276
267 -;=== READ EXAMPLE SED DATA 277 +;;===================================
  278 +;;=== READ EXAMPLE SED DATA
  279 +;;===================================
268 dir=!dustem_wrap_soft_dir+'/Data/EXAMPLE_OBSDATA/' 280 dir=!dustem_wrap_soft_dir+'/Data/EXAMPLE_OBSDATA/'
269 file=dir+'example_SED_1.xcat' 281 file=dir+'example_SED_1.xcat'
270 IF keyword_set(sed_file) THEN file=sed_file 282 IF keyword_set(sed_file) THEN file=sed_file
@@ -275,17 +287,22 @@ if keyword_set(wait) then begin @@ -275,17 +287,22 @@ if keyword_set(wait) then begin
275 wait,wait 287 wait,wait
276 end 288 end
277 289
  290 +;;===================================
278 ;;=== ADJUST THE UNCERTAINTIES FROM WITHIN THE CODE (FOR ILLUSTRATION) 291 ;;=== ADJUST THE UNCERTAINTIES FROM WITHIN THE CODE (FOR ILLUSTRATION)
  292 +;;===================================
279 ind=where(sed.sigmaII LT (0.2*sed.StokesI)^2,count) 293 ind=where(sed.sigmaII LT (0.2*sed.StokesI)^2,count)
280 IF count NE 0 THEN sed[ind].sigmaII=(0.2*sed[ind].StokesI)^2 294 IF count NE 0 THEN sed[ind].sigmaII=(0.2*sed[ind].StokesI)^2
281 295
282 -;== SET THE OBSERVATIONAL STRUCTURE  
283 -;== sed is passed twice in the call -- the first occurrence is the SED that you  
284 -;== wish to fit, the second occurrence is the SED that you wish to visualise. 296 +;;===================================
  297 +;=== SET THE OBSERVATIONAL STRUCTURE
  298 +;;===================================
  299 +;== sed is passed twice in the call -- the first occurrence (m_sed) is the SED that you
  300 +;== wish to fit, the second occurrence (m_show) is the SED that you wish to visualise.
285 dustem_set_data,m_fit=sed,m_show=sed 301 dustem_set_data,m_fit=sed,m_show=sed
286 302
287 -;== SET INITIAL VALUES AND LIMITS OF THE PARAMETERS THAT WILL BE  
288 -;== ADJUSTED DURING THE FIT 303 +;;===================================
  304 +;=== INITIALISE DUSTEM WITH INITIAL VALUES AND LIMITS OF ALL PARAMETERS
  305 +;;===================================
289 dustem_init_params,use_model,pd,iv,fpd=fpd,fiv=fiv,ulimed=ulimed,llimed=llimed,ulims=ulims,llims=llims 306 dustem_init_params,use_model,pd,iv,fpd=fpd,fiv=fiv,ulimed=ulimed,llimed=llimed,ulims=ulims,llims=llims
290 307
291 308
@@ -294,18 +311,24 @@ if keyword_set(wait) then begin @@ -294,18 +311,24 @@ if keyword_set(wait) then begin
294 wait,wait 311 wait,wait
295 end 312 end
296 313
297 -;=== INFORMATION TO RUN THE FIT 314 +;;===================================
  315 +;;=== INFORMATION TO RUN THE FIT
  316 +;;===================================
298 tol=1.e-16 ;fit tolerence 317 tol=1.e-16 ;fit tolerence
299 318
300 -;=== INFORMATION TO MAKE THE PLOT 319 +;;===================================
  320 +;;=== INFORMATION TO MAKE THE PLOT
  321 +;;===================================
301 yr=[1.00e-4,1.00E2] ; y-axis limits 322 yr=[1.00e-4,1.00E2] ; y-axis limits
302 xr=[1.00E0,6.00e4] ; x-axis limits 323 xr=[1.00E0,6.00e4] ; x-axis limits
303 tit='FIT INTENSITY EXAMPLE' ; plot title 324 tit='FIT INTENSITY EXAMPLE' ; plot title
304 ytit=textoidl('I_\nu (MJy/sr) for N_H=10^{20} H/cm^2') ; y-axis title 325 ytit=textoidl('I_\nu (MJy/sr) for N_H=10^{20} H/cm^2') ; y-axis title
305 xtit=textoidl('\lambda (\mum)') ; x-axis title 326 xtit=textoidl('\lambda (\mum)') ; x-axis title
306 327
307 -;stop  
308 -;=== RUN THE FIT 328 +
  329 +;;===================================
  330 +;;=== RUN THE FIT
  331 +;;===================================
309 t1=systime(0,/sec) 332 t1=systime(0,/sec)
310 res=dustem_mpfit_data(tol=tol,Nitermax=use_Nitermax,gtol=gtol $ 333 res=dustem_mpfit_data(tol=tol,Nitermax=use_Nitermax,gtol=gtol $
311 ,/xlog,/ylog,xr=xr,yr=yr,xtit=xtit,ytit=ytit,title=tit $ 334 ,/xlog,/ylog,xr=xr,yr=yr,xtit=xtit,ytit=ytit,title=tit $
@@ -319,58 +342,28 @@ if keyword_set(wait) then begin @@ -319,58 +342,28 @@ if keyword_set(wait) then begin
319 wait,wait 342 wait,wait
320 end 343 end
321 344
322 -;=== MAKE THE FINAL PLOT  
323 -IF keyword_set(postscript) THEN BEGIN  
324 -; dir_ps='./'  
325 - mydevice=!d.name  
326 - set_plot,'PS'  
327 -; ps_file=dir_ps+postscript  
328 - ps_file=postscript  
329 - device,filename=ps_file,/color  
330 -ENDIF  
331 -  
332 -;stop  
333 - 345 +;;===================================
  346 +;;=== MAKE THE FINAL PLOT
  347 +;;===================================
334 IF !dustem_noobj THEN BEGIN 348 IF !dustem_noobj THEN BEGIN
335 - dustemwrap_plot_noobj,*(*!dustem_fit).CURRENT_PARAM_VALUES,st=dummy,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit+' (Final fit)' 349 + dustem_plot_noobj,*(*!dustem_fit).CURRENT_PARAM_VALUES,st=dummy,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit+' (Final fit)'
336 ENDIF ELSE BEGIN 350 ENDIF ELSE BEGIN
337 dustemwrap_plot,*(*!dustem_fit).CURRENT_PARAM_VALUES,st=dummy,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit+' (Final fit)' 351 dustemwrap_plot,*(*!dustem_fit).CURRENT_PARAM_VALUES,st=dummy,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit+' (Final fit)'
338 ENDELSE 352 ENDELSE
339 -  
340 -IF keyword_set(postscript) THEN BEGIN  
341 - device,/close  
342 - set_plot,mydevice  
343 - message,'Wrote '+ps_file,/info  
344 -ENDIF  
345 -  
346 if keyword_set(wait) then begin 353 if keyword_set(wait) then begin
347 message,'Made the plot of the final results',/info 354 message,'Made the plot of the final results',/info
348 wait,wait 355 wait,wait
349 end 356 end
350 357
  358 +;;===================================
  359 +;;=== WRITE OUT THE DUSTEMWRAP FITTING RESULTS IN A BINARY FITS FILE
  360 +;;===================================
351 IF keyword_set(fits_save) THEN BEGIN 361 IF keyword_set(fits_save) THEN BEGIN
352 message,'Writing out results structure: '+fits_save,/info 362 message,'Writing out results structure: '+fits_save,/info
353 dustem_write_fits_table,filename=fits_save,help=help 363 dustem_write_fits_table,filename=fits_save,help=help
354 -;=== At this point, you could erase all dustem system variables, or exit idl... all the  
355 -;=== information needed to recover the results and remake the plots has been saved in the FITS table  
356 -  
357 -;=== Moved the following to dustem_fits_io_example  
358 - ;; dustem_read_fits_table,filename=fits_save,dustem_st=dustem_spectra_st  
359 - ;; ;stop  
360 - ;; ;!dustem_show=ptr_new(*!dustem_data) ;test  
361 - ;; !dustem_noobj=1  
362 - ;; ;==== plot result taken from the saved fits table  
363 - ;; res=*(*!dustem_fit).CURRENT_PARAM_VALUES  
364 - ;; IF !dustem_noobj THEN BEGIN  
365 - ;; ;dustemwrap_plot_noobj,res,st=dustem_spectra_st,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit+' (From Saved FITS file)'  
366 - ;; dustemwrap_plot_noobj,res,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit+' (From Saved FITS file)'  
367 - ;; ENDIF ELSE BEGIN  
368 - ;; ;dustemwrap_plot,res,st=dustem_spectra_st,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit+' (From Saved FITS file)'  
369 - ;; dustemwrap_plot,res,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit+' (From Saved FITS file)'  
370 - ;; ENDELSE  
371 - ;; ;stop  
372 -  
373 - IF keyword_set(wait) THEN BEGIN 364 +;=== At this point, you could erase all dustem system variables, or exit IDL... all the
  365 +;=== information needed to recover the fitting results and remake any plots has been saved in the FITS table
  366 +IF keyword_set(wait) THEN BEGIN
374 message,'Saved the results as FITS in the file: '+fits_save,/info 367 message,'Saved the results as FITS in the file: '+fits_save,/info
375 wait,wait 368 wait,wait
376 ENDIF 369 ENDIF