;plot_ellipticities
;
;PURPOSE:
;    This function will take an a 4x12xN array of filtered ellipticities and
;    elliptiticy angles, histogram them, and plot them.
;
;    
;INPUTS:
;    EllipticityArr:
;      EllipticityArr(0,k,*) = Ellipticities of High Pass Filtered at cutoff k
;      EllipticityArr(1,k,*) = Angles of High Pass Filtered at cutoff k
;      EllipticityArr(2,k,*) = Ellipticities of Low Pass Filtered at cutoff k
;      EllipticityArr(3,k,*) = Angles of Low Pass Filtered at cutoff k
;   
;    PlotStyle:
;      0 = Plot to X Windwow
;      1 = Plot a PNG file
;      2 or 3 = postscript
      
function plot_elliphistogram_ff,EHistFileName,SOARDataFileName,PlotStyle, $
	 ParamStr, PostScriptDir, IncludeSoarData = IncludeSoarData

If not(keyword_set(IncludeSoarData)) then IncludeSoarData = 0

white='FFFFFF'x
black='000000'x
red='FF0000'x

readcol,EHistFileName,$
        LocE,EHist,LocTheta,ThetaHist,$
        format='f,f,f,f'
readcol,SOARDataFileName,$
        basename,uttime,date,frame_e,frame_e1,frame_e2,$
        frame_theta,phi_array,WSpeedArr,WDirArr,$
        PAltArr,PAzArr,xcenters,ycenters,xfcenters,yfcenters,$
        format='a,a,f,f,f,f,f,f,f,f,f,f,f,f,f,f'

ro=sort(uttime)
basename=basename(ro)
date=date(ro)
frame_e=frame_e(ro)
frame_e1=frame_e1(ro)
frame_e2=frame_e2(ro)
frame_theta=frame_theta(ro)
phi_array=phi_array(ro)
WSpeedArr=WSpeedArr(ro)
WDirArr=WDirArr(ro)
PAltArr=PAltArr(ro)
PAzArr=PAzArr(ro)
xcenter=xcenters(ro)
ycenters=ycenters(ro)
xfcenters=xfcenters(ro)
yfcenters=yfcenters(ro)


!p.multi=[0,1,1]

ThetaMin=-!pi/2
NoBins=20.
ThetaBinWidth=!pi/NoBins
ThetaMax=ThetaMin+(NoBins-1)*ThetaBinWidth
ThetaBinSize=(ThetaMax-ThetaMin)/(NoBins-1)

If IncludeSoarData then begin
   SOARThetaHist=histogram(Frame_Theta,Nbins=NoBins,locations=loc_theta,$
                 reverse_indices=theta_ind,$
                 max=thetamax,min=thetamin)

   plot,LocTheta+ThetaBinSize/2,SOARThetaHist,psym=10,xtitle='Theta',$
     ytitle='Number of Events',xrange=[-1.6,1.6],$
     background=white,color=black
  oplot,LocTheta+ThetaBinSize/2,ThetaHist,psym=10,linestyle=3,color=black

Endif Else Begin

  plot, LocTheta+ThetaBinSize/2, ThetaHist,psym=10,xtitle='Theta',$
     ytitle='Number of Events',xrange=[-1.6,1.6],$
     background=white,color=black

EndElse

if PlotStyle eq 1 then begin

  jpgimg=tvrd()
  tvlct,reds,greens,blues,/get
  write_png,PostScriptDir+ParamStr+'ThetaHistogram.png',$
    jpgimg,reds,greens,blues

  erase
endif

if PlotStyle eq 0 then stop
Emin=0                                     ;ELLIPTICITY
NoEBins=20.
EBinWidth=(1-Emin)/NoEBins
Emax=Emin+(NoEBins)*EBinWidth
Ebinsize=(Emax-Emin)/(NoEBins-1)

If IncludeSoarData then begin
  SOAREHist=histogram(Frame_E,Nbins=NoEbins,locations=loc_e,$
                 reverse_indices=e_ind,$
                 max=emax,min=emin)

  plot,LocE,Ehist,psym=10,xtitle='e',$
     ytitle='Number of Events',$
     background=white,color=black,linestyle=3
  oplot,LocE,SOAREHist,psym=10, color =black

EndIf Else begin

  plot,LocE,Ehist,psym=10,xtitle='e',$
     ytitle='Number of Events',$
     background=white,color=black

EndElse

if PlotStyle eq 1 then begin 

  jpgimg=tvrd()
  tvlct,reds,greens,blues,/get
  write_png,PostScriptDir+ParamStr+'EHistogram.png',$
    jpgimg,reds,greens,blues

  erase
endif


if PlotStyle eq 0 then stop
erase

return,1

end
