Skip to content

Commit

Permalink
Added code to save as fixed-with column file
Browse files Browse the repository at this point in the history
  • Loading branch information
jkarns275 committed Aug 16, 2019
1 parent ba02cd7 commit a6de618
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/widgets/graphing/graph_display_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,42 @@ def to_x_y_arrays(series):
file.write(json.dumps(d, indent=4))
except Exception as e:
print("Encountered error {} while saving to file".format(str(e)))


def __on_save_as_fixed_column_triggered(self, _checked: bool):
if len(self.plots) == 0:
return
import re
filename = self.get_file_save_name(".data", "Fixed-width Column Data File")
header_filename = re.sub("\\.data$", ".header", filename)
try:
point_vectors = []
order = list(self.plots.keys())
lens = list(map(lambda plot_name: len(self.plots[plot_name][0]), order))
max_len = max(lens)
with open(filename, "w") as file:
for point_index in range(0, max_len):
for i, name in enumerate(order):
if point_index >= lens[i]:
file.write('{:10s}{:10s}'.format('', ''))
else:
file.write('{:10E}{:10E}'.format(self.plots[name][0][point_index],
self.plots[name][1][point_index]))
file.write('\n')
with open(header_filename, "w") as file:
d = {}
d['order'] = []
fmts = {}
for p in order:
xn = "x_{}".format(p)
yn = "y_{}".format(p)
d['order'].append(xn)
d['order'].append(yn)
fmts[xn] = "%10.E"
fmts[yn] = "%10.E"
d['formats'] = fmts
file.write(json.dumps(d))
except Exception as e:
print(str(e))
def __on_save_as_csv_triggered(self, _checked: bool):
if len(self.plots) == 0:
return
Expand Down Expand Up @@ -222,4 +257,4 @@ def __on_save_as_csv_triggered(self, _checked: bool):
file.write('{}\n'.format(s))

except Exception as e:
print("Encountered error {} while saving to file".format(str(e)))
print("Encountered error {} while saving to file".format(str(e)))

0 comments on commit a6de618

Please sign in to comment.