From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 12-JUN-1992 18:13:00.71
To:	info-vax@kl.sri.com
CC:	
Subj:	Re: format translators ieee->vms

In article <1992May21.075058.15047@avalon.nwc.navy.mil>, howe%3915c.decnet@nwc.navy.mil (Steven Howe) writes:
> I have this data on my VAX/VMS workstation, taken (via tar) from a HP 
> computer.  I've been told that the data storage format on the HP is IEEE, 
> which is different in various way from VMS data storage.  Does anyone 
> know of a IEEE -> VMS translation algorithm and/or code and what site such 
> material is located.  
> 
> Thanks in advance.
> 
> Steven Howe
> Code 3915
> Naval Air Warefare Center - Weapons Division
> China Lake, CA 93555
> 
> howe%3915c.decnet@nwc.navy.mil

This should be a FAQ - I think I have responded at leat 5 times to this one (:-)!

After my .sig block tAfter my .sig are two comp.os.vms postings from long ago...
 /---------------------------------------------------------------------------\
| Rob Wright                | Wright_RJ@cc.curtin.edu.au                      |
| Curtin University         |                                                 |
| Perth, Western Australia  | psi%050529452300070:Wright_RJ                   |
| Voice:+61 9 351 7385      | Wright_RJ%cc.curtin.edu.au@cunyvm.bitnet        |
| FAX:     09-351-2673      | uunet!munnari.oz!cc.curtin.edu.au!Wright_RJ     |
|-----------------------------------------------------------------------------|
|    A nation which can not trust its intellectuals does not trust itself.    |
 \---------------------------------------------------------------------------/

X-VMS-News: vax3 comp.os.vms:1034
From: woods@ncar.ucar.edu (Greg Woods)
Subject:Re: difference between vax floating point representation and IEEE
Date: 21 Jul 88 22:08:44 GMT
Message-ID:<462@ncar.ucar.edu>

In article <2256@hubcap.UUCP> ghosh@hubcap.UUCP (Amitava Ghosh) writes:
>does anyone know what the difference is between the IEEE floating
>point representation and the way the VAX stores numbers. If so
>how does one convert from one format to the other.  

  Here's some C subroutines to convert back and forth between VAX and
IEEE format. I use them to convert binary files between VAXes and Suns
and it works fairly well. They all take a pointer to the data and
how many data elements to convert as arguments.

--Greg
-------------------------------------------------------------------------
union  ie3float { char c[4]; int  exp; float f; };
void vf2ie3f(u,n) register union ie3float *u; register int n; {
/* VAX float to IEEE float */
register char tmp;
register int i;
for (i=0; i < n; u++,i++) {
   if (! u->exp) continue;
   tmp=u->c[0]; u->c[0]=u->c[1]-1; u->c[1]=tmp;
   tmp=u->c[2]; u->c[2]=u->c[3];   u->c[3]=tmp;
}
}

void ie3f2vf(u,n) register union ie3float *u; register int n; {
/* IEEE float to VAX float */
register char tmp;
register int i;
for (i=0; i < n; u++,i++) {
   if (! u->exp) continue;
   tmp=u->c[0]+1; u->c[0]=u->c[1]; u->c[1]=tmp;
   tmp=u->c[2]; u->c[2]=u->c[3];   u->c[3]=tmp;
}
}

void i4conv(u,n) union ie3float *u; register int n; {
/* 4-byte integers; self-inverting operation so only one routine needed
   to go both ways */
register char tmp; register int i;
for (i=0; i < n; u++,i++) {
   tmp=u->c[0]; u->c[0]=u->c[3]; u->c[3]=tmp;
   tmp=u->c[1]; u->c[1]=u->c[2]; u->c[2]=tmp;
}
}

void i2conv(u,n) register union ie3float *u; int n; {
   swab(u,2*n); /* included for the hell of it */
}


X-VMS-News: vax3 comp.os.vms:1041
From: pack@acdpyr.ucar.edu (Dan Packman)
Subject:Re: difference between vax floating point representation and IEEE
Date: 22 Jul 88 22:37:55 GMT
Message-ID:<471@ncar.ucar.edu>

In article <2256@hubcap.UUCP> ghosh@hubcap.UUCP (Amitava Ghosh) writes:
>does anyone know what the difference is between the IEEE floating
>point representation and the way the VAX stores numbers. If so
>how does one convert from one format to the other...
The following program converts from vax f format to IEEE (UNIX point of view)
--------cut here-------------
      subroutine vax2lcl(n,iarray)
      dimension iarray(n)
      character*1 conv(4),ccc
      integer iconv
      equivalence (iconv,conv)
c Convert from vax floating point f format to pyramid IEEE single
      do 10 i=1,n
        iconv=iarray(i)
        if (iconv.ne.0) then
         ccc=conv(1)
         iii=ichar(conv(2))-1
         if (iii.lt.0)then
           write(0,100)iconv
 100       format(' vax2lcl: overflow int in =',i10)
           call exit(1)
         endif
         conv(1)=char(iii)
         conv(2)=ccc
         ccc=conv(3)
         conv(3)=conv(4)
         conv(4)=ccc
         iarray(i)=iconv
        endif
  10  continue
      return
      end
--------cut here-------------
The following converts an array of IEEE single floats to vax floats
It is written to work on a VAX/VMS machine
--------cut here-------------
      subroutine pyr2lcl(n,iarray)
      dimension iarray(n)
      byte conv(4),ccc
      integer iconv
      equivalence (iconv,conv)
c Convert from pyramid IEEE single to vax floating point f format
      do 10 i=1,n
        iconv=iarray(i)
        if (iconv.ne.0) then
         ccc=conv(2)
         iii=conv(1)+1
         if (iii.gt.255)then
           write(0,100)iconv
 100       format(' pyr2lcl: overflow int in =',i10)
           call exit(1)
         endif
         conv(2)=iii
         conv(1)=ccc
         ccc=conv(3)
         conv(3)=conv(4)
         conv(4)=ccc
         iarray(i)=iconv
        endif
  10  continue
      return
      end

