# StdMapTool.py

# try importing modules, catch exceptions if a module isn't installed
try:
	import sys
	
	import numpy as np
	import StandardMapClasses as stdm

except ImportError, msg:
	print 'Error importing modules:', msg
	sys.exit()

# Create a dictionary of map choices with pointers to their classes.
# Note that only references to the classes are stored below and no objects
# are actually created until the main loop.
maps = {
	'1' : ['Standard Map: x_n+1=x_n+y_n+1,\n%sy_n+1=y_n+k/(2pi)*sin((2pi)x_n)  (mod 1)' % (' '*18), stdm.StandardMap],
	'2' : ['Shifted Standard Map: x_n+1=x_n+y_n+1,\n%sy_n+1=y_n-k/(2pi)*sin((2pi)x_n) (mod 1)' % (' '*18),	stdm.StandardMapShift],
	'3' : ['Same as the shifted map but y is left without (mod 1)',	stdm.StandardMapShift_ynotmod1],
}


actions = {
	'1' : ['Iterate an array of initial conditions', stdm.IterArray],
	'2' : ['Iterate random intitial conditions in a prescribed box', stdm.RandInitialIterate],
	'3' : ['Iterate a line segment', stdm.LineIterate],
	'4' : ['Find manifold', stdm.Manifold]

}
mapList = maps.keys()	# convenient for looping in order
mapList.sort()	

actionList = actions.keys()
actionList.sort()

mapChoice = None

# main loop...
while mapChoice != '0':

	# prompt user for map choice
	print '\nStandard Map Tool'
	print 'Maps available:'
	for item in mapList:
		print item, '-', maps[item][0]

	# get choice from user		
	mapChoice = raw_input('\nEnter choice (%s-%s) or 0 to quit: ' % (mapList[0], mapList[-1]))
	
	# check if user wants to quit
	if mapChoice == '0': 
		print 'Exiting Standard Map tool...'
		break	# break out of main loop

	# else check if valid choice
	elif mapChoice not in mapList: 
		print '\n-->Invalid choice! Please try again...'
		continue	# skip to beginning of main loop to try again

	# this is where we actually create a map object
	Map = maps[mapChoice][1]
	
	print 'Actions available:'
	for item in actionList:
		print item, '-', actions[item][0]
	
	actionChoice = raw_input('\nEnter choice (%s-%s): ' % (actionList[0], actionList[-1]))
	
	stuff = actions[actionChoice][1]
	
	# get stuff from user
	N = raw_input('\nEnter number of iterations: ')
	k = raw_input('\nEnter number of the parameter K: ')

	# now do the do
	stuff(float(k),int(N),Map)

	

## end main loop ##