Thanks to all who responded to this request for help.
The soultion that suited my application best came from
Tom Leitner and is enclosed: Many Thanks Tom.
Thanks also to:
Dr Tom Blinn
Eugene Chu
Roddy McColl
Lucio Chiappetti
Original message:
Does anyone have a 'C' routine to convert floating point data stored as a binary file from a VMS machine to the IEEE format recognised by gcc on DEC Unix that they could let me have.
These routines successfully converted the floats generated on VMS to the IEEE unix format.
#include <stdio.h>
typedef unsigned char u_char;
#include <math.h>
#endif
/* ------------------------------------------------------------------------ */
/* local constants and variables */
/* ------------------------------------------------------------------------ */
/* IEEE single precision floating point */
struct ieee_single {
unsigned int mantissa: 23;
unsigned int exp : 8;
unsigned int sign : 1;
};
/* VAX single precision floating point */
struct vax_single {
unsigned int mantissa1 : 7;
unsigned int exp : 8;
unsigned int sign : 1;
unsigned int mantissa2 : 16;
};
#define VAX_SNG_BIAS 0x81
#define IEEE_SNG_BIAS 0x7f
static struct sgl_limits {
struct vax_single s;
struct ieee_single ieee;
} sgl_limits[2] = {
{{ 0x7f, 0xff, 0x0, 0xffff }, /* Max Vax */
{ 0x0, 0xff, 0x0 }}, /* Max IEEE */
{{ 0x0, 0x0, 0x0, 0x0 }, /* Min Vax */
{ 0x0, 0x0, 0x0 }} /* Min IEEE */
};
#endif
/*#------------------------------------------------------------------------#*/
u_char *vax_to_ieee(float *f)
/*
Description:
Converts a float from VAX to (IEEE) format
Parameters:
*fp: pointer to the float to be converted
return value: converted float
*/
{
struct ieee_single is;
struct vax_single vs;
struct sgl_limits *lim;
int i;
vs = *((struct vax_single *) f);
for (i = 0, lim = sgl_limits;
i < sizeof(sgl_limits) / sizeof(struct sgl_limits); i++, lim++) {
if ((vs.mantissa2 == lim->s.mantissa2) &&
(vs.exp == lim->s.exp) &&
(vs.mantissa1 == lim->s.mantissa1)) {
is = lim->ieee;
goto shipit;
}
}
is.exp = vs.exp - VAX_SNG_BIAS + IEEE_SNG_BIAS;
is.mantissa = (vs.mantissa1 << 16) | vs.mantissa2;
shipit:
is.sign = vs.sign;
memcpy((void*) f, &is, sizeof(float));
return (u_char*) f;
return (u_char*) f;
}
/* End of File */
--
--------------------------------------------------------------------------
*****************************
Dr Neil Higson
WX1 System Manager
Weapon Systems
Room 1009 A2 Building
DERA Farnborough
Tel: 01252 396977
Fax: 01252 394720
*****************************
"The Information contained in this e-mail and any
subsequent correspondence is private and is intended
solely for the intended recipient(s). For those
other than the intended recipient any disclosure,
copying, distribution, or any action taken or
omitted to be taken in reliance on such information
is prohibited and may be unlawful."
Received on Fri Jan 15 1999 - 10:44:44 NZDT