Blame view

src/idl/dustem_run_example.pro 7.83 KB
e93c2314   Annie Hughes   cleaned up for tuto
1
2
3
4
PRO dustem_run_example, model $
                        ,show=show $
                        ,postscript=postscript $
                        ,help=help
9ebef1db   Jean-Philippe Bernard   First commit
5
6
7

;+
; NAME:
3583bcca   Annie Hughes   bug fix
8
;    dustem_run_example
bff3067a   Annie Hughes   inline help
9
;
9ebef1db   Jean-Philippe Bernard   First commit
10
; PURPOSE:
80eb3ca5   Annie Hughes   clean up
11
;    This is an example of how to run the DustEM fortran code using DustEMWrap
bff3067a   Annie Hughes   inline help
12
;
9ebef1db   Jean-Philippe Bernard   First commit
13
; CATEGORY:
80eb3ca5   Annie Hughes   clean up
14
;    DustEMWrap, Distributed, High-Level, User Example
bff3067a   Annie Hughes   inline help
15
;
9ebef1db   Jean-Philippe Bernard   First commit
16
; CALLING SEQUENCE:
e93c2314   Annie Hughes   cleaned up for tuto
17
;    dustem_run_example,model,show=show,postscript=postscript,help=help
bff3067a   Annie Hughes   inline help
18
;
9ebef1db   Jean-Philippe Bernard   First commit
19
; INPUTS:
e93c2314   Annie Hughes   cleaned up for tuto
20
;        model = specifies the interstellar dust mixture used by DustEM
80eb3ca5   Annie Hughes   clean up
21
22
23
24
25
26
27
28
29
30
31
;           'MC10' model from Compiegne et al 2010 (default)
;           'DBP90' model from Desert et al 1990
;           'DL01' model from Draine & Li 2001
;           'WD01_RV5p5B' model from Weingartner & Draine 2002 with Rv=5.5
;           'DL07' model from Draine & Li 2007
;           'J13' model from Jones et al 2013, as updated in
;                 Koehler et al 2014
;           'G17_ModelA' model A from Guillet et al (2018). Includes
;                 polarisation. See Tables 2 and 3 of that paper for details.
;           'G17_ModelB' model B from Guillet et al (2018)
;           'G17_ModelC' model C from Guillet et al (2018)
b125205a   Annie Hughes   updated examples ...
32
;           'G17_ModelD' model D from Guillet et al (2018)
bff3067a   Annie Hughes   inline help
33
;
e93c2314   Annie Hughes   cleaned up for tuto
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
; OPTIONAL INPUT PARAMETERS:
;       show = vector specifying the type of plot(s) to show. Possible
;       values (for all dust models) are
;       ["emis", "extuv", "extir", "alb", "sdist","rfield"]
;       Additionally, for the G17_MODEL?s with polarisation, you can specify
;        [ "polext", "polsed", "align"]
;       "emis" -- Stokes I SED in emission predicted by the model
;       "extuv" -- Extinction in the UV predicted by the model
;       "extir" -- Extinction in the IR predicted by the model
;       "alb" -- Albedo of the grain types
;       "sdist" -- Size distribution of the grain types
;       "rfield" -- Dust-heating radiation field
;       "polsed" -- Polarised intensity SED predicted by the model
;       "polext" -- Polarised extinction predicted by the model
;       "align" -- Grain alignment fraction predicted by the model
;       "all" -- All plots appropriate to the model  
bff3067a   Annie Hughes   inline help
50
;
e93c2314   Annie Hughes   cleaned up for tuto
51
52
; OUTPUTS:
;    Plots
bff3067a   Annie Hughes   inline help
53
;
e93c2314   Annie Hughes   cleaned up for tuto
54
55
; OPTIONAL OUTPUT PARAMETERS:
;    None
bff3067a   Annie Hughes   inline help
56
;
e93c2314   Annie Hughes   cleaned up for tuto
57
58
59
; ACCEPTED KEY-WORDS:
;    postscript = on/off if set, plots are saved as postscript in the
;                 current working directory (and not shown on screen)
80eb3ca5   Annie Hughes   clean up
60
;    help      = if set, print this help
bff3067a   Annie Hughes   inline help
61
;
9ebef1db   Jean-Philippe Bernard   First commit
62
63
; COMMON BLOCKS:
;    None
bff3067a   Annie Hughes   inline help
64
;
9ebef1db   Jean-Philippe Bernard   First commit
65
66
; SIDE EFFECTS:
;    None
bff3067a   Annie Hughes   inline help
67
;
9ebef1db   Jean-Philippe Bernard   First commit
68
; RESTRICTIONS:
80eb3ca5   Annie Hughes   clean up
69
70
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
bff3067a   Annie Hughes   inline help
71
;
9ebef1db   Jean-Philippe Bernard   First commit
72
73
; PROCEDURE:
;    None
bff3067a   Annie Hughes   inline help
74
;
9ebef1db   Jean-Philippe Bernard   First commit
75
; EXAMPLES
e93c2314   Annie Hughes   cleaned up for tuto
76
;    dustem_run_example,'DBP90',show="all",/post
bff3067a   Annie Hughes   inline help
77
;
9ebef1db   Jean-Philippe Bernard   First commit
78
; MODIFICATION HISTORY:
80eb3ca5   Annie Hughes   clean up
79
80
81
;    Written JPB Apr-2011
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
9ebef1db   Jean-Philippe Bernard   First commit
82
83
84
;-

