;PURPOSE:
;    This function will take an a 4x25xN array of Covariances and plot them.
;    
;INPUTS:
;    EllipticityArr:
;      Covariances(0,*,n)= X longitudinal
;      Covariances(0,*,n)= X transverse
;      Covariances(0,*,n)= Y longitudinal
;      Covariances(0,*,n)= Y transverse
;    PlotStyle:
;      0 = Plot to X Windwow
;      1 = Plot a PNG file
;
function plot_covariance, CovarianceArr, PlotStyle

AvgCovarianceArr=avg(CovarianceArr,2)
Cxl=AvgCovarianceArr(0,*)
Cxt=AvgCovarianceArr(1,*)
Cyl=AvgCovarianceArr(2,*)
Cyt=AvgCovarianceArr(3,*)

if PlotStyle eq 1 then begin
  set_plot,'z'
  erase
  device, set_font='Courier'
  device,set_resolution=[800,600]
  !p.charsize=1
  !p.charthick=1.2
  !x.thick=2
  !y.thick=2
  !p.thick=4
  !p.noerase=0
  loadct,39

  white='FFFFFF'x
  black='000000'x
  blue='FF0000'x
  red='0000FF'x
endif else begin
  set_plot,'x'
endelse

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

plot,Cxt,psym=1,title="Transverse correlation along X direction",$
           xtitle="n",ytitle="Covariance",$
           background=white,color=black,$
           yrange=[-1,1],$
           POSITION=[0.10,0.10,0.9,0.9]
oplot,Cxl,psym=2,color=80
oplot,Cyt,psym=4,color=160
oplot,Cyl,psym=5,color=240
itemsC=['Transverse X', 'Longitudinal X', 'Transverse Y', 'Longitudinal Y']
psymC=[1,2,4,5]
colorsC=[0,80,160,240]
legend,itemsC,psym=psymC,colors=colorsC,pos=[0.8,0.8],/norm

stop

return,1
end


