# ben165/realtime_cli_plotting

Real time plotting of an differential equation with keyboard interaction (Linux and DOS)
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
code
pics

Real time plotting of an differential equation with keyboard interaction

09.2016

## Content

• Real time plotting in DOS
• Real time plotting in LINUX with Ncurses

## Real time plotting in DOS

With real time plotting I call a programm that displays some stuff durably like a waving sine function. The special on it is that you can change for example the amplitude while the program is still plotting. This is easy to solve on DOS, because you don't need any program libraries like in Windows or Linux. You can solve this things only with BIOS interrupts.

I wrote a program who solves a first order differential equation approximately (with Euler forward). The equation is:

y + a * dy/dt = b
dy/dt = (b-y) / a

With a start value t0 and y0 you can use the Euler forward method to calculate the function:

y[n+1] = y[n] + (( b - y[n]) / a ) * Δt

How the program should work

• The program is divided in three parts: Plotting the results as a graph, displaying the values of the parameters and checking keyboard pressing to modify these
• To make this whole stuff much easier the choosen display is text (80 x 25)
• The user can modify the speed of calculation, the diff. equation parameters and the scaling of the plotting area
• The user should change the valü of a parameter with hitting one key on the keyboard. For example the value of variable a should increase if he hits A and decrease if he hits a
• The programming language is C with the Borland Turbo C Compiler
• Some function like the character position and the color of it is solved with the BIOS interrupts

A: increase value a
a: decrease value a

B: increase value b
b: decrease value b

y: change value y

V: increase velocity
v: decrease velocity

S: increase border scale
s: decrease border scale

p: pause, continue with any key
q: quit

Source: realtimedos.c

## Real time plotting in LINUX with ncurses

01.2017

On Linux (also BSD and Mac OS) exists the nice library ncurses for the C programming language to make more things than only print text with printf() for example. The library is also available in C++ and Python. The use is very simple and offers you lots of things to manipulate the characters on the screen:

• Color and background color for each character
• Move your cursor wherever you want
• You can check if a key on keyboard is pressed without interrupting the program
• Only easy function calls, no object-oriented scheme
• Good examples on the web

To install the library on you Linux distribution you need the packages like libncurses5 and libncurses5-dev.

With this possibilities I could write the same real time calculating program for Linux. But I changed some things:

• The values are displayed on the top of the command window
• The program stops if some special keys is pressed. In this status you can change the value by typing it in (like scanf in C)
• The program continues then with the new value
• If the value b and y are the same, then the background color of the plotting point is changed to see both points.

The differential equation is the same then above

dy/dt = (b-y) / a

Characters and their functions:

a: change value a
b: change value b
y: change value y

+: increase velocity
-: decrease velocity
S: increase border scale
s: decrease border scale

p: pause, continue with any key
q: quit

Source: realtimelinux.c

You can’t perform that action at this time.