	SUBROUTINE IMTOOLCHECKSUM(IBUFFER)
C
C       This function calculates the checksum for an IMTOOL header packet.
C  An IMTOOL header has 16 bytes, or 8 INTEGER*2 words.  The fourth word
C  is the checksum.  This function is used to send IMTOOL-like packets to
C  SAOimage.
C				Donald H. Gudehus, August, 1993
C			Version 2UM, D. Gudehus, March 17, 2005
C			Modified CHECKSUM for Mac OS
C
C	IBUFFER		(C/R)	The IMTOOL header array of 8 INTEGER*2 
C				words.  In the call, all words except 
C				the fourth, are ready for use.  Upon 
C				return, the fourth word equals the 
C				checksum.
C				
	INTEGER SUM
	INTEGER*2 IBUFFER(8),CHECKSUM(2)
	EQUIVALENCE (CHECKSUM(1),ISUM)
C
	SUM=0
C  Set IBUFFER(4) to zero in order to compute the initial sum
	IBUFFER(4)=0
	DO I=1,8
	  SUM=SUM+IBUFFER(I)
	END DO
C	PRINT *, IAND('177777'O-IAND(SUM,'177777'O),'177777'O)
	ISUM=IAND('177777'O-IAND(SUM,'177777'O),'177777'O)
	IBUFFER(4)=CHECKSUM(2)
C  Check that all is well
	SUM=0
	DO I=1,8
	  SUM=SUM+IBUFFER(I)
	END DO
	SUM=IAND(SUM,'177777'O)
	IF (SUM.NE.'177777'O) 
	1 CALL ERROR(-1,'Failure of checksum in IMTOOLCHECKSUM')
	END
