Blame view

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

;+
; NAME:
3583bcca   Annie Hughes   bug fix
9
;    dustem_run_example
bff3067a   Annie Hughes   inline help
10
;
9ebef1db   Jean-Philippe Bernard   First commit
11
; PURPOSE:
80eb3ca5   Annie Hughes   clean up
12
;    This is an example of how to run the DustEM fortran code using DustEMWrap
bff3067a   Annie Hughes   inline help
13
;
9ebef1db   Jean-Philippe Bernard   First commit
14
; CATEGORY:
80eb3ca5   Annie Hughes   clean up
15
;    DustEMWrap, Distributed, High-Level, User Example
bff3067a   Annie Hughes   inline help
16
;
9ebef1db   Jean-Philippe Bernard   First commit
17
; CALLING SEQUENCE:
e93c2314   Annie Hughes   cleaned up for tuto
18
;    dustem_run_example,model,show=show,postscript=postscript,help=help
bff3067a   Annie Hughes   inline help
19
;
9ebef1db   Jean-Philippe Bernard   First commit
20
; INPUTS:
6735604d   Annie Hughes   making FITS read ...
21
22
23
;    model = specifies the interstellar dust mixture used by
;            DustEM. See userguide or dustem_test_model_exists.pro
;            for more details about available models in current release.
bff3067a   Annie Hughes   inline help
24
;
e93c2314   Annie Hughes   cleaned up for tuto
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
; 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
41
;
e93c2314   Annie Hughes   cleaned up for tuto
42
43
; OUTPUTS:
;    Plots
bff3067a   Annie Hughes   inline help
44
;
e93c2314   Annie Hughes   cleaned up for tuto
45
46
; OPTIONAL OUTPUT PARAMETERS:
;    None
bff3067a   Annie Hughes   inline help
47
;
e93c2314   Annie Hughes   cleaned up for tuto
48
49
50
; 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
bff3067a   Annie Hughes   inline help
52
;
9ebef1db   Jean-Philippe Bernard   First commit
53
54
; COMMON BLOCKS:
;    None
bff3067a   Annie Hughes   inline help
55
;
9ebef1db   Jean-Philippe Bernard   First commit
56
57
; SIDE EFFECTS:
;    None
bff3067a   Annie Hughes   inline help
58
;
9ebef1db   Jean-Philippe Bernard   First commit
59
; RESTRICTIONS:
80eb3ca5   Annie Hughes   clean up
60
61
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
bff3067a   Annie Hughes   inline help
62
;
9ebef1db   Jean-Philippe Bernard   First commit
63
64
; PROCEDURE:
;    None
bff3067a   Annie Hughes   inline help
65
;
9ebef1db   Jean-Philippe Bernard   First commit
66
; EXAMPLES
e93c2314   Annie Hughes   cleaned up for tuto
67
;    dustem_run_example,'DBP90',show="all",/post
bff3067a   Annie Hughes   inline help
68
;
9ebef1db   Jean-Philippe Bernard   First commit
69
; MODIFICATION HISTORY:
80eb3ca5   Annie Hughes   clean up
70
71
72
;    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
73
74
75
;-

IF keyword_set(help) THEN BEGIN
3583bcca   Annie Hughes   bug fix
76
  doc_library,'dustem_run_example'
9ebef1db   Jean-Philippe Bernard   First commit
77
78
79
  goto,the_end
ENDIF

e93c2314   Annie Hughes   cleaned up for tuto
80
81
IF keyword_set(show) THEN BEGIN
  use_show=show
9ebef1db   Jean-Philippe Bernard   First commit
82
ENDIF ELSE BEGIN
e93c2314   Annie Hughes   cleaned up for tuto
83
  use_show=['all']    ;Default is to show everything
9ebef1db   Jean-Philippe Bernard   First commit
84
85
ENDELSE

f93c1fe3   Wilma Kiviaho   stopped help dump...
86
exists=dustem_test_model_exists(model,/silent)
6735604d   Annie Hughes   making FITS read ...
87
88
89
if exists ne 1 then $
   message,'Unknown dust model'
polct=dustem_test_model_exists(model,/pol,/silent)
e93c2314   Annie Hughes   cleaned up for tuto
90

80eb3ca5   Annie Hughes   clean up
91
;== INITIALISE DUSTEM
e93c2314   Annie Hughes   cleaned up for tuto
92
dustem_init,model=model
1efc19ff   Annie Hughes   changes for HD22
93
94
95
;=== The following line shows how to initialise dustem using
;=== non-default grain keywords. ? indicates default. 
;=== dustem_init,model='DBP90',grain_keywords=['?','logn','?']
9ebef1db   Jean-Philippe Bernard   First commit
96
97
!dustem_verbose=1
!dustem_show_plot=1
e93c2314   Annie Hughes   cleaned up for tuto
98
99
!dustem_which='RELEASE'
dir_in=!dustem_soft_dir  
9ebef1db   Jean-Philippe Bernard   First commit
100

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

b125205a   Annie Hughes   updated examples ...
104

e93c2314   Annie Hughes   cleaned up for tuto
105
106
107
108
109
;=== 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
1efc19ff   Annie Hughes   changes for HD22
110
;=== st_model.grains[3].mdust_O_mh=2.e-3 ; change the abundance of grain[3]
e93c2314   Annie Hughes   cleaned up for tuto
111
;=== st_model.grains[1].type_keywords='plaw' ; change the size distribution description of grain[1]
80eb3ca5   Annie Hughes   clean up
112

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

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

e93c2314   Annie Hughes   cleaned up for tuto
119
120
known_plots=["emis", "extuv", "extir", "alb", "sdist"]
if polct gt 0 then known_plots=["emis", "extuv", "extir", "alb", "sdist","polext", "polsed", "align"]
66c68b4a   Annie Hughes   not sure
121
122
if n_elements(use_show) eq 1 then $
   if strupcase(use_show) eq "ALL" then use_show=[known_plots,"rfield"]
e93c2314   Annie Hughes   cleaned up for tuto
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

;== 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)]')
6735604d   Annie Hughes   making FITS read ...
143
      tit='DustEM_run_example : ISRF'
e93c2314   Annie Hughes   cleaned up for tuto
144
145
146
      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
6735604d   Annie Hughes   making FITS read ...
147
      window,use_win,xs=600,ys=400,tit='DustEM-run_example: ISRF '+strtrim(use_win,2) & use_win=use_win+2
e93c2314   Annie Hughes   cleaned up for tuto
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
      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
202
203

the_end:
e431104b   Annie Hughes   general updates f...
204
message,'Finished dustem_run_example',/info
aae54086   Annie Hughes   noexit keyword an...
205
if keyword_set(noexit) then stop
9ebef1db   Jean-Philippe Bernard   First commit
206
207

END