;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_ff, ScreenCovarFileName, SoarCovarFileNames,$
	 PlotStyle

readcol,ScreenCovarFileName,$
    Cxl,Cxt,Cyl,Cyt,$
    format='f,f,f,f'

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 
!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.7,0.7],/norm

if PlotStyle eq 0 then stop
Date=['10','11','12']
for Datei =0, 2 do begin
 readcol,SOARCovarFileNames(Datei),$
    Cxl,Cxt,Cyl,Cyt,$
    format='f,f,f,f'
 
 plot,Cxt,psym=1,title="Night of May "+Date(Datei),$
           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.7,0.7],/norm

endfor
return,1
end


