Blame view

src/idl/dustem_read_grain.pro 6.34 KB
f09e876c   Annie Hughes   updated doc help
1
 FUNCTION dustem_read_grain,file,silent=silent,key_str=key_str,G0=G0,help=help
452c334e   Ilyes Choubani   Implementation Of...
2

68d2f391   Jean-Philippe Bernard   modified to cope ...
3
4
5
;+
; NAME:
;    dustem_read_grain
f09e876c   Annie Hughes   updated doc help
6
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
7
8
; PURPOSE:
;    reads the file GRAIN.dat and returns the corresponding grain structure
f09e876c   Annie Hughes   updated doc help
9
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
10
; CATEGORY:
f09e876c   Annie Hughes   updated doc help
11
12
;    Dustem, Distributed, Mid-Level, Fortran
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
13
14
; CALLING SEQUENCE:
;    st=dustem_read_grain(file,[/silent][,key_str=][,G0=][,/help])
f09e876c   Annie Hughes   updated doc help
15
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
16
17
; INPUTS:
;    file = file name to be read
f09e876c   Annie Hughes   updated doc help
18
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
19
20
; OPTIONAL INPUT PARAMETERS:
;    None
f09e876c   Annie Hughes   updated doc help
21
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
22
23
; OUTPUTS:
;    st: output structure
f09e876c   Annie Hughes   updated doc help
24
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
25
26
27
; OPTIONAL OUTPUT PARAMETERS:
;    key_str : a string containing grain keywords
;    G0      : The G0 value (scaling factor for radiation field)
f09e876c   Annie Hughes   updated doc help
28
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
29
30
31
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
;    silent      = If set, keeps quiet
f09e876c   Annie Hughes   updated doc help
32
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
33
34
; COMMON BLOCKS:
;    None
f09e876c   Annie Hughes   updated doc help
35
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
36
37
; SIDE EFFECTS:
;    None
f09e876c   Annie Hughes   updated doc help
38
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
39
; RESTRICTIONS:
f09e876c   Annie Hughes   updated doc help
40
41
42
;    The DustEM fortran code must be installed
;    The DustEMWrap idl code must be installed
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
43
44
; PROCEDURE:
;    None
f09e876c   Annie Hughes   updated doc help
45
;
68d2f391   Jean-Philippe Bernard   modified to cope ...
46
47
48
; EXAMPLES
;    
; MODIFICATION HISTORY:
f09e876c   Annie Hughes   updated doc help
49
50
51
;    Written by JPB,NF,DP Jan-2007
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
68d2f391   Jean-Philippe Bernard   modified to cope ...
52
;-
427f1205   Jean-Michel Glorian   version 4.2 merged
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

;=== Format for DUSTEM_WHICH=VERSTRAETE
;; # DUSTEM: definition of grain populations
;; # for each grain TYPE make sure you have the following files
;; # Q_TYPE.DAT in code_f90/les_QABS
;; # C_TYPE.DAT in code_f90/les_CAPA
;; # if option(MIX) MIX_TYPE.DAT in code_f90/les_DAT
;; # if option(POL) POL_TYPE.DAT in code_f90/les_DAT
;; # if keyword(SIZE) SIZE_TYPE.DAT in code_f90/les_DAT
;; # 
;; # run keywords
;; # G0 scaling factor for radiation field
;; # nr of grain types
;; # grain type -  Mdust/MH - rho(g/cm3) - amin(cm) - amax(cm) - alpha - nsize
;; #
;; SIZE
;; 1.00D+00
;; 3
;; PAH1    4.50D-04  2.25D+00  3.50D-08  7.22D-08  -3.50D+00   10  NONE
;; Gra     2.30D-03  2.25D+00  1.00D-07  5.00D-07  -3.50D+00   20  NONE
;; aSil    7.00D-03  3.30D+00  5.00D-07  1.10D-05  -3.50D+00   20  NONE
;; #

