/**************************************************************************/
/*                                                                        */
/*                                 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: b_errr.c,v 1.2 1997/09/25 17:02:06 ae59 Exp $ */
/*
$Log: b_errr.c,v $
 * Revision 1.2  1997/09/25  17:02:06  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:22  ae59
 * Put under RCS control
 *
 */
/*************************************************************************
 *                                                                       *
 * Descriptive Name : Lerror             Processor : C                   *
 *                                                                       *
 * Routine for Printing Error Message and Handling Errors                *
 * ======================================================                *
 *                                                                       *
 * Include files :  b_lari.h  - definitions for INTERN standard functions*
 *                                                                       *
 * Function value : int       - 0                                        *
 *                                                                       *
 * Used Functions :                                                      *
 *    none                                                               *
 *                                                                       *
 * Used Global UNSIGNED Variables :                                      *
 *    Lgiflag         Flag for Initialization of Global INTERN Variables *
 *    Ldebug          Flag for printing additional information           *
 *                                                                       *
 * Used Global STRING Variables :                                        *
 *    Lroutine        Name of the Routine called by user                 *
 *                                                                       */
/*      Date            : 1991-09-09                            */
/*      1991-09-09 : reduce max. line length                    */
/*      1990-09-06 : stderr replaced by f_errr.fp               *
 *                   f_errr declared                            *
 *      1990-09-04 : Larith.h replaced by b_lari.h              *
 *      1990-08-02 : switch variable cast (int)                 *
 *************************************************************************/

#ifdef AIX
#include "/u/p88c/runtime/base/b_lari.h"
#else
#include "b_lari.h"
#endif

extern f_text f_errr;

#define  printe(x)     fprintf(f_errr.fp,x)
#define  printe2(x,y)  fprintf(f_errr.fp,x,y)

char  *Lroutine, *Lerrmsg;

static char  Unknown[] = "(unknown)";

#ifdef LINT_ARGS
int b_errr(a_btyp err)
#else
int b_errr(err)

a_btyp err;
#endif
#define  LRoutine    "Lerror"
{
   int   rc;

#ifdef Debug
   extern int       Ldebug;
#endif


   if (err == 0) return(0);

  /*--------------------------------------*
   | Print Version and modify Debug Level |
   *--------------------------------------*/

#ifdef Debug
   Ldebug -= 1;                 /* Diminish Debug Level      */
   if (Ldebug >= 0) printf("\n Entering Routine %s",LRoutine);
#endif


  /*------------------------------------*
   | Check and Handle Undefined Routine |
   *------------------------------------*/

   if (Lroutine == NULL) {      /* Name of user called routine   */
      Lerrmsg = Unknown;        /*    is not known               */
      rc = NANDE;
      }
    else {
      rc = 0;
      }


  /*---------------------------*
   | Print appropriate Message |
   *---------------------------*/

   printe2("\n ***ERROR*** in Routine \"%s\" : ",Lroutine);
   switch ((int)err) {
      case DENOR   :  printe("Denormalized number converted");
                      break;
      case MINFI   :  printe("Minus infinity detected");
                      break;
      case NANDE   :  printe("NAN detected");
                      break;
      case OFLOW   :  printe("Exponent overflow");
                      break;
      case PINFI   :  printe("Plus infinity detected");
                      break;
      case ROUND   :  printe("Double value is rounded");
                      break;
      case UFLOW   :  printe("Exponent underflow");
                      break;
      case ZEROD   :  printe("Division by zero");
                      break;
      case RANGE   :  printe("Range error");
                      break;
      case ALLOC   :  printe("Allocation error");
                      break;
      case NALLO   :  printe("Data not allocated");
                      break;

      case ASSGN   :  printe("Assignment of result failed");
                      break;
      case ERRBD   :  printe("Determined error bound is invalid");
                      break;

      case PEVAL   :  printe("Error during polynomial evaluation");
                      break;
      case RESUL   :  printe("Error during result adaptation");
                      break;
      case CONVD   :  printe("Error during conversion to double");
                      break;
      case EPERR   :  printe("Error during computation of error bound");
                      break;
      case UNITS   :  printe("Error during computation of number of ulp's");
                      break;
      case DUFLW   :  printe("Floating point underflow during computation");
                      break;
      default      :  printe2("Return Code : %d",rc);
      }

   printe("\n");
   Lerrmsg = NULL;

   EXIT(rc);
}
