Blame view

src/idl/dustem_read_qabs_lv.pro 3.53 KB
3c33391b   Annie Hughes   modifs for K15 an...
1
2
3
FUNCTION dustem_read_qabs_lv,file,silent=silent,read_densities=read_densities $
                             ,qabs_values=qabs_values $
                             ,qsca_values=qsca_values 
427f1205   Jean-Michel Glorian   version 4.2 merged
4

eafc1f8f   Annie Hughes   updated help info
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;+
; NAME:
;   dustem_read_qabs_lv
;
; PURPOSE:
;   reads information relating to the grain QABS
;   from the corresponding .DAT file for the LV fortran version
;
; CATEGORY:
;    DustEMWrap, Distributed, LowLevel, Initialization
;
; CALLING SEQUENCE:
;   st=dustem_read_qabs_lv(file)
;
; INPUTS:
;   file  : input file to be read
;
; OPTIONAL INPUT PARAMETERS:
;
; OUTPUTS:
;    st   : dustem data structure
;
; OPTIONAL OUTPUT PARAMETERS:
3c33391b   Annie Hughes   modifs for K15 an...
28
29
30
;    qabs_values : values of qabs read from file [Nsize x Nwav]
;    qsca_values : values of qsca read from file [Nsize x Nwav]
;  
eafc1f8f   Annie Hughes   updated help info
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
60
; ACCEPTED KEY-WORDS:
;    read_densities : if grain densities are size-dependent they should be
;    read here
;    help     : writes this help
;
; COMMON BLOCKS:
;    None
;
; SIDE EFFECTS:
;
; RESTRICTIONS:
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
;
; PROCEDURES AND SUBROUTINES USED:  
;
; EXAMPLES:
;
; MODIFICATION HISTORY:
;    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_read_qabs_lv'
   full_st=0.
   goto,the_end
ENDIF
  

427f1205   Jean-Michel Glorian   version 4.2 merged
61
st=''
1efc19ff   Annie Hughes   changes for HD22
62
Nmax=10000L ; we assume that there are less than this many lines in the file
427f1205   Jean-Michel Glorian   version 4.2 merged
63
64
65
66
67
68
69
70
71
72
73
74
75
76
sts=strarr(Nmax)
openr,unit,file,/get_lun

;==read comments
str='' & first_char='#'
WHILE first_char EQ '#' DO BEGIN
  readf,unit,str
  first_char=strmid(str,0,1)
ENDWHILE

;read number of sizes
Nsizes=fix(str)

;Get sizes
bcae1765   Annie Hughes   tidied up reading...
77
78
readf,unit,str
sizes=float(str_sep(strcompress(strtrim(str,2)),' '))
427f1205   Jean-Michel Glorian   version 4.2 merged
79
80
Ncol=Nsizes

bcae1765   Annie Hughes   tidied up reading...
81
82
83
84
85
; test read the next line to see if it contains densities 
readf,unit,str
first_char=strmid(str,0,1)
IF first_char ne '#' THEN BEGIN
  densities=float(str_sep(strcompress(strtrim(str,2)),' '))
2399e73e   Jean-Philippe Bernard   imprved towards r...
86
87
88
ENDIF ELSE BEGIN
  densities=fltarr(Nsizes)+la_undef()
ENDELSE
2399e73e   Jean-Philippe Bernard   imprved towards r...
89

427f1205   Jean-Michel Glorian   version 4.2 merged
90
91
92
93
94
95
96
97
;==read comments
str='' & first_char='#'
WHILE first_char EQ '#' DO BEGIN
  readf,unit,str
  first_char=strmid(str,0,1)
ENDWHILE

;== read Qabs
2399e73e   Jean-Philippe Bernard   imprved towards r...
98
sts[0]=str
427f1205   Jean-Michel Glorian   version 4.2 merged
99
100
101
102
nlines=1L
first_char=' '
WHILE first_char NE '#' DO BEGIN
    readf,unit,st
