Blame view

src/idl/dustem_write_isrf_lv.pro 7.07 KB
389a2b1d   Jean-Philippe Bernard   improved
1
2
3
4
5
PRO dustem_write_isrf_lv,file,st,help=help

;+
; NAME:
;    dustem_write_isrf_lv
a5d1ca4f   Annie Hughes   updated doc help
6
;
389a2b1d   Jean-Philippe Bernard   improved
7
; PURPOSE:
a5d1ca4f   Annie Hughes   updated doc help
8
9
;    Writes file ISRF.DAT used by DustemWrap
;
389a2b1d   Jean-Philippe Bernard   improved
10
; CATEGORY:
a5d1ca4f   Annie Hughes   updated doc help
11
12
;    DustEMWrap, Distributed, Low-level, Fortran
;
389a2b1d   Jean-Philippe Bernard   improved
13
14
; CALLING SEQUENCE:
;    dustem_write_isrf_lv,file,st[,/help]
a5d1ca4f   Annie Hughes   updated doc help
15
;
389a2b1d   Jean-Philippe Bernard   improved
16
17
; INPUTS:
;    file : file name 
a5d1ca4f   Annie Hughes   updated doc help
18
19
;    st   : input structure containing ISRF information (will be modified)
;
389a2b1d   Jean-Philippe Bernard   improved
20
21
; OPTIONAL INPUT PARAMETERS:
;    None
a5d1ca4f   Annie Hughes   updated doc help
22
;
389a2b1d   Jean-Philippe Bernard   improved
23
24
; OUTPUTS:
;    None
a5d1ca4f   Annie Hughes   updated doc help
25
;
389a2b1d   Jean-Philippe Bernard   improved
26
27
; OPTIONAL OUTPUT PARAMETERS:
;    None
a5d1ca4f   Annie Hughes   updated doc help
28
;
389a2b1d   Jean-Philippe Bernard   improved
29
30
; ACCEPTED KEY-WORDS:
;    help      = If set print this help
a5d1ca4f   Annie Hughes   updated doc help
31
;
4750086c   Ilyes Choubani   nouvelle philosph...
32
; COMMON BLOCKS: 
389a2b1d   Jean-Philippe Bernard   improved
33
;    None
a5d1ca4f   Annie Hughes   updated doc help
34
;
389a2b1d   Jean-Philippe Bernard   improved
35
; SIDE EFFECTS:
a5d1ca4f   Annie Hughes   updated doc help
36
37
;    Writes a file
;
389a2b1d   Jean-Philippe Bernard   improved
38
; RESTRICTIONS:
a5d1ca4f   Annie Hughes   updated doc help
39
40
41
42
43
44
45
46
47
48
49
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
;
; PROCEDURE AND SUBROUTINES
;    
; EXAMPLES
;    
; MODIFICATION HISTORY:
;    Written by Ilyes Choubani 2022
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
389a2b1d   Jean-Philippe Bernard   improved
50
51
52
;-

IF keyword_set(help) THEN BEGIN
4750086c   Ilyes Choubani   nouvelle philosph...
53
  doc_library,'dustem_write_isrf_lv'
389a2b1d   Jean-Philippe Bernard   improved
54
55
56
  goto,the_end
ENDIF

f9089dc2   Ilyes Choubani   implementing the ...
57
58
;Replacing the old block with an iteration over the plugins' scopes 
scopes = strarr(n_tags(*!dustem_plugin))
b9bf16a2   Ilyes Choubani   adjusting tests o...
59
IF (tag_names(*!dustem_plugin))[0] EQ 'NONE' then goto, the_after
f9089dc2   Ilyes Choubani   implementing the ...
60
61
;Getting the actual scopes 
FOR i=0L, n_tags(*!dustem_plugin)-1 DO BEGIN
2cd69ae7   Ilyes Choubani   Corrected small b...
62
    if isa((*!dustem_plugin).(i).scope) THEN BEGIN
b9bf16a2   Ilyes Choubani   adjusting tests o...
63
64
        scopes[i] = (*(*!dustem_plugin).(i).scope)
    ENDIF ELSE goto, the_after
f9089dc2   Ilyes Choubani   implementing the ...
65
ENDFOR
427f1205   Jean-Michel Glorian   version 4.2 merged
66

f9089dc2   Ilyes Choubani   implementing the ...
67
68
tstpop = where(scopes EQ 'STELLAR_POPULATION',ctpop)
tstusrisrf = where(scopes EQ 'USER_ISRF',ctusrisrf)
f9089dc2   Ilyes Choubani   implementing the ...
69
70
71
72
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 ...
73
    ;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 ...
74
75
76
77
    ;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)
2cd69ae7   Ilyes Choubani   Corrected small b...
78
79
80
81
    IF countg0 NE 0 THEN BEGIN
        IF isa((*!dustem_fit).current_param_values) THEN G0_mathis = (*(*!dustem_fit).current_param_values)[ind_G0] $
            ELSE G0_mathis = (*(*!dustem_fit).param_init_values)[ind_G0] 
    ENDIF
f9089dc2   Ilyes Choubani   implementing the ...
82
83
84
85
86
87
    ;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
f9089dc2   Ilyes Choubani   implementing the ...
88
89
    ;Locating gas.G0 in the free parameters vector
    ind_GASG0 = where(strupcase(strmid((*(*!dustem_fit).param_descs),5,/reverse)) EQ 'GAS.G0', countgasg0)
