/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: s_rhex.c,v 1.2 1997/09/25 18:01:23 ae59 Exp $ */
/*
$Log: s_rhex.c,v $
 * Revision 1.2  1997/09/25  18:01:23  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:44  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : s_rhex.c                              */
/*                                                              */
/*      Entry           : a_real s_rhex(s_trng)                 */
/*                        s_trng s;                             */
/*                                                              */
/*      Arguments       : s      - input string                 */
/*                                                              */
/*      Description     : convert hex real string to real       */
/*                                                              */
/*      Date            : 1993-08-25                            */
/*      1993-08-25  : new                                       */
/****************************************************************/
 
#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
#endif
 
#ifdef LINT_ARGS
local a_real s_rhex(s_trng s)
#else
local a_real s_rhex(s)
 
s_trng s;
#endif
        {
        int i;
        a_real r ;
        a_btyp b = ZERO;
	   int reallen= 2*sizeof(a_real); /* number of nibbles a word */
 
        E_TPUSH("s_rhex")

        /* check string lenght */
        if (reallen != s.alen)
	   {
                 e_trap(INV_ARG    ,6,E_TMSG,56,E_TSTR,&s.ptr[0],
				    E_TINT,&s.alen);
        }
        for (i=0;i<reallen;i++)
        {
                    b <<= 4;
                    if (isdigit(s.ptr[i]))
                       b += s.ptr[i]-'0';
                    else if (isalpha(s.ptr[i]))
                       b += toupper(s.ptr[i])-('A'-10);
                    else
                       {
                       e_trap(I_O_ERROR,4,E_TMSG,52,
                              E_TCHR+E_TEXT(10),&s.ptr[i]);
                       }
 
                    if (i==7)
                       {
                       ((a_btyp *)&r)[B_HPART] = b;
                       b = ZERO;
                       }
                    else if (i==15) ((a_btyp *)&r)[B_LPART] = b;
           }
 
        E_TPOPP("s_rhex")
        return(r);
        }