;=== Format for DUSTEM_WHICH=WEB3p8
;; # DUSTEM: definition of grain populations
;; # 
;; # run keywords 
;; # G0 scaling factor for radiation field
;; # grain type, nsize, type keywords, Mdust/MH, rho, amin, amax, alpha/a0 [, at, ac, gamma (ED)] [, au, zeta, eta (CV)]
;; # cgs units
;; #
;; sdist
;; 1.000000
;; PAH0              10 mix-logn           7.8000E-04  2.2400E+00  3.5000E-08  1.2000E-07  6.4000E-08  1.0000E-01
;; PAH1              10 mix-logn           7.8000E-04  2.2400E+00  3.5000E-08  1.2000E-07  6.4000E-08  1.0000E-01
68d2f391   Jean-Philippe Bernard   modified to cope ...
88
89
90
91
92
93
94
95
96
;; amCBEx            15 logn             1.6500E-04  1.8100E+00  6.0000E-08  2.0000E-06  2.0000E-07  3.5000E-01
;; amCBEx            25 plaw-ed      1.4500E-03  1.8100E+00  4.0000E-07  2.0000E-04 -2.8000E+00  1.5000E-05  1.5000E-05  2.0000E+00
;; aSil              25 plaw-ed        7.8000E-03  3.5000E+00  4.0000E-07  2.0000E-04 -3.4000E+00  2.0000E-05  2.0000E-05  2.0000E+00

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_read_grain'
  full_st=0.
  goto,the_end
ENDIF
427f1205   Jean-Michel Glorian   version 4.2 merged
97

b5ccb706   Jean-Philippe Bernard   improved to fit p...
98
99
;!run_pol now defined in dustem_init.pro
;defsysv, '!run_pol', 0.         ; Global flag to know if polarisation is being run
68d2f391   Jean-Philippe Bernard   modified to cope ...
100
defsysv,'!run_tls',0.           ; Global flag to know if TLS is being run
427f1205   Jean-Michel Glorian   version 4.2 merged
101

427f1205   Jean-Michel Glorian   version 4.2 merged
102
CASE !dustem_which OF
3c479f24   Ilyes Choubani   Allowing to fix p...
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
  
  'VERSTRAETE':BEGIN
    frmt='(A,D,D,D,D,D,I,A)'
    openr,unit,file,/get_lun
    str=''
    REPEAT BEGIN
      readf,unit,str
      first_char=strmid(str,0,1)
    ENDREP UNTIL first_char NE '#'
    key_str=str
    readf,unit,G0
    readf,unit,nspecies
    one_st={type:'',propmass:0.D0,densgr:0.D0,tmin:0.D0,tmax:0.D0,alpha:0.D0,ndiscr:0,flag:''}
    st=replicate(one_st,nspecies)
    FOR i=0L,nspecies-1 DO BEGIN
      readf,unit,str
      strv=str_sep(strcompress(str),' ')
      st(i).type=strv(0)
      st(i).propmass=double(strv(1))
      st(i).densgr=double(strv(2))
      st(i).tmin=double(strv(3))
      st(i).tmax=double(strv(4))
      st(i).alpha=double(strv(5))
      st(i).ndiscr=fix(strv(6))
      st(i).flag=strv(7)
    ENDFOR
    full_st=st
    close,unit
    free_lun,unit
  END

;   ELSE:BEGIN
;     readcol,file,type,albmax,densgr,ngem,hydro,ioni,silent=silent
;     nlines=n_elements(type)
; 
;     one_st={type:0,albmax:0.,densgr:0.,ngem:0,hydro:0.,ioni:0.}
;     st=replicate(one_st,Nlines)
;     st.type=type
;     st.albmax=albmax
;     st.densgr=densgr
;     st.ngem=ngem
;     st.hydro=hydro
;     st.ioni=ioni
;     full_st=st
;   END
    
  
  
  ELSE: BEGIN 
427f1205   Jean-Michel Glorian   version 4.2 merged
152
153
154
155
156
157
158
159
160
161
    frmt='(A,D,D,D,D,D,I,A)'
    ;count # of lines
    openr,unit,file,/get_lun
    Nlines=0L
    str=''
    WHILE not eof(unit) DO BEGIN
      readf,unit,str
      Nlines=Nlines+1
    ENDWHILE
    close,unit
68d2f391   Jean-Philippe Bernard   modified to cope ...
162
    free_lun,unit
427f1205   Jean-Michel Glorian   version 4.2 merged
163
164
165
166
167
168
169
170
171
    ;== now read the file
    openr,unit,file,/get_lun
    ncurrent=0L
    REPEAT BEGIN
      readf,unit,str
      ncurrent=ncurrent+1
      first_char=strmid(str,0,1)
    ENDREP UNTIL first_char NE '#'
    key_str=str
