Blame view

src/idl/dustem_write_isrf_release.pro 4.8 KB
29421054   Ilyes Choubani   write_isrf_lv is ...
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
PRO dustem_write_isrf_release,file,st,help=help

;+
; NAME:
;    dustem_write_isrf_release
;
; PURPOSE:
;    Writes file ISRF.DAT used by DustemWrap
;
; CATEGORY:
;    DustEMWrap, Distributed, Low-level, Fortran
;
; CALLING SEQUENCE:
;    dustem_write_isrf_release,file,st[,/help]
;
; INPUTS:
;    file : file name 
;    st   : input structure containing ISRF information (will be modified)
;
; OPTIONAL INPUT PARAMETERS:
;    None
;
; OUTPUTS:
;    None
;
; OPTIONAL OUTPUT PARAMETERS:
;    None
;
; ACCEPTED KEY-WORDS:
;    help      = If set print this help
;
; COMMON BLOCKS: 
;    None
;
; SIDE EFFECTS:
;    Writes a file
;
; RESTRICTIONS:
;    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.  
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_write_isrf_release'
  goto,the_end
ENDIF

;LOCATING THE ISRF PLUGINS

;IF PLUGINS AREN'T SET. WRITE THE DEFAULT DUSTEM ISRF.DAT FILE
5eebdedb   Jean-Philippe Bernard   changed plugin st...
60
61
Nplugins=n_elements(*!dustem_plugin)
scopes = strarr(Nplugins)
35b69f9a   Jean-Philippe Bernard   removed allusions...
62
Ncomments=4 ;Maximum number of comments in the .DAT file
6baf9f1f   Jean-Philippe Bernard   fixed a few issue...
63
64
c=strarr(Ncomments)
c[*]='#'
35b69f9a   Jean-Philippe Bernard   removed allusions...
65
66
ic=0L
c[ic]='# DUSTEM_WRAP: Interstellar radiation field ' & ic=ic+1
6baf9f1f   Jean-Philippe Bernard   fixed a few issue...
67

25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
68
IF (*!dustem_plugin)[0].name EQ 'NONE' THEN GOTO,write_isrf_file
29421054   Ilyes Choubani   write_isrf_lv is ...
69
70

;IF PLUGINS ARE SET, LOOP OVER THEIR SCOPES.
5eebdedb   Jean-Philippe Bernard   changed plugin st...
71
72
73
74
75
;Getting the actual scopes
FOR i=0L, Nplugins-1 DO BEGIN
    ;IF isa((*!dustem_plugin).(i).scope) THEN BEGIN
        scopes[i] = (*!dustem_plugin)[i].scope
    ;ENDIF ELSE goto, the_after
29421054   Ilyes Choubani   write_isrf_lv is ...
76
77
ENDFOR

25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
78
79
80
;Testing for the two current ISRF plugin scopes
ind_replace_isrf = where(scopes EQ 'REPLACE_ISRF',count_replace_isrf)
ind_add_isrf = where(scopes EQ 'ADD_ISRF',count_add_isrf)
29421054   Ilyes Choubani   write_isrf_lv is ...
81

25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
82
;stop
29421054   Ilyes Choubani   write_isrf_lv is ...
83

25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
84
IF count_add_isrf NE 0 OR count_replace_isrf NE 0 THEN BEGIN
35b69f9a   Jean-Philippe Bernard   removed allusions...
85
    ;lambir=dustem_get_wavelengths()   ;ACTUALLY not used
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
86
    ;IF ctpop NE 0 or ctusrisrf NE 0 THEN BEGIN
29421054   Ilyes Choubani   write_isrf_lv is ...
87
88
    ;NB: Since we're using G0_mathis=1 by default now. We will test on the !dustem_params sysvar instead of the parameter description vectors
    
35b69f9a   Jean-Philippe Bernard   removed allusions...
89
    ;G0_mathis = 1. ;Default value. This is actually not used in this code (!)
29421054   Ilyes Choubani   write_isrf_lv is ...
90
    
35b69f9a   Jean-Philippe Bernard   removed allusions...
91
92
93
    ;IF ((*!dustem_params).g0) NE 1. THEN BEGIN
    ;    G0_mathis = ((*!dustem_params).g0)
    ;ENDIF
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
94
95
96
    ; Fortran now uses negative numbers to specify Gas.dat G0
    ; If positive G0 present in Gas.dat, it takes precedence over the G0 value in GRAIN.DAT
    ; IF ((*!dustem_params).gas.g0) NE 1. then G0_mathis = float((*!dustem_params).gas.g0)
35b69f9a   Jean-Philippe Bernard   removed allusions...
97
98
99
    ;IF ((*!dustem_params).gas.g0) gt 0. THEN BEGIN
    ;    G0_mathis = float((*!dustem_params).gas.g0)
    ;ENDIF
