[comp.sys.sgi] unsigned variables in f77 ???

mccalpin@vax1.acs.udel.EDU (John D Mccalpin) (06/10/90)

I am working with lots of 8-bit image data that I want to transfer
rapidly to the screen using an f77 program.  Since RECTWR wants
16-bit data, I have to copy the 8-bit data to a 16-bit array.
Unfortunately, f77 considers the 8-bit (integer*1) data to be 
signed, and so it does sign extension in the transfer to the
integer*2 array.  Is there any clean way of turning this off?
(Without coding in C!)

My workaround is based on the old FORTRAN trick of adding an
extra dimension of 2 at the beginning of the array an using
that to refer to the real and imaginary parts, only here I use
it to refer to the high and low bytes of the 16-bit pixel values.
In the production code, I collapse the DO loops and unroll them
to a depth of 4 to decrease the overhead.

Anybody have any better ideas?

	subroutine putpix(irec)
	parameter (n=512)
	integer*1 byte(n,n)
	integer*1 pixel(2,n,n)
	logical first
	save pixel,first
	data first /.true./

	if (first) then			! clear high-order bytes
	    do 2 j=1,n
		do 1 i=1,n
		    pixel(1,i,j) = 0
    1		continue
    2 	    continue
	    first = .false.
	endif

*	----- get data -----
	read (iunit,rec=irec) byte

*	----- copy array byte to low-order bytes of array pixel -----
	do 20 j=1,n
	    do 10 i=1,n
		pixel(2,i,j) = byte(i,j)
   10	    continue
   20	continue

*	----- send to pix buffer -----
	call rectwr(1,1,n,n,pixel)

	return
	end
-- 
John D. McCalpin                               mccalpin@vax1.udel.edu
Assistant Professor                            mccalpin@delocn.udel.edu
College of Marine Studies, U. Del.             mccalpin@scri1.scri.fsu.edu

calvin@dinkum.sgi.com (Calvin H. Vu) (06/12/90)

In article <6583@vax1.acs.udel.EDU> mccalpin@vax1.acs.udel.EDU (John D Mccalpin) writes:

>I am working with lots of 8-bit image data that I want to transfer
>rapidly to the screen using an f77 program.  Since RECTWR wants
>16-bit data, I have to copy the 8-bit data to a 16-bit array.
>Unfortunately, f77 considers the 8-bit (integer*1) data to be 
>signed, and so it does sign extension in the transfer to the
>integer*2 array.  Is there any clean way of turning this off?
>(Without coding in C!)

>Anybody have any better ideas?

    The intrinsic function ichar() returns an unsigned byte result so if
    you do short(ichar(char(byte(n,n)))) you will get what you need.
    This is my simple test case:

	byte a
	character b
	a = -5
	b = char(-5)
	print 10, a, b, short(a), short(ichar(b)), short(ichar(char(a)))
10	format(2(z2,1x), 3(z4,1x))
	end

and this is the result I got:
FB FB FFFB   FB   FB

Unfortunately, this only works in our latest release (3.3 release) so you
can only do this trick if you have the latest release.

>John D. McCalpin                               mccalpin@vax1.udel.edu
>Assistant Professor                            mccalpin@delocn.udel.edu
>College of Marine Studies, U. Del.             mccalpin@scri1.scri.fsu.edu

--------------------------------------------------------------------------
Calvin H. Vu			   | "We are each of us angels with
Silicon Graphics Computer Systems  | only one wing.  And we can only
calvin@sgi.com   (415) 962-3679	   | fly embracing each other."

blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS361 x42854") (06/12/90)

    I usually use "iand" to change an integer*1 to an integer*2 or
an integer*2 to an interger*4:

      integer*1 byte
      integer*2 pixel
      pixel=iand($00ff,byte)
--

	Brent L. Bates
	NASA-Langley Research Center
	M.S. 361
	Hampton, Virginia  23665-5225
	(804) 864-2854
	E-mail: blbates@aero4.larc.nasa.gov or blbates@aero2.larc.nasa.gov