dustem_read_align.pro 3.79 KB
FUNCTION dustem_read_align,dir_in,st_grains,silent=silent

;moved to dustem_init.pro
;defsysv, '!run_circ', 0.  
;defsysv, '!run_anis', 0.  
;defsysv, '!run_rrf', 0.    
;defsysv, '!run_univ', 0.    
;defsysv, '!run_lin', 0.    

file=dir_in+(*!dustem_inputs).align
openr,unit,file,/get_lun
Nlines=0L
str=''
WHILE not eof(unit) DO BEGIN
      readf,unit,str
      Nlines=Nlines+1
ENDWHILE
close,unit
free_lun,unit

;== now read the file
openr,unit,file,/get_lun
ncurrent=0L
REPEAT BEGIN
      readf,unit,str
      ncurrent=ncurrent+1
      first_char=strmid(str,0,1)
ENDREP UNTIL first_char NE '#'
key_str=str

IF stregex(key_str, 'lin', /bool) THEN !run_lin = 1
IF stregex(key_str, 'univ', /bool) THEN !run_univ = 1
IF stregex(key_str, 'circ', /bool) THEN !run_circ = 1
IF stregex(key_str, 'anis', /bool) THEN !run_anis = 1
IF stregex(key_str, 'rrf', /bool) THEN !run_rrf = 1

readf,unit,str,format='(A100)'
xx=strsplit(str,' ',/regex,/extr)
anisG0 = float(xx(0))
ncurrent+=+1
nalig=nlines-ncurrent

;stop

one_st={aligned:0.,law:'',athresh:0.,plev:0.,pstiff:0.,TdsTg:0.,a0:0.,rvcut:0.}
;Ngrains=st_grains.Ngrains
Ngrains=n_elements(st_grains)

st=replicate(one_st,Ngrains)

;st.aligned = stregex(st_grains.grains.type_keywords, 'pol', /bool) 
;count=0

FOR i=0L,Ngrains-1 DO BEGIN
  ;stop
  is_aligned = stregex(st_grains(i).type_keywords, 'pol', /bool) 

  ;IF st(i).aligned then begin
  IF is_aligned THEN BEGIN
    ;stop
    readf,unit,str,format='(A100)'
    strv=str_sep(strcompress(strtrim(str,2)),' ')
    Nstrv=n_elements(strv)
  
    ii=0L
    st(i).law=strv(ii) & ii=ii+1

    ; IDG
    IF stregex(st(i).law, 'idg', /bool) THEN BEGIN
      st[i].TdsTg = strv[ii] & ii=ii+1
      st[i].a0    = strv[ii] & ii=ii+1
      st[i].rvcut = strv[ii] & ii=ii+1
    ENDIF

    ; RAT
    IF stregex(st(i).law, 'rat', /bool) THEN BEGIN
    ENDIF

    ; PARAMETRIC
    IF stregex(st(i).law, 'par', /bool) THEN BEGIN
      ; Grain radius Threshold for alignment, given in microns and converted in cm
      st[i].athresh = strv(ii) & ii=ii+1
      st[i].pstiff  = strv(ii) & ii=ii+1
      st[i].plev    = strv(ii) & ii=ii+1
    ENDIF
    st[i].aligned = stregex(st_grains(i).type_keywords, 'pol', /bool) 
    ;stop

    IF !run_univ eq 1 THEN BEGIN
      st = replicate(st(i),Ngrains)
      ;st.aligned = stregex(st_grains.grains.type_keywords, 'pol', /bool) 
      st.aligned = stregex(st_grains(i).type_keywords, 'pol', /bool) 
      break
    ENDIF
  ENDIF
ENDFOR

; FOR i=0L,st_grains.Ngrains-1 DO BEGIN
;    IF st(i).aligned then begin
;         ; if count EQ 0. then begin   
;          readf,unit,str,format='(A100)'   
;       ;endif 
     
;       	strv=str_sep(strcompress(strtrim(str,2)),' ')
;       	Nstrv=n_elements(strv)

; 	ii=0L
;       	st(i).law=strv(ii) & ii=ii+1 

; 	; IDG
;         IF stregex(st(i).law, 'idg', /bool) THEN begin
;            ii=ii+1 
;       		st(i).TdsTg = strv(ii) & ii=ii+1
;       		st(i).a0    = strv(ii) & ii=ii+1
;       		st(i).rvcut = strv(ii) & ii=ii+1
; 	endif

; 	; RAT
;       	IF stregex(st(i).law, 'rat', /bool) THEN begin
; 	endif

; 	; PARAMETRIC
;         IF stregex(st(i).law, 'par', /bool) THEN begin
;                                 ; Grain radius Threshold for
;                                 ; alignment, given in microns and
;                                 ; converted in cm
;       		st(i).athresh = strv(ii) & ii=ii+1
;       		st(i).pstiff  = strv(ii) & ii=ii+1
;                 st(i).plev    = strv(ii) & ii=ii+1
;                 ; count=1
; 	endif

;         IF !run_univ eq 1 then begin
; 		st = replicate(st(i),st_grains.Ngrains)
;                 st.aligned = stregex(st_grains.grains.type_keywords, 'pol', /bool)
;                 ;stop
; 		break
; 	endif
       
    
       
;       ENDIF

; ENDFOR

close,unit
free_lun,unit

full_st={keywords:key_str,anisG0:anisG0,gamma:0,grains:st}

RETURN,full_st

END