From bc007e6d32c5cdbb06adc9ecdda7415920a7b2d8 Mon Sep 17 00:00:00 2001 From: giuliadei Date: Wed, 29 Jan 2025 17:09:36 +0000 Subject: [PATCH] Adding octave example --- octave/.gitignore | 1 + octave/Dockerfile | 12 ++++++++++++ octave/README.md | 11 +++++++++++ octave/src/plot_example.m | 31 +++++++++++++++++++++++++++++++ octave/src/run_octave.sh | 5 +++++ 5 files changed, 60 insertions(+) create mode 100644 octave/.gitignore create mode 100644 octave/Dockerfile create mode 100644 octave/README.md create mode 100644 octave/src/plot_example.m create mode 100644 octave/src/run_octave.sh diff --git a/octave/.gitignore b/octave/.gitignore new file mode 100644 index 0000000..6a3e68d --- /dev/null +++ b/octave/.gitignore @@ -0,0 +1 @@ +**/.DS_Store \ No newline at end of file diff --git a/octave/Dockerfile b/octave/Dockerfile new file mode 100644 index 0000000..7f7590c --- /dev/null +++ b/octave/Dockerfile @@ -0,0 +1,12 @@ +FROM matpower/octave:latest@sha256:5d1683c81873c56a37774bc7c42ef3d78a7e107781e974a1b8957073bac4436a + +ARG OCTAVE_VERSION="9.2.0" +ARG OCTAVE_IMAGE_REVISION="1" + +RUN mkdir /safe_data /safe_outputs /scratch /test + +WORKDIR /test + +COPY --chmod=0755 src/* . + +CMD ["/bin/bash", "run_octave.sh"] \ No newline at end of file diff --git a/octave/README.md b/octave/README.md new file mode 100644 index 0000000..318c67f --- /dev/null +++ b/octave/README.md @@ -0,0 +1,11 @@ +# TRE Octave example + +## Running + +Run with standard `ces-run` command. + +## Notes + +In this example, a bash script uses an octave script to generate a plot and then saves the `.png` output to `/safe_outputs`. Both files are found under the `src` directory, which is copied inside the container in the `Dockerfile`. + +This example is not interactive. \ No newline at end of file diff --git a/octave/src/plot_example.m b/octave/src/plot_example.m new file mode 100644 index 0000000..19eb590 --- /dev/null +++ b/octave/src/plot_example.m @@ -0,0 +1,31 @@ +% declaring variable var_x +var_x = [0:0.01:1]; + +% declaring variable var_y1 +var_y1 = sin(4 * pi * var_x); + +% declaring variable var_y2 +var_y2 = cos(3 * pi * var_x); + +% plot var_x with var_y1 +plot(var_x, var_y1); + +% hold the above plot or figure +hold on; + +% plot var with var_y2 with red color +plot(var_x, var_y2, 'r'); + +% adding label to the x-axis +xlabel('time'); + +% adding label to the y-axis +ylabel('value'); + +% adding title for the plot +title('my first plot'); + +% add legends for these 2 curves +legend('sin', 'cos'); + +print -dpng 'plot.png' \ No newline at end of file diff --git a/octave/src/run_octave.sh b/octave/src/run_octave.sh new file mode 100644 index 0000000..b4ecfa0 --- /dev/null +++ b/octave/src/run_octave.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +octave plot_example.m + +mv *.png /safe_outputs \ No newline at end of file