
/*
 * Copyright (c) 2001 BBNT Solutions LLC
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that the above copyright notice and this permission
 * appear in all copies and in supporting documentation, and that the
 * name of BBN Technologies not be used in advertising or publicity
 * pertaining to distribution of the software without specific,
 * written prior permission.  BBN makes no representations about the
 * suitability of this software for any purposes.  It is provided "AS
 * IS" without express or implied warranties.
 */

#ifdef IMPL_A2

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stats.h"


void a2_usage ()
{
    fprintf (stderr,"\nusage: a2 distribution [parameters]\n");
    fprintf (stderr," distributions:\n");
    fprintf (stderr,"   unif    uniform (parameters: min max)\n");
    fprintf (stderr,"   exp     exponential (parameters: mean)\n");
    fprintf (stderr,"\n");
}


void cmd_a2 ()
{
    unsigned short bad = FALSE;
    char *dist, *param1, *param2;
    double mean, upper, lower, sig;

    if ((dist = strtok (NULL," ")) == NULL)
	bad = TRUE;
    else
    {
	if (!strcmp (dist,"unif"))
	{
	    if ((param1 = strtok (NULL," ")) == NULL)
		bad = TRUE;
	    else if ((param2 = strtok (NULL," ")) == NULL)
		bad = TRUE;
	    else
	    {
		upper = atof (param1);
		lower = atof (param2);
		sig = unif_A2_known_range (sample,num_samples,upper,lower);
	    }
	}
	else if (!strcmp (dist,"exp"))
	{
	    if ((param1 = strtok (NULL," ")) == NULL)
		bad = TRUE;
	    else
	    {
		mean = atof (param1);
		sig = exp_A2_known_mean (sample,num_samples,mean);
	    }
	}
    }
    if (bad)
    {
	a2_usage ();
	if (script_file)
	    exit (1);
    }	
    else
    {
	print_label ("A2 sig");
	fprintf (out,"%0.3f\n", sig);
    }
}

#endif /* IMPL_A2 */
