def read_plot(filename): """ reads a plot file returns an ordered bunch with the headers for keys and a list of each header's floats for values. """ extension = os.path.splitext(filename)[1] # open history file plot_file = open(filename) # title? line = plot_file.readline() if line.startswith('TITLE'): title = line.split('=')[1].strip() # not used right now line = plot_file.readline() # process header if '=' in line: line = line.split("=")[1].strip() line = line.split(",") Variables = [x.strip('" ') for x in line] n_Vars = len(Variables) # initialize plot data dictionary plot_data = ordered_bunch.fromkeys(Variables) # must default each value to avoid pointer problems for key in plot_data.keys(): plot_data[key] = [] # zone list zones = [] # read all data rows while 1: # read line line = plot_file.readline() if not line: break #zone? if line.startswith('ZONE'): zone = line.split('=')[1].strip('" ') zones.append(zone) continue # split line line_data = line.strip().split(',') line_data = [float(x.strip()) for x in line_data] # store to dictionary for i_Var in range(n_Vars): this_variable = Variables[i_Var] plot_data[this_variable] = plot_data[this_variable] + [ line_data[i_Var] ] #: for each line # check for number of zones if len(zones) > 1: raise IOError, 'multiple zones not supported' # done plot_file.close() return plot_data
def read_plot( filename ): """ reads a plot file returns an ordered bunch with the headers for keys and a list of each header's floats for values. """ extension = os.path.splitext( filename )[1] # open history file plot_file = open(filename) # title? line = plot_file.readline() if line.startswith('TITLE'): title = line.split('=')[1] .strip() # not used right now line = plot_file.readline() # process header if '=' in line: line = line.split("=")[1].strip() line = line.split(",") Variables = [ x.strip('" ') for x in line ] n_Vars = len(Variables) # initialize plot data dictionary plot_data = ordered_bunch.fromkeys(Variables) # must default each value to avoid pointer problems for key in plot_data.keys(): plot_data[key] = [] # zone list zones = [] # read all data rows while 1: # read line line = plot_file.readline() if not line: break #zone? if line.startswith('ZONE'): zone = line.split('=')[1].strip('" ') zones.append(zone) continue # split line line_data = line.strip().split(',') line_data = [ float(x.strip()) for x in line_data ] # store to dictionary for i_Var in range(n_Vars): this_variable = Variables[i_Var] plot_data[this_variable] = plot_data[this_variable] + [ line_data[i_Var] ] #: for each line # check for number of zones if len(zones) > 1: raise IOError , 'multiple zones not supported' # done plot_file.close() return plot_data