	SUBROUTINE SAOCAPTION
C
C  Note:  This is the UNIX version
C
C	This subroutine displays a caption on SAOimage.  The calling 
C  routine should have the caption available in the array TV_FILENAME
C  and NPIC set to point to the requested caption.  XLOC, YLOC, AMIN, and
C  AMAX should be established as well, since the world coordinate system
C  in SAOimage is reinitialized when SAOCAPTION is called.
C
C			Donald H. Gudehus, July, 1994
C			Version 1U, D. Gudehus, September, 1994
C			Converted it into UNIX
C			Version 2, D. Gudehus, June, 1995
C			Allowed caption to have spaces in it.
C			Version 3, D. Gudehus, July 25, 2006
C			Incorporated new saofacts.for
C
	INCLUDE 'saofacts.for'
C
C  Set up the new WCS header information
	I=40
	DO WHILE(TV_FILENAME(NPIC_SAO)(I:I).EQ.' '.AND.I.GE.1)
	  I=I-1
	END DO
	LF=MAX(I,1) !  Length of file name
	IBUFFER_SAO(1)='40000'O !  PACKED and IMC_SAMPLE
	IBUFFER_SAO(2)=-(LF+59)
	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
	IBUFFER_SAO(8)=IFB_SAO-1 !  Frame buffer configuration - 1
	CALL IMTOOLCHECKSUM(IBUFFER_SAO)
	NBYTES=16
C  Send the WCS header
	CALL SI_WRITE(BUFFER_SAO,NBYTES)
C  Set up the WCS data packet
	IXLOC=XLOC_SAO(1)
	IYLOC=YLOC_SAO(1)
	CBUFFER_SAO(1:LF)=TV_FILENAME(NPIC_SAO)(1:LF)
	BUFFER_SAO(LF+1)=10
	CBUFFER_SAO(LF+2:LF+14)='1. 0. 0. -1. ' !  xx yx xy yy
	ENCODE (7,1000,CBUFFER_SAO(LF+15:LF+21)) 2-0.5-IXLOC !  xo =
	!  X Coordinate at left edge of buffer;  0.5 added to conform with 
	!  corner of pixel being x.0, y.0.
1000	FORMAT(F7.1)
	CBUFFER_SAO(LF+22:LF+22)=' '
	ENCODE (7,1000,CBUFFER_SAO(LF+23:LF+29)) IYLOC+2-0.5 !  yo =
	!  Y Coordinate at top edge of buffer;  0.5 added to conform with 
	!  corner of pixel being x.0, y.0.
	CBUFFER_SAO(LF+30:LF+30)=' '
	ENCODE (12,2000,CBUFFER_SAO(LF+31:LF+42)) AMIN_SAO(NFRAME_SAO) !  low
2000	FORMAT(E12.5)
	CBUFFER_SAO(LF+43:LF+43)=' '
	ENCODE (12,2000,CBUFFER_SAO(LF+44:LF+55)) AMAX_SAO(NFRAME_SAO) !  high
	CBUFFER_SAO(LF+56:LF+57)=' 1' !  w_type (=linear)
	BUFFER_SAO(LF+58)=10
	BUFFER_SAO(LF+59)=0
	NBYTES=LF+59
C  Send the WCS data packet
	CALL SI_WRITE(BUFFER_SAO,NBYTES)	
C
	RETURN
C
	END
