wollte hier mein skript vorstellen, wo glaube ich noch viel am Style zu tun ist.
Allerdings bräuchte ich dazu eure Hilfe. Die Beschreibung steht
im Code.
Grüße Markus
Code: Alles auswählen
#!/usr/bin/env python
# encoding: utf8
#
# Autor: M a r k u s --> F e l d m a n n
#
# Lizenz: GPL
#
# Discription: Convert all *.eps files to *.pdf files,
# also create tables which may be inserted into your
# tex document. At least you need one file containing
# the extension *.dat which includes tables of numbers
# according the gnuplot format.
# You also may wish to change the gnuplot commands
# below.
# This script should be exist in the same directory
# where is your *.dat file.
#
# You also may convert only one *.dat file by switch
# the variable <convert_all_dat_files> to False.
# (See below.)
#
#
import os
import re
import subprocess
def create_eps(name_dat_file):
name_plot_file = "."+name_dat_file.rstrip(".dat")+".plot"
name_eps_file = name_dat_file.rstrip(".dat")+".eps"
gnuplot_file = file(name_plot_file, 'w')
gnuplot_commands ="""
reset
set encoding utf8
set terminal postscript enhanced colo
set output "%s"
set xlabel "Signalamplitude/Einheiten -------->"
set ylabel "U_{pp}/V des Signals ------->"
set grid
plot "%s" index 0 using ($1):(($3)/(2*sqrt(2))) title "A)mit 0dB" with lp ,\\
"%s" index 1 using ($1):(($3)/(2*sqrt(2))) title "B)mit -6dB" with lp""" \
%(name_eps_file, name_dat_file, name_dat_file)
gnuplot_file.write(gnuplot_commands)
gnuplot_file.close()
return_code = subprocess.call("gnuplot " +name_plot_file \
+"; rm " +name_plot_file, \
shell=True)
if return_code == 0:
conv_eps_to_pdf(name_eps_file)
else:
print "Errorcode: ",return_code
def conv_eps_to_pdf(name_eps_file):
name_pdf_file = name_eps_file.rstrip(".eps")+".pdf"
subprocess.call("epstopdf " +name_eps_file \
+" --outfile=" +name_pdf_file, \
shell=True)
def convert_table(name_dat_file):
laufende_nummer = 1
letzte_zeile = ""
name_tex_file = name_dat_file.rstrip(".dat")+str(laufende_nummer)+".tex"
dat_file = file(name_dat_file, 'r')
tex_file = file(name_tex_file, 'w')
re_wert = re.compile('[\w\.-]+')
re_leerzeile = re.compile('^\s*\Z')
re_kommentar = re.compile('#')
for j in dat_file.readlines():
if not re_leerzeile.match(j) and letzte_zeile == "Leerzeile":
laufende_nummer += 1
name_tex_file = name_dat_file.rstrip(".dat")+str(laufende_nummer)+".tex"
tex_file = file(name_tex_file, 'w')
if not re_leerzeile.match(j):
if not re_kommentar.search(j) and re_wert.search(j):
str_zeile = ""
for k in re_wert.findall(j):
str_zeile += k+" & "
tex_file.write(str_zeile.rstrip(" & ")+"\\\ \hline\n")
letzte_zeile = "ZeileMitWerten"
else:
if letzte_zeile == "ZeileMitWerten":
tex_file.close()
letzte_zeile = "Leerzeile"
else:
letzte_zeile = "Leerzeile"
tex_file.close()
dat_file.close()
if __name__ == '__main__':
os.chdir(os.path.dirname(os.path.realpath( __file__ )))
# Here you can switch to convert all
# *.dat files in the directory of your script
# or to convert only the *.dat file which name
# belongs to the name of this script.
# For example:
# table2-1.py --> table2-1.dat
#
convert_all_dat_files = True
if convert_all_dat_files is True:
for i in os.listdir('.'):
re_dat_files = re.compile('\w*\.dat\Z')
if re_dat_files.match(i):
convert_table(i)
create_eps(i)
else:
re_name_this_script = re.compile('/[\w-]+\.py\Z')
name_this_script = re_name_this_script.findall(__file__)
name_dat_file = name_this_script[0].rstrip(".py").lstrip("/")+".dat"
convert_table(name_dat_file)
create_eps(name_dat_file)