6730c3f8   Jean-Philippe Bernard   modified to be co...
172
    readf,unit,G0 & ncurrent=ncurrent+1
427f1205   Jean-Michel Glorian   version 4.2 merged
173
    nspecies=nlines-ncurrent
427f1205   Jean-Michel Glorian   version 4.2 merged
174
175
176
177
    one_st={grain_type:'',nsize:0L,type_keywords:'',Mdust_o_MH:0.D0,rho:0.D0,amin:0.D0,amax:0.D0,alpha_o_a0:0.D0, $
            at:0.D0,ac:0.D0,gamma:0.D0, $
            au:0.D0,zeta:0.D0,eta:0.D0}
    st=replicate(one_st,nspecies)
eef37ef9   Annie Hughes   do not remember, ...
178
    
427f1205   Jean-Michel Glorian   version 4.2 merged
179
180
    FOR i=0L,nspecies-1 DO BEGIN
      readf,unit,str
427f1205   Jean-Michel Glorian   version 4.2 merged
181
      strv=str_sep(strcompress(strtrim(str,2)),' ')
427f1205   Jean-Michel Glorian   version 4.2 merged
182
183
184
185
186
      Nstrv=n_elements(strv)
      ii=0L
      st(i).grain_type=strv(ii) & ii=ii+1
      st(i).nsize=long(strv(ii)) & ii=ii+1
      st(i).type_keywords=strv(ii) & ii=ii+1
06fe3845   Ilyes Choubani   general update
187
      if isa(!dustem_kwords) then st(i).type_keywords=(*!dustem_kwords)(i)
427f1205   Jean-Michel Glorian   version 4.2 merged
188
      IF stregex(st(i).type_keywords, 'pol', /bool) THEN !run_pol = 1
427f1205   Jean-Michel Glorian   version 4.2 merged
189
      IF stregex(st(i).type_keywords, 'dtls', /bool) THEN !run_tls = 1
6730c3f8   Jean-Philippe Bernard   modified to be co...
190
      st(i).Mdust_o_MH=double(strv(ii)) & ii=ii+1
427f1205   Jean-Michel Glorian   version 4.2 merged
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
      st(i).rho=double(strv(ii))  & ii=ii+1
      st(i).amin=double(strv(ii)) & ii=ii+1
      st(i).amax=double(strv(ii)) & ii=ii+1
      st(i).alpha_o_a0=double(strv(ii)) & ii=ii+1
      IF ii LE Nstrv-1 THEN BEGIN
        st(i).at=double(strv(ii)) & ii=ii+1
      ENDIF
      IF ii LE Nstrv-1 THEN BEGIN
        st(i).ac=double(strv(ii)) & ii=ii+1
      ENDIF
      IF ii LE Nstrv-1 THEN BEGIN
        st(i).gamma=double(strv(ii)) & ii=ii+1
      ENDIF
      IF ii LE Nstrv-1 THEN BEGIN
        st(i).au=double(strv(ii)) & ii=ii+1
      ENDIF
      IF ii LE Nstrv-1 THEN BEGIN
        st(i).zeta=double(strv(ii)) & ii=ii+1
      ENDIF
      IF ii LE Nstrv-1 THEN BEGIN
        st(i).eta=double(strv(ii)) & ii=ii+1
      ENDIF
    ENDFOR
6730c3f8   Jean-Philippe Bernard   modified to be co...
214
    full_st=st
427f1205   Jean-Michel Glorian   version 4.2 merged
215
216
    close,unit
    free_lun,unit
3c479f24   Ilyes Choubani   Allowing to fix p...
217
218
219
  END  
    

427f1205   Jean-Michel Glorian   version 4.2 merged
220

427f1205   Jean-Michel Glorian   version 4.2 merged
221
222
ENDCASE

e69bf245   Jean-Philippe Bernard   improved
223

68d2f391   Jean-Philippe Bernard   modified to cope ...
224
the_end:
427f1205   Jean-Michel Glorian   version 4.2 merged
225

e69bf245   Jean-Philippe Bernard   improved
226
227
;stop 

68d2f391   Jean-Philippe Bernard   modified to cope ...
228
RETURN,full_st
427f1205   Jean-Michel Glorian   version 4.2 merged
229
230

END