Skip to content

Commit

Permalink
A way to build a multi-calc table.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreww committed Mar 15, 2016
1 parent 18c85cb commit 68d0b46
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
11 changes: 7 additions & 4 deletions CijUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ def latexCij(Cij, eCij, outputfile, nt=False):
for j in range(i,6):
if ((Cij[i,j] != 0.0) and (eCij[i,j] != 0.0)):
if (nt):
f.write("c$_{{{0}{1}}}$ & {2:5.1f}$\pm${3:3.1f} \n".
format(i+1,j+1,Cij[i,j],eCij[i,j]))
f.write("& {0:5.1f}$\pm${1:3.1f} \n".
format(Cij[i,j],eCij[i,j]))
else:
f.write("c$_{{{0}{1}}}$ & {2:5.1f}$\pm${3:3.1f} \\\\ \n".
format(i+1,j+1,Cij[i,j],eCij[i,j]))
f.write(" & \\\\ \n")
if (nt):
f.write(" & \n")
else:
f.write(" & \\\\ \n")

(vB, rB, vG, rG, hB, hG, evB, erB, evG, erG, ehB, ehG) = polyCij(Cij, eCij)
(Ua, eUa) = uAniso(Cij, eCij)
Expand All @@ -42,7 +45,7 @@ def latexCij(Cij, eCij, outputfile, nt=False):
f.write("& {0:5.1f}$\pm${1:3.1f} \n".format(vG, evG))
f.write("& {0:5.1f}$\pm${1:3.1f} \n".format(rG, erG))
f.write("& {0:5.1f}$\pm${1:3.1f} \n".format(hG, ehG))
f.write("& \\\\ \n")
f.write("& \n")
f.write("& {0:5.2f}$\pm${1:4.2f} \n".format(Ua, eUa))
else:
f.write("B$^v$ & {0:5.1f}$\pm${1:3.1f} \\\\ \n".format(vB, evB))
Expand Down
36 changes: 36 additions & 0 deletions concat_cij_latex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
# encoding: utf-8
"""
concat_cij_latex.py
Widen a LaTeX table for an additional Cij calculation
Copyright (c) 2016 Andrew Walker. All rights reserved.
"""

import re

end_row_RE = re.compile(r'\\\\\s*$')
def latex_table_cocat(left_file, right_file, out_file=None):

# We work with the file in memory, so we can overwrite
with open(left_file, 'r') as f:
left_lines = f.read().splitlines()

with open(right_file, 'r') as f:
right_lines = f.read().splitlines()

if out_file is None:
out_file = left_file

with open(out_file, 'w') as f:
for left, right in zip(left_lines, right_lines):
new_line = end_row_RE.sub(right, left)
new_line = new_line + r' \\' + ' \n'
f.write(new_line)

if __name__ == "__main__":
import sys
latex_table_cocat(sys.argv[1], sys.argv[2])

0 comments on commit 68d0b46

Please sign in to comment.