function ell=ellfix(ellm2)
%                    for fixing third and fourth row of ellipses
ell=ellm2;

for ind=3:4
  ph=mode(ell(:,ind),20);
  phase(ind)=ph(1);
end

%....................................do all necessary 360 degree rotations
for ind=3:4
a=find( (ell(:,ind)-phase(ind))>280);
a=find( (ell(:,ind)-phase(ind))>280);
if length(a)>0
	ell(a,ind)=ell(a,ind)-360;
end
a=find( (ell(:,ind)-phase(ind))<-280);

if length(a)>0
	ell(a,ind)=ell(a,ind)+360;
end
end         %ind=3:4
a=find( (ell(:,4)-phase(4))>100);
if length(a)>0
	ell(a,4)=ell(a,4)-180;
	ell(a,3)=ell(a,3)-180;
end
a=find((ell(:,4)-phase(4))<-100);
if length(a)>0
	ell(a,4)=ell(a,4)+180;
	ell(a,3)=ell(a,3)+180;
end

for ind=3:4
if maxg(ell(:,ind))>360
             ell(:,ind)=ell(:,ind)-360;
end
end
