	PROGRAM SAODEMO2

C  Note:  This is the UNIX version
C
C	This program demonstrates the control of SAOimage from a
C  standalone program.  Here an image representing a star is repeatedly
C  made larger and smaller, as if it is being focused at a telescope.
C  SAOimage could in fact aid in the focusing of a star on a CCD.
C
C				Donald H. Gudehus, July, 1994
C				Version 1U, D. Gudehus, September, 1994
C				Converted code to UNIX
C				Version 2U, D. Gudehus, September 4, 1999
C				Added interframe delay time
C
	INCLUDE 'saofacts.for'  ! UNIX likes lower case
C
	CHARACTER*40 ARRAY_NAME
	REAL ARRAY(64,64)
C
	CALL GET_ENDIAN
C  Ask the user for a delay time
	CALL USRINP(DELAY_TIME,1,'F',4,1,'DELAY_TIME=',
	1'Enter an interframe delay time in seconds:  (default = 0.0)')
	IFB_SAO=11  ! Gives a 128 by 128 buffer
	CALL SAOSTART
	CALL SAOFIRST
C
	IVAL='300'X
	CALL SAOCONVLT(IVAL)
C
	NCOLS=64
	NROWS=64
	BRIGHTNESS_MIN=0.0
	BRIGHTNESS_MAX=1000.0
C  Center the pictures within the frame
	IXFRAME=MAXFB_COLS_SAO/2-32
	IYFRAME=MAXFB_ROWS_SAO/2+32
	ARRAY_NAME='Focus Sequence'
	MODE=0  ! Fast load of a single picture
	DO NREPEAT=1,6
	  DO NPICTURE=1,16
	    a=2.0*ABS(MOD(NPICTURE+8,16)-8)+2.0
C  The lower left corner of each data file is considered to be at 1, 1.
	    DO J=1,NROWS
C  Vary the pictures
	      DO I=1,NCOLS
	        R=SQRT((I-32.5)**2+(J-32.5)**2)
	        IF (R/a.LT.8.0) THEN
	          ARRAY(I,J)=5000.0/a**1.6*EXP(-(R/a)**2)
	        ELSE
	          ARRAY(I,J)=0.0
	        END IF
	      END DO
	    END DO
	    CALL SAOLOAD(ARRAY,NCOLS,NROWS,IXFRAME,IYFRAME,
	1   BRIGHTNESS_MIN,BRIGHTNESS_MAX,ARRAY_NAME,NPICTURE,MODE)
	    CALL DELAY(DELAY_TIME)
	  END DO
	END DO
	END
