From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  7-JUN-1991 04:20:37.10
To:	ARISIA::EVERHART
CC:	
Subj:	RE: Floating point data conversion from Sun to VMS and back

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.99)
	 id AA07290; Fri, 7 Jun 91 04:05:02 EDT
Received: From MAGGIE.TELCOM.ARIZONA.EDU by CRVAX.SRI.COM with TCP; Thu,  6 JUN 91 10:07:21 PDT
Date:    Thu, 6 Jun 1991 10:06:51 MST
From: "VIPS::VRH"@Arizona.EDU (Junk E-mail)
Message-Id: <910606100651.2020c68b@Arizona.EDU>
Subject: RE: Floating point data conversion from Sun to VMS and back
To: info-vax@sri.com
X-Vmsmail-To: TELCOM::SMTP%"info-vax@sri.com"

>A. C. Segal (segal@uicbert.eecs.uic.edu) writes:
>
> Does anyone have a conversion program that will take floating
> point data in VMS floating point format and put it into Sun
> floating point format and visa-versa?

     I've written and used the following FORTRAN routine to convert
     from SUN floating point to VAX floating point successfully.  
     It uses the VAX FORTRAN extensions IBITS to extract a bit pattern
     and MVBITS which transfers a bit pattern.  These are described in
     the VAX FORTRAN Language and Reference Manual.

     Vance Haemmerle
     Research Specialist
     Lunar & Planetary Lab
     University of Arizona
     (602) 621-4021

================= cut here =====================================

	subroutine sun_to_vax(bit_pattern,outbit_pattern)
	integer*4 bit_pattern, outbit_pattern
C
C  Converts SUN 4-byte floating point to VAX F-floating point number
C  by Vance Haemmerle, Lunar & Planetary Lab, University of Arizona
C  (vrh@vips.lpl.arizona.edu)  Feb 1990
C
C  usage:  call sun_to_vax(sun_real,vax_real)
C          where sun_real is a 4-byte variable and vax_real is REAL*4
C          sun_real and vax_real can be the same memory location
C
	integer*4 fraction
	integer*2 exp

C Extract Sun info
	fraction = IBITS(bit_pattern,0,23)
	exp = IBITS(bit_pattern,23,8)

C Correct for VAX
	if(exp.ne.0) exp = exp + 2

C Build VAX number
	Call MVBITS(bit_pattern,31,1,outbit_pattern,15)  ! Sign bit
	Call MVBITS(exp,0,8,outbit_pattern,7)  ! Exponent
	Call MVBITS(fraction,16,7,outbit_pattern,0)  ! Fraction
	Call MVBITS(fraction,0,16,outbit_pattern,16)  ! Fraction

	return
	end

