#! /usr/bin/python	
	
from html_elements import *
import cgi,string,sys
from ini_read import *
Choice=[]	
List=[]
	
def header_read(Filename,List):
	Fileobject_read = open(Filename, 'r')
	Data = Fileobject_read.readline()
	Fileobject_read.close()
	Row = string.split(Data)
	List[1] = int(Row[0])
	List[2] = float(Row[1])
	List[3] = float(Row[2])
	List[4] = float(Row[3])
	return(List)

def html_java(Temp,Flag,Output,Debug):
	input={}
	Temp_name=[]
	Temp_internal=[]
	#####################################################
	#
	#	initial parameter settings
	#
	#####################################################
	List_name=['Telescopemode', 'Object_choice', 'Choice_spectra', 'Spectrum', 'Spectrum_short', 'Filter_mag', 'Object_brightness_choice', 'Detector', 'Filter_choice', 'Camera_choice', 'Water_vapor', 'Airmass', 'Background', 'Sky_brightness', 'Seeing', 'SN', 'DIT', 'Blackbody_temperature', 'Line_wavelength', 'Line_flux', 'Line_width', 'Lucifermode', 'Slit_width', 'Strehl', 'Central_wavelength', 'Exposuretime', 'Redshift']
	List_value=['Seeing', 'Point source', 'Template', 'uniform', 't', 'V', '18', '1', 'J', 'N1.8', '1.60', '1.50', 'User_theoretical', '18', '0.8', '10', '10', '4000', '1.2500', '1.0000e-8', '600', 'Imaging', '0.50', '0.5', '1.250 / 210', '10', '0.0']
	j=0
	for i in List_name:
		input[i]=List_value[j]
		j=j+1
	
	j=0
	
	if Temp.has_key('Telescopemode'):
		Temp_name=Temp.keys()
		for i in Temp_name:
			#print 
			input[i]=Temp[Temp_name[j]].value
			j=j+1
	
	Spectrum_list.append('uniform')
	Filter_list_target = [['U','0','U'],['B','0','B'],['V','0','V'],['R','0','R'],['I','0','I']]
	for i in range(0,len(Filter_list)):
		if Filter_list[i][1] == input['Detector'] and Filter_list[i][0] <> "clear":# or Filter_list[i][1] == "0":
			Filter_list_target.append([Filter_list[i][0],Filter_list[i][1],Filter_list[i][2]])
	
	if input['Background']<>"User_file":
		for i in range(len(Water_list)):
			Water_list[i]="%.2f" % Water_list[i]
	else:
		for i in range(len(Water_list)):
			Water_list[i]="0"
		for i in range(len(Water_list)):
			Water_list.remove("0")
		Water_list.append("1.60")
		input['Water_vapor']="1.60"
	Water_list.sort()
	for i in range(len(Airmass_list)):
		Airmass_list[i]="%.2f" % Airmass_list[i]
	Airmass_list.sort()
	
	########################################################
	#
	#	Generating the source code of the web page
	#
	#
	########################################################
	
	header("LUCI - Exposure Time Calculator", Output['css'])
	body()
	if Debug == 2:
		Temp1 = "?Calibration=1"
	elif Debug == 1:
		Temp1 = "?Debug=1"
	else:
		Temp1=""
	form(Output['code_path']+Temp1, "POST")
	headline ("LUCI - Exposure Time Calculator",'1')
	#blink("Warning")
	if Debug != 2:
		headline("WARNING!",'4')
		headline("Valid for 2012A. Data for new detector for Luci1 based on lab-measurements.",'1')
		headline("Will be updated once on-sky calibration beginning of March has been carried out.",'1')
		headline("The calculations are not corrected for sky concentration and backscattering yet. If you have questions, please ask<br>Dave Thompson (dthompson[at]as.arizona.edu) or Jochen Heidt (J.Heidt[at]lsw.uni-heidelberg.de).",'1')
	else:
		headline("ETC calibration mode","4")
	par("")
	link(Output['help_web']+'/files/history.html',"Version 1.34.11")
	coda_par()
	hline('100%', "left", 4)
	headline("Telescope Modes",'2')
	
	if input['Telescopemode']=='Seeing':
		Flag1="1"
		Flag2="0"
	else:
		Flag1="0"
		Flag2="1"
	par('five')
	coda_par()
	
	par('seeing')
	radio('Telescopemode', 'Seeing', Output['code_path'], Flag1)
	link(Output['help_web']+'node10.html', "Seeing-limited mode")
	coda_par()
	
	par('diffraction')
	radio('Telescopemode', 'Diffraction', Output['code_path'], Flag2)
	link(Output['help_web']+'node9.html', "Diffraction-limited mode")
	coda_par()
	
	par('strehl')
	link(Output['help_web']+'node9.html', "Strehl ratio:")
	input_field('Strehl', input['Strehl'], '0.54in', '1.6em', '100%', Flag2)
	coda_par()
	
	par('clear')
	coda_par()
	
	hline("80%","CENTER","2")
	
	headline("Object Characteristics",'2')
	
	if input['Object_choice']=='Point source':
		Flag1="1"
		Flag2="0"
	else:
		Flag1="0"
		Flag2="1"
	
	par('five')
	coda_par()
	
	par('point')
	radio('Object_choice', 'Point source', '', Flag1)
	print ('Point source')
	coda_par()
	
	par('extended')
	radio('Object_choice', 'Extended source', '', Flag2)
	print ('Extended source')
	coda_par()
	
	par('clear')
	coda_par()
	
	if input['Choice_spectra']=='Template':
		Flag1="1"
		Flag2="0"
		Flag3="0"
	elif input['Choice_spectra']=='Blackbody':
		Flag1="0"
		Flag2="1"
		Flag3="0"
	elif input['Choice_spectra']=='Single line':
		Flag1="0"
		Flag2="0"
		Flag3="1"
	
	par('spectrum_template')
	radio('Choice_spectra', 'Template', Output['code_path'], Flag1)
	link(Output['help_web']+'node12.html', "Template Spectrum:")
	selection_list('Spectrum', Spectrum_list, input['Spectrum'], '27%', '1.6em', '100%', Flag1)
	print " "
	link(Output['help_web']+'node12.html#redshift', "Redshift:")
	input_field('Redshift', input['Redshift'], '10%', '1.6em', '100%', Flag1)
	coda_par()
	
	par('blackbody')
	if Debug != 2:
		radio('Choice_spectra', 'Blackbody', Output['code_path'], Flag2)
	else:
		radio('Choice_spectra', 'Blackbody', Output['code_path'], '3')
	link(Output['help_web']+'node13.html', 'Blackbody')
	print ' with T='
	if Debug != 2:
		input_field('Blackbody_temperature', input['Blackbody_temperature'], '30%', '1.6em', '100%', Flag2)
	else:
		input_field('Blackbody_temperature', input['Blackbody_temperature'], '30%', '1.6em', '100%', '3')
	print "K"
	coda_par()
	
	par('single_line_radio')
	if Debug != 2:
		radio('Choice_spectra', 'Single line', Output['code_path'], Flag3)
	else:
		radio('Choice_spectra', 'Single line', Output['code_path'], '3')
	link(Output['help_web']+'node14.html', 'Single line')
	print ' with ...'
	coda_par()
	
	par('single_line_text')
	print '... Wavelength:<br>'
	print '... Flux:<br>'
	print '... Width: '
	coda_par()
	
	par('single_line_boxes')
	input_field('Line_wavelength', input['Line_wavelength'], '80%', '1.6em', '100%', Flag3)
	input_field('Line_flux', input['Line_flux'], '80%', '1.6em', '100%', Flag3)
	input_field('Line_width', input['Line_width'], '80%', '1.6em', '100%', Flag3)
	coda_par()
	
	par('single_line_units')
	print 'micron<br>'
	print 'erg/s/cm<sup>2</sup><br>'
	print '&Aring;'
	coda_par()
	
	par('Clear')
	coda_par()
	
	par('target_magnitude')
	link(Output['help_web']+'node15.html','Target magnitude')
	print ' (Vega):'
	Temp_name=[]
	Temp_internal=[]
	for i in range(0,len(Filter_list_target)):
		Temp_name.append(Filter_list_target[i][0])
		Temp_internal.append(Filter_list_target[i][2])
	if input['Filter_mag'] not in Temp_internal:
		Raw = input['Filter_mag'].split("_")
		for i in Temp_internal:
			if i[0:len(Raw[0])+1] == Raw[0]+"_":
				input['Filter_mag'] = i
	selection_list_internal('Filter_mag', Temp_name, input['Filter_mag'], '1.50in', '1.6em', '100%', '1', Temp_internal)	
	print "="
	input_field('Object_brightness_choice', input['Object_brightness_choice'], '0.54in', '1.6em', '100%', str(int(Flag1) or int(Flag2)))
	print 'mag (mag/sq.arcsec for extended sources)'
	coda_par()
	
	par('clear')
	coda_par()
	
	hline("80%","CENTER","2")
	
	par("")
	target('MIDDLE','0')
	coda_par()
	headline("Hardware Characteristics",'2')
	if input['Detector']=='1':
		Flag1="1"
		Flag2="0"
	else:
		Flag1="0" 
		Flag2="1"
	
	par('five')
	coda_par()
	
	par('lucifer1')
	radio('Detector', '1', Output['code_path']+'#MIDDLE', Flag1)
	link(Output['help_web']+'node19.html', "LUCI 1")
	coda_par()
	
	par('lucifer2')
	radio('Detector', '2', Output['code_path']+'#MIDDLE', Flag2)
	link(Output['help_web']+'node19.html', "LUCI 2")
	coda_par()
	
	par('clear')
	coda_par()
	
	if input['Lucifermode']=='Imaging':
		Flag1="1"
		Flag2="0"
	else:
		Flag1="0"
		Flag2="1"
	
	par('five')
	coda_par()
	
	par('imaging')
	if Debug != 2:
		radio('Lucifermode', 'Imaging', Output['code_path']+'#MIDDLE', Flag1)
	else:
		radio('Lucifermode', 'Imaging', Output['code_path']+'#MIDDLE', "1")
	print 'Imaging mode'
	coda_par()
	
	par('spectroscopic')
	if Debug != 2:
		radio('Lucifermode', 'Spectroscopy', Output['code_path']+'#MIDDLE', Flag2)
	else:
		radio('Lucifermode', 'Spectroscopy', Output['code_path']+'#MIDDLE', "3")
	print 'Spectroscopic mode'
	coda_par()
	
	par('clear')
	coda_par()
	
	par('five')
	coda_par()

	par('filter')
	link(Output['help_web']+'node17.html', "Filter:")
	Temp_name=[]
	Temp_internal=[]
	for i in range(0,len(Filter_list)):
		if Filter_list[i][1] == input['Detector']:# or Filter_list[i][1] == "0":
			Temp_name.append(Filter_list[i][0])
			Temp_internal.append(Filter_list[i][2])
	if Flag == 1:
		for i in range(0,len(Grating_list)):
			if Grating_list[i][0] == input['Central_wavelength'] and Grating_list[i][1] == input['Detector']:
				break
		input['Filter_choice'] = Grating_list[i][2]
	if input['Filter_choice'] not in Temp_internal:
		Raw = input['Filter_choice'].split("_")
		for i in Temp_internal:
			if i[0:len(Raw[0])+1] == Raw[0]+"_":
				input['Filter_choice'] = i
	selection_list_internal('Filter_choice', Temp_name, input['Filter_choice'], '1.50in', '1.6em', '100%', '1', Temp_internal)
	coda_par()
	
	par('camera')
	link(Output['help_web']+'node18.html', "Camera:")
	if input['Telescopemode']=='Diffraction' and input['Lucifermode']=='Imaging':
		del Camera_list[0:Camera_list.index("N30")]
		if len(Camera_list) != 1:
			del Camera_list[1:len(Camera_list)]
		input['Camera_choice']="N30"
	if input['Telescopemode']=='Seeing':
		if input['Camera_choice']=="N30":
			input['Camera_choice']="N1.8"
	selection_list('Camera_choice', Camera_list, input['Camera_choice'], '0.81in', '1.6em', '100%', '1')
	coda_par()
	
	par('clear')
	coda_par()
	
	par('twenty')
	coda_par()
	
	par('slit')
	link(Output['help_web']+'node27.html', "Slit width:")
	Temp_name=[]
	for i in range(0,len(Slit_list)):
		if Slit_list[i][2] == input['Detector'] or Slit_list[i][1] == "0":
			Temp_name.append(Slit_list[i][0])
	selection_list('Slit_width', Temp_name, input['Slit_width'], '0.61in', '1.6em', '100%', Flag2)
	coda_par()
	
	par('central_wavelength')
	print 'Central wavelength of the'
	link(Output['help_web']+'node20.html', "grating")
	print 'in &micro;m / Number of lines per millimeter:'
	Temp_name=[]
	for i in range(0,len(Grating_list)):
		if Grating_list[i][1] == input['Detector'] or Grating_list[i][1] == "0":
			Temp_name.append(Grating_list[i][0])
	selection_list_new('Central_wavelength', Temp_name, input['Central_wavelength'], '8em', '1.6em', '100%', Flag2, Output['code_path']+'#MIDDLE')
	coda_par()
	
	par('clear')
	field_hidden('Hidden_actual',input['Central_wavelength'])
	try:
		if input['Lucifermode'] == "Spectroscopy":
			field_hidden('Hidden_old',input['Central_wavelength'])
		else:
			field_hidden('Hidden_old',"empty")
	except:
		pass
	coda_par()
	
	hline("80%","CENTER","2")
	
	headline("Atmospheric Conditions",'2')
	
	par('five')
	coda_par()
	
	par('water_vapor')
	link(Output['help_web']+'node21.html', "Water vapor:")
	selection_list('Water_vapor', Water_list, input['Water_vapor'], '0.61in', '1.6em', '100%', '1')
	print 'mm'
	coda_par()
	
	par('airmass')
	link(Output['help_web']+'node22.html', "Airmass:")
	selection_list('Airmass', Airmass_list, input['Airmass'], '0.61in', '1.6em', '100%', '1')
	coda_par()
	
	par('sky_seeing')
	print 'Seeing:'
	input_field('Seeing', input['Seeing'], '0.54in', '1.6em', '100%', '1')
	print 'arcsec'
	coda_par()
	
	par('clear')
	coda_par()

	if input['Background']=="User_sky":
		Flag1="1"
		Flag2="0"
		Flag3="0"
	elif input['Background']=="User_file":
		Flag1="0"
		Flag2="1"
		Flag3="0"
	elif input['Background']=="User_theoretical":
		Flag1="0"
		Flag2="0"
		Flag3="1"
	
	par('user_sky')
	if Debug != 2:
		radio('Background', 'User_sky', Output['code_path']+'#END', Flag1)
	else:
		radio('Background', 'User_sky', Output['code_path']+'?Calibration=1', Flag1)
	link(Output['help_web']+'node24.html', "Sky brightness")
	print ' for the zenith (Vega):'
	input_field('Sky_brightness', input['Sky_brightness'], '0.54in', '1.6em', '100%', str(int(Flag1)))
	print 'mag/sq.arcsec'
	newline()
	print 'uniform flux density distribution, no sky lines'
	coda_par()
	
	par('user_file')
	if Debug != 2:
		radio('Background', 'User_file', Output['code_path']+'#END', Flag2)
	else:
		radio('Background', 'User_file', Output['code_path']+'?Calibration=1', Flag2)
	link(Output['help_web']+'node25.html', "Background file")
	print ' with 1.6 mm water vapor and selected airmass'
	coda_par()
	
	par('user_theoretical')
	if Debug != 2:
		radio('Background', 'User_theoretical', Output['code_path']+'#END', Flag3)
	else:
		radio('Background', 'User_theoretical', Output['code_path']+'?Calibration=1', Flag3)
	link(Output['help_web']+'node26.html', "Theoretical background spectrum")
	coda_par()
	
	par('clear')
	coda_par()
	
	hline("80%","CENTER","2")
	
	headline("Parameters of Exposure",'2')
	if input['Lucifermode']=="Imaging":
		if Temp.has_key('Exp_ima'):
			if Temp['Exp_ima'].value == "SNR":
				Flag1="1"
				Flag2="0"
				Flag3="0"
			else:
				Flag1="0"
				Flag2="1"
				Flag3="0"
		else:
			Flag1="1"
			Flag2="0"
			Flag3="0"
	elif input['Lucifermode']=="Spectroscopy":
		Flag1="3"
		Flag2="1"
		Flag3="1"	
	
	par('five')
	coda_par()
	
	par('snr_imaging')
	if Debug != 2:
		radio('Exp_ima', 'SNR', Output['code_path']+'#END', Flag1)
	else:
		radio('Exp_ima', 'SNR', Output['code_path']+'?Calibration=1', '3')
	link(Output['help_web']+'node4.html#SNR', "SNR")
	if Debug != 2:
		input_field('SN', input['SN'], '0.54in', '1.6em', '100%', Flag1)
	else:
		input_field('SN', input['SN'], '0.54in', '1.6em', '100%', '3')
	coda_par()
	
	par('t_imaging')
	if Debug != 2:
		radio('Exp_ima', 'total', Output['code_path']+'#END', Flag2)
	else:
		radio('Exp_ima', 'total', Output['code_path']+'?Calibration=1', '1')
	link(Output['help_web']+'node4.html#SNR', "Total exposure time")
	if Debug != 2:
		input_field('Exposuretime', input['Exposuretime'], '0.54in', '1.6em', '100%', Flag2)
	else:
		input_field('Exposuretime', input['Exposuretime'], '0.54in', '1.6em', '100%', '1')
	print 'sec'
	coda_par()
	
	par('clear')
	coda_par()
	
	par('dit')
	link(Output['help_web']+'node4.html#SNR', "Detector Integration Time (DIT):")
	input_field('DIT', input['DIT'], '0.54in', '1.6em', '100%', '1')
	print 'sec (the minimum DIT is %4.2f sec)' % Hawaii_conditions['Min_DIT_%d' % int(input['Detector'])]
	coda_par()
	
	hline("80%","CENTER","2")
	par('center')
	submit_button("Button", "SUBMIT", "Submit", "0.7in", "1.6em")
	coda_par()
	
	coda_form()
	
	par("")
	target('END','0')
	coda_par()
	
	coda_body(Output['help_web']+"index.html","Help")
	

