/**************************************************************************/
/*                                                                        */
/*                                 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: r_aval.c,v 1.2 1997/09/25 17:43:24 ae59 Exp $ */
/*
$Log: r_aval.c,v $
 * Revision 1.2  1997/09/25  17:43:24  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:23:49  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : r_aval.c                              */
/*                                                              */
/*      Entries         : a_real r_aval(s,n,rnd)                */
/*                        a_char s[];                           */
/*                        a_intg n;                             */
/*                        a_intg rnd;                           */
/*                                                              */
/*      Arguments       : s   - input string                    */
/*                        n   - length of input string          */
/*                        rnd - rounding mode                   */
/*                              -1 = rounding downwards         */
/*                               0 = round to nearest           */
/*                               1 = round upwards              */
/*                                                              */
/*      Description     : Convert a character string            */
/*                        to IEEE double format                 */
/*                                                              */
/*      Date            : 1991-04-22                            */
/*      1991-04-22 : real assignment replaced by R_ASSIGN()     */
/*      1991-01-22 : r_ass() used                               */
/*      1991-01-17 : (size_t) cast in memcpy()                  */
/*      1990-11-22 : replace strncpy by memcpy                  */
/*      1990-11-19 : E_TPUSH+E_TPOPP                            */
/*      1990-10-23 : new argument next in r_conv                */
/*      1990-10-17 : (char *) cast in strncpy                   */
/*      1990-10-15 : new argument n                             */
/*      1990-07-17 : LINT_ARGS prototype                        */
/*      1990-07-30 : string replaced by a_char[]                */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
extern dotprecision b_cm__;
extern a_real *r_zero;
#endif

#ifdef LINT_ARGS
local a_real r_aval(a_char s[],a_intg n,a_intg rnd)
#else
local a_real r_aval(s,n,rnd)

a_char s[];
a_intg n;
a_intg rnd;
#endif
        {
        a_real res;
        a_char *buffer;
        a_char *next;

        E_TPUSH("r_aval")

        if (n>=BUFFERSIZE)
           {
           R_ASSIGN(res,*r_zero);
           e_trap(I_O_BUFFER,2,E_TMSG,56);
           }
        else
           {
           buffer = (a_char *)b_cm__;
           memcpy((char *)buffer,(char *)s,(size_t)n);
           buffer[n] = '\0';

           r_conv(buffer,&res,rnd,&next);
           }

        E_TPOPP("r_aval")
        return(res);
        }
