Blame view

src/idl/dustem_read_gas.pro 3.59 KB
98d63e54   Jean-Philippe Bernard   added new files
1
2
3
4
5
FUNCTION dustem_read_gas,file,silent=silent,help=help

;+
; NAME:
;    dustem_read_gas
f09e876c   Annie Hughes   updated doc help
6
;
98d63e54   Jean-Philippe Bernard   added new files
7
8
; PURPOSE:
;    reads the file GAS.dat and returns the corresponding grain structure
f09e876c   Annie Hughes   updated doc help
9
;
98d63e54   Jean-Philippe Bernard   added new files
10
11
; CATEGORY:
;    Dustem
f09e876c   Annie Hughes   updated doc help
12
;
98d63e54   Jean-Philippe Bernard   added new files
13
14
; CALLING SEQUENCE:
;    st=dustem_read_gas(file,[/silent][,/help])
f09e876c   Annie Hughes   updated doc help
15
;
98d63e54   Jean-Philippe Bernard   added new files
16
17
; INPUTS:
;    file = file name to be read
f09e876c   Annie Hughes   updated doc help
18
;
98d63e54   Jean-Philippe Bernard   added new files
19
20
; OPTIONAL INPUT PARAMETERS:
;    None
f09e876c   Annie Hughes   updated doc help
21
;
98d63e54   Jean-Philippe Bernard   added new files
22
23
; OUTPUTS:
;    st: output structure
f09e876c   Annie Hughes   updated doc help
24
;
98d63e54   Jean-Philippe Bernard   added new files
25
26
; OPTIONAL OUTPUT PARAMETERS:
;    None
f09e876c   Annie Hughes   updated doc help
27
;
98d63e54   Jean-Philippe Bernard   added new files
28
29
30
; ACCEPTED KEY-WORDS:
;    silent      = If set, keeps quiet
;    help      = If set, print this help
f09e876c   Annie Hughes   updated doc help
31
;
98d63e54   Jean-Philippe Bernard   added new files
32
33
; COMMON BLOCKS:
;    None
f09e876c   Annie Hughes   updated doc help
34
;
98d63e54   Jean-Philippe Bernard   added new files
35
36
; SIDE EFFECTS:
;    None
f09e876c   Annie Hughes   updated doc help
37
;
98d63e54   Jean-Philippe Bernard   added new files
38
; RESTRICTIONS:
f09e876c   Annie Hughes   updated doc help
39
40
41
;    The DustEM fortran code must be installed
;    The DustEMWrap idl code must be installed
;
98d63e54   Jean-Philippe Bernard   added new files
42
43
; PROCEDURE:
;    None
f09e876c   Annie Hughes   updated doc help
44
;
98d63e54   Jean-Philippe Bernard   added new files
45
46
47
; EXAMPLES
;    
; MODIFICATION HISTORY:
f09e876c   Annie Hughes   updated doc help
48
49
50
;    Written by JPB,NF,DP Jan-2007
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
98d63e54   Jean-Philippe Bernard   added new files
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
;-

;=== Format for DUSTEM_WHICH=WEB3p8
;# DUSTEM : Gas quantities from Ysard, Juvela & Verstraete (2011)
;# 
;# Gas temperature (K), hydrogen density, H2 density, CR rate, G0 (if>0 supersedes GRAIN.DAT)
;# number of charge type (electrons, H+, C+, ...)
;# ion density (cm-3), mass (amu), charge, polarizability (A^3)
;# >>>>> 1st line is electron <<<<<<<
;# 
;  3.5550e+03 1e-1 -1e0 5e-17   1.0000e+00 3
;-1e0 5.4858e-04 -1e0 0.00
;0e0  1.00794e0   1e0 0.67
; -1.3000e-05 12.0107e0   1e0 1.54

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_read_gas'
  st=0.
  goto,the_end
ENDIF

CASE !dustem_which OF
3c479f24   Ilyes Choubani   Allowing to fix p...
73
  'RELEASE': BEGIN
98d63e54   Jean-Philippe Bernard   added new files
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
    ;==read and count comments
    openr,unit,file,/get_lun
    str=''
    comments=['']
    first_char='#'
    Ncomments=0L
    WHILE first_char EQ '#' DO BEGIN
       readf,unit,str
       first_char=strmid(str,0,1)
       comments=[comments,str]
       IF first_char EQ '#' THEN Ncomments=Ncomments+1
    ENDWHILE
    comments=comments[1:*]
    IF Ncomments NE 0 THEN comments=comments[0:Ncomments-1]
    close,unit
    free_lun,unit
    st={file:file, $
        Tgas:0.D0,nH:0.D0,nh2:0.D0,CR_rate:0.D0,G0:0.D0,n_charges:0L, $
        charges_props:ptr_new(), $
        comments:comments}
    one_charge_st={density:0.D0,mass:0.D0,charge:0.D0,polarizability:0.D0}
    ;== pass comments
    openr,unit,file,/get_lun
    str=''
    FOR i=0L,Ncomments-1 DO BEGIN
      readf,unit,str
    ENDFOR
    ;== read data
    readf,unit,str
    strv=str_sep(strcompress(strtrim(str,2)),' ') & ii=0L
    st.Tgas=double(strv[ii]) & ii=ii+1
    st.nH=double(strv[ii]) & ii=ii+1
    st.nH2=double(strv[ii]) & ii=ii+1
    st.CR_rate=double(strv[ii]) & ii=ii+1
42004ff8   Jean-Philippe Bernard   fixed bug due to ...
108
109
    ;modified because the file geometry did change !!
    ;st.G0=double(strv[ii]) & ii=ii+1
98d63e54   Jean-Philippe Bernard   added new files
110
    st.G0=double(strv[ii]) & ii=ii+1
117c8f36   Jean-Philippe Bernard   modified to cope ...
111
112
113
114
115
    ;This for the version distributed by Nathalie
    ;readf,unit,str
    ;strv=str_sep(strcompress(strtrim(str,2)),' ') & ii=0L
    ;st.n_charges=long(strv[ii])
    ;This for the right version, not distributed by Nathalie !
98d63e54   Jean-Philippe Bernard   added new files
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
    st.n_charges=long(strv[ii])
    charges_st=replicate(one_charge_st,st.n_charges)
    FOR i=0L,st.n_charges-1 DO BEGIN
      readf,unit,str
      strv=str_sep(strcompress(strtrim(str,2)),' ') & ii=0L
      charges_st[i].density=double(strv[ii]) & ii=ii+1
      charges_st[i].mass=double(strv[ii]) & ii=ii+1
      charges_st[i].charge=double(strv[ii]) & ii=ii+1
      charges_st[i].polarizability=double(strv[ii])
    ENDFOR
    close,unit
    free_lun,unit
    st.charges_props=ptr_new(charges_st)
  END
  'VERSTRAETE':BEGIN
    ;GAS.DAT did not exist in that version. Kept empty
    st=0
  END
  ELSE:BEGIN
    ;GAS.DAT did not exist in that version. Kept empty
    st=0
  END
ENDCASE

;stop 

the_end:

RETURN,st

f09e876c   Annie Hughes   updated doc help
146
END