eef37ef9   Annie Hughes   do not remember, ...
103
    sts[nlines]=st
427f1205   Jean-Michel Glorian   version 4.2 merged
104
105
106
    nlines=nlines+1
    first_char=strmid(st,0,1)
ENDWHILE
2399e73e   Jean-Philippe Bernard   imprved towards r...
107
qabs_str=sts[0:nlines-2]
eef37ef9   Annie Hughes   do not remember, ...
108
;stop
427f1205   Jean-Michel Glorian   version 4.2 merged
109
110
111
112
113
114
115
116
117

;==read comments
str='' & first_char='#'
WHILE first_char EQ '#' DO BEGIN
  readf,unit,str
  first_char=strmid(str,0,1)
ENDWHILE

;== read Qsca
eef37ef9   Annie Hughes   do not remember, ...
118
119
sts[*]=''
sts[0]=str
427f1205   Jean-Michel Glorian   version 4.2 merged
120
121
122
123
nlines=1L
first_char=' '
WHILE not eof(unit) and first_char NE '#' DO BEGIN
    readf,unit,st
eef37ef9   Annie Hughes   do not remember, ...
124
    sts[nlines]=st
427f1205   Jean-Michel Glorian   version 4.2 merged
125
126
127
128
129
130
    nlines=nlines+1
    first_char=strmid(st,0,1)
ENDWHILE
close,unit
free_lun,unit

eef37ef9   Annie Hughes   do not remember, ...
131
qsca_str=sts[0:nlines-1]
427f1205   Jean-Michel Glorian   version 4.2 merged
132

eef37ef9   Annie Hughes   do not remember, ...
133
134
Nlines=n_elements(qsca_str); -- ORIGINAL
;Nlines=n_elements(qabs_str)
427f1205   Jean-Michel Glorian   version 4.2 merged
135
136
137

qabs_values=fltarr(Nlines,Ncol)
qsca_values=fltarr(Nlines,Ncol)
da01e0aa   Annie Hughes   comments editing ...
138

607060e5   Ilyes Choubani   test version
139
FOR i=0L,Nlines-2 DO BEGIN
eef37ef9   Annie Hughes   do not remember, ...
140
141
   qabs_values[i,*]=str_sep(strcompress(strtrim(qabs_str[i],2)),' ')
   qsca_values[i,*]=str_sep(strcompress(strtrim(qsca_str[i],2)),' ')
427f1205   Jean-Michel Glorian   version 4.2 merged
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
ENDFOR

;== Make output structure
cmd='one_st={'
FOR i=0L,Ncol-1 DO BEGIN
  cmd=cmd+'v'+strtrim(i+1,2)+':'+'0.'
  IF i NE Ncol-1 THEN BEGIN
    cmd=cmd+','
  ENDIF ELSE BEGIN
    cmd=cmd+'}'
  ENDELSE
ENDFOR
toto=execute(cmd)
qabs_st=replicate(one_st,Nlines)
qsca_st=replicate(one_st,Nlines)

;=== fill in the qabs structure
FOR j=0L,Ncol-1 DO BEGIN
  qabs_st.(j)=reform(qabs_values(*,j))
  qsca_st.(j)=reform(qsca_values(*,j))
ENDFOR
eef37ef9   Annie Hughes   do not remember, ...
163
;stop
427f1205   Jean-Michel Glorian   version 4.2 merged
164

2399e73e   Jean-Philippe Bernard   imprved towards r...
165
full_st={file:file,Nsizes:Nsizes,sizes:sizes,densities:densities,Qabs:qabs_st,Qsca:qsca_st}
427f1205   Jean-Michel Glorian   version 4.2 merged
166

eafc1f8f   Annie Hughes   updated help info
167
the_end:
427f1205   Jean-Michel Glorian   version 4.2 merged
168
169
170
return,full_st

END