-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·121 lines (98 loc) · 3.36 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# Script to run the demo designs in this repository.
#
# USAGE:
#
# ./run PATH_TO_POIETIC_FRAME
#
#
# REQUIREMENTS
#
# Requires the following executables to be discoverable through your PATH:
#
# poietic - the poietic command-line tool from the PoieticFlows package
#
# Other optional tools that will be used if installed:
#
# gnuplot - tool to create charts
# dot - graphviz command
#
# Environment variables used (optional):
#
# OUTPUT - path to the output directory, default: ./out
#
#
# STUDY:
#
# Search for capitalised word MAIN in this file to see how the poietic
# command is being used. The rest is just convenience.
#
set -e
# -----------------------------------------------------------------------------------
# Some internal config, you might skip this to the next section ...
# Path to the output directory, default ./out
OUTPUT_DIR="${OUTPUT:-./out}"
DOT_FILE=$OUTPUT_DIR/diagram.dot
if ! command -v poietic &> /dev/null
then
echo "ERROR: Command 'poietic' not found." 1>&2
echo "HINT: Follow the installation instructions in the PoieticTool package" 1>&2
echo "HINT: Get the tool at https://github.com/OpenPoiesis/poietic-tool" 1>&2
echo "HINT: Make sure you have '~/.swiftpm/bin' in your PATH." 1>&2
exit 1
fi
if [ -z "$1" ] ; then
echo "Please specify a path to the poietic frame bundle (*.poieticframe)."
exit 1
fi
FRAME_BUNDLE=$1
#
# -----------------------------------------------------------------------------------
mkdir -p "${OUTPUT_DIR}"
# Path to the database.
export POIETIC_DESIGN="${OUTPUT_DIR}/design.poietic"
# -----------------------------------------------------------------------------------
# MAIN: Prepare the database and run the example
# -----------------------------------------------------------------------------------
# BEGIN main
#
echo "Building and running ${FRAME_BUNDLE}"
# Create a new empty database.
poietic new --import $FRAME_BUNDLE ${POIETIC_DESIGN}
poietic edit auto-parameters
# Create graphviz output
poietic write-dot \
--output ${DOT_FILE} \
-l name \
-m "(other)"
# Run the model and generate output into the ./out directory.
poietic run --solver euler -f gnuplot -o ${OUTPUT_DIR}
# END main
# -----------------------------------------------------------------------------------
# Create graphviz diagram image.
# -----------------------------------------------------------------------------------
if command -v dot &> /dev/null
then
dot -Tpng -o${OUTPUT_DIR}/diagram.png ${DOT_FILE}
echo "Diagram image created in ${OUTPUT_DIR}/diagram.png"
else
echo "WARNING: Graphviz tool 'dot' not found, diagram image not created." 1>&2
echo "HINT: Install package 'graphviz' using your system's package manager." 1>&2
echo "HINT: On a mac, run: brew install graphviz" 1>&2
fi
# Create charts using gnuplot.
# -----------------------------------------------------------------------------------
if command -v gnuplot &> /dev/null
then
# Create charts using gnuplot.
cd ${OUTPUT_DIR}
rm "*.gnuplot" 2> /dev/null && echo "Removed previous gnuplots."
gnuplot *.gnuplot
echo "Chart images created in ${OUTPUT_DIR}"
else
echo "WARNING: Gnuplot not found, chart images not created." 1>&2
echo "HINT: Install package 'gnuplot' using your system's package manager." 1>&2
echo "HINT: On a mac, run: brew install gnuplot" 1>&2
fi
echo "Output created in ${OUTPUT_DIR}"