IF keyword_set(help) THEN BEGIN
3583bcca   Annie Hughes   bug fix
85
  doc_library,'dustem_run_example'
9ebef1db   Jean-Philippe Bernard   First commit
86
87
88
  goto,the_end
ENDIF

e93c2314   Annie Hughes   cleaned up for tuto
89
90
IF keyword_set(show) THEN BEGIN
  use_show=show
9ebef1db   Jean-Philippe Bernard   First commit
91
ENDIF ELSE BEGIN
e93c2314   Annie Hughes   cleaned up for tuto
92
  use_show=['all']    ;Default is to show everything
9ebef1db   Jean-Philippe Bernard   First commit
93
94
ENDELSE

e93c2314   Annie Hughes   cleaned up for tuto
95
96
97
98
99
100
101
102
103
104
known_mdls=['MC10','DBP90','DL01','WD01_RV5P5B','DL07','J13','G17_MODELA','G17_MODELB','G17_MODELC','G17_MODELD'] 
pol_mdls=['G17_MODELA','G17_MODELB','G17_MODELC','G17_MODELD'] 
test_model = where(known_mdls eq strupcase(model),ct)
if ct eq 0 then begin
   message,'ISM dust model '+model+' unknown',/continue
   message,'Known models are MC10,DBP90,DL01,WD01_RV5P5B,DL07,J13,G17_MODELA,G17_MODELB,G17_MODELC,G17_MODELD',/continue
   stop
end
test_pol_model = where(pol_mdls eq model,polct)

80eb3ca5   Annie Hughes   clean up
105
;== INITIALISE DUSTEM
e93c2314   Annie Hughes   cleaned up for tuto
106
dustem_init,model=model
9ebef1db   Jean-Philippe Bernard   First commit
107
108
!dustem_verbose=1
!dustem_show_plot=1
e93c2314   Annie Hughes   cleaned up for tuto
109
110
!dustem_which='RELEASE'
dir_in=!dustem_soft_dir  
9ebef1db   Jean-Philippe Bernard   First commit
111

80eb3ca5   Annie Hughes   clean up
112
;== Fill the following structure contains with default inputs to the model
9ebef1db   Jean-Philippe Bernard   First commit
113
st_model=dustem_read_all(dir_in)
80eb3ca5   Annie Hughes   clean up
114

b125205a   Annie Hughes   updated examples ...
115

e93c2314   Annie Hughes   cleaned up for tuto
116
117
118
119
120
121
122
;=== You could modify the model inputs here by directly editing the values in the
;=== st_model structure. To inspect contents, type IDL> help,st_model,/str
;=== e.g.
;=== st_model.G0=2.0 ; change the default value of the ISRF intensity used by DustEM
;=== st_model.isrf.isrf=sqrt(st_model.isrf.isrf) ; change the shape of ISRF
;=== st_model.grains[0].mdust_O_mh=5.e-4 ; change the abundance of grain[0]
;=== st_model.grains[1].type_keywords='plaw' ; change the size distribution description of grain[1]
80eb3ca5   Annie Hughes   clean up
123

e93c2314   Annie Hughes   cleaned up for tuto
124
;== The following line saves the modified inputs for use by the fortran
9ebef1db   Jean-Philippe Bernard   First commit
125
dustem_write_all,st_model,!dustem_dat
80eb3ca5   Annie Hughes   clean up
126
127

;== The following line runs the Fortran. The ouput structure st contains the results
9ebef1db   Jean-Philippe Bernard   First commit
128
st=dustem_run()
80eb3ca5   Annie Hughes   clean up
129

