# ----------------------------------------------------------------------- #
# FROM ORIGINAL gen_and_run code (V2)
# Information require for the genAndRun portion of the code. Gathers
# info about the nuclides for [n] mode and isotopes for [x] mode. 
# ----------------------------------------------------------------------- #
# Python packages
import fileinput as fi 
import linecache as lc 
import numpy     as np

# ----------------------------------------------------------------------- #
def getInfo( arg ):
# ----------------------------------------------------------------------- #

	if str( arg ) == 'a':
		inputFileName = raw_input(' Enter name of input information: ')

		temp = fi.input( inputFileName )
		lineno = np.zeros(8, dtype = int)

		for line in temp:
			if line.find('# Name of interaction file') !=-1:
				lineno[0] = fi.lineno() + 1
			elif line.find('# Number of nuclides to run in [n] ') !=-1:
				lineno[1] = fi.lineno() + 1
			elif line.find('# Number of states to keep') !=-1:
				lineno[2] = fi.lineno() + 1
			elif line.find('# Max number of iterations') !=-1:
				lineno[3] = fi.lineno() + 1
			elif line.find('# Number of parameters') !=-1:
				lineno[4] = fi.lineno() + 1
			elif line.find('# Name of .sps file (w/out extension)') !=-1:
				lineno[5] = fi.lineno() + 1
			elif line.find('# Number of isotopes') !=-1:
				lineno[6] = fi.lineno() + 1
			elif line.find('# General output name') !=-1:
				lineno[7] = fi.lineno() + 1
			else:
				continue 

		intName    = str(lc.getline( inputFileName, int(lineno[0]) ).split()[0])
		nuclideNum = int(lc.getline( inputFileName, int(lineno[1]) ).split()[0])
		numStates  = int(lc.getline( inputFileName, int(lineno[2]) ).split()[0])
		numIter    = int(lc.getline( inputFileName, int(lineno[3]) ).split()[0])
		numParams  = int(lc.getline( inputFileName, int(lineno[4]) ).split()[0])
		spsName    = str(lc.getline( inputFileName, int(lineno[5]) ).split()[0])
		isotopeNum = int(lc.getline( inputFileName, int(lineno[6]) ).split()[0])
		mkdirName  = str(lc.getline( inputFileName, int(lineno[7]) ).split()[0])
		outputName = str(lc.getline( inputFileName, int(lineno[7]) ).split()[0])

		# Create arrays to contain nuclide information
		nuclideName = []
		nuclideA    = []
		valProNuc   = []
		valNeutNuc  = []
		jzSysNuc    = []
		# Create arrays to contain isotope information
		isotopes    = []
		valProIso   = []
		valNeutIso  = []
		jzSysIso    = []

		for i in range( nuclideNum ):
			nuclideName.append( str( lc.getline (inputFileName, lineno[1] + 1 + 5*i ).split()[0]) ) 
			nuclideA.append(    int( lc.getline (inputFileName, lineno[1] + 2 + 5*i ).split()[0]) )
			valProNuc.append(   int( lc.getline (inputFileName, lineno[1] + 3 + 5*i ).split()[0]) ) 
			valNeutNuc.append(  int( lc.getline (inputFileName, lineno[1] + 4 + 5*i ).split()[0]) ) 
			jzSysNuc.append(    int( lc.getline (inputFileName, lineno[1] + 5 + 5*i ).split()[0]) ) 

		for i in range( isotopeNum ):
			isotopes.append(   str( lc.getline (inputFileName, lineno[6] + 1 + 4*i ).split()[0]) )
			valProIso.append(  int( lc.getline (inputFileName, lineno[6] + 2 + 4*i ).split()[0]) )
			valNeutIso.append( int( lc.getline (inputFileName, lineno[6] + 3 + 4*i ).split()[0]) )
			jzSysIso.append(   int( lc.getline (inputFileName, lineno[6] + 4 + 4*i ).split()[0]) )

		return ( intName, nuclideNum, numStates, numIter, numParams, spsName, 
						 isotopeNum, mkdirName, outputName, nuclideName, nuclideA, valProNuc,
						 valNeutNuc, jzSysNuc, isotopes, valProIso, valNeutIso, jzSysIso )

	# Get information interactively 
	else:
		# Name of interaction file (ex: USDB)
		print ('')
		print (' NAME OF INTERACTION ------------------------------------------------ ')
		intName = raw_input('\t Name of interaction file: ')

		# Number of nuclides
		print ('')
		print (' NUMBER OF NUCLIDES ------------------------------------------------- ')
		nuclideNum = int(input(' \t Enter number of nuclides to run in [n]: '))

		# Create arrays to contain nuclide information
		nuclideName = []
		nuclideA    = []
		valProNuc   = []
		valNeutNuc  = []
		jzSysNuc    = []
		# Create arrays to contain isotope information
		isotopes    = []
		valProIso   = []
		valNeutIso  = []
		jzSysIso    = []


		# For each nuclide:
		# Information about [n] mode nuclides 
		print ('')
		print (' FOR EACH NUCLIDE --------------------------------------------------- ')
		for i in range( nuclideNum ):
			nuclideName.append( raw_input(' \t Name of nuclide:            '))
			nuclideA.append(    int(input(' \t Atomic number of nuclide:   ')))
			valProNuc.append(   int(input(' \t Number of valence protons:  ')))
			valNeutNuc.append(  int(input(' \t Number of valence neutrons: ')))
			jzSysNuc.append(    int(input(' \t 2 x J_z of system:          ')))

		# Information about all [n] runs 
		print ('')
		print (' INFO ABOUT ALL [n] RUNS -------------------------------------------- ')
		numStates = int(input(' \t Number of states to keep:            '))
		numIter   = int(input(' \t Max number of iterations:            '))
		numParams = int(input(' \t Enter number of parameters:          '))
		spsName   = int(input(' \t Name of .sps file (w/out extension): ')) 

		# Check that .sps file is in current directory 
		checkFor = spsName + ".sps"
		while not os.path.exists( checkFor ):
			print ('')
			print (' !! INCORRECT .sps name !! ')
			spsName  = raw_input(' \t Name of .sps file (w/out extension): ')
			checkFor = spsName + ".sps"

		print ('')
		print (' NUMBER OF ISOTOPES ------------------------------------------------- ')
		isotopeNum = int(input(' \t Enter number of isotopes to create: '))

		# Get information about each isotope
		for i in range( isotopeNum ):
			print (' \n Information for isotope %i: ' % ( i + 1 ))
			isotopes.append(   raw_input(' \t Name and A of isotope:      '))
			valProIso.append(  int(input(' \t Number of valence protons:  ')))
			valNeutIso.append( int(input(' \t Number of valence neutrons: ')))
			jzSysIso.append(   int(input(' \t 2 x J_z of system:          ')))

		# Directory name for file storage 
		print (' OUTPUT DIRECTORY --------------------------------------------------- ')
		mkdirName = raw_input(' \t Name for directory for [x] output: ')
		os.system('mkdir %s' % mkdirName )

		# FROM ORIGINAL GEN AIJ
		# General output name (same as directory name)
		outputName = mkdirName

	return  ( intName, nuclideNum, numStates, numIter, numParams, spsName, 
					  isotopeNum, mkdirName, outputName, nuclideName, nuclideA, valProNuc,
					  valNeutNuc, jzSysNuc, isotopes, valProIso, valNeutIso, jzSysIso )

# FROM ORIGINAL GENERATE MILCOMS
# File name containg Aij matrix

# Number of evecs to keep 

# Name for outputs (evals, evecs)

# FROM ORIGINAL GENERATE TRANSFORM
# Name of interaction to compare to MILCOMs 

# File containing MILCOMs 