/*Translated by FOR_C, v3.4.2 (-), on 07/09/115 at 08:33:14 */
/*FOR_C Options SET: ftn=u io=c no=p op=aimnv pf=,p_isort s=dbov str=l x=f - prototypes */
#include <math.h>
#include "fcrt.h"
#include <stdio.h>
#include <stdlib.h>
#include "p_isort.h"
/*>>   1988-11-22  DRISORT  Snyder  Initial code.
 *
 *     Test driver for ISORT and ISORTP.
 *
 *     Construct an array of 1000 random numbers using SRANUA.
 *     Scale it onto 1..1,000,000 and convert to integers.
 *     Sort it using ISORTP.
 *     Check whether it is in order.
 *     Sort it using ISORT.
 *     Check whether it is in order.
 * */
 
int main( )
{
	LOGICAL32 ok;
	long int i, p[1000-(1)+1], v[1000-(1)+1];
	float r[1000-(1)+1];
 
 
	/*     Generate 1000 random numbers */
	sranua( r, 1000 );
	/*     Scale them onto 1..1,000,000 and convert to integers. */
	for (i = 1; i <= 1000; i++)
	{
		v[i-(1)] = 1000000*r[i-(1)];
	}
	/*     Sort them using ISORTP.  Assume the sort will work. */
	ok = TRUE;
	isortp( v, 1, 1000, p );
	/*     Check the order. */
	for (i = 2; i <= 1000; i++)
	{
		if (v[p[i-(1)]-(1)] < v[p[i - 1-(1)]-(1)])
			ok = FALSE;
	}
	/*     Print the results. */
	if (ok)
	{
		printf("ISORTP succeeded\n");
	}
	else
	{
		printf("ISORTP failed\n");
	}
	/*     Sort them using ISORT.  Assume the sort will work. */
	ok = TRUE;
	isort( v, 1, 1000 );
	/*     Check the order. */
	for (i = 2; i <= 1000; i++)
	{
		if (v[i-(1)] < v[i - 1-(1)])
			ok = FALSE;
	}
	/*     Print the results. */
	if (ok)
	{
		printf("ISORT succeeded\n");
	}
	else
	{
		printf("ISORT failed\n");
	}
 
	exit(0);
} /* end of function */