	SUBROUTINE SAO_LOAD_VLT(BLUE,GREEN,RED)
C
C  Note:  This is the UNIX version.
C
C       This subroutine loads a custom video look-up table into SAOimage.  It
C  is up to the calling routine to have loaded each array with an 8-bit
C  value.  The SAOimage built-in look-up tables, on the other hand, are 
C  selected by calling SAOCONVLT.
C
C			Donald H. Gudehus, October, 17, 1994
C			Version 1U, D. Gudehus, October 27, 1994
C			Converted code to UNIX
C			Version 2, D. Gudehus, July 25, 2006
C			Incorporated new saofacts.for
C
	INTEGER BLUE(0:199),GREEN(0:199),RED(0:199)
C
	INCLUDE 'saofacts.for'
C
	IVERTEX_COUNT=200
	JMAX=IVERTEX_COUNT-1
	ICOUNT=3*(25+12*JMAX)
	I2VAL='FFFF'X  ! Flag to SAOimage that the internal LUTs will not 
		       ! be used.  The LUT information will follow in the
		       ! next packet.
	IBUFFER_SAO(1)='40000'O  ! = PACKED;  since is not IIS_READ, is write
C	IBUFFER_SAO(1)=256  ! imhead.tid,  no name
	IBUFFER_SAO(2)=-ICOUNT  ! imhead.thingct
	IBUFFER_SAO(3)=2  ! imhead.subunit = LUT
	IBUFFER_SAO(4)=0  ! imhead.checksum;  initially set to zero
	IBUFFER_SAO(5)=0  ! imhead.x
	IBUFFER_SAO(6)=0  ! imhead.y
	IBUFFER_SAO(7)=I2VAL  ! imhead.z
	IBUFFER_SAO(8)=0  ! imhead.t
	CALL IMTOOLCHECKSUM(IBUFFER_SAO)
	NBYTES=16
	CALL SI_WRITE(BUFFER_SAO,NBYTES)
C
	IFLAG_GAMMA=0
	GAMMA=1.0
	DO K=1,3
	  KD=(K-1)*(25+12*JMAX)
	  CBUFFER_SAO(1+KD:1+KD)=' '
	  ENCODE (3,2003,CBUFFER_SAO(2+KD:4+KD)) IVERTEX_COUNT
2003	  FORMAT(I3)
	  CBUFFER_SAO(5+KD:5+KD)=' '
	  ENCODE (1,2001,CBUFFER_SAO(6+KD:6+KD)) IFLAG_GAMMA
2001	  FORMAT(I1)
	  CBUFFER_SAO(7+KD:7+KD)=' '
	  ENCODE (6,1006,CBUFFER_SAO(8+KD:13+KD)) GAMMA
1006	  FORMAT(F6.4)
	  DO J=0,JMAX
	    JD=12*J
	    CBUFFER_SAO(14+JD+KD:14+JD+KD)=' '
	    ENCODE (5,1005,CBUFFER_SAO(15+JD+KD:19+JD+KD)) 1.0*J/JMAX
1005	    FORMAT(F5.3)
	    CBUFFER_SAO(20+JD+KD:20+JD+KD)=' '
	    IF (K.EQ.1) THEN
	      ENCODE (5,1005,CBUFFER_SAO(21+JD+KD:25+JD+KD)) RED(J)/255.0
	    ELSE IF (K.EQ.2) THEN
	      ENCODE (5,1005,CBUFFER_SAO(21+JD+KD:25+JD+KD)) GREEN(J)/255.0
	    ELSE IF (K.EQ.3) THEN
	      ENCODE (5,1005,CBUFFER_SAO(21+JD+KD:25+JD+KD)) BLUE(J)/255.0
	    END IF
	  END DO
	END DO
	NBYTES=ICOUNT
	CALL SI_WRITE(BUFFER_SAO,NBYTES)
C
	RETURN
	END
