	PROGRAM SAODEMO6
C
C  Note:  This is the UNIX version
C
C	This program demonstrates the control of SAOimage from a
C  standalone program.  Here we request the user to position the mouse
C  pointer at various places within the frame buffer and press the 
C  carriage return in order to draw a polygon.
C
C			Donald H. Gudehus, September, 1994
C			Version 1U, D. Gudehus, September, 1994
C			Changed code to work under UNIX
C			Version 2, D. Gudehus, August 29, 2006
C			Incorporated changes from saofacts.for and
C			added call to GET_ENDIAN.
C
	INCLUDE 'saofacts.for'
C
	INTEGER*4 ACTION,COLOR_TYPE
	LOGICAL MESSAG,FIRST_VERTEX
C
	CALL GET_ENDIAN
C  Don't prompt the user for the size of the buffer, just use a big
C  enough one.
	IFB_SAO=1 !  Gives a 512 by 512 buffer
	CALL SAOSTART
	CALL SAOFIRST
	NPIC_SAO=1
C  Establish the starting location on the frame
        XLOC_SAO(NPIC_SAO)=0
        YLOC_SAO(NPIC_SAO)=MAXFB_ROWS_SAO-1
C  Establish the number of pixels in the picture (assumed to be as
C  big as the frame buffer).  This information is needed by SAO_CURN,
C  and would normally be provided by the call to SAOLOAD, but since we
C  are not loading a picture, we must do this manually.
	NPTSX_SAO(NPIC_SAO)=MAXFB_COLS_SAO
	NPTSY_SAO(NPIC_SAO)=MAXFB_ROWS_SAO
C  Establish the starting location in the array.  NFRAME_SAO was set
C  in SAOFIRST.
        IMSX_SAO(NFRAME_SAO,NPIC_SAO)=1
        IMSY_SAO(NFRAME_SAO,NPIC_SAO)=1
C
C  Preset the lookup table to a convenient range of colors
	IVAL='A00'X
	CALL SAOCONVLT(IVAL)
C
C  Read the cursor coordinates
	CALL MESSAGE('Be sure SAOimage has focus, and position the mouse'//
	1' pointer at')
	CALL MESSAGE('successive vertices of a polygon.')
	CALL MESSAGE('Press the Carriage Return at each vertex, but press'//
	1' q or Q at the last one.')
	ACTION=3 !  Immediate vector draw
	COLOR_TYPE=50
	KEY=0 !  Initializes the returned ASCII code of the key that will
	      !  be pressed
	FIRST_VERTEX=.TRUE.
	MESSAG=.TRUE.
        DO WHILE (KEY.NE.81.AND.KEY.NE.113)
C  We are interested in the map coordinates, XM and YM
	  CALL SAO_CURN(NPICN,IXT,IYT,XF,YF,XM,YM,KEY,MESSAG)
	  IF (FIRST_VERTEX) THEN
	    FIRST_VERTEX=.FALSE.
	    X_FIRST=XM
	    Y_FIRST=YM
	  ELSE
	    CALL SAO_VECT(ACTION,COLOR_TYPE,X_PRIOR,Y_PRIOR,XM,YM,
	1   NPIC_SAO)
	  END IF
	  X_PRIOR=XM
	  Y_PRIOR=YM
	END DO
C  When the user exits, close the polygon.
	CALL SAO_VECT(ACTION,COLOR_TYPE,XM,YM,X_FIRST,Y_FIRST,NPIC_SAO)
C
	END
