[comp.unix.ultrix] REAL*4 VMS v. ULTRIX

kemp@uiatma.atmos.uiuc.edu (John Kemp) (06/18/91)

We have a bunch of REAL*4 binary files on a VMS machine.
We want to move them to an ULTRIX machine.  Here are the 
two $64,000,000 questions:

1) If we want to ftp the binaries, how should they be converted
   first before ftping them to the Ultrix machine?

2) What are the differences between the REAL*4 format on
   VMS and Ultrix?

Correct answers will be rewarded with a network cookie!

--------  john kemp            (  (  )_  internet - kemp@uiatma.atmos.uiuc.edu
  -----                       (  (   __)   decnet - uiatmb::kemp
   ---    univ of illinois   (_ (   __)    bitnet - {uunet,convex}
   --     dept of atmos sci  .(____).               !uiucuxc!uiatma!kemp
   -      105 s gregory ave    ...          phone - (217) 333-6881
    -     urbana, il 61801    ...             fax - (217) 244-4393

kemp@uiatma.atmos.uiuc.edu (John Kemp) (06/19/91)

Here is a summary of responses.  I obviously should have said
"VAX/VMS-to-RISC/Ultrix floats" in my question, as a number of
people pointed out.

The network cookies are to be split between David Warren and
Jim Pflugrath:  one sent an actual subroutine for doing the 
conversion, the other sent the man page for a RISC/Ultrix library
subroutine that deals with the conversion.

Thanks for all the contributions people!
--------  john kemp            (  (  )_  internet - kemp@uiatma.atmos.uiuc.edu
  -----                       (  (   __)   decnet - uiatmb::kemp
   ---    univ of illinois   (_ (   __)    bitnet - {uunet,convex}
   --     dept of atmos sci  .(____).               !uiucuxc!uiatma!kemp
   -      105 s gregory ave    ...          phone - (217) 333-6881
    -     urbana, il 61801    ...             fax - (217) 244-4393

-------------------- Original Posting -----------------------------

We have a bunch of REAL*4 binary files on a VMS machine.
We want to move them to an ULTRIX machine.  Here are the 
two $64,000,000 questions:

1) If we want to ftp the binaries, how should they be converted
   first before ftping them to the Ultrix machine?

2) What are the differences between the REAL*4 format on
   VMS and Ultrix?

Correct answers will be rewarded with a network cookie!

----------------------- Responses ----------------------------

From: Richard Seymour <seymour@milton.u.washington.edu>
Subject: Re: REAL*4 VMS v. ULTRIX

is your target machine a VAX running ULTRIX (in which case, the numbers
should just work...)
or a RISC DECstation (in which case, i don't know what will happen
-- but they may work)?

(gee -- i should look/test this one -- i'm bound to run into it...)
--dick

From: pflugrat@cshl.org (Jim Pflugrath)

I recommend ftping first, then converting.  Mostly because the Ultrix machine
is probably a faster machine.

2) What are the differences between the REAL*4 format on
   VMS and Ultrix?

Below is code to convert from VMS to IEEE floating format.  Note that
the Ultrix supplied ftoi procedure does not work properly for some
numbers (as we found out to our dismay!).

Jim Pflugrath

P.S.  Since VMS and Ultrix have same byte-order, SWAP should be undefined
below.

========cut here for vureal.c==================
/*
** vureal_
**
** Convert a VMS 4 byte floating point representation to a IEEE 754 floating
** point representation.
**
** 19-Dec-1990        Ching-Lin Lun         Cold Spring Harbor Laboratory
**    Created.
*/
void vureal_(n)
unsigned long *n;
{

#ifdef SWAP
/*
** swap bytes  (may not be necessary on your machine)
*/
  *n =   ((*n & 0xff) << 24) + ((*n & 0xff00) << 8) + ((*n & 0xff0000) >> 8)
       + ((*n & 0xff000000) >> 24);
#endif

/*
** On VMS, if exponent is 0, then number is 0 no matter how other bits are set
*/
  if ( (*n & 0x0001fe00) == 0) {
     *n = 0;
     }
  else {
/*
** shift the bits from VMS format to Sun format 
** ffffffffffffffffseeeeeeeefffffff => seeeeeeeefffffffffffffffffffffff 
*/
     *n = ((*n & 0x8000) << 16)     + ((*n & 0x7f80) << 16) +
          ((*n & 0xffff0000) >> 16) + ((*n & 0x7f) << 16);
/*
**  ... and subtract 2 from exponent
*/
     *n = *n - 0x1000000;
   }
}

From: Ed Otto <edotto@ux1.cso.uiuc.edu>

Read them in, and write them unformatted to a file.
FTP the ASCII file.
Read them in unformatted and write them formatted to a new file.

That will GUARANTEE the port.  I'll do it for a fee in my free time.

>2) What are the differences between the REAL*4 format on
>   VMS and Ultrix?

I don't think there any; just in the format of the file itself. (I.E.:
the record terminators are different...)

>Correct answers will be rewarded with a network cookie!
Make mine chocolate chip.


*************************************************************************
**	Edward C. Otto III	* Email:  UIPSA::OTTO                  **
**	University of Illinois  *         UIPSB::OTTO                  **
**	Printing Division	* 	  edotto@uipsuxb.ps.uiuc.edu   **
**	54A E. Gregory		* 	  edotto@ux1.cso.uiuc.edu      **
**	Champaign, IL		*         otto@uipsa.dnet.nasa.gov     **
**	217/333-9422		*				       **
*************************************************************************

	"As knowledge is to ignorance, so is light unto the darkness."

			--  GO 'PODS!  --


From: Stephan Jansen <SJANSEN@vms.macc.wisc.edu>
Hi,
 
1) If the Ultrix machine is a RISC machine, then you need to do one of
   two things: 1) convert the data to either I*2 or I*4 files, scale
   the data if it is needed, either way you need to write a program to
   do this,  or 2) send the real*4 data to the Ultrix machine and write
   a program to convert the VAX real*4 data into IEEE single precision
   (there are C runtime routines for doing the conversion).  There may
   actually be a program somewhere that does either one of these things
   to a file but I dont know where they would be.
 
   If the Ultrix machine is a VAX, then you should be able to just ftp
   the file.
 
   In both cases you want the VMS file to either be fixed-length or
   Stream-LF format files and use IMAGE when FTPing.
 
