DO 6 1=1, N 



DIST(I)=ABS((Y(I)-A2*X(I)-A1)/ (SQRT(A2**2+1.0)) ) 



6 SUM=SUM+DIST(I)**2 

 P I VOT=SQRT( SUM/AN) 



C REMOVE POINTS THAT MAY HAVE A BAD POSITION 

 XPIV0T=3.0*PIV0T 

 J=0 



DO 42 1=1, N 



IF(DIST(I).GT.XPIVOT) GO TO 42 

 J=J+1 

 X(J)=X(I) 

 Y(J)=Y(I) 

 Z(J)=Z(I) 

 DIST(J)=DIST(I) 

 42 CONTINUE 

 N=J 

 AN=N 



DO 7 1=1, N 

 IF (DIST(I)- PIVOT) 8,8,7 



7 CONTINUE 



8 A3= -1.0/A2 



AX ( I )= (A1+A3*X ( I )-Y ( I ) ) / ( A3-A2 ) 



AY(I)= A2*AX(I) +A1 



AZ(I)=Z(I) 



IA=I+1 

 C NOW WORK BACKWARDS ON TRACK TO PICK UP POINTS THAT FAILED 

 C PIVOT TEST 



11 J=I-1 

 IF(J)12,12,9 



9 0ELZ=(Z(J)-Z(I))/SQRT((X(I)-X(J))**2 +(Y(I )-Y( J))**2) 

 AX(J)=(A1+A3*X(J)-Y(J))/(A3-A2) 

 AY(J)=A2*AX(J)+A1 



AZ(J)=(DELZ*SQRT((AX(I)-AX(J))**2+(AY(I)-AY(J))**2))+AZ(I) 

 1=0 



GO TO 11 

 C NOW WORK FORWARD ON TRACK TO PICK UP REMAINING PTS. 



12 DO 13 I=IA,N 



IF (DIST(I)- PIVOT) 14,14,15 



14 AX(I)=(A1+A'3*X(I)-Y(I))/(A3-A2) 

 AY(I)= A2*AX(I) +A1 

 AZ(I)=Z(I) 



GO TO 13 



15 J= I-l 

 DELZ=(Z(I)-Z(J))/SQRT((X(I)-X(J))**2 +(Y(I )-Y( J))**2) 

 AX(I)=(A1+A3*X(I)-Y(I))/(A3-A2) 



AY(I )=A2*AX(I ) +A1 

 AZ(I)=(DELZ*SQRT((AX(I)-AX(J))**2+(AY(I)-AY(J))**2))+AZ(J) 



13 CONTINUE 



C SORT INPUT SO THAT THE INDEPENDENT VARIABLE IS MONOTONIC AND REMOVE 

 C aOSELY SPACED POINTS TO CONTROL SPLINE INTERPOLATION 



DAVE =0.0 



DO 44 1=2, N 



J=I-1 



160 



