Blame view

src/idl/dustem_run_example.pro 7.75 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
9ebef1db   Jean-Philippe Bernard   First commit
9
; PURPOSE:
80eb3ca5   Annie Hughes   clean up
10
;    This is an example of how to run the DustEM fortran code using DustEMWrap
9ebef1db   Jean-Philippe Bernard   First commit
11
; CATEGORY:
80eb3ca5   Annie Hughes   clean up
12
;    DustEMWrap, Distributed, High-Level, User Example
9ebef1db   Jean-Philippe Bernard   First commit
13
; CALLING SEQUENCE:
e93c2314   Annie Hughes   cleaned up for tuto
14
;    dustem_run_example,model,show=show,postscript=postscript,help=help
9ebef1db   Jean-Philippe Bernard   First commit
15
; INPUTS:
e93c2314   Annie Hughes   cleaned up for tuto
16
;        model = specifies the interstellar dust mixture used by DustEM
80eb3ca5   Annie Hughes   clean up
17
18
19
20
21
22
23
24
25
26
27
;           '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)
e93c2314   Annie Hughes   cleaned up for tuto
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
; 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  
; OUTPUTS:
;    Plots
; OPTIONAL OUTPUT PARAMETERS:
;    None
; 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
51
;    help      = if set, print this help
9ebef1db   Jean-Philippe Bernard   First commit
52
53
54
55
56
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    None
; RESTRICTIONS:
80eb3ca5   Annie Hughes   clean up
57
58
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
9ebef1db   Jean-Philippe Bernard   First commit
59
60
61
; PROCEDURE:
;    None
; EXAMPLES
e93c2314   Annie Hughes   cleaned up for tuto
62
;    dustem_run_example,'DBP90',show="all",/post
9ebef1db   Jean-Philippe Bernard   First commit
63
; MODIFICATION HISTORY:
80eb3ca5   Annie Hughes   clean up
64
65
66
;    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
67
68
69
;-

IF keyword_set(help) THEN BEGIN
3583bcca   Annie Hughes   bug fix
70
  doc_library,'dustem_run_example'
9ebef1db   Jean-Philippe Bernard   First commit
71
72
73
  goto,the_end
ENDIF

e93c2314   Annie Hughes   cleaned up for tuto
74
75
IF keyword_set(show) THEN BEGIN
  use_show=show
9ebef1db   Jean-Philippe Bernard   First commit
76
ENDIF ELSE BEGIN
e93c2314   Annie Hughes   cleaned up for tuto
77
  use_show=['all']    ;Default is to show everything
9ebef1db   Jean-Philippe Bernard   First commit
78
79
ENDELSE

e93c2314   Annie Hughes   cleaned up for tuto
80
81
82
83
84
85
86
87
88
89
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
90
;== INITIALISE DUSTEM
e93c2314   Annie Hughes   cleaned up for tuto
91
dustem_init,model=model
9ebef1db   Jean-Philippe Bernard   First commit
92
93
!dustem_verbose=1
!dustem_show_plot=1
e93c2314   Annie Hughes   cleaned up for tuto
94
95
!dustem_which='RELEASE'
dir_in=!dustem_soft_dir  
9ebef1db   Jean-Philippe Bernard   First commit
96

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

e93c2314   Annie Hughes   cleaned up for tuto
100
101
102
103
104
105
106
;=== 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
107

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

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

e93c2314   Annie Hughes   cleaned up for tuto
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
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
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
196
197
198
199

the_end:

END