#!/usr/bin/env python

"""Expand a set of coefficients of orthogonal polynomials
into a list of x, y points.
"""

import ortho_poly
import sys
import die



try:
	enumerate([])
except NameError:
	from g_enumerate import enumerate



if __name__ == '__main__':
	N = 100
	xa = None
	name = 'Legendre'
	arglist = sys.argv[1:]
	while arglist and arglist[0].startswith('-'):
		arg = arglist.pop(0)
		if arg == '-name':
			name = arglist.pop(0)
		elif arg == '-n':
			N = int(arglist.pop(0))
		elif arg == '-x':
			N = None
			xa = []
			for l in sys.stdin:
				if l.startswith('#'):
					continue
				l = l.strip()
				if l == '':
					continue
				xa.append(float(l))
		elif arg == '--':
			break
		else:
			die.die('Bad arg: %s' % arg)
	c = [ float(x) for x in arglist ]
	op = ortho_poly.F(name, n=N, x=xa)
	s = op.expand(c)

	for i in range(len(s)):
		print i, op.x[i], s[i]
