function ptx =getptx(ptA1,ptA2,ptD1,ptD2)
%-------------------------------------------------------|
%|  function ptx = getptx(ptA1,ptA2,ptD1,ptD2)		|
%|							|
%|  function to obtain coordinate [lon,lat] of xover	|
%|    location given coordinates of 2 points on ascen-	|
%|    ding track and  2 points on descending track.	|
%|  							|
%|  INPUT:  ptA1,ptA2 (Mx2), ascending or t1		|
%|          ptD1,ptD2 (Mx2), descending or t2		|
%|  OUTPUT: ptx (Mx2) [lon,lat] of x-over		|
%|							|
%|  ATN 10.10.03					|
%|------------------------------------------------------|


% -- getting x-over position:
slopea=(ptA2(:,2)-ptA1(:,2))./(ptA2(:,1)-ptA1(:,1));
sloped=(ptD2(:,2)-ptD1(:,2))./(ptD2(:,1)-ptD1(:,1));
ij=find(slopea~=sloped);ik=find(slopea==sloped);
x_x=zeros(1,size(ptA1,1));y_x=x_x;ptx=[x_x',y_x'];
if(isempty(ij)==0);
   x_x(ij)=((ptA1(ij,2)-ptD1(ij,2))-slopea(ij).*ptA1(ij,1)+sloped(ij).*ptD1(ij,1))./(sloped(ij)-slopea(ij));
   if(size(x_x,1)<size(x_x,2));x_x=x_x';end;
   y_x(ij)=ptA1(ij,2)+slopea(ij).*(x_x(ij)-ptA1(ij,1));
   if(size(y_x,1)<size(y_x,2));y_x=y_x';end;
   ptx(ij,:)=[x_x(ij),y_x(ij)];							% lon,lat
end;
if(isempty(ik)==0);ptx(ik,:)=NaN.*ptx(ik,:);end;

return
