/* errors.c
********************************************************************************
* errors.c -- a collection of routines to simplify and unify error messages.
*
* Mark Showalter & Neil Heather, PDS Ring-Moon Systems Node, March 1998
*******************************************************************************/
#include <stdio.h>
#include "profile.h"

/* This is the defining declaration, referenced externally in profile.h */
RL_CHAR		xpro_message[XPRO_MESSAGE_LEN+1];

/*
********************************************************************************
* XPro_NullError() raises a PRO_CLASS_ERROR when an object contains a NULL
*                  pointer.
*******************************************************************************/

void		XPro_NullError(info, object)
RL_CHAR		*info;
PRO_OBJECT	*object;
{
    (void) sprintf(xpro_message, "null %s pointer in object \"%s\"",
		info, XPro_ObjectName(object,0));
    RL_RaiseError("PRO_CLASS_ERROR", xpro_message);
}

/*
********************************************************************************
* XPro_ClassError() raises a PRO_CLASS_ERROR when an object is used in the
*                   wrong context.
*******************************************************************************/

void		XPro_ClassError(info, object)
RL_CHAR		*info;
PRO_OBJECT	*object;
{
    (void) sprintf(xpro_message, "object \"%s\" is not a %s",
		XPro_ObjectName(object,0), info);
    RL_RaiseError("PRO_CLASS_ERROR", xpro_message);
}

/*
********************************************************************************
* XPro_DomainError() raises a PRO_DOMAIN_ERROR when a floating-point number is
*                    outside its allowed range.
*******************************************************************************/

void		XPro_DomainError(info, object, x1, x2, x)
RL_CHAR		*info;
PRO_OBJECT	*object;
RL_FLT8		x1, x2, x;
{
    (void) sprintf(xpro_message, "\
%s is outside allowed range\n\
domain = [%#g,%#g] in object \"%s\"\n\
value = %#g",
		info, x1, x2, XPro_ObjectName(object,0), x);

    RL_RaiseError("PRO_DOMAIN_ERROR", xpro_message);
}

/*
********************************************************************************
* XPro_IDomainError() raises a PRO_DOMAIN_ERROR when an integer is outside its
*                     allowed range.
*******************************************************************************/

void		XPro_IDomainError(info, object, k1, k2, k)
RL_CHAR		*info;
PRO_OBJECT	*object;
RL_INT4		k1, k2, k;
{
    (void) sprintf(xpro_message, "\
%s is outside allowed range\n\
domain = [%1d,%1d] in object \"%s\"\n\
value = %1d",
		info, k1, k2, XPro_ObjectName(object,0), k);

    RL_RaiseError("PRO_DOMAIN_ERROR", xpro_message);
}

/*
********************************************************************************
* XPro_EmptyDomain() raises a PRO_EMPTY_DOMAIN condition when two objects have
*                    floating-point domains that do not overlap.
*******************************************************************************/

void		XPro_EmptyDomain(info, object1, object2, x1a, x2a, x1b, x2b)
RL_CHAR		*info;
PRO_OBJECT	*object1, *object2;
RL_FLT8		x1a, x2a, x1b, x2b;
{
    if (object2 == NULL) {
	(void) sprintf(xpro_message, "\
%s has empty domain\n\
domain = [%#g,%#g] in object \"%s\"\n\
domain = [%#g,%#g] in requested window",
		info, x1a, x2a, XPro_ObjectName(object1,0), x1b, x2b);
    }
    else {
	(void) sprintf(xpro_message, "\
%s has empty domain\n\
domain = [%#g,%#g] in object \"%s\"\n\
domain = [%#g,%#g] in object \"%s\"",
		info, x1a, x2a, XPro_ObjectName(object1,0),
		      x1b, x2b, XPro_ObjectName(object2,0));
    }

    RL_RaiseError("PRO_EMPTY_DOMAIN", xpro_message);
}

/*
********************************************************************************
* XPro_IEmptyDomain() raises a PRO_EMPTY_DOMAIN condition when two objects have
*                     integer domains that do not overlap.
*******************************************************************************/

void		XPro_IEmptyDomain(info, object1, object2, k1a, k2a, k1b, k2b)
RL_CHAR		*info;
PRO_OBJECT	*object1, *object2;
RL_INT4		k1a, k2a, k1b, k2b;
{
    if (object2 == NULL) {
	(void) sprintf(xpro_message, "\
%s has empty domain\n\
domain = [%1d,%1d] in object \"%s\"\n\
domain = [%1d,%1d] in selected window",
		info, k1a, k2a, XPro_ObjectName(object1,0), k1b, k2b);
    }
    else {
	(void) sprintf(xpro_message, "\
%s has empty domain\n\
domain = [%1d,%1d] in object \"%s\"\n\
domain = [%1d,%1d] in object \"%s\"",
		info, k1a, k2a, XPro_ObjectName(object1,0),
		      k1b, k2b, XPro_ObjectName(object2,0));
    }

    RL_RaiseError("PRO_EMPTY_DOMAIN", xpro_message);
}

/*
********************************************************************************
* XPro_CoordMismatch() raises a PRO_COORD_MISMATCH condition when two objects
*                      have coordinates with different names.
*******************************************************************************/

void		XPro_CoordMismatch(info, object1, object2, name1, name2)
RL_CHAR		*info;
PRO_OBJECT	*object1, *object2;
RL_CHAR		*name1, *name2;
{
    if (object2 == NULL) {
	(void) sprintf(xpro_message, "\
coordinate name mismatch in %s\n\
name = \"%s\" in object \"%s\"\n\
name = \"%s\" in selected window",
		info, name1, XPro_ObjectName(object1,0),
		      name2);
    }
    else {
	(void) sprintf(xpro_message, "\
coordinate name mismatch in %s\n\
name = \"%s\" in object \"%s\"\n\
name = \"%s\" in object \"%s\"",
		info, name1, XPro_ObjectName(object1,0),
		      name2, XPro_ObjectName(object2,0));
    }

    RL_RaiseError("PRO_COORD_MISMATCH", xpro_message);
}

/*******************************************************************************
*/