2cd69ae7   Ilyes Choubani   Corrected small b...
90
91
92
93
    IF countgasg0 THEN BEGIN
        IF isa((*!dustem_fit).current_param_values) THEN G0_mathis = (*(*!dustem_fit).current_param_values)[ind_GASG0] $ 
            ELSE G0_mathis = (*(*!dustem_fit).param_init_values)[ind_GASG0]
    ENDIF
f9089dc2   Ilyes Choubani   implementing the ...
94
95
96
97
98
99
100
101
102
103
    ;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
491838b5   Ilyes Choubani   Corrected comment...
104
    Ncomments=3 ;default number of comments in the .DAT file (minus the ISRF used)
f9089dc2   Ilyes Choubani   implementing the ...
105
    c=strarr(Ncomments)
2bbb56cf   Jean-Philippe Bernard   modified to fix b...
106
107
    c(0)='# DUSTEM: exciting radiation field featuring'
    ;stop
a73f6031   Ilyes Choubani   small corrections...
108
109
    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)
2cd69ae7   Ilyes Choubani   Corrected small b...
110
    
491838b5   Ilyes Choubani   Corrected comment...
111
112
    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'
f9089dc2   Ilyes Choubani   implementing the ...
113
114
115
    
    IF ctpop NE 0 and ctusrisrf NE 0 THEN BEGIN
        Ncomments+=1
a73f6031   Ilyes Choubani   small corrections...
116
117
        c=strarr(Ncomments)
        c(0)='# DUSTEM: exciting radiation field featuring'  
491838b5   Ilyes Choubani   Corrected comment...
118
119
        c(1) = '# STELLAR POPULATION ISRF'
        c(2) = '# USER-DEFINED ISRF'
f9089dc2   Ilyes Choubani   implementing the ...
120
    ENDIF
e1f224ac   Ilyes Choubani   Not thoroughly te...
121
    
bb69363f   Annie Hughes   G0 to float
122
    IF G0_mathis EQ 0 THEN G0_mathis=1.
e1f224ac   Ilyes Choubani   Not thoroughly te...
123
124
    
    ;the below condition will always be valid
75d04dc3   Ilyes Choubani   removed forgotten...
125
    IF G0_mathis NE 0 THEN BEGIN 
f9089dc2   Ilyes Choubani   implementing the ...
126
127
128
129
        ;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)
a73f6031   Ilyes Choubani   small corrections...
130
        final_isrf=final_isrf/G0_mathis[0]+ma_isrf.isrf
491838b5   Ilyes Choubani   Corrected comment...
131
        Ncomments=4
a5d1ca4f   Annie Hughes   updated doc help
132
        c=strarr(Ncomments)
a73f6031   Ilyes Choubani   small corrections...
133
        c(0)='# DUSTEM: exciting radiation field featuring'
491838b5   Ilyes Choubani   Corrected comment...
134
        IF ctpop NE 0 and ctusrisrf EQ 0 THEN c(1) = '# STELLAR POPULATION ISRF'
a5d1ca4f   Annie Hughes   updated doc help
135
        IF ctpop EQ 0 and ctusrisrf NE 0 THEN c(1) = '# USER-DEFINED ISRF'
a73f6031   Ilyes Choubani   small corrections...
136
        IF ctpop NE 0 and ctusrisrf NE 0 THEN BEGIN
491838b5   Ilyes Choubani   Corrected comment...
137
            Ncomments+=2
a73f6031   Ilyes Choubani   small corrections...
138
139
            c=strarr(Ncomments)
            c(0)='# DUSTEM: exciting radiation field featuring'  
491838b5   Ilyes Choubani   Corrected comment...
140
141
142
143
            c(1) = '# STELLAR POPULATION ISRF'
            c(2) ='# USER-DEFINED ISRF'
            c(3) = '# MATHIS ISRF'
        ENDIF ELSE c(Ncomments-3) = '# MATHIS ISRF'
a73f6031   Ilyes Choubani   small corrections...
144
        
f9089dc2   Ilyes Choubani   implementing the ...
145
    ENDIF
e1f224ac   Ilyes Choubani   Not thoroughly te...
146
    
f9089dc2   Ilyes Choubani   implementing the ...
147
    st.isrf = final_isrf  
a5d1ca4f   Annie Hughes   updated doc help
148

f9089dc2   Ilyes Choubani   implementing the ...
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
    ;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
184
ENDIF
19e26da9   Ilyes Choubani   corrected stellar...
185

f9089dc2   Ilyes Choubani   implementing the ...
186
187
188
189
190
the_after:
;Defaut ISRF writing (MATHIS)
;This was changed because 6 comments aren't needed
;Ncomments=6
Ncomments=4
19e26da9   Ilyes Choubani   corrected stellar...
191
192
c=strarr(Ncomments)

19e26da9   Ilyes Choubani   corrected stellar...
193
194
195
;First lines of the ISRF.DAT file
c(0)='# DUSTEM: exciting radiation field featuring'
c(1)='# Mathis ISRF'
f9089dc2   Ilyes Choubani   implementing the ...
196
197
198
199
;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...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

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
218

427f1205   Jean-Michel Glorian   version 4.2 merged
219
220

END