dustem_read_qabs_lv.pro 3.31 KB
FUNCTION dustem_read_qabs_lv,file,silent=silent,read_densities=read_densities

;+
; 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:
;
; 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
  

  
st=''
Nmax=10000L
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,st
sizes=float(str_sep(strcompress(strtrim(st,2)),' '))
Ncol=Nsizes

IF keyword_set(read_densities) THEN BEGIN
  readf,unit,st
  ;stop
  IF st EQ '#### Qabs ####' THEN BEGIN
    message,'Problem with size dependent densities in Qabs.DAT',/continue
    ;stop
 ENDIF
  densities=float(str_sep(strcompress(strtrim(st,2)),' '))
ENDIF ELSE BEGIN
  densities=fltarr(Nsizes)+la_undef()
ENDELSE
;stop

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

;== read Qabs
sts[0]=str
nlines=1L
first_char=' '
WHILE first_char NE '#' DO BEGIN
    readf,unit,st
    sts[nlines]=st
    nlines=nlines+1
    first_char=strmid(st,0,1)
ENDWHILE
qabs_str=sts[0:nlines-2]
;stop

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

;== read Qsca
sts[*]=''
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
close,unit
free_lun,unit

qsca_str=sts[0:nlines-1]
;stop

Nlines=n_elements(qsca_str); -- ORIGINAL
;Nlines=n_elements(qabs_str)

qabs_values=fltarr(Nlines,Ncol)
qsca_values=fltarr(Nlines,Ncol)

FOR i=0L,Nlines-2 DO BEGIN
   ;print,i
   qabs_values[i,*]=str_sep(strcompress(strtrim(qabs_str[i],2)),' ')
   qsca_values[i,*]=str_sep(strcompress(strtrim(qsca_str[i],2)),' ')
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
;stop

full_st={file:file,Nsizes:Nsizes,sizes:sizes,densities:densities,Qabs:qabs_st,Qsca:qsca_st}

the_end:
return,full_st

END