29421054   Ilyes Choubani   write_isrf_lv is ...
100
101
    ;Getting the ISRF default wavelengths
    ;using this structure
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
102
    ;st=((*!dustem_params).isrf)
29421054   Ilyes Choubani   write_isrf_lv is ...
103
    final_isrf = fltarr(n_elements(st)) ;Initializing the ISRF vector
5eebdedb   Jean-Philippe Bernard   changed plugin st...
104
    ;=== ADD to the ISRF
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
105
106
107
108
    ;IF ctpop NE 0. THEN final_isrf=final_isrf+(*(*!dustem_plugin)[tstpop].spec)
    ;JPB: This line below can have an undefined plugin ISRF if the REPLACE_ISRF plugin has not been called earlier except with /scope or paramtags keywords
    IF count_replace_isrf NE 0. THEN BEGIN
        IF ptr_valid((*!dustem_plugin)[ind_replace_isrf].spec) THEN BEGIN
35b69f9a   Jean-Philippe Bernard   removed allusions...
109
110
                c[ic]='# DUSTEM_WRAP: replaced by radiation field from plugin '+(*!dustem_plugin)[ind_replace_isrf].name & ic=ic+1
                 final_isrf=*(*!dustem_plugin)[ind_replace_isrf].spec
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
111
112
113
114
115
116
117
118
119
        ENDIF ELSE BEGIN
                message,'Replacement ISRF not found. Using Mathis',/continue
                ;stop
                mathis_isrf_datfile=!dustem_soft_dir+'data/ISRF_MATHIS.DAT'
                sst=dustem_read_isrf(mathis_isrf_datfile)
                final_isrf=sst.isrf
                 ;stop
                ;LEFT blank intensionally
       ENDELSE
29421054   Ilyes Choubani   write_isrf_lv is ...
120
    ENDIF
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
121
122
    IF count_add_isrf NE 0 THEN BEGIN
        IF ptr_valid((*!dustem_plugin)[ind_add_isrf].spec) THEN BEGIN
35b69f9a   Jean-Philippe Bernard   removed allusions...
123
                c[ic]='# DUSTEM_WRAP: added radiation field from plugin '+(*!dustem_plugin)[ind_replace_isrf].name & ic=ic+1
cc81fcdc   Jean-Philippe Bernard   improved
124
                final_isrf=final_isrf+(*(*!dustem_plugin)[ind_add_isrf].spec)
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
125
126
127
128
129
        ENDIF ELSE BEGIN
                ;stop
                ;LEFT blank intensionally
        ENDELSE
    ENDIF    
29421054   Ilyes Choubani   write_isrf_lv is ...
130
    st.isrf = final_isrf  
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
131
132
133
134
ENDIF ELSE BEGIN       ;This is Mathis field only
    ;==== default comment lines for ISRF.DAT
    Ncomments=4
    c=strarr(Ncomments)
0b328f8c   Jean-Philippe Bernard   fixed a bug
135
    c[*]='#'
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
136
137
    c[1]='# Mathis ISRF'
ENDELSE
29421054   Ilyes Choubani   write_isrf_lv is ...
138

35b69f9a   Jean-Philippe Bernard   removed allusions...
139
;These are the last two comments
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
140
141
c[Ncomments-2]='# Nbr of points'
c[Ncomments-1]='# wave (microns), 4*pi*Inu (erg/cm2/s/Hz)'
29421054   Ilyes Choubani   write_isrf_lv is ...
142

25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
143
144
;==== Write the ISRF file
write_isrf_file:
29421054   Ilyes Choubani   write_isrf_lv is ...
145
146

openw,unit,file,/get_lun
29421054   Ilyes Choubani   write_isrf_lv is ...
147
FOR i=0,Ncomments-1 DO BEGIN
5eebdedb   Jean-Philippe Bernard   changed plugin st...
148
    printf,unit,c[i]
29421054   Ilyes Choubani   write_isrf_lv is ...
149
ENDFOR
29421054   Ilyes Choubani   write_isrf_lv is ...
150
151
n_waves=n_elements(st)
printf,unit,n_waves
29421054   Ilyes Choubani   write_isrf_lv is ...
152
FOR i=0L,n_waves-1 DO BEGIN
5eebdedb   Jean-Philippe Bernard   changed plugin st...
153
    printf,unit,st[i].lambisrf,st[i].isrf
29421054   Ilyes Choubani   write_isrf_lv is ...
154
ENDFOR
29421054   Ilyes Choubani   write_isrf_lv is ...
155
156
157
close,unit
free_lun,unit

29421054   Ilyes Choubani   write_isrf_lv is ...
158
159
160
161
the_end:


END