#include <v_lib.h>
#include "../utils/math_u.h"

int main(int argc,char *argv[])
{
	matrix_t **mset;
	int i,order,n,lower,upper;
	file_t out, an;
	puts(
		"Determinants generator ver. 2.0.\n"
		"Copyright (C) Vladimir A. Smirnov, 1997-2000.");
	if(argc<5)
	{
		puts("Usage: dgen <order> <lower limit> <upper limit> "
			"<number of determinants> [output file name] [file name for answers]");
		return -1;
	}
	order=atoi(argv[1]);
	lower=atoi(argv[2]);
	upper=atoi(argv[3]);
	n=atoi(argv[4]);
	out=fileOpenWrite(argc<6 ? "CON" : argv[5]);
	an=argc < 7 ? 0 : fileOpenWrite(argv[6]);
	umCreateRandomMatrixSet(&mset,n,order,order,lower,upper,false,true);
	filePrintf(out,";\t%d determinants of order %d\n;\tproduced by %s\n",
		n,order,argv[0]);
	if(an)
	{
		for(i=0;i<n;i++)
		{
			filePrintf(an,"%d == %g\n",i+1,
				matDeterm(mset[i],true));
			filePrintf(out,"\n----- %d ------\n",i+1);
			umDumpMatrix(out,mset[i],NULL,NULL,NULL,"| ","  "," |\n",true);
		}
		fileClose(an);
	}
	else
	{
		for(i=0;i<n;i++)
		{
			filePrintf(out,"%d == %g\n",i+1,
				matDeterm(mset[i],true));
			umDumpMatrix(out,mset[i],NULL,NULL,NULL,"| ","  "," |\n",true);
		}
	}
	fileClose(out);
	umDestroyRandomMatrixSet(mset,n);
}
