@readbin
@bhmie

pro  mie

; IDL/DDSCAT postprocessing code
; Mie vs DDSCAT results  plot
; This code uses IDL version of the double precision Bohren-Huffman
; Mie scattering code and calculates efficiencies and asymmetry 
; parameter on the basis of size parameter and  refractive index as used
; in DDSCAT run. Thus, size parametr and refractive index are double
; precision here. So are elements of the amplitude matrix S1, S2 
; (output from BHMIE). The binary file was created for "ellips" target
; shape with all 3 shape parameters set to the same value (i.e. sphere).
; There is only one refractive index for one wavelength)
; The 5 dimensional arrays qext_all, qext_abs, g_all,  cxrfr_all
; contain results for each wavelength (1), radius (10), and
; orientation (1 angle for theta, beta, phi). There are 2 polarizations.
; We use "aeffa" (AEFF Array) for plot purposes.
; Another (elegant) solution is available in IDL - dynamic declaration of 
; array dimensions. It is used here extensively.
; Thus,  we do not use  "mx"-dimensions which are so prevalent in DDSCAT code.
; 
; History:
; 96.11.14      (PJF): First version
;end history
;Copyright (C) 1996 B.T. Draine and P.J. Flatau
;This code is covered by the GNU General Public License.

common ddcom1,  iorth, nx, ny, nz,$
      nat0, nat, nat3, nscat, ncomp,$
      nori, nwav, nrad, ntheta, nphi, nbeta, ntimers
common ddcom2, mxnx, mxny, mxnz, mxcomp, mxsca
common ddcom3, BETMID, BETMXD, THTMID, THTMXD, PHIMID, PHIMXD
common ddcom4, phin, thetan
common ddcom5, ICTHM, IPHIM, TOL
common ddcom6, wavea, aeffa, theta, beta, phi, a1, a2, icomp, ix0,iy0,iz0
common ddcom7, qext_all, qext_abs, g_all,  cxrfr_all
common ddcom8, sm11a, sm22a

iunitbin=50
file=fstat(50) & if(file.open ne 0) then close,50
openr,iunitbin,'dd.bin', /f77_unformatted
readall, iunitbin
close,iunitbin

qextmie=fltarr(nrad)
qscamie=fltarr(nrad)
qbackmie=fltarr(nrad)
gscamie=fltarr(nrad)

;assume that there is only one wavelength and one component
refrel=dcomplex(cxrfr_all(0,0))

nang=50
for i=0, nrad-1 do begin
 x = double(aeffa(i))
 bhmie, x,refrel,nang,s1,s2,qext,qsca,qback,gsca
 qextmie(i)=qext
 qscamie(i)=qsca
 qbackmie(i)=qback
 gscamie(i)=gsca
endfor

;window,retain=2
;plot, aeffa, qext_all(0,*,0,0,0,0)
;oplot, aeffa, qextmie

stop
end

