Skip to content
Snippets Groups Projects
Commit 235381e4 authored by Ge Baolai's avatar Ge Baolai
Browse files

Added Makefile to heat1d and symlinks to heat2d.

parent f5fdf801
Branches
No related tags found
No related merge requests found
# How to run the examples
## Using pipe to chain the program ad Gnuplot
Compile the code `sinwave.1c`
```{bash}
gcc -c sinwave.c
gcc -c plot2d.c
gcc -o sinwave sinwave.o plot2d.o -lm
```
To run program with command pipe
```{bash}
sinwave | gnuplot --persist sinwave.plt
```
Note, this may sometimes file due to the race conditon of the availability of
data file `sinwave.dat` and the launch of `gnuplot`. Note, the commands on
each side the of pipe `|` are executed in parallel.
## Using pipe via system call inside the program
Compile the code `sinwave1.c`
```{bash}
gcc -c sinwave1.c
gcc -c plot2d.c
gcc -o sinwave1 sinwave1.o plot2d.o -lm
```
In this approch, a pipe is created via the call to system function `popen()`
```{C}
ofifo = popen("gnuplot --persist","w");
```
The `gnuplot` commands, along with the data to plot are sent to the stream
with statements
```{C}
// Set output
fprintf(ofifo, "set term X11\n");
fprintf(ofifo, "set xrange[-1:1]\n");
fprintf(ofifo, "set yrange[0:1]\n");
... ...
// Plot generated data, with '-' for data to feed plot
fprintf(ofifo, "plot '-' using 1:2 with lines;\n");
for (int i=0; i<n; i++)
fprintf(ofifo, "%f %f\n", x[i], y[i]);
fprintf(ofifo,"e\n");
fflush(ofifo);
```
The outpu setup can also be loaded from a file, e.g. `conf.plt`, containing
```{bash}
set term X11
set xrange [0:2*pi]
```
Then simply run the program with the binary name
```{bash}
sinwave1
```
set term X11
set xrange [-1:1]
set yrange [0:1]
unset key
# Plot config file for Gnuplot
set term X11 size 1300, 720
unset parametric
set style data lines
set zrange[-1:1]
set view 40,120,1,1
unset key
unset border
unset xtics
unset ytics
unset ztics
unset colorbox
set pm3d interpolate 0,0
../common/plot2d.c
\ No newline at end of file
../common/plot2d.h
\ No newline at end of file
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment