       SUBROUTINE HULL(YX,YY,NBR,RX,RY,K,TX,TY,N)
       REAL YX(NBR),YY(NBR)
       REAL RX(3),RY(3),TX(3),TY(3)
C ----------------------------------------------------------------------
C      CST = THE LARGEST POSITIVE FLOATING POINT NUMBER
C ----------------------------------------------------------------------
       CST=SPMPAR(3)
       CALL SHELL2(YY,YX,NBR)
       YMIN=YY(1)
       YMAX=YY(NBR)
       IF (YMIN.EQ.YMAX) GO TO 6000
C ----------------------------------------------------------------------
       IF ( YY(1).NE.YY(2) )  GO TO 3331
       I=2
 3321  CONTINUE
       I=I+1
       IF ( YY(1).EQ.YY(I) )  GO TO 3321
       I=I-1
       CALL SHELL(YX(1),I)
 3331  CONTINUE
       IF ( YY(NBR).NE.YY(NBR-1) )  GO TO 3381
       I=NBR-1
 3341  CONTINUE
       I=I-1
       IF ( YY(NBR).EQ.YY(I) )  GO TO 3341
       I=I+1
       L=NBR-(I-1)
       CALL SHELL(YX(I),L)
C ----------------------------------------------------------------------
 3381  CONTINUE
       XMAX=YX(1)
       XMIN=XMAX
       DO 3471  I=2,NBR
       IF ( YX(I)-XMIN )  3421,3471,3431
 3421  CONTINUE
       XMIN=YX(I)
       GO TO 3471
 3431  CONTINUE
       IF ( YX(I).LE.XMAX )  GO TO 3471
       XMAX=YX(I)
 3471  CONTINUE
       XLYMIN=YX(1)
       XHYMAX=YX(NBR)
C ----------------------------------------------------------------------
       RX(1)=YX(1)
       RY(1)=YY(1)
       TX(1)=YX(1)
       TY(1)=YY(1)
       K=1
       N=1
       DO 5101 J=2,NBR
       IF ( YY(J).NE.RY(1) )  GO TO 5111
       RX(J)=YX(J)
       RY(J)=YY(J)
       K=J
 5101  CONTINUE
 5111  CONTINUE
       L=K
       IF ( K.EQ.1 )  GO TO 5131
       N=2
       TX(2)=RX(K)
       TY(2)=RY(K)
C ----------------------------------------------------------------------
 5131  CONTINUE
       IF (RX(K).EQ.XMAX)  GO TO 5181
       KM1=K
       XALPHK=CST
 5141  CONTINUE
       L=L+1
       IF ( YX(L).LE.RX(KM1) )  GO TO 5141
       XALPHA=(YY(L)-RY(KM1))/(YX(L)-RX(KM1) )
       IF ( XALPHK-XALPHA )  5171,5151,5161
 5151  CONTINUE
       K=K+1
       GO TO 5165
 5161  CONTINUE
       K=KM1+1
 5165  CONTINUE
       RX(K)=YX(L)
       RY(K)=YY(L)
       XALPHK=XALPHA
       LSAV=L
 5171  CONTINUE
       IF ( YX(L).LT.XMAX )  GO TO 5141
       N=N+1
       TX(N)=RX(K)
       TY(N)=RY(K)
       L=LSAV
       GO TO 5131
C ----------------------------------------------------------------------
 5181  CONTINUE
       KSAV=K
       LSAV=L
 5191  CONTINUE
       L=L+1
       IF ( L.GT.NBR )  GO TO 5201
       IF ( YX(L).LT.XMAX )  GO TO 5191
       K=K+1
       RX(K)=YX(L)
       RY(K)=YY(L)
       LSAV=L
       GO TO 5191
 5201  CONTINUE
       L=LSAV
       IF ( KSAV.EQ.K )  GO TO 5221
       N=N+1
       TX(N)=RX(K)
       TY(N)=RY(K)
