|
@@ -0,0 +1,79 @@
|
|
1
|
+#!/usr/bin/env python3
|
|
2
|
+# -*- coding: UTF-8 -*-
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+import math
|
|
6
|
+import jinja2
|
|
7
|
+import optparse
|
|
8
|
+import os
|
|
9
|
+import shutil
|
|
10
|
+import time
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+example_gnuplot = """
|
|
14
|
+set terminal wxt
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+#set xdata time # tells gnuplot the x axis is time data
|
|
18
|
+#set timefmt '%s' # specify our time string format
|
|
19
|
+#set format x '%H' # otherwise it will show only MM:SS
|
|
20
|
+
|
|
21
|
+set title "GnuPlot Example"
|
|
22
|
+set xlabel "X"
|
|
23
|
+set ylabel "Y"
|
|
24
|
+
|
|
25
|
+set key autotitle columnhead
|
|
26
|
+set datafile separator ','
|
|
27
|
+
|
|
28
|
+plot 'example.csv' using 1:2 with lines title "title 1", \
|
|
29
|
+ '' using 1:3 with lines title "title 2", \
|
|
30
|
+ '' using 1:2 with lines, \
|
|
31
|
+ '' using 1:3 with lines
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+pause -1 "Hit any key to continue"
|
|
35
|
+"""
|
|
36
|
+
|
|
37
|
+example_csv = "x, sin(x)/x, sin(x)\n"
|
|
38
|
+for i in range (-500, 500):
|
|
39
|
+ x = 3* i * math.pi / 500
|
|
40
|
+ f2_x = math.sin(x)
|
|
41
|
+ if x == 0:
|
|
42
|
+ f1_x = 1
|
|
43
|
+ else:
|
|
44
|
+ f1_x = f2_x / x
|
|
45
|
+ example_csv += "%f, %f, %f\n" % (x, f1_x, f2_x)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+def mkdir(path):
|
|
49
|
+ """.. warning:: Needs to be documented
|
|
50
|
+ """
|
|
51
|
+ path=os.path.abspath(path)
|
|
52
|
+ if not os.path.exists(os.path.dirname(path)):
|
|
53
|
+ mkdir(os.path.dirname(path))
|
|
54
|
+ if not os.path.exists(path):
|
|
55
|
+ os.mkdir(path)
|
|
56
|
+ return os.path.isdir(path)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+if __name__ == "__main__":
|
|
60
|
+ parser = optparse.OptionParser("usage: %%prog [options] folder_for_document")
|
|
61
|
+ parser.add_option("-f", "--force", dest="force", action="store_true", default=False)
|
|
62
|
+ (options, args) = parser.parse_args()
|
|
63
|
+
|
|
64
|
+ if len(args) != 1:
|
|
65
|
+ parser.print_help()
|
|
66
|
+ else:
|
|
67
|
+ target_path = os.path.join(os.path.abspath('.'), args[0])
|
|
68
|
+
|
|
69
|
+ #
|
|
70
|
+ # Main Actions
|
|
71
|
+ #
|
|
72
|
+ if not os.path.exists(target_path) or options.force:
|
|
73
|
+ mkdir(target_path)
|
|
74
|
+ with open(os.path.join(target_path, 'example.gnuplot'), 'w+') as fh:
|
|
75
|
+ fh.write(example_gnuplot)
|
|
76
|
+ with open(os.path.join(target_path, 'example.csv'), 'w+') as fh:
|
|
77
|
+ fh.write(example_csv)
|
|
78
|
+ else:
|
|
79
|
+ print("Folder exists. Use option -f to force creation")
|