/*Translated by FOR_C, v3.4.2 (-), on 07/09/115 at 08:30:07 */
/*FOR_C Options SET: ftn=u io=c no=p op=aimnv s=dbov str=l x=f - prototypes */
#include <math.h>
#include "fcrt.h"
#include "dstat2.h"
#include <stdio.h>
#include <stdlib.h>
/*++D Default ctypec = "double,"
 *++S Default ctypec = "float, "
 *++ Replace "double," = ctypec
 *++ CODE for .C. is active */
 void  dprpl(double,byte,byte[],long,double,double,LOGICAL32);
void /*FUNCTION*/ dstat2(
double stats[],
long ihist[],
long ncells,
double x1,
double x2)
{
	long int i, maxcnt;
	double brkpt, flmaxc, step, temp;
		/* OFFSET Vectors w/subscript range: 1 to dimension */
	long *const Ihist = &ihist[0] - 1;
	double *const Stats = &stats[0] - 1;
		/* end of OFFSET VECTORS */
 
	/*++ END
	 * Copyright (c) 1996 California Institute of Technology, Pasadena, CA.
	 * ALL RIGHTS RESERVED.
	 * Based on Government Sponsored Research NAS7-03001.
	 *>> 2001-03-30 DSTAT2 Krogh  Change for C conversion.
	 *>> 1996-07-01 DSTAT2 Krogh  Added special code for C conversion.
	 *>> 1995-11-17 DSTAT2 Krogh  Moved formats up for C conversion.
	 *>> 1994-10-20 DSTAT2 Krogh  Changes to use M77CON
	 *>> 1989-04-26 DSTAT2 CLL  Changed to use DPRPL instead of PRPL.
	 *>> 1987-11-24 DSTAT2 Lawson  Initial code.
	 *--D replaces "?": ?STAT2, ?PRPL, ?STAT1
	 *++D Default ctype = "(double)"
	 *++  Default ctype = " (float)"
	 *++ Replace "(double)" = ctype
	 *
	 *-- Begin mask code changes
	 *        This subr produces a printer-plot of the histogram from
	 *     IHIST() and prints the statistics from STATS(1:5).
	 *     This subr is intended to be used following the computation of
	 *     statistics and the building of a histogram by subr DSTAT1.
	 *        On entry STATS(1:5) must contain:
	 *             STATS(1) = Total count.
	 *             STATS(2) = Min
	 *             STATS(3) = Max
	 *             STATS(4) = Mean
	 *             STATS(5) = Standard deviation
	 *-- End mask code changes
	 *
	 *     See subr DSTAT1 for description of the other
	 *     subroutine arguments.
	 *     C. L. Lawson and S. Y. Chiu, JPL, Apr 1987.
	 *     ------------------------------------------------------------------ */
   char image[31];
	/*      character*(NLEN) IMAGE
	 *     ------------------------------------------------------------------ */
 
	/*                        Get max count to scale the plot. */
	maxcnt = 0;
	for (i = 1; i <= ncells; i++)
	{
		maxcnt = max( Ihist[i], maxcnt );
	}
	/*                      The following 2 stmts convert integer to float. */
	flmaxc = maxcnt;
	temp = ncells - 2;
	step = (x2 - x1)/temp;
	printf("  BREAK PT     COUNT          PLOT OF COUNT\n");
	if (Ihist[1] != 0)
	{
      dprpl( (double)( Ihist[1] ),'*',image,30,0.e0,flmaxc,TRUE );
      printf("             %7ld     %30.30s\n", Ihist[1], image);
	}
	/*         call DPRPL(dble(IHIST(1)),'*',IMAGE,NLEN,0.D0,FLMAXC,.TRUE.)
	 *         print '(13X,I7,5X,A)', IHIST(1),IMAGE */
	brkpt = x1;
	for (i = 2; i <= (ncells - 1); i++)
	{
      dprpl( (double)( Ihist[i] ),'*',image,30,0.e0,flmaxc,TRUE );
		printf("  %6.2f ----------------------------------------------\n", brkpt);
		/*         call DPRPL(dble(IHIST(I)),'*',IMAGE,NLEN,0.D0,FLMAXC,.TRUE.) */
      printf("             %7ld     %30.30s\n", Ihist[i], image);
		brkpt += step;
		/*         print '(13X,I7,5X,A)', IHIST(I),IMAGE */
	}
	printf("  %6.2f ----------------------------------------------\n", brkpt);
	if (Ihist[ncells] != 0)
	{
   dprpl((double)( Ihist[ncells] ),'*',image,30,0.e0,flmaxc,TRUE);
   printf("             %7ld     %30.30s\n", Ihist[ncells], image);
	}
	/*      call DPRPL(dble(IHIST(NCELLS)),'*',IMAGE,NLEN,0.D0,FLMAXC,.TRUE.)
	 *      print '(13X,I7,5X,A)', IHIST(NCELLS),IMAGE
	 *                           Finished with printer-plot of histogram.
	 * */
	printf(" \n   Count   Minimum      Maximum       Mean     Std. Deviation\n");
	printf(" \n %7ld%13.5g%13.5g%13.5g%14.5g\n", (long)( Stats[1] ), Stats[2], Stats[3],
	   Stats[4], Stats[5]);
	return;
} /* end of function */