/**********************************************************************/
/* NAME: get_float(&ddata,byte[],type,order)                          */
/*                                                                    */
/*   IN: byte     > pointer or array containing UUT data              */
/*       type     > type of floating conversion                       */
/*       order    > byte order of data (see byte_order)               */
/*                                                                    */
/*  OUT: ddata    > variable receiving double float value             */
/*                                                                    */
/*  RET:   0      > no errors                                         */
/*         1      > illegal floating point item                       */
/*                                                                    */
/* DATE: 01-feb-01        VERSION: 1.02       FILE: getfloat.c        */
/*                                                                    */
/* Revision Record:                                                   */
/*                                                                    */
/* 01-feb-01 Added type 10 6-byte IEEE-754 (16 lsbs missing).         */
/**********************************************************************/
/* This routine extracts a floating point item from the UUTs buffer   */
/* and returns it as a double (if there are no conversion errors).    */
/* The byte order of the data is accounted for during extraction.     */
/*                                                                    */
/* The floating point conversion routines expect data to be passed to */
/* them in the "PC" order, least significant byte first ... most      */
/* significant byte last.                                             */
/**********************************************************************/
/*  Floating Point Types:                                             */
/*                                                                    */
/*     0    IEEE-754    single precision (PC's format)                */
/*     1    IEEE-754    double precision (PC's format)                */
/*     2    DEC         single precision                              */
/*     3    DEC         double precision                              */
/*     4    1750A       single precision                              */
/*     5    1750A       extended precision                            */
/*     6    C30         single precision                              */
/*     7    C30         double precision                              */
/*     8    CAPS        single precision                              */
/*     9    CAPS        extended precision                            */
/*    10    IEEE-754    extended precision (Type 1 w/o 16 lsbs)       */
/**********************************************************************/

int     byte_order(void *, char *, int, int);
int     C30ToHost_d(double *, void *);
int     C30ToHost_s(double *, void *);
int     CAPToHost_d(double *, void *);
int     CAPToHost_s(double *, void *);
int     DECToHost_d(double *, void *);
int     DECToHost_s(double *, void *);
int     EEEToHost_d(double *, void *);
int     EEEToHost_s(double *, void *);
int     MILToHost_d(double *, void *);
int     MILToHost_s(double *, void *);

int  get_float(
			double *ddata,          /* out: as PC double precision */
			char *byte,             /* in:  ptr to 1st byte of data */
			int type,               /* in:  type of floating point */
			int order)              /* in:  byte order (see byte_order) */
{
char    tbuf[8];                    /* temporary buffer */
int     ret;                        /* conversion pass(0)/fail(1) flag */

	switch(type)
		{
		case 0:     /*---------- IEEE-754 single precision -----------*/

			byte_order(tbuf,byte,4,order);      /* reorder data */
			ret = EEEToHost_s(ddata,tbuf);      /* convert */
			break;

		case 1:     /*---------- IEEE-754 double precision -----------*/

			byte_order(tbuf,byte,8,order);      /* reorder */
			ret = EEEToHost_d(ddata,tbuf);      /* convert */
			break;

		case 2:     /*--------------- DEC single precision -----------*/

			byte_order(tbuf,byte,4,order);      /* reorder */
			ret = DECToHost_s(ddata,tbuf);      /* convert */
			break;

		case 3:     /*--------------- DEC double precision -----------*/

			byte_order(tbuf,byte,8,order);      /* reorder */
			ret = DECToHost_d(ddata,tbuf);      /* convert */
			break;

		case 4:     /*------------- 1750A single precision -----------*/

			byte_order(tbuf,byte,4,order);      /* reorder */
			ret = MILToHost_s(ddata,tbuf);      /* convert */
			break;

		case 5:     /*------------- 1750A extend precision -----------*/

			byte_order(tbuf,byte,6,order);      /* reorder */
			ret = MILToHost_d(ddata,tbuf);      /* convert */
			break;

		case 6:     /*--------------- C30 single precision -----------*/

			byte_order(tbuf,byte,4,order);      /* reorder */
			ret = C30ToHost_s(ddata,tbuf);      /* convert */
			break;

		case 7:     /*--------------- C30 double precision -----------*/

			byte_order(tbuf,byte,8,order);      /* reorder */
			ret = C30ToHost_d(ddata,tbuf);      /* convert */
			break;

		case 8:     /*-------------- CAPS single precision -----------*/

			byte_order(tbuf,byte,4,order);      /* reorder */
			ret = CAPToHost_s(ddata,tbuf);      /* convert */
			break;

		case 9:     /*-------------- CAPS extend precision -----------*/

			byte_order(tbuf,byte,6,order);      /* reorder */
			ret = CAPToHost_d(ddata,tbuf);      /* convert */
			break;

		case 10:    /*---------- IEEE-754 extended precision ----------*/

			byte_order(&tbuf[2],byte,6,order);  /* reorder */
			tbuf[0] = tbuf[1] = '\0';           /* zero LSBs */
			ret = EEEToHost_d(ddata,tbuf);      /* convert */
			break;

		default:    /*--------------- undefinded type ----------------*/

			return 1;
	   }
	return ret;
}
