	SUBROUTINE SAO_VECT(ACTION,COLOR_TYPE,X1,Y1,X2,Y2,NPIC_SELECTED)
C
C  Note:  This is the UNIX version
C
C       This subroutine sends commands to SAOimage via the Imtool protocol
C  in order to draw straight lines (vectors) on the frame buffer.  This
C  subroutine duplicates the action of SAO_DRAW in the case of ACTION=3
C  but does it with less overhead.
C			Donald H. Gudehus, September, 1994
C			Version 1U, D. Gudehus, September, 1994
C			Modified code for UNIX
C			Version 2, D. Gudehus, July 25, 2006
C			Incorporated new saofacts.for
C			Version 3, D. Gudehus, April 14, 2009
C			Declared NPIC_SELECTED as INTEGER*2 for
C			reliability.
C
C	ACTION		(C)	Two values are permitted.  If equal to 3
C				the vector is immediately displayed.  If
C				equal to 4 it is not immediately displayed
C				and must be later followed with a call with
C				ACTION=3 and a Y range large enough to include
C				the vector.  More simply one could call
C				SAO_DISPLAY_VECTOR. This is useful for saving 
C				time when many vectors are being drawn.
C	COLOR_TYPE	(C)	The color of the cursor.  Some examples are:
C				201 = green
C				202 = black
C				203 = white
C				204 = red
C				206 = blue
C				207 = yellow
C				Other values, depending on the lookup table
C				are possible in the range 0 to 199.
C	X1		(C)	The starting x location in array, file,
C				or map coordinates.  The lower left corner
C				of the picture has coordinates (1.0,1.0).
C				The maximum possible value depends on the size
C				of the frame buffer selected.
C	Y1		(C)	The starting y location
C	X2		(C)	The ending x location
C	Y2		(C)	The ending y location
C	NPIC_SELECTED	(C)	The picture (which of several in frame buffer)
C
	INTEGER*2 NPIC_SELECTED
C
	INTEGER ACTION,COLOR_TYPE
C
	INCLUDE 'saofacts.for'
C
	INTEGER*2 ICOUNT
C
	ICOUNT=67
	IBUFFER_SAO(1)='40000'O !  = PACKED;  since is not IIS_READ, is write
	IBUFFER_SAO(2)=-ICOUNT !  imhead.thingct
	IBUFFER_SAO(3)=13 !  = imhead.subunit
        IBUFFER_SAO(4)=0
	IBUFFER_SAO(5)=0
        IBUFFER_SAO(6)=0
        IBUFFER_SAO(7)=1 !  Frame number
        IBUFFER_SAO(8)=0
	CALL IMTOOLCHECKSUM(IBUFFER_SAO)
	NBYTES=16
C  NPIC_SAO is the most recent picture number loaded.
	CALL SI_WRITE(BUFFER_SAO,NBYTES)
	XSAO1=X1-IMSX_SAO(NFRAME_SAO,NPIC_SELECTED)+
	1IMSX_SAO(NFRAME_SAO,NPIC_SAO)+XLOC_SAO(NPIC_SELECTED)-
	2XLOC_SAO(NPIC_SAO)
	YSAO1=Y1-IMSY_SAO(NFRAME_SAO,NPIC_SELECTED)+
	1IMSY_SAO(NFRAME_SAO,NPIC_SAO)-YLOC_SAO(NPIC_SELECTED)+
	2YLOC_SAO(NPIC_SAO)
	XSAO2=X2-IMSX_SAO(NFRAME_SAO,NPIC_SELECTED)+
	1IMSX_SAO(NFRAME_SAO,NPIC_SAO)+XLOC_SAO(NPIC_SELECTED)-
	2XLOC_SAO(NPIC_SAO)
	YSAO2=Y2-IMSY_SAO(NFRAME_SAO,NPIC_SELECTED)+
	1IMSY_SAO(NFRAME_SAO,NPIC_SAO)-YLOC_SAO(NPIC_SELECTED)+
	2YLOC_SAO(NPIC_SAO)
	ENCODE (2,2002,CBUFFER_SAO(1:2)) ACTION
2002	FORMAT(I2)
	CBUFFER_SAO(3:3)=' '
	CBUFFER_SAO(4:7)='  0' !  Cursor type
	CBUFFER_SAO(8:8)=' '
	ENCODE (8,2008,CBUFFER_SAO(9:16)) COLOR_TYPE
2008	FORMAT(I8)
	CBUFFER_SAO(17:17)=' '
	ENCODE (9,1009,CBUFFER_SAO(18:26)) XSAO1
1009	FORMAT(F9.3)
	CBUFFER_SAO(27:27)=' '
	ENCODE (9,1009,CBUFFER_SAO(28:36)) YSAO1
	CBUFFER_SAO(37:37)=' '
	ENCODE (9,1009,CBUFFER_SAO(38:46)) XSAO2
	CBUFFER_SAO(47:47)=' '
	ENCODE (9,1009,CBUFFER_SAO(48:56)) YSAO2
	CBUFFER_SAO(57:57)=' '
	CBUFFER_SAO(58:66)='      0.0' !  INCLINA
	CBUFFER_SAO(67:67)=' '
	NBYTES=ICOUNT
	CALL SI_WRITE(BUFFER_SAO,NBYTES)
C
	RETURN
	END
