	SUBROUTINE SAOFIRST
C
C  Note:  This is the UNIX version
C
C       This subroutine initializes SAOimage by setting up the world coordinate
C  system (WCS) and erasing the screen.  The Imtool protocol is used.
C			Donald H. Gudehus, August, 1993
C			Version 1U, D. Gudehus, September, 1994
C			Changed code to work under UNIX
C			Version 2, D. Gudehus, July 25, 2006
C			Incorporated new saofacts.for
C
	INCLUDE 'saofacts.for'
C
	IBUFFER_SAO(1)=256 !  imhead.tid,  no name
	IBUFFER_SAO(2)=-3 !  imhead.thingct = 3 words
	IBUFFER_SAO(3)=12 !  imhead.subunit = LOOK_FEEL
	IBUFFER_SAO(4)=0 !  imhead.checksum;  initially set to zero
	IBUFFER_SAO(5)=IOR(0,'100000'O)  ! imhead.x
	IBUFFER_SAO(6)=0 !  imhead.y
	IBUFFER_SAO(7)=0 !  imhead.z
	IBUFFER_SAO(8)=3 !  imhead.t = IOP_MIIPS;  used for control.look_and_feel
	CALL IMTOOLCHECKSUM(IBUFFER_SAO)
	NBYTES=16
	CALL SI_WRITE(BUFFER_SAO,NBYTES)
	IBUFFER_SAO(1)=0
	IBUFFER_SAO(2)=0
	IBUFFER_SAO(3)=0
	NBYTES=6
	CALL SI_WRITE(BUFFER_SAO,NBYTES)
C
	IBUFFER_SAO(1)='40000'O !  PACKED and IMC_SAMPLE
	IBUFFER_SAO(2)=-51
	IBUFFER_SAO(3)=17 !  imhead.subunit = WCS (World coordinate system)
	IBUFFER_SAO(4)=0
	IBUFFER_SAO(5)=0
	IBUFFER_SAO(6)=0
	IBUFFER_SAO(7)=1 !  Frame number (SAOimage system);  not useful on SAOimage
	IBUFFER_SAO(8)=IFB_SAO-1 !  Frame buffer configuration - 1
	CALL IMTOOLCHECKSUM(IBUFFER_SAO)
	NBYTES=16
	CALL SI_WRITE(BUFFER_SAO,NBYTES)
	CBUFFER_SAO(1:9)='         '
	BUFFER_SAO(10)=10
	CBUFFER_SAO(11:30)='1. 0. 0. -1.    1.5 ' !  xx yx xy yy xo
C  CBUFFER_SAO(24:30) is X Coordinate at left edge of buffer
	ENCODE (7,1000,CBUFFER_SAO(31:37)) MAXFB_ROWS_SAO+0.5 !  yo;  0.5 added to
                                !  conform with corner of pixel being x.0, y.0.
1000	FORMAT(F7.1)
C  CBUFFER_SAO(31:37) is Y Coordinate at top edge of buffer
	CBUFFER_SAO(38:49)='   1. 200. 1' !  low high w_type (=linear)
	BUFFER_SAO(50)=10
	BUFFER_SAO(51)=0
	NBYTES=51
	CALL SI_WRITE(BUFFER_SAO,NBYTES)
C
C  Establish some initial values useful in SAOERAS
	NFRAME_SAO=0 !  MIIPS system
	NPIC_SAO=1
	CALL SAOERAS
	RETURN
	END
