Blame view

src/idl/dustem_write_isrf_lv.pro 6.57 KB
389a2b1d   Jean-Philippe Bernard   improved
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
PRO dustem_write_isrf_lv,file,st,help=help

;+
; NAME:
;    dustem_write_isrf_lv
; PURPOSE:
;    Writes file ISRF.DAT used by DustemWrapper
; CATEGORY:
;    Dustem
; CALLING SEQUENCE:
;    dustem_write_isrf_lv,file,st[,/help]
; INPUTS:
;    file : file name 
;    st   : input ISRF structure
; OPTIONAL INPUT PARAMETERS:
;    None
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help      = If set print this help
4750086c   Ilyes Choubani   nouvelle philosph...
23
; COMMON BLOCKS: 
389a2b1d   Jean-Philippe Bernard   improved
24
25
26
27
28
29
30
;    None
; SIDE EFFECTS:
;    None
; RESTRICTIONS:
;    The dustem fortran code must be installed
;    The dustem idl wrapper must be installed
; PROCEDURE:
dc84fd94   Ilyes Choubani   Small corrections...
31
;    Write ISRF for the DustEmWrap
389a2b1d   Jean-Philippe Bernard   improved
32
33
34
;-

IF keyword_set(help) THEN BEGIN
4750086c   Ilyes Choubani   nouvelle philosph...
35
  doc_library,'dustem_write_isrf_lv'
389a2b1d   Jean-Philippe Bernard   improved
36
37
38
  goto,the_end
ENDIF

f9089dc2   Ilyes Choubani   implementing the ...
39
40
;Replacing the old block with an iteration over the plugins' scopes 
scopes = strarr(n_tags(*!dustem_plugin))
b9bf16a2   Ilyes Choubani   adjusting tests o...
41
42

IF (tag_names(*!dustem_plugin))[0] EQ 'NONE' then goto, the_after
f9089dc2   Ilyes Choubani   implementing the ...
43
44
;Getting the actual scopes 
FOR i=0L, n_tags(*!dustem_plugin)-1 DO BEGIN
a73f6031   Ilyes Choubani   small corrections...
45
    if isa((*!dustem_plugin).(i).spec) THEN BEGIN
b9bf16a2   Ilyes Choubani   adjusting tests o...
46
47
        scopes[i] = (*(*!dustem_plugin).(i).scope)
    ENDIF ELSE goto, the_after
f9089dc2   Ilyes Choubani   implementing the ...
48
ENDFOR
427f1205   Jean-Michel Glorian   version 4.2 merged
49

f9089dc2   Ilyes Choubani   implementing the ...
50
51
52
53
54
55
56
tstpop = where(scopes EQ 'STELLAR_POPULATION',ctpop)
tstusrisrf = where(scopes EQ 'USER_ISRF',ctusrisrf)

IF ctpop NE 0 or ctusrisrf NE 0 THEN BEGIN
    
    G0_mathis = 0. ;Just an initialization
    ;The initial test was going to be on ((*!dustem_params).g0) and ((*!dustem_params).gas.g0) but it isn't enough...
5739d143   Ilyes Choubani   correcting small ...
57
    ;this is because the case where mathis ISRF is used with G0=1 oughtn't be forgotten and should be distinguishable
f9089dc2   Ilyes Choubani   implementing the ...
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
    ;A solution is to instead test on the parameter vectors (fixed and thawed alike)

    ;Locating G0 in the free parameters vector
    ind_G0 = where(strupcase(strmid((*(*!dustem_fit).param_descs),5,/reverse)) EQ 'MS).G0', countg0)
    IF countg0 NE 0 THEN G0_mathis = (*(*!dustem_fit).param_init_values)[ind_G0] 
    
    ;Locating G0 in the fixed parameters vector
    ;under the assumption that the user will always have a free parameter vector set but not necessarily a fixed one
    IF isa((*!dustem_fit).fixed_param_descs) THEN BEGIN
        ind_G0 = where(strupcase(strmid((*(*!dustem_fit).fixed_param_descs),5,/reverse)) EQ 'MS).G0', countg0)
        IF countg0 NE 0 THEN G0_mathis = (*(*!dustem_fit).fixed_param_init_values)[ind_G0]
    ENDIF
    
    ;Locating gas.G0 in the free parameters vector
    ind_GASG0 = where(strupcase(strmid((*(*!dustem_fit).param_descs),5,/reverse)) EQ 'GAS.G0', countgasg0)
    IF countgasg0 THEN G0_mathis = (*(*!dustem_fit).param_init_values)[ind_GASG0]
    
    ;Locating gas.G0 in the fixed parameters vector
    ;under the assumption that the user will always have a free parameter vector set but not necessarily a fixed one
    IF isa((*!dustem_fit).fixed_param_descs) THEN BEGIN
        ind_GASG0 = where(strupcase(strmid((*(*!dustem_fit).fixed_param_descs),5,/reverse)) EQ 'GAS.G0', countgasg0)
        IF countgasg0 THEN G0_mathis = (*(*!dustem_fit).fixed_param_init_values)[ind_GASG0]
    ENDIF   
    ;Getting the ISRF default wavelengths
    ;using this structure
    st=((*!dustem_params).isrf)
    final_isrf = fltarr(n_elements(st)) ;Initializing the ISRF vector
    Ncomments=4 ;default number of comments in the .DAT file
    c=strarr(Ncomments)
