dustem_read_calor.pro 2.21 KB
FUNCTION dustem_read_calor,file,silent=silent,help=help

;+
; NAME:
;   dustem_read_calor
;
; PURPOSE:
;   reads information relating to grain heat capacities from the
;    .DAT file to a dustem data structure
;
; CATEGORY:
;    DustEMWrap, Distributed, LowLevel, Initialization
;
; CALLING SEQUENCE:
;   st=dustem_read_calor(file)
;
; INPUTS:
;    file  : input file to be read
;
; OPTIONAL INPUT PARAMETERS:
;    None
;
; OUTPUTS:
;    st   : dustem data structure
;
; OPTIONAL OUTPUT PARAMETERS:
;    None
;
; 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_calor'
     st=0.
     goto,the_end
  ENDIF
  
  
;  READ(UNIT = fspecem%unit,FMT = *) COEFFISRF, NTEMP,NSPINC,NIT

;num_char=['1.','2.','3.','4.','5.']+' pour '
num_char=['1.','2.','3.','5.','4.']+' pour '

openr,unit,file,/get_lun

str='    '
all_str=['']
WHILE not eof(unit) DO BEGIN
  readf,unit,str
  all_str=[all_str,str]
ENDWHILE

close,unit
free_lun,unit

all_str=all_str(1:*)
all_str=strtrim(all_str,2)
ind=where(strlen(all_str) NE 0,count)
all_str=all_str(ind)
first_char=strmid(all_str,0,8)
match,first_char,num_char,ind1,ind2,count=count
order=sort(ind1)
ind1=ind1(order)
ind2=ind2(order)

eptr=ptr_new()
one_st={type:0,st:'',lnC:eptr,lnT:eptr}
st=replicate(one_st,count)

FOR i=0L,count-1 DO BEGIN
  IF i NE count-1 THEN Nel=ind1(i+1)-ind1(i)-1 ELSE Nel=n_elements(all_str)-ind1(i)-1
  lnT=fltarr(Nel)
  lnC=fltarr(Nel)
  FOR j=0L,Nel-1 DO BEGIN
    sst=strcompress(all_str(ind1(i)+j+1))
    toto=strsplit(strcompress(sst))
    lnT(j)=float(strmid(sst,toto(0),toto(1)-toto(0)))
    lnC(j)=float(strmid(sst,toto(1),100))
;    print,float(strmid(sst,toto(0),toto(1)-toto(0))),float(strmid(sst,toto(1),100))
  ENDFOR
  st(i).type=strmid(first_char(ind1(i)),0,1)
  st(i).st=all_str(ind1(i))
  st(i).lnC=ptr_new(LnC)
  st(i).lnT=ptr_new(LnT)
ENDFOR

the_end:
return,st

END