2) The VAX real*4 format is the same between VMS and Ultrix (this is
   machine dependent and not operating system dependent).  The real*4
   format on the RISC Ultrix machines is actually IEEE sigle precision
   the VMS real*4 format is the VAX  D_FLOAT format.  I dont know off-
   hand what the difference is as far as bit fields.
 
Hope this helps.
 
Stephan


From: cdl@mpl.UCSD.EDU (Carl Lowenstein)

REAL*4 format is not necessarily a function of VMS vs. Ultrix, but rather
VAX vs. IEEE.  DECstations (RISC) use IEEE format, VAXstations (vax)
don't.  Suns, NeXTs, etc. etc. use IEEE format.

So the question really depends on what kind of hardware you are porting
to, not software.  There should be a library of VAX to IEEE conversion
routines somewhere in your RISC Ultrix software.

-- 
        carl lowenstein         marine physical lab     u.c. san diego
        {decvax|ucbvax} !ucsd!mpl!cdl                 cdl@mpl.ucsd.edu
                                                  clowenstein@ucsd.edu
From: przemek@rrdstrad.nist.gov (Przemek Klosowski)

VAXes (I assume that you run VMS on a VAX :^) has different floating
point format than IEEE used on R3000-based machines like our DEC 5810.
If however you are running ultrix on VAX, you are OK here. The FTP
format you should use depends on
	- the RMS format your files are in (the easiest are fixed
	binary 512 bytes/record)
	- the FTP you use.
