	PROGRAM SAODEMO5
C
C  Note:  This is the UNIX version
C
C	This program demonstrates the control of SAOimage from a
C  standalone program.  Here we send randomly oriented colored vectors
C  of various lengths.  The user is given a choice on whether to display
C  the vectors immediately as they are drawn (slow) or at the end (faster).
C
C			Donald H. Gudehus, September, 1994
C			Version 1U, D. Gudehus, September, 1994
C			Modified code to run 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'
	CHARACTER*1 CHOICE
	INTEGER*4 ACTION,COLOR_TYPE
C
	CALL GET_ENDIAN
	IFB_SAO=0 !  Lets the user be prompted for the size of the buffer
C  Establish the buffer size
	CALL SAOSTART
C  Initialize SAOimage
	CALL SAOFIRST
C
C  Get some parameters set up.  
	NCOLS=MAXFB_COLS_SAO
	NROWS=MAXFB_ROWS_SAO
	NPIC_SAO=1 !  Pictures run from 1 to 16
	NFRAME_SAO=0 !  Frames run from 0 to 3.  Only one frame is supported
		     !  on SAOimage
C  Establish the starting location on the frame
	XLOC_SAO(NPIC_SAO)=0
	YLOC_SAO(NPIC_SAO)=MAXFB_ROWS_SAO-1
C  Establish the starting location in the array
	IMSX_SAO(NFRAME_SAO,NPIC_SAO)=1
	IMSY_SAO(NFRAME_SAO,NPIC_SAO)=1
C
C  Write random colored vectors onto the display
C  Send a caption now that we have set up the parameters
	TV_FILENAME(NPIC_SAO)='Colored vectors'
	CALL SAOCAPTION
C
	CHOICE=' '
	DO WHILE (CHOICE.NE.'A'.AND.CHOICE.NE.'B')
	  CHOICE='B'
	  CALL MESSAGE('Enter a choice:')
	  CALL MESSAGE(
	1 '      A = Vectors are displayed as they are drawn(slow)')
	  CALL MESSAGE(
	1 '      B = Vectors are displayed at end (faster, default)')
	  CALL USRINP_CHAR(1,'A',1,1,'CHOICE=',' ',%REF(CHOICE))
	END DO
	IF (CHOICE.EQ.'A') THEN
	  ACTION=3
	ELSE IF (CHOICE.EQ.'B') THEN
	  ACTION=4
	END IF
	ISEED=12345
	DO K=1,40
	  COLOR_TYPE=MOD(K,5)+203
	  X1=RAN(ISEED)*(NCOLS-1)+1
	  Y1=RAN(ISEED)*(NROWS-1)+1
	  X2=RAN(ISEED)*(NCOLS-1)+1
	  Y2=RAN(ISEED)*(NROWS-1)+1
	  CALL SAO_VECT(ACTION,COLOR_TYPE,X1,Y1,X2,Y2,NPIC_SAO) !  Map coordinates
	END DO
	IF (CHOICE.EQ.'B') CALL SAO_DISPLAY_VECT
	END
