OpenCores
URL https://opencores.org/ocsvn/tcp_socket/tcp_socket/trunk

Subversion Repositories tcp_socket

[/] [tcp_socket/] [trunk/] [chips2/] [examples/] [example_4.py] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 jondawson
#!/usr/bin/env python
2
 
3
import subprocess
4
import atexit
5
from math import pi
6
 
7
try:
8
    from matplotlib import pyplot
9
    from mpl_toolkits.mplot3d import Axes3D
10
except ImportError:
11
    print "You need matplotlib to run this script!"
12
    exit(0)
13
 
14
children = []
15
def cleanup():
16
    for child in children:
17
        print "Terminating child process"
18
        child.terminate()
19
atexit.register(cleanup)
20
 
21
def run_c(file_name):
22
    process = subprocess.Popen(["../c2verilog", "iverilog", "run", str(file_name)])
23
    children.append(process)
24
    process.wait()
25
    children.remove(process)
26
 
27
def test():
28
    run_c("rand.c")
29
    x = [float(i) for i in open("x")]
30
    y = [float(i) for i in open("y")]
31
    z = [float(i) for i in open("z")]
32
 
33
    fig = pyplot.figure()
34
    ax = fig.add_subplot(111, projection="3d")
35
    ax.scatter(x, y, z, c='b', marker='^')
36
    pyplot.title("Random Plot")
37
    pyplot.savefig("../docs/source/examples/images/example_4.png")
38
    pyplot.show()
39
 
40
def indent(lines):
41
    return "\n    ".join(lines.splitlines())
42
 
43
def generate_docs():
44
 
45
    documentation = """
46
 
47
Pseudo Random Number Generator
48
------------------------------
49
 
50
This example uses a
51
`Linear Congruential Generator (LCG) <http://en.wikipedia.org/wiki/Linear_congruential_generator>`_ to generate Pseudo Random Numbers.
52
 
53
.. code-block:: c
54
 
55
    %s
56
 
57
.. image:: images/example_4.png
58
 
59
"""%indent(open("rand.c").read())
60
 
61
    document = open("../docs/source/examples/example_4.rst", "w").write(documentation)
62
 
63
test()
64
generate_docs()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.