e93c2314   Annie Hughes   cleaned up for tuto
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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
known_plots=["emis", "extuv", "extir", "alb", "sdist"]
if polct gt 0 then known_plots=["emis", "extuv", "extir", "alb", "sdist","polext", "polsed", "align"]
if strupcase(use_show) eq "ALL" then use_show=[known_plots,"rfield"]

;== The following lines generate plots that show the outputs of the fortran.
;=== For this release (V2.0), we use the old method (dustem_show_fortran) to
;=== access model quantities.
;=== This method will be deprecated in a future release and plots will be
;=== constructed directly from the st and st_model structures.
match,known_plots,use_show,a,b
if total(a,/nan) ne -1 and keyword_set(postscript) then $
   dustem_show_fortran,model=model,st=st,show=known_plots[a],hard=1,tit="DustEM_run_example "+model+" :"
if total(a,/nan) ne -1 and not keyword_set(postscript) then $
   dustem_show_fortran,model=model,st=st,show=known_plots[a],tit="DustEM_run_example "+model+" :"

;== The following lines generate a plot of the ISRF using the
;== st_model structure. For illustration purposes.
use_win=12
rfield_plot=["rfield"]
match,rfield_plot,use_show,a,b
if total(a,/nan) ne -1 then begin
      xtit=textoidl('\lambda (\mum)')
      ytit=textoidl('log ISRF [4 \pi I_\nu (erg/cm^2/s/Hz)]')
      tit='DustEM_run_example ISRF'
      yr=[min(st_model.isrf.isrf),5.*max(st_model.isrf.isrf)]
      xr=[min(st_model.isrf.lambisrf),max(st_model.isrf.lambisrf)]
   IF not keyword_set(postscript) THEN BEGIN
      window,use_win,xs=600,ys=400,tit='DUSTEM_SHOW_FORTRAN: ISRF '+strtrim(use_win,2) & use_win=use_win+2
      cgplot,st_model.isrf.lambisrf,st_model.isrf.isrf $
             ,yr=yr,/ysty,xr=xr,/xsty,/xlog,/ylog $
             ,title=tit,xtit=xtit,ytit=ytit,color=cgcolor('black'),/nodata
      oplot,st_model.isrf.lambisrf,st_model.isrf.isrf,col=cgcolor('black')
   END ELSE BEGIN
      file_ps="isrf.ps"
      previous_device=!d.name
       !y.thick = 5
       !x.thick = 5
       !p.thick = 5
       !p.charsize = 1.3
       !p.charthick = 5
       !x.ticklen = 0.04
      set_plot,'PS'
      device,filename=file_ps,/portrait,/color
      cgplot,st_model.isrf.lambisrf,st_model.isrf.isrf $
             ,yr=yr,/ysty,xr=xr,/xsty,/xlog,/ylog $
             ,title=tit,xtit=xtit,ytit=ytit,color=cgcolor('black'),/nodata
      oplot,st_model.isrf.lambisrf,st_model.isrf.isrf ,col=cgcolor('black')
      device,/close
      !y.thick = 0
      !x.thick = 0
      !p.thick = 0
      !p.charsize = 1
      !p.charthick = 0
      !x.ticklen = 0.02
      set_plot,previous_device
   END
end

goto,the_end     

;;== The following lines plot the resulting SED (emission)
;;== using st/st_model structure and a dedicated plotting function 
;;== Prototype for future releases.
;; win=0L
;; window,win & win=win+2
;; xtit=textoidl('\lambda (\mum)')
;; ytit=textoidl('\nuI_\nu^{em} (W/m^2/sr for N_H=1.e20 H/cm^2)')
;; tit='DustEMWrap Emission: '+model
;; yr=[1e-11,6.e-7]
;; xr=[1,5e3]
;; dustem_plot_nuinu_em,st,yr=yr,/ysty,xr=xr,/xsty,/xlog,/ylog,title=tit,xtit=xtit,ytit=ytit,post=postscript

;;== The following plots the resulting SED (extinction)
;;== using st/st_model structure and a dedicated plotting function 
;;== Prototype for future releases.
;; window,win & win=win+1
;; yr=[0,2.5]  ;range of 1/lambda
;; xr=[1,10]   ;range of sigma
;; xtit=textoidl('1/\lambda (\mum^{-1})')
;; ytit=textoidl('\sigma_{ext} (1e-21 cm^2/H)')
;; tit='DustEMWrap extinction: '+model
;; dustem_plot_extinction,st,st_model,xr=xr,yr=yr,/xsty,/ysty,xtit=xtit,ytit=ytit,title=tit,post=postscript
9ebef1db   Jean-Philippe Bernard   First commit
212
213
214
215

the_end:

END