If they are fix/512, you should be able just to issue `bin' ftp command
and transfer. If not, I don't know.
	przemek



From: David Warren <warren@atmos.washington.edu>

The difference isn't between VMS and ULTRIX it is between the VAX and 
DECstation architecture. The MIPS chip uses ieee. If you are going to a 
DECstation, there are some undocumented system calls that translate between
VAX and ieee floating point. They can be found with man ftoi. Incase your
man pages are not loaded:
     Name
          ftoi, itof, dtoi, itod, gtoi, itog - convert floating values
          between VAX and IEEE format

     Syntax
          int ftoi(value)
              float *value;

          int itof(value)
              float *value;

          int dtoi(value)
              double *value;

          int itod(value)
              double *value;

          int gtoi(value)
              double *value;

          int itog(value)
              double *value;

     Description
          The following C library functions convert floating values between
          VAX and IEEE formats.

          The ftoi function converts the specified VAX ffloat number to
          IEEE single-precision format.  It returns zero if successful and
          nonzero without performing the conversion if not successful (for
          example, underflow).

          The itof function converts the specified IEEE single-precision
          number to VAX ffloat format.  It returns zero if successful and
          nonzero without performing the conversion if not successful (for
          example, overflow).

          The dtoi function converts the specified VAX dfloat number to
          IEEE double-precision format.  It returns zero if successful and
          nonzero without performing the conversion if not successful (for
          example, underflow).

          The itod function converts the specified IEEE double-precision
          number to VAX dfloat format.  It returns zero if successful and
          nonzero without performing the conversion if not successful (for
          example, underflow or overflow).

          The gtoi function converts the specified VAX gfloat number to
          IEEE double-precision format.  It returns zero if successful and
          nonzero without performing the conversion if not successful (for
          example, underflow).

         The itog function converts the specified IEEE double-precision
          number to VAX gfloat format.  It returns zero if successful and
          nonzero without performing the conversion if not successful (for
          example, underflow).


-- 
David Warren 		INTERNET: warren@atmos.washington.edu
(206) 543-0945		UUCP:	  uw-beaver!atmos.washington.edu!warren
Dept of Atmospheric Sciences, AK-40
University of Washington

kemp@uiatma.atmos.uiuc.edu (John Kemp) (06/21/91)

Following up on the Q&A's we had about converting
VAX/VMS binaries to RISC/Ultrix binaries,  I wrote a little
"C" program to call ftoi() to process our files.  It 
works fairly well, so I thought I would post it for other
people who are making the move from VAX/VMS to RISC/Ultrix.

This is just for 4-byte floats, but there are a number of
other conversion routines in RISC/Ultrix.  Type "man ftoi"
for more information.  

In addition, one DEC person says that the latest version of 
the RISC Fortran Compiler V3.0 has an open statement for 
VAX/VMS binary files, which would make this little program
irrelevant.

Hope someone finds it of use.  If nothing else, it is good
to know that the "ftoi()" subroutine exists.

--------  john kemp            (  (  )_  internet - kemp@uiatma.atmos.uiuc.edu
  -----                       (  (   __)   decnet - uiatmb::kemp
   ---    univ of illinois   (_ (   __)    bitnet - {uunet,convex}
   --     dept of atmos sci  .(____).               !uiucuxc!uiatma!kemp
   -      105 s gregory ave    ...          phone - (217) 333-6881
    -     urbana, il 61801    ...             fax - (217) 244-4393

------------------- cut here -----------------------
/*
 * convert -- convert VAX/VMS binary to RISC/Ultrix binary
 *
 * To convert a VMS binary file full of 4-byte floating point
 * numbers, ftp the file to the RISC Ultrix machine in binary
 * mode, then run this program.  It will make a copy of the 
 * original binary file, but in Ultrix floating point format.
 *
 * John Kemp
 * UIUC Atmospheric Sciences
 * June 20, 1991
 */
#include <stdio.h>
FILE *infile; 
FILE *outfile;

char *usage="usage: convert <infile> <outfile>\n\t this program converts VAX/VMS binary float files to RISC/Ultrix float\n\t format using the ftoi(f) subroutine. remove the old VAX binary file\n\t after you perform the conversion.";

main(argc,argv)
int argc;
char *argv[];
{
	float f;
	int res=1, fres, cntr=0, size, nitems=1;

	if ( argc != 3 ) {
		fprintf(stderr,"%s\n",usage);
		exit(1);
	}

/* open files */
	infile = fopen(argv[1],"r+");
	outfile = fopen(argv[2],"w+");

/* read floats and convert */
	size = sizeof(f);
	while ( (res = fread(&f,size,nitems,infile)) > 0 ) {
		cntr++;
		fres = ftoi(&f);
		if ( fres != 0 ) 
			fprintf(stderr,"ftoi failed on num %d value %04x\n",cntr,f);
		else 
			fwrite(&f,size,nitems,outfile);
	}

/* close files */
	fclose(infile);
	fclose(outfile);
}