Skip to content

Instantly share code, notes, and snippets.

@shivkiyer
Created May 22, 2013 23:55
# Wait for the user to enter parameters before
# reading the *_desc.csv file.
cont_ans="n"
while cont_ans.lower()!="y":
print "Enter control parameters in the following files --> "
for c1 in range(len(control_descs)):
print "%s " %control_descs[c1]
cont_ans=raw_input("When ready press y and enter to continue -> ")
# Read the parameters from the descriptor spreadsheet.
control_desc_handles=[]
for c1 in range(len(control_files)):
control_desc_handles.append(open(control_descs[c1],"r"))
params_from_file=reading_params(control_desc_handles[c1])
for c2 in range(len(params_from_file)):
# Scrubbing blank spaces from the beginning
# and the end of the first cell.
while params_from_file[c2][0][0]==" ":
params_from_file[c2][0]=params_from_file[c2][0][1:]
while params_from_file[c2][0][-1]==" ":
params_from_file[c2][0]=params_from_file[c2][0][:-1]
if params_from_file[c2][0].lower()=="input":
# If it is an input, it will be a meter.
meter_type=params_from_file[c2][1].split("=")[1]
while meter_type[0]==" ":
meter_type=meter_type[1:]
while meter_type[-1]==" ":
meter_type=meter_type[:-1]
# Look for the meter in components_found
# and get the cell position from the meter tag.
# The cell position which is unique will be the
# dictionary key for control_file_inputs.
for c3 in range(len(components_found[meter_type.split("_")[0].lower()])):
if components_found[meter_type.split("_")[0].lower()][c3][1]==meter_type.split("_")[1]:
meter_type_ref=meter_type.split("_")[0].lower()
control_file_inputs[c1][components_found[meter_type_ref][c3][0]]=[components_found[meter_type_ref][c3][1]]
var_name=params_from_file[c2][2].split("=")[1]
while var_name[0]==" ":
var_name=var_name[1:]
while var_name[-1]==" ":
var_name=var_name[:-1]
control_file_inputs[c1][components_found[meter_type_ref][c3][0]].append(var_name)
if params_from_file[c2][0].lower()=="output":
# If it is an output, it is a controlled element
element_type=params_from_file[c2][1].split("=")[1]
while element_type[0]==" ":
element_type=element_type[1:]
while element_type[-1]==" ":
element_type=element_type[:-1]
# Look for the controlled element in components_found
# and get the cell position from the device tag.
# The cell position will be the unique dictionary key
for c3 in range(len(components_found[element_type.split("_")[0].lower()])):
if components_found[element_type.split("_")[0].lower()][c3][1]==element_type.split("_")[1]:
element_type_ref=element_type.split("_")[0].lower()
# Since a controlled element can have more than one control input
# Check if it has been found before.
if not components_found[element_type_ref][c3][0] in control_file_outputs[c1].keys():
control_file_outputs[c1][components_found[element_type_ref][c3][0]]=[components_found[element_type_ref][c3][1]]
control_tag_name=params_from_file[c2][2].split("=")[1]
control_var_name=params_from_file[c2][3].split("=")[1]
while control_tag_name[0]==" ":
control_tag_name=control_tag_name[1:]
while control_tag_name[-1]==" ":
control_tag_name=control_tag_name[:-1]
while control_var_name[0]==" ":
control_var_name=control_var_name[1:]
while control_var_name[-1]==" ":
control_var_name=control_var_name[:-1]
control_file_outputs[c1][components_found[element_type_ref][c3][0]].append([control_tag_name, control_var_name, 0.0])
if params_from_file[c2][0].lower()=="staticvariable":
# If it is a staticvariable, the dictionary key
# will be the variable name.
staticvar_type=params_from_file[c2][1].split("=")[1]
while staticvar_type[0]==" ":
staticvar_type=staticvar_type[1:]
while staticvar_type[-1]==" ":
staticvar_type=staticvar_type[:-1]
staticvar_val=params_from_file[c2][2].split("=")[1]
while staticvar_val[0]==" ":
staticvar_val=staticvar_val[1:]
while staticvar_val[-1]==" ":
staticvar_val=staticvar_val[:-1]
control_file_staticvars[c1][staticvar_type]=float(staticvar_val)
if params_from_file[c2][0].lower()=="timeevent":
# If it is a timeevent, the dictionary key
# will be the variable name.
timeevent_type=params_from_file[c2][1].split("=")[1]
while timeevent_type[0]==" ":
timeevent_type=timeevent_type[1:]
while timeevent_type[-1]==" ":
timeevent_type=timeevent_type[:-1]
timeevent_val=params_from_file[c2][2].split("=")[1]
while timeevent_val[0]==" ":
timeevent_val=timeevent_val[1:]
while timeevent_val[-1]==" ":
timeevent_val=timeevent_val[:-1]
control_file_timeevents[c1][timeevent_type]=float(timeevent_val)
control_desc_handles[c1].close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment