/**************************************************************************/
/*                                                                        */
/*                                 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_read.c,v 1.2 1997/09/25 17:49:42 ae59 Exp $ */
/*
$Log: r_read.c,v $
 * Revision 1.2  1997/09/25  17:49:42  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:09  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : r_read.c                              */
/*                                                              */
/*      Entries         : void r_read(device,s,rnd,i)           */
/*                        FILE *device;                         */
/*                        a_real *s;                            */
/*                        a_intg rnd;                           */
/*                        int i;                                */
/*                                                              */
/*      Arguments       : device - input device reading string  */
/*                        s - resultant IEEE variable           */
/*                        rnd - rounding mode                   */
/*                              -1 = rounding downwards         */
/*                               0 = round to nearest           */
/*                               1 = round upwards              */
/*                        i - window character                  */
/*                                                              */
/*      Description     : Read a character string from input    */
/*                        device and convert to IEEE double     */
/*                        format                                */
/*                                                              */
/*      Date            : 1992-01-15                            */
/*      1992-01-15 : converted value s added to e_trap()        */
/*      1991-04-24 : check for exceding exponent range          */
/*                   remove e_trap() in case 5:                 */
/*      1991-02-18 : variable 'buffer' introduced               */
/*                   b_scan argument changed                    */
/*      1990-11-12 : E_TPUSH+E_TPOPP                            */
/****************************************************************/

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

#ifdef LINT_ARGS
local void r_read(FILE *device,a_real *s,a_intg rnd,int i)
#else
local void r_read(device,s,rnd,i)

FILE *device;
a_real *s;
a_intg rnd;
int i;
#endif
        {
        a_intg dp,expo,length,size;
        a_bool sign;
        a_btyp rc;
        char *buffer;

        E_TPUSH("r_read")

        buffer = (char *)b_cp__;
        size = BUFFERSIZE;

        switch (b_scan(device,&buffer,&size,&expo,&dp,&length,&sign,i))
           {
           case  1: e_trap(ALLOCATION,2,E_TMSG,56);
                    break;
           case  2:
           case  3:
           case  4: e_trap(I_O_ERROR,2,E_TMSG,58);
                    break;
           case  5: /* e_trap(NO_ERROR+E_EMSG+E_ECNT,2,E_TMSG,64); */
           default:
              if (expo>DBL_MAX_10_EXP+2)
                 expo = DBL_MAX_10_EXP+2;
              else if (expo<DBL_MIN_10_EXP-DBL_MANT_DIG-2)
                 expo = DBL_MIN_10_EXP-DBL_MANT_DIG-2;
              if ((rc = b_form((a_btyp *)buffer,&size,
                               expo,dp,length,sign,rnd,s))!=0)
                 e_trap(rc,6,E_TMSG,56,E_TDBL+E_TEXT(3),s,
                                       E_TDBL+E_TRES,s);
           }

        if (size!=BUFFERSIZE)
           {
#ifdef HEAP_CHECK
b_freh((a_char *)&buffer,(a_char *)buffer,(a_char *)"r_read");
#endif
           free(buffer);
           }

        E_TPOPP("r_read")
        }
