198 lines
6.5 KiB
Prolog
198 lines
6.5 KiB
Prolog
pro loadopt, file, optable,bin=bin
|
|
if n_params() lt 2 then begin
|
|
print,' LOADOPT,file,optable,/bin'
|
|
print,'file =STRING : name of the ASCII opacity table(input)'
|
|
print,'optable=STRUCT : loaded data from the optable (output)'
|
|
print,'/bin : the table is in binary format'
|
|
return
|
|
endif
|
|
defsysv,'!gdl',exist=gdl ; 1 is GDL , 0 is IDL
|
|
if keyword_set(bin) then begin
|
|
openr, lun, file, /f77_un,/get_lun
|
|
type = STRARR(30)
|
|
abnd = FLTARR(30)
|
|
abnd2 = FLTARR(30)
|
|
hdr='opacity table with element abundances:'
|
|
hdr=[hdr,'element for EOS for opacities']
|
|
FOR ii = 0, 29 DO begin
|
|
a = 'aaaa'
|
|
b = 0.D
|
|
c = 0.D
|
|
READU,lun, a, b, c
|
|
; PRINT, a, b, c
|
|
type[ii]=a & abnd[ii]=b & abnd2[ii]=c
|
|
hdr=[hdr,string(a,b,c,format='(3x,a4,2e12.3E3)')]
|
|
ENDFOR
|
|
hdr=[hdr,'']
|
|
hdr=[hdr,'molecules - ifmol,tmolim:']
|
|
ifmol = LONG(0)
|
|
tmolim = 0.D0
|
|
READU,lun, ifmol, tmolim
|
|
; print, ifmol, tmolim
|
|
hdr=[hdr,string(ifmol,tmolim,format='(3x,i4,f12.1)')]
|
|
hdr=[hdr,'additional opacities']
|
|
hdr=[hdr,' H- H2+ He- CH OH']
|
|
iophmp = LONG(0)
|
|
ioph2p = LONG(0)
|
|
iophem = LONG(0)
|
|
iopch = LONG(0)
|
|
iopoh = LONG(0)
|
|
READU,lun, iophmp,ioph2p,iophem,iopch,iopoh
|
|
; print, iophmp,ioph2p,iophem,iopch,iopoh
|
|
hdr=[hdr,string(iophmp,ioph2p,iophem,iopch,iopoh,format='(5i4)')]
|
|
hdr=[hdr,'']
|
|
hdr=[hdr,'number of frequencies, temperatures, densities:']
|
|
nfgrid = LONG(0)
|
|
ntemp = LONG(0)
|
|
ndens = LONG(0)
|
|
READU,lun, nfgrid,ntemp,ndens
|
|
; PRINT, nfgrid,ntemp,ndens
|
|
temp = DBLARR(ntemp)
|
|
dens = DBLARR(ndens)
|
|
elec = DBLARR(ntemp, ndens)
|
|
READU,lun, temp
|
|
READU,lun, dens
|
|
READU,lun, elec
|
|
; absgrd = DBLARR(ntemp, ndens, nfgrid)
|
|
opt=DBLARR(nfgrid,ntemp,ndens)
|
|
wlgrid = DBLARR(nfgrid)
|
|
FOR k = 0L, nfgrid-1 DO BEGIN
|
|
w = 0.D0
|
|
READU,lun, w
|
|
wlgrid[k] = w
|
|
FOR j = 0, ndens-1 DO BEGIN
|
|
abs = FLTARR(ntemp)
|
|
READU,lun, abs
|
|
; absgrd[*, j, k] = abs
|
|
opt[k,*, j] = abs
|
|
; print, abs
|
|
ENDFOR
|
|
ENDFOR
|
|
close,lun & free_lun,lun
|
|
optable={hdr:hdr,wave:wlgrid,temp:exp(temp),rho:exp(dens),nel:exp(transpose(elec)),opt:opt}
|
|
return
|
|
endif
|
|
|
|
openr,lun,file,/get_lun
|
|
line=''
|
|
; read header ...
|
|
readf,lun,line ; 'opacity table with element abundances:'
|
|
hdr=line
|
|
readf,lun,line ; 'element for EOS for opacities'
|
|
while strpos(line,'frequenc') eq -1 and strpos(line,'temper') eq -1 do begin
|
|
hdr=[hdr,line]
|
|
readf,lun,line
|
|
endwhile
|
|
readf, lun, line ; numfreq numtemp numrho
|
|
kas=strsplit(line,' ',/extract)
|
|
numfreq=long(kas[0])
|
|
numtemp=long(kas[1])
|
|
numrho=long(kas[2])
|
|
opt=dblarr(numfreq,numtemp,numrho)
|
|
topt=dblarr(numtemp,numrho)
|
|
lambda=dblarr(numfreq)
|
|
readf,lun,line ; "log temperatures"
|
|
if strtrim(line,2) ne 'log temperatures' then stop,'Temperatures not where they should be. Check op table '
|
|
readf,lun,line ; array of temperatures
|
|
tempvec=strsplit(line,' ',/extract)
|
|
if n_elements(tempvec) ne numtemp then begin
|
|
repeat begin
|
|
readf,lun,line
|
|
tempvec=[tempvec,strsplit(line,' ',/extract)]
|
|
endrep until n_elements(tempvec) eq numtemp
|
|
endif
|
|
|
|
readf,lun,line ; "log densities"
|
|
if strtrim(line,2) ne 'log densities' then stop,' Densities not where they should be. Check op table '
|
|
readf,lun,line ; array of temperatures
|
|
rhovec=strsplit(line,' ',/extract)
|
|
if n_elements(rhovec) ne numrho then begin
|
|
repeat begin
|
|
readf,lun,line
|
|
rhovec=[rhovec,strsplit(line,' ',/extract)]
|
|
endrep until n_elements(rhovec) eq numrho
|
|
endif
|
|
readf,lun,line ; "log electron densities from EOS"
|
|
nel=dblarr(numtemp,numrho)
|
|
nel=transpose(nel)
|
|
ii=0
|
|
repeat begin
|
|
readf,lun,line
|
|
kas=strsplit(line,' ',/extract)
|
|
nel[ii : ii+n_elements(kas)-1]=double(kas)
|
|
ii+=n_elements(kas)
|
|
endrep until ii eq numtemp*numrho
|
|
nel=transpose(nel) ; to have it nel[ntemp,ndens]
|
|
|
|
line=findline(lun,'frequency') ; '*** frequency # :' ind lambda
|
|
kas=strsplit(line,' ',/extract)
|
|
lambda[0]=double(kas[-1])
|
|
readf,lun,line ; frequency
|
|
freqvec=double(line)
|
|
readf,lun,line
|
|
kas=double(strsplit(line,' ',/extract))
|
|
repeat begin
|
|
readf,lun,line
|
|
kas=[kas,double(strsplit(line,' ',/extract))]
|
|
endrep until n_elements(kas) eq numtemp*numrho
|
|
topt[*]=kas
|
|
opt[0,*,*]=topt
|
|
|
|
for ii=2L, numfreq do begin
|
|
; for ii=2, 1000 do begin
|
|
readf,lun,line ; empty line
|
|
readf,lun,line ; '*** frequency # :' ind lambda
|
|
kas=strsplit(line,' ',/extract)
|
|
lambda[ii-1]=double(kas[-1])
|
|
if ii mod 100 eq 0 then progress,'',round((ii*100)/(numfreq)),' % '
|
|
readf,lun,line ; frequency
|
|
freqvec=[freqvec,double(line)]
|
|
readf,lun,line
|
|
kas=double(strsplit(line,' ',/extract))
|
|
; kas[where(kas eq 0.)]=-99.00
|
|
repeat begin
|
|
readf,lun,line
|
|
kas=[kas,double(strsplit(line,' ',/extract))]
|
|
if n_elements(kas) gt numtemp*numrho then stop,'something is wrong in the opacity table !'
|
|
endrep until n_elements(kas) eq numtemp*numrho
|
|
topt[*]=kas
|
|
opt[ii-1,*,*]=topt
|
|
endfor
|
|
print,''
|
|
close,lun
|
|
free_lun,lun
|
|
optable={hdr:hdr,wave:lambda,temp:exp(tempvec),rho:exp(rhovec),nel:exp(nel),opt:opt}
|
|
end
|
|
|
|
pro printopt,opt,fileout
|
|
if n_params() eq 0 then begin
|
|
print,' prints the opacity table.'
|
|
print,' printopt,opt,fileout'
|
|
print,''
|
|
return
|
|
endif
|
|
openw,lun,fileout,/get_lun
|
|
for ii=0,n_elements(opt.hdr)-1 do printf,lun,opt.hdr[ii]
|
|
clight=2.99792548d18
|
|
printf,lun,'number of frequencies, temperatures, densities: '
|
|
nfr=n_elements(opt.wave)
|
|
nt=n_elements(opt.temp)
|
|
nr=n_elements(opt.rho)
|
|
printf,lun,nfr,nt,nr,format='(10x,3i10)'
|
|
printf,lun,'log temperatures'
|
|
printf,lun,alog(opt.temp),format='(6f11.6)'
|
|
printf,lun,'log densities'
|
|
printf,lun,alog(opt.rho),format='(6f11.6)'
|
|
printf,lun,'log electron densities from EOS'
|
|
printf,lun,alog(transpose(opt.nel)),format='(6f11.6)'
|
|
for ii=0L, nfr-1 do begin
|
|
printf,lun,''
|
|
printf,lun,ii+1,opt.wave[ii],format='(" *** frequency # :",i9,f15.5)'
|
|
printf,lun,clight/opt.wave[ii],format='(e20.8E3)'
|
|
for jj=0, nr-1 do printf,lun,opt.opt[ii,*,jj],format='(6E14.6E3)'
|
|
endfor
|
|
close,lun
|
|
free_lun,lun
|
|
end
|
|
|