	PROGRAM SAODEMO3
C
C  Note:  This is the UNIX version
C
C	This program demonstrates the control of SAOimage from a
C  standalone program.  Here we see a contact binary in action
C  by successively loading frames at various phases of the orbital 
C  motion.
C
C			Donald H. Gudehus, July, 1994
C			Version 1U, D. Gudehus, September, 1994
C			Converted code to UNIX
C			Version 2U, D. Gudehus, August 28, 1999
C			Added interframe delay
C			Version 3, D. Gudehus, August 29, 2006
C			Incorporated changes from saofacts.for and
C			added call to GET_ENDIAN.
C
	INCLUDE 'saofacts.for' !  UNIX likes lowercase
C
	CHARACTER*40 ARRAY_NAME
	PARAMETER NCOLS=70,NROWS=70,NIMAGES=20
	REAL ARRAY(NCOLS,NROWS,NIMAGES) !  Array size is compromise between 
					!  visible area and speed
C
	CALL GET_ENDIAN
C  Ask the user for a delay time
        DELAY_TIME=0.0
        CALL USRINP(DELAY_TIME,1,'F',4,1,'DELAY_TIME=',
	1'Enter an interframe delay time in seconds:  (default = 0.0)')
C
	IFB_SAO=13 !  Gives a 90 by 90 buffer which fills the frame in 1 buffer
		   !  load of 8192 bytes.
	CALL SAOSTART
	CALL SAOFIRST
C
C  Select a color look-up table
	IVAL='300'X
	CALL SAOCONVLT(IVAL)
	CALL MESSAGE('Creating the images')
C  Zero the arrays
	DO K=1,NIMAGES
	  DO J=1,NCOLS
	    DO I=1,NROWS
	      ARRAY(I,J,K)=0.0
	    END DO
	  END DO
	END DO
	NC1=NCOLS/2
	NR1=NROWS/2-1
	BRIGHTNESS_MIN=5.0
	BRIGHTNESS_MAX=800.0
C  Center the images within the frame
	IXFRAME=MAXFB_COLS_SAO/2-NC1
	IYFRAME=MAXFB_ROWS_SAO/2+NR1
	ARRAY_NAME='Contact Binary System'
	MODE=0 !  Fast load of a single picture
	a=2.0
	NPICTURE=1
C  First create the images.  This will result in a faster repetition rate
C  than if we calculate the images while they are being sent to SAOimage
	DO K=1,NIMAGES
	  X1=10.0*COSD(18.0*K)+NC1
	  Y1=10.0*SIND(18.0*K)+NR1
	  X2=-22.0*COSD(18.0*K)+NC1
	  Y2=-22.0*SIND(18.0*K)+NR1
C  The lower left corner of each data array is considered to be at 1, 1.
	  DO J=1,NROWS
	    DO I=1,NCOLS
	      R1=SQRT((I-X1)**2+(J-Y1)**2)
	      R2=SQRT((I-X2)**2+(J-Y2)**2)
	      ARRAY(I,J,K)=880.0/(1+R1/a)**2+440.0/(1+R2/a)**2
	    END DO
	  END DO
	END DO
	DO NREPEAT=1,8
	  DO K=1,20
	    CALL SAOLOAD(ARRAY(1,1,K),NCOLS,NROWS,IXFRAME,IYFRAME,
	1   BRIGHTNESS_MIN,BRIGHTNESS_MAX,ARRAY_NAME,NPICTURE,MODE)
	    CALL DELAY(DELAY_TIME)
	  END DO
	END DO
	END
