Commit 797bd3a9db90a71985c07d178abc323815353aed

Authored by Annie Hughes
1 parent abb4c515
Exists in master

added all grain types and play nice with system variables

Showing 1 changed file with 58 additions and 13 deletions   Show diff stats
src/idl/dustem_plugin_dl07_isrf_model.pro
... ... @@ -61,21 +61,21 @@ IF keyword_set(help) THEN BEGIN
61 61 goto,the_end
62 62 ENDIF
63 63  
  64 +spec=0.
  65 +
64 66 IF keyword_set(scope) THEN BEGIN
65   - out=0
  67 + out=0 & st=0
66 68 goto, the_end
67 69 ENDIF
68 70  
69 71 IF keyword_set(paramtag) THEN BEGIN
70   - out=0
  72 + out=0 & st=0
71 73 goto, the_end
72 74 ENDIF
73 75  
74 76 ;dustem_print_params
75 77 ;stop
76 78  
77   -spec=0.
78   -
79 79 ;==== default parameter values
80 80 Umin=1.
81 81 Umax=1.e6
... ... @@ -106,19 +106,47 @@ Umean=(1.-gamma)*Umin+gamma*Umin*alog(Umax/Umin)/(1.-Umin/Umax)
106 106 lambir=dustem_get_wavelengths()
107 107  
108 108 Nwavs=n_elements(lambir)
109   -spec=fltarr(Nwavs,3)
110   -spec2=fltarr(Nwavs,3)
  109 +;spec=fltarr(Nwavs,3) ; if ever one day we enforce IQU outputs
  110 +;spec2=fltarr(Nwavs,3)
  111 +spec=fltarr(Nwavs)
  112 +spec2=fltarr(Nwavs)
  113 +
  114 +Ngrains=(*!dustem_params).ngrains
  115 +spec_grains=fltarr(Nwavs,ngrains)
  116 +spec2_grains=fltarr(Nwavs,ngrains)
  117 +
  118 +
  119 +;==== save everything to put back later
  120 +saved_pd=0 & saved_pinfo=0 & saved_fpd=0
  121 +IF ptr_valid((*!dustem_fit).param_descs) THEN BEGIN
  122 + pd=*(*!dustem_fit).param_descs
  123 + iv=*(*!dustem_fit).param_init_values
  124 + cv=*(*!dustem_fit).current_param_values
  125 + saved_pd=1
  126 +ENDIF
  127 +IF ptr_valid(!dustem_parinfo) THEN BEGIN
  128 + parinfo=*(!dustem_parinfo)
  129 + saved_pinfo=1
  130 +ENDIF
  131 +IF ptr_valid((*!dustem_fit).fixed_param_descs) THEN BEGIN
  132 + fpd=*(*!dustem_fit).fixed_param_descs
  133 + fiv=*(*!dustem_fit).fixed_param_init_values
  134 + saved_fpd=1
  135 +ENDIF
111 136  
112 137 ;==== Run dustem with G0(a.k.a. U)=1.
113 138 param_desc=['(*!dustem_params).G0']
114 139 param_values=[Umin]
115   -
116 140 dustem_init_params,!dustem_model,param_desc,param_values
117 141  
118 142 ;stop
119 143 st=dustem_run(param_values)
120 144 spec1=st.sed.em_tot
121 145 spec=(1.-gamma)*spec1
  146 +for k=0,ngrains-1 do begin
  147 + this_spec=st.sed.(k+1) ; position 0 is the wavelengths
  148 + spec_grains[*,k]=(1.-gamma)*this_spec
  149 +endfor
122 150  
123 151 ;==== add contribution of dust seeing a power law of U
124 152 spec2[*]=0.
... ... @@ -128,7 +156,9 @@ NUs=10L ;This seems sufficient
128 156 ;U values over which integration will be performed
129 157 Us=range_gen(NUs,[Umin,Umax],/log)
130 158 specs=fltarr(NUs,Nwavs)
  159 +specs_grains=fltarr(NUs,Nwavs,Ngrains)
131 160 ;stop
  161 +
132 162 ffacts=fltarr(NUs)
133 163 IF gamma NE 0. THEN BEGIN
134 164 fact=gamma*(alpha-1.)/(Umin^(1.-alpha)-Umax^(1.-alpha))
... ... @@ -138,29 +168,44 @@ IF gamma NE 0. THEN BEGIN
138 168 st=dustem_run(param_values)
139 169 ffacts[i]=Us[i]^(-1.*alpha)*fact
140 170 specs[i,*]=ffacts[i]*st.sed.em_tot
  171 + for k=0,ngrains-1 do specs_grains[i,*,k]=ffacts[i]*st.sed.(k+1)
141 172 ENDFOR
142 173 ;integrate over U
143 174 ;stop
144 175 FOR j=0L,Nwavs-1 DO BEGIN
145 176 integ=integral(Us,reform(specs[*,j]),Umin,Umax)
146 177 spec[j]=spec[j]+integ[0]
  178 + for k=0,ngrains-1 do begin
  179 + integ_grains=integral(Us,reform(specs_grains[*,j,k]),Umin,Umax)
  180 + spec_grains[j,k]=spec_grains[j,k]+integ_grains[0]
  181 + endfor
147 182 ENDFOR
148 183 ENDIF
149 184  
150   -;stop
151   -
152   -;This is to update keyword st with final spectrum. Useless, as there is no st keyword !
  185 +;This is to update keyword st with the final spectra.
153 186 ;Not necessary here, but to be used in plugins with scope 'REPLACE_FORTRAN' which actually do not call the Fortran at all.
154 187 ;Ngrains=3
155 188 ;st=dustem_make_empty_fortran_st(Ngrains)
156 189 st.sed.em_tot=spec
  190 +for k=0,ngrains-1 do st.sed.(k+1)=spec_grains[*,k]
  191 +
  192 +;restore params to their original values
  193 +if saved_pd eq 1 then begin
  194 + (*!dustem_fit).param_descs=ptr_new(pd)
  195 + (*!dustem_fit).param_init_values=ptr_new(iv)
  196 + (*!dustem_fit).param_init_values=ptr_new(cv)
  197 +end
  198 +if saved_fpd eq 1 then begin
  199 + (*!dustem_fit).fixed_param_descs=ptr_new(fpd)
  200 + (*!dustem_fit).fixed_param_init_values=ptr_new(fiv)
  201 +end
  202 +if saved_pinfo eq 1 then begin
  203 + !dustem_parinfo=ptr_new(parinfo)
  204 +end
157 205  
158   -;dustem_print_params
159   -;stop
160 206  
161 207 the_end:
162 208 scope='REPLACE_FORTRAN'
163   -
164 209 ;parameter tags.
165 210 paramtag=['gamma','alpha','Umin','Umax']
166 211  
... ...