% copyright 2003 by DGL at Brigham Young University
%
% plot egg response shapes produced by egg (eggs near the equator)
%

if ~exist('egg')
  load egg.DAT
end
isize=5;
M=2*isize+1;
N=M^2;
pnt=8+3*[0:(N-1)];
rad=0.5;

for ib=0:1,
  for ascend=0:1,
    figure(ib+2*ascend+1)
    clf
    hold on
    
    for ang=0:45:(360-45)
      if ascend == 1
	lon_off=rad*cos((-ang+90)*pi/180);
	lat_off=rad*sin((-ang+90)*pi/180);
      else
	lon_off=-rad*cos((-ang+90)*pi/180);
	lat_off=-rad*sin((-ang+90)*pi/180);  
      end
      ind=find(egg(:,5)==ib & egg(:,2)==ascend);
      mv=min(abs(egg(ind,4)-ang));
      ind=find(egg(:,5)==ib & egg(:,2)==ascend & abs(egg(:,4)-ang)==mv);

      resp=reshape(egg(ind(1),pnt),M,M);
      resp=resp-max(max(resp));
      lon=mod(egg(ind(1),pnt+1)-egg(ind(1),6)+360.0,360.0);
      if max(lon)-min(lon) > 180
	ind=find(lon>180);
	lon(ind)=lon(ind)-360.0;
      end
      lon=reshape(lon-mean(lon)+lon_off,M,M);
      lat=reshape(egg(ind(1),pnt+2)-egg(ind(1),7)+lat_off,M,M);
      contour(lon,lat,resp,[-0.01 -3 -6 -9])
    end
    if ascend == 1
      myarrow([0, 0]',[0.3*rad*cos((90+7)*pi/180),0.3*rad]');
    else
      myarrow([0, 0]',[0.3*rad*cos((90+7)*pi/180),-0.3*rad]');
    end
    hold off
    xlabel('Longitude (deg)')
    ylabel('Lattitude (deg)')
    
    if ascend==1
      if ib==0
	title('H-pol Inner Beam, Ascending')
	print -djpeg AHeggs.jpg
      else
	title('V-pol Outer Beam, Ascending')
	print -djpeg AVeggs.jpg
      end
    else
      if ib==0
	title('H-pol Inner Beam, Descending')
	print -djpeg DHeggs.jpg
      else
	title('V-pol Outer Beam, Descending')
	print -djpeg DVeggs.jpg
      end
    end
    
  end
end