C ----------------------------------------------------------------------
 5221  CONTINUE
       IF ( RY(K).EQ.YMAX )  GO TO 5271
       XALPHK=0.0
       KM1=K
 5231  CONTINUE
       L=L+1
       IF ( YX(L).LT.XHYMAX )  GO TO 5231
       XALPHA=(YY(L)-RY(KM1) )/(YX(L)-RX(KM1) )
       IF ( XALPHA-XALPHK )  5251,5241,5261
 5241  CONTINUE
       K=K+1
       GO TO 5255
 5251  CONTINUE
       K=KM1+1
 5255  CONTINUE
       RX(K)=YX(L)
       RY(K)=YY(L)
       XALPHK=XALPHA
       LSAV=L
 5261  CONTINUE
       IF ( YY(L).LT.YMAX )  GO TO 5231
       N=N+1
       TX(N)=RX(K)
       TY(N)=RY(K)
       L=LSAV
       GO TO 5221
C ----------------------------------------------------------------------
 5271  CONTINUE
       IF (K.LT.NBR) GO TO 5281
       K=K+1
       RX(K)=RX(1)
       RY(K)=RY(1)
       N=N+1
       TX(N)=TX(1)
       TY(N)=TY(1)
       RETURN
C ----------------------------------------------------------------------
 5281  CONTINUE
       L=L-1
       IF ( YY(L).LT.YMAX )  GO TO 5291
       K=K+1
       RX(K)=YX(L)
       RY(K)=YY(L)
       GO TO 5281
 5291  CONTINUE
       L=L+1
       IF (     L.EQ.NBR )  GO TO 5301
       N=N+1
       TX(N)=RX(K)
       TY(N)=RY(K)
C ----------------------------------------------------------------------
 5301  CONTINUE
       IF ( RX(K).EQ.XMIN )  GO TO 5351
       XALPHK=CST
       KM1=K
 5311  CONTINUE
       L=L-1
       IF ( YX(L).GE.RX(KM1) )  GO TO 5311
       XALPHA=(YY(L)-RY(KM1) )  /(YX(L)-RX(KM1) )
       IF ( XALPHK-XALPHA )  5341,5321,5331
 5321  CONTINUE
       K=K+1
       GO TO 5335
 5331  CONTINUE
       K=KM1+1
 5335  CONTINUE
       RX(K)=YX(L)
       RY(K)=YY(L)
       XALPHK=XALPHA
       LSAV=L
 5341  CONTINUE
       IF ( YX(L).GT.XMIN )  GO TO 5311
       N=N+1
       TX(N)=RX(K)
       TY(N)=RY(K)
       L=LSAV
       GO TO 5301
C ----------------------------------------------------------------------
 5351  CONTINUE
       KSAV=K
       LSAV=L
 5361  CONTINUE
       L=L-1
       IF ( L.LT.1 )  GO TO 5371
       IF ( YX(L).GT.XMIN )  GO TO 5361
       K=K+1
       RX(K)=YX(L)
       RY(K)=YY(L)
       LSAV=L
       GO TO 5361
 5371  CONTINUE
       L=LSAV
       IF ( KSAV.EQ.K )  GO TO 5391
       N=N+1
       TX(N)=RX(K)
       TY(N)=RY(K)
C ----------------------------------------------------------------------
 5391  CONTINUE
       IF ( RX(K).EQ.XLYMIN )  RETURN
       KM1=K
       XALPHK=0.0
 5401  CONTINUE
       L=L-1
       IF ( YX(L).GT.XLYMIN )  GO TO 5401
       XALPHA=(YY(L)-RY(KM1) )/(YX(L)-RX(KM1) )
       IF ( XALPHA-XALPHK )  5421,5411,5431
 5411  CONTINUE
       K=K+1
       GO TO 5425
 5421  CONTINUE
       K=KM1+1
 5425  CONTINUE
       RX(K)=YX(L)
       RY(K)=YY(L)
       XALPHK=XALPHA
       LSAV=L
 5431  CONTINUE
       IF ( YY(L).GT.YMIN )  GO TO 5401
       N=N+1
       TX(N)=RX(K)
       TY(N)=RY(K)
       L=LSAV
       GO TO 5391
C ----------------------------------------------------------------------
 6000  CONTINUE
       CALL SHELL(YX,NBR)
       DO 6010 I=1,NBR
       RX(I)=YX(I)
       RY(I)=YY(I)
 6010  CONTINUE
       K=NBR+1
       RX(K)=RX(1)
       RY(K)=RY(1)
       N=3
       TX(1)=YX(1)
       TX(2)=YX(NBR)
       TX(3)=YX(1)
       TY(1)=YY(1)
       TY(2)=YY(NBR)
       TY(3)=YY(1)
       RETURN
C ----------------------------------------------------------------------
       END
