dustem_plugin_modify_isrf.pro
4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
Function dustem_plugin_modify_isrf, key=key, val=val, scope=scope, paramtag=paramtag,help=help
;+
; NAME:
; dustem_plugin_modify_isrf
; PURPOSE:
; REPLACES THE DEFAULT DUSTEM ISRF with a user-defined one
; CATEGORY:
; DUSTEM Wrapper
; CALLING SEQUENCE:
; dustem_plugin_modify_isrf(key=key,val=val)
; INPUTS:
; None
; OPTIONAL INPUT PARAMETERS:
; key = input parameter number
; val = input parameter value
; key = 1 sets the ISRF file path. The call is placed in the fixed parameters vector.
; It can also mean that G0 or gas.GO is present in PD vector and is thus not handled here.
; key = 2 means G0/gas.G0 isn't present in the PD vector and is handled here.
; The plugin is placed in the parameters vector and G0 is fitted through this plugin.
; if key=1, val = 1 means the !dustem_free1 pointer (containing the user-defined file's directory) is used.
; if key=2, val = value of G0. The file path has supposedly already been defined.
; OUTPUTS:
; None
; OPTIONAL OUTPUT PARAMETERS:
; None
; ACCEPTED KEY-WORDS:
; help = if set, print this help
; COMMON BLOCKS:
; None
; SIDE EFFECTS:
; None
; RESTRICTIONS:
; The dustem fortran code must be installed
; The dustem idl wrapper must be installed
; The path of the ISRF must be assigned to one of the dustemwrap free pointers.
; Two calls of the plugin are necessary if fitting of G0 through this plugin is done.
; The user-defined ISRF needs to be on the same dustem ISRF grid.
; PROCEDURE:
; This is a dustem plugin
;-
;-
IF keyword_set(help) THEN BEGIN
doc_library,'dustem_plugin_modify_isrf'
goto,the_end
ENDIF
IF keyword_set(scope) THEN BEGIN
out=0
goto, the_end
ENDIF
IF keyword_set(paramtag) THEN BEGIN
out=0
goto, the_end
ENDIF
out=0;?
G0=1.
IF keyword_set(key) THEN BEGIN
ind1=where(key EQ 1,count1) ;G0/gas.GO is present in PD vector
ind2=where(key EQ 2,count2) ;G0/gas.GO is not present in PD vector
IF count1 NE 0 then begin
file_idx=val[ind1[0]]
file_str = 'file=(*!dustem_free'+strtrim(string(fix(file_idx)),2)+')'
toto = execute(file_str)
ENDIF
IF count2 NE 0 then begin
G0=val[ind2[0]]
ENDIF
ENDIF
;This is because the mathis ISRF is automatically read and written.
;We just need the wavelengths. This means that this wavelength vector is the dustem (IAS) provided one.
;We don't use the ISRF values in this structure to read the mathis ISRF because
;the ISRF in this structure might be the altered one.
st=((*!dustem_params).isrf) ;this is just to read the wavelengths
;storing the mathis isrf in variable mathis_isrf - if the user wants to use
ma_isrf_dir=!dustem_soft_dir+'data/ISRF_MATHIS.DAT'
ma_isrf=dustem_read_isrf(ma_isrf_dir)
if isa(file) then user_ISRF = dustem_read_isrf(file)
IF isa(ma_isrf) THEN Ncomments=5 ELSE Ncomments=4
c = strarr(Ncomments)
;First and last lines of the new composite ISRF.DAT file
c(0)='# DUSTEM: exciting radiation field featuring'
IF isa(ma_isrf) THEN BEGIN
c(1)='# Mathis ISRF'
c(2)='# User ISRF'
ENDIF ELSE c(1)='# User ISRF'
c(Ncomments-2)='# Nbr of points'
c(Ncomments-1)='# wave (microns), 4*pi*Inu (erg/cm2/s/Hz)'
;decided to do something else:
IF G0 EQ 1. THEN BEGIN
IF ((*!dustem_params).g0) NE 1. THEN G0 = ((*!dustem_params).g0)
IF ((*!dustem_params).gas.g0) NE 1. THEN G0 = ((*!dustem_params).gas.g0)
ENDIF
IF isa(ma_isrf) THEN st.isrf=ma_isrf.isrf+user_ISRF/(G0) ELSE st.isrf=user_ISRF
;TEST IF THE PLUGIN WORKSs
; print,'The user_ISRF is:'
;
; print, user_isrf
;
; print, 'Final isrf is:'
; print, st.isrf
file=!dustem_dat+'data/ISRF.DAT'
openw,unit,file,/get_lun
FOR i=0,Ncomments-1 DO BEGIN
printf,unit,c(i)
ENDFOR
n_waves=n_elements(st)
printf,unit,n_waves
FOR i=0L,n_waves-1 DO BEGIN
printf,unit,st(i).lambisrf,st(i).isrf
ENDFOR
close,unit
free_lun,unit
out=st.isrf
the_end:
scope='USER_ISRF'
;paramtag will only matter if G0 is fitted through the plugin.
paramtag=['G0']
return, out
end