a73f6031   Ilyes Choubani   small corrections...
87
88
89
    c(0)='# DUSTEM: exciting radiation field featuring' 
    IF ctpop NE 0 THEN final_isrf=final_isrf+(*(*!dustem_plugin).(tstpop).spec)
    IF ctusrisrf NE 0 THEN final_isrf=final_isrf+(*(*!dustem_plugin).(tstusrisrf).spec)
f9089dc2   Ilyes Choubani   implementing the ...
90
91
92
93
94
95

    IF ctpop NE 0 and ctusrisrf EQ 0 THEN c(1) = '#STELLAR POPULATION ISRF'
    IF ctpop EQ 0 and ctusrisrf NE 0 THEN  c(1) = '#USER-DEFINED ISRF'
    
    IF ctpop NE 0 and ctusrisrf NE 0 THEN BEGIN
        Ncomments+=1
a73f6031   Ilyes Choubani   small corrections...
96
97
        c=strarr(Ncomments)
        c(0)='# DUSTEM: exciting radiation field featuring'  
f9089dc2   Ilyes Choubani   implementing the ...
98
99
100
        c(1) = '#STELLAR POPULATION ISRF'
        c(2) = '#USER-DEFINED ISRF'
    ENDIF
a73f6031   Ilyes Choubani   small corrections...
101

f9089dc2   Ilyes Choubani   implementing the ...
102
103
104
105
106
    IF G0_mathis NE 0 THEN BEGIN ;storing the mathis isrf in variable mathis_isrf if the user wants to use it
        ;This is reading the mathis isrf from the fortran release
        ;Let's hope they keep releasing it otherwise we'll have to include it ourselves
        ma_isrf_dir=!dustem_soft_dir+'data/ISRF_MATHIS.DAT'
        ma_isrf=dustem_read_isrf(ma_isrf_dir)
3d0f6b67   Ilyes Choubani   rest of plotting ...
107
        stop
a73f6031   Ilyes Choubani   small corrections...
108
        final_isrf=final_isrf/G0_mathis[0]+ma_isrf.isrf
f9089dc2   Ilyes Choubani   implementing the ...
109
        Ncomments+=1
a73f6031   Ilyes Choubani   small corrections...
110
111
112
113
114
115
116
117
118
119
120
121
122
        c=strarr(Ncomments)
        c(0)='# DUSTEM: exciting radiation field featuring'
        IF ctpop NE 0 and ctusrisrf EQ 0 THEN c(1) = '#STELLAR POPULATION ISRF'
        IF ctpop EQ 0 and ctusrisrf NE 0 THEN  c(1) = '#USER-DEFINED ISRF'
        IF ctpop NE 0 and ctusrisrf NE 0 THEN BEGIN
            Ncomments+=1
            c=strarr(Ncomments)
            c(0)='# DUSTEM: exciting radiation field featuring'  
            c(1) = '#STELLAR POPULATION ISRF'
            c(2) = '#MATHIS ISRF'
            c(3) ='#USER-DEFINED ISRF'
        ENDIF
        
f9089dc2   Ilyes Choubani   implementing the ...
123
124
        c(Ncomments-3) = '#MATHIS ISRF'
    ENDIF
f9089dc2   Ilyes Choubani   implementing the ...
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
    ;Will this enable us to have the current 'updated' ISRF through the !dustem_params system variable?
    st.isrf = final_isrf  
    
    ;Last .DAT header comments lines
    c(Ncomments-2)='# Nbr of points'
    c(Ncomments-1)='# wave (microns), 4*pi*Inu (erg/cm2/s/Hz)'

    ;internally displaying the 'G0' of the new ISRF (integral(ISRF)/integral(MATHIS_ISRF))
    ;     un=uniq(ma_isrf.isrf)
    ;     
    ;     int_mathis=INT_TABULATED((ma_isrf.lambisrf)[un],(ma_isrf.isrf)[un])
    ;     
    ;     
    ;     ;integrating the composite isrf
    ;     int_isrf=INT_TABULATED((ma_isrf.lambisrf)[un],(st.isrf)[un])
    ;     print, 'G0_stellar_population='
    ;     print, int_isrf/(int_mathis)
    
    ;WRITING THE NEW 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 

    goto, the_end
759a527d   Ilyes Choubani   general update
163
ENDIF
19e26da9   Ilyes Choubani   corrected stellar...
164

f9089dc2   Ilyes Choubani   implementing the ...
165
166
167
168
169
the_after:
;Defaut ISRF writing (MATHIS)
;This was changed because 6 comments aren't needed
;Ncomments=6
Ncomments=4
19e26da9   Ilyes Choubani   corrected stellar...
170
171
c=strarr(Ncomments)

19e26da9   Ilyes Choubani   corrected stellar...
172
173
174
;First lines of the ISRF.DAT file
c(0)='# DUSTEM: exciting radiation field featuring'
c(1)='# Mathis ISRF'
f9089dc2   Ilyes Choubani   implementing the ...
175
176
177
178
;c(2)='# Blackbody with     T=   0.0000E+00'
;c(3)='# dilution factor wdil=   1.0000E+00'
c(2)='# Nbr of points'
c(3)='# wave (microns), 4*pi*Inu (erg/cm2/s/Hz)'
19e26da9   Ilyes Choubani   corrected stellar...
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

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

the_end:
389a2b1d   Jean-Philippe Bernard   improved
197

427f1205   Jean-Michel Glorian   version 4.2 merged
198
199

END