def user_input(Web, Formdata,Output):
	Error=0
	if Web < 2:
		Temp=''	
		Mode=1	
		if Formdata['Lucifermode'].value=='Spectroscopy':	
			Mode=Mode+1
		if Formdata['Telescopemode'].value=='Diffraction':	
			Mode=Mode+2
		Choice.append(Formdata['Object_choice'].value)	
		if Formdata['Choice_spectra'].value == "Template":	
			Choice.append('t')
			Choice.append(Formdata['Spectrum'].value)
			Temp=(Formdata['Redshift'].value)
			Temp1=(Formdata['Spectrum'].value)
			if Temp1.find('galaxy') == -1:
				Choice.append(Temp1)
			else:
				try:
					float(Temp)
					if Temp[0]<>'-':
						Choice.append(Temp)
					if Temp[0]=='-':
						Error = 1
						Choice.append('<font color="red">%s</font>' % Temp)
				except:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
		elif Formdata ['Choice_spectra'].value == "Blackbody":	
			Choice.append('b')
			try:
				Temp=float(Formdata['Blackbody_temperature'].value)
				if Temp>0:
					Choice.append(str(Temp))
				else:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Blackbody_temperature'].value)
				Error = 1
			Choice.append('0')
		elif Formdata ['Choice_spectra'].value == "Single line":	
			try:
				Temp=float(Formdata['Line_wavelength'].value)
				if Temp>0:
					Choice.append(str(Temp))
				else:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Line_wavelength'].value)
				Error = 1
			try:
				Temp=float(Formdata['Line_flux'].value)
				if Temp>0:
					Temp = "%e" % Temp
					Choice.append(str(Temp))
				else:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Line_flux'].value )
				Error=1
			try:
				Temp=float(Formdata['Line_width'].value)
				if Temp>0:
					Choice.append(str(Temp))
				else:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Line_width'].value)
				Error = 1
		if Formdata['Choice_spectra'].value == "Template" or Formdata ['Choice_spectra'].value == "Blackbody":	
			Choice.append(Formdata['Filter_mag'].value)
			try:
				Temp=float(Formdata['Object_brightness_choice'].value)
				Choice.append(Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Object_brightness_choice'].value)
				Error = 1
		else:	
			Choice.append('U')
			Choice.append(-27)
		Choice.append(Formdata['Detector'].value)	
		Choice.append(Formdata['Filter_choice'].value)	
		Choice.append(Formdata['Camera_choice'].value)	
		if Mode == 2 or Mode ==4:	
			Choice.append(float(Formdata['Slit_width'].value))
		else:	
			Choice.append('0')
		Water_vapor=int(float(Formdata['Water_vapor'].value)*100)	
		Airmass=int(float(Formdata['Airmass'].value)*100)	
		Temp="air_transmission/%d_%d.csv" % (Water_vapor, Airmass)	
		Choice.append(Temp)	
		if Formdata['Background'].value=="User_sky":	
			Choice.append("0")
			Choice.append(float(Formdata['Sky_brightness'].value))
		elif Formdata['Background'].value=="User_file":	
			Temp="oh_lines/160_%d.csv" % Airmass
			Choice.append(Temp)
			Choice.append(-27)
		elif Formdata['Background'].value=="User_theoretical":	
			Temp="oh_lines/rousselot.csv"
			Choice.append(Temp)
			Choice.append(-17)
		if Mode == 3 or Mode == 4:	
			Choice.append(float(Formdata['Strehl'].value))
		else:	
			Choice.append('-1')
		try:
			Temp=float(Formdata['Seeing'].value)
			if Temp>0:
				Choice.append(Temp)
			else:
				Error = 1
				Choice.append('<font color="red">%s</font>' % Temp)
		except:
			Choice.append('<font color="red">%s</font>' % Formdata['Seeing'].value)
			Error = 1
		if Mode == 2 or Mode ==4:	
			Data = Formdata['Central_wavelength'].value
			Row = string.split(Data)
			Temp="grating/%d_%d_%s.csv" % (float(Row[0])*1000, float(Row[2]),Formdata['Detector'].value)
			Choice.append(Temp)
			Choice.append(float(Row[0]))
			Choice.append(float(Row[2]))
		else:	
			Choice.append('0')
			Choice.append('0')
			Choice.append('0')
		try:
			Temp=float(Formdata['DIT'].value)
			if Temp>0:
				Choice.append(Temp)
			else:
				Error = 1
				Choice.append('<font color="red">%s</font>' % Temp)
		except:
			Choice.append('<font color="red">%s</font>' % Formdata['DIT'].value)
			Error = 1
		if Mode == 1 or Mode ==3:
			try:
				if Formdata['Exp_ima'].value == "SNR":
					Temp=float(Formdata['SN'].value)
					if Temp>0:
						Choice.append(Temp)
						Choice.append('0')
					else:
						Error = 1
						Choice.append('<font color="red">%s</font>' % Temp)
						Choice.append('0')
				if Formdata['Exp_ima'].value == "total":
					Temp=float(Formdata['Exposuretime'].value)
					if Temp>0 and Temp>=Choice[len(Choice)-1]:
						Choice.append('0')
						Choice.append(Temp)
					else:
						Error = 1
						Choice.append('0')
						Choice.append('<font color="red">%s</font>' % Temp)
					Mode=Mode+4
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['SN'].value)
				Choice.append(Temp)
				Error = 1
		else:	
			try:
				Temp=float(Formdata['Exposuretime'].value)
				if Temp>0 and Temp>=Choice[len(Choice)-1]:
					Choice.append('0')
					Choice.append(Temp)
				else:
					Error = 1
					Choice.append('0')
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('0')
				Choice.append('<font color="red">%s</font>' % Formdata['Exposuretime'].value)
				Error = 1			
		Choice.append(Mode)
		Choice.append(Error)
	else:
		File = Formdata
		Formdata = {}
		Batch = open(File,"r")
		Data = Batch.readline()
		while Data != "":
			Row=Data.split("|")
			Temp = map(string.strip,Row)
			Row = Temp
			#print Row
			Formdata[Row[0]] = Row[1]
			Data = Batch.readline()
		Batch.close()
		Temp=''
		Mode=1	
		if Formdata['Lucifermode']=='Spectroscopy':	
			Mode=Mode+1
		if Formdata['Telescopemode']=='Diffraction':	
			Mode=Mode+2
		Choice.append(Formdata['Object_choice'])	
		if Formdata['Choice_spectra'] == "Template":	
			Choice.append('t')
			Choice.append(Formdata['Spectrum'])
			Temp=(Formdata['Redshift'])
			Temp1=(Formdata['Spectrum'])
			if Temp1.find('galaxy') == -1:
				Choice.append(Temp1)
			else:
				try:
					if Temp[0]<>'-':
						Choice.append(Temp)
					if Temp[0]=='-':
						Error = 1
						Choice.append('<font color="red">%s</font>' % Temp)
				except:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
		elif Formdata ['Choice_spectra'] == "Blackbody":
			Choice.append('b')
			try:
				Temp=string.atof(Formdata['Blackbody_temperature'])
				if Temp>0:
					Choice.append(str(Temp))
				else:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Blackbody_temperature'])
				Error = 1
			Choice.append('0')
		elif Formdata ['Choice_spectra'] == "Single line":	
			try:
				Temp=string.atof(Formdata['Line_wavelength'])
				if Temp>0:
					Choice.append(str(Temp))
				else:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Line_wavelength'])
				Error = 1
			try:
				Temp=string.atof(Formdata['Line_flux'])
				if Temp>0:
					Temp = "%e" % Temp
					Choice.append(str(Temp))
				else:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Line_flux'] )
				Error=1
			try:
				Temp=string.atof(Formdata['Line_width'])
				if Temp>0:
					Choice.append(str(Temp))
				else:
					Error = 1
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Line_width'])
				Error = 1
		else:
			Error = 1
			Choice.append('The Choice_spectra keyword in batch.ini is not valid!')
			Choice.append('-1')
			Choice.append('-1')
		if Formdata['Choice_spectra'] == "Template" or Formdata ['Choice_spectra'] == "Blackbody":	
			Choice.append(Formdata['Filter_mag'])
			try:
				Temp=string.atof(Formdata['Object_brightness_choice'])
				Choice.append(Temp)
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['Object_brightness_choice'])
				Error = 1
		else:	
			Choice.append('U')
			Choice.append(-27)
		Choice.append(Formdata['Detector'])	
		Choice.append(Formdata['Filter_choice'])	
		Choice.append(Formdata['Camera_choice'])	
		if Mode == 2 or Mode ==4:	
			Choice.append(string.atof(Formdata['Slit_width']))
		else:	
			Choice.append('0')
		Water_vapor=int(string.atof(Formdata['Water_vapor'])*100)	
		Airmass=int(string.atof(Formdata['Airmass'])*100)	
		Temp="air_transmission/%d_%d.csv" % (Water_vapor, Airmass)	
		Choice.append(Temp)	
		if Formdata['Background']=="User_sky":	
			Choice.append("0")
			Choice.append(string.atof(Formdata['Sky_brightness']))
		elif Formdata['Background']=="User_file":	
			Temp="oh_lines/160_%d.csv" % Airmass
			Choice.append(Temp)
			Choice.append(-27)
		elif Formdata['Background']=="User_theoretical":	
			Temp="oh_lines/rousselot.csv"
			Choice.append(Temp)
			Choice.append(-17)
		if Mode == 3 or Mode == 4:	
			Choice.append(string.atof(Formdata['Strehl']))
		else:	
			Choice.append('-1')
		try:
			Temp=string.atof(Formdata['Seeing'])
			if Temp>0:
				Choice.append(Temp)
			else:
				Error = 1
				Choice.append('<font color="red">%s</font>' % Temp)
		except:
			Choice.append('<font color="red">%s</font>' % Formdata['Seeing'])
			Error = 1
		if Mode == 2 or Mode ==4:	
			Data = Formdata['Central_wavelength']
			Row = string.split(Data)
			Temp="grating/%d_%d_%s.csv" % (string.atof(Row[0])*1000, string.atof(Row[2]),Formdata['Detector'])
			Choice.append(Temp)
			Choice.append(string.atof(Row[0]))
			Choice.append(string.atof(Row[2]))
		else:	
			Choice.append('0')
			Choice.append('0')
			Choice.append('0')
		try:
			Temp=string.atof(Formdata['DIT'])
			if Temp>0:
				Choice.append(Temp)
			else:
				Error = 1
				Choice.append('<font color="red">%s</font>' % Temp)
		except:
			Choice.append('<font color="red">%s</font>' % Formdata['DIT'])
			Error = 1
		if Mode == 1 or Mode ==3:
			try:
				if Formdata['Exp_ima'] == "SNR":
					Temp=string.atof(Formdata['SN'])
					if Temp>0:
						Choice.append(Temp)
						Choice.append('0')
					else:
						Error = 1
						Choice.append('<font color="red">%s</font>' % Temp)
						Choice.append('0')
				if Formdata['Exp_ima'] == "total":
					Temp=string.atof(Formdata['Exposuretime'])
					if Temp>0 and Temp>=Choice[len(Choice)-1]:
						Choice.append('0')
						Choice.append(Temp)
					else:
						Error = 1
						Choice.append('0')
						Choice.append('<font color="red">%s</font>' % Temp)
					Mode=Mode+4
			except:
				Choice.append('<font color="red">%s</font>' % Formdata['SN'])
				Choice.append(Temp)
				Error = 1
		else:	
			try:
				Temp=string.atof(Formdata['Exposuretime'])
				if Temp>0:
					Choice.append('0')
					Choice.append(Temp)
				else:
					Error = 1
					Choice.append('0')
					Choice.append('<font color="red">%s</font>' % Temp)
			except:
				Choice.append('0')
				Choice.append('<font color="red">%s</font>' % Formdata['Exposuretime'])
				Error = 1			
		Choice.append(Mode)
		Choice.append(Error)
	return(Choice)	
