Blame view

src/idl/dustem_read_gcosth.pro 2.71 KB
ed96a6b1   Annie Hughes   first commit
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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
FUNCTION dustem_read_gcosth,file,silent=silent $
                             ,gcosth_values=gcosth_values 

;+
; NAME:
;   dustem_read_gcosth
;
; PURPOSE:
;   reads information relating to the grain G=cos(theta) scattering factors
;   from the corresponding .DAT file 
;
; CATEGORY:
;    DustEMWrap, Distributed, LowLevel, Initialization
;
; CALLING SEQUENCE:
;   st=dustem_read_gcosth(file)
;
; INPUTS:
;   file  : input file to be read
;
; OPTIONAL INPUT PARAMETERS:
;
; OUTPUTS:
;    st   : dustem data structure
;
; OPTIONAL OUTPUT PARAMETERS:
;    gcosth_values : values of gcosth read from file [Nsize x Nwav]
;  
; ACCEPTED KEY-WORDS:
;    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_gcosth'
   full_st=0.
   goto,the_end
ENDIF
  

st=''
Nmax=10000L ; we assume that there are less than this many lines in the file
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
readf,unit,str
sizes=float(str_sep(strcompress(strtrim(str,2)),' '))
Ncol=Nsizes

; 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
;  sizes=float(str_sep(strcompress(strtrim(str,2)),' '))
;ENDIF ELSE BEGIN
;  sizes=fltarr(Nsizes)+la_undef()
;ENDELSE

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

;== read Gcosth
sts[0]=str
nlines=1L
first_char=' '
WHILE  not eof(unit) and first_char NE '#' DO BEGIN
    readf,unit,st
    sts[nlines]=st
    nlines=nlines+1
    first_char=strmid(st,0,1)
ENDWHILE
gcosth_str=sts[0:nlines-1]
close,unit
free_lun,unit

Nlines=n_elements(gcosth_str)
gcosth_values=fltarr(Nlines,Ncol)

FOR i=0L,Nlines-1 DO gcosth_values[i,*]=str_sep(strcompress(strtrim(gcosth_str[i],2)),' ')

;== 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)
gcosth_st=replicate(one_st,Nlines)

;=== fill in the gcosth structure
FOR j=0L,Ncol-1 DO BEGIN
  gcosth_st.(j)=reform(gcosth_values(*,j))
ENDFOR

full_st={file:file,Nsizes:Nsizes,sizes:sizes,Gcosth:gcosth_st}

the_end:
return,full_st

END