import numpy as np
import DiscretizedMaps as dm
import DiscretizedBifurcationPlot as dbp
import matplotlib.pyplot as plt
import sys

#This is the main user interface to DiscretizedBifurcationPlot

# here are some parameters which the user cannot adjust via arguments to the program
paramSteps=1024 # number of steps to increment the parameter
iterations=1024 # number of times to iterate the map after skipping transients
transients=256 # number of transients to skip
ic=.4 # initial condition to iterate

# here, the arguments to the program are assigned to the appropriate variables
# mapkey is a string which determines which map to use
# param is a string which determines which parameter to vary
# paramMin/paramMax are the min/max values of the parameter to use 
# param2val is the value of the parameter which is being held fixed
# paramInc is  the increment size for the varied parameter
mapkey,param,paramMin,paramMax,param2val=sys.argv[1:]
paramMin,paramMax,param2val=float(paramMin),float(paramMax),float(param2val)
paramInc=float(paramMax-paramMin)/float(paramSteps)

# here the map strings are associated with their  DiscretizedMaps object.
maps = {'logistic':dm.Logistic, 'tent':dm.Tent, 'logisticrand':dm.LogisticRand, 'tentrand':dm.TentRand}
# the map is assigned using the user input mapkey string
map=maps[mapkey]

# the if then statement below considers the case where r is the varied parameter, or N is the varied parameter.
# in both cases, the variables are put in the proper form to  be used as arguments to BifnPlot.
if param=='r':
	r=[paramMin,paramMax,paramInc]
	N=param2val	
	print 'Running...'
	dbp.BifnPlot(map,r,N,ic,iterations,transients)
	plt.show()
	
elif param=='N':
	N=[paramMin,paramMax,paramInc]
	r=param2val	
	print 'Running...'
	dbp.BifnPlot(map,r,N,ic,iterations,transients)
	plt.show()
	
else: raise ValueError, 'Unknown parameter'