Interactive Mode and Scripting

The following x-terminal commands show example of the interactive mode session, where $ and q2d> are the command prompts of the x-terminal and the q2d program.

$ q2d
q2d> curve c x y
q2d> plot P c
q2d> read - x y
0 0
1 1
2 4
@end
q2d> show
q2d> read - x y
3 9
4 16
5 25
@end
q2d> show
q2d> q

The commands are almost self-explanatory. After read command, the program enters the data reading mode, shows the plot window, and accepts the data to be plotted. Each entered point appears in the plot immediately after entering lhe data line. The @end instructions brings the program back to the command mode, indicated by the command prompt q2d>, and the plot window closes. To see it again, enter show command. You can push the ESC key to go back to the command mode and add more points to the plot or exit the progam with CTRL-ESC key.

Several example of sending the same commands and data to the q2d program are shown below:

echo -e "curve c x y; plot P c; read . x y; show\n\
0 0;1 1;2 4; 3 9; 4 16;5 25" | q2d -

or

echo "0 0;1 1;2 4; 3 9; 4 16;5 25" |\ 
q2d -e "curve xy x y; plot P xy; read - x y; show\n" -

The data in a file my_data_file can be plotted similiarly as ffollows:

$ q2d
q2d> curve c x y
q2d> plot P c
q2d> read my_data_file x y
q2d> show
q2d> q

Here it is assumed that the file contains at least two columns of data. The last script can be put in a file and made executable. Another way is to put commands at the beginning of data file.

#!/usr/bin/env q2d 
curve H-M H M
plot P H-M
read . H M; show
#
-188.984027771454           -109.786089619607
-179.343127482157           -109.741266474941
...

Let your program my_prog calculates some data and prints them as a several number of columns. To see the 2d plots, you need to describe what curve shall be placed on which plot. Let us assume that there are three columns of variables:

<t> <x> <y>

The values may be separated by spaces or commas. Suppose, you want to see calculated data as two plots:

This can be done with following Q2D commands:

q2d> curve a t x; curve b t y; curve c x y
q2d> plot P a b; plot Q c
q2d> readx my_prog t x y
You can also make a script by saving
!# /bin/env q2d
curve a t x; curve b t y; curve c x y
plot P a b; plot Q c
readx "my_prog" t x y
show

to a file named, e.g., view_t_xy.q2d, and make it executable. Command readx causes the data to be read from the output of the program my_prog into the buffers. If my_prog has arguments, place its name with the arguments inside double or single quotes. To test this without writing own program, replace my_prog with a demo q2d_demo_d, which had been installed along with Q2D.

view_t_xy.q2d "my_prog"

and in the second:

my_prog | view_t_xy.q2d

Several examples of plotting data by using the demo programs are shown below.

q2d -e "delay 2; curve c x y - O; plot P c; readx q2d_demo_a * x y"

q2d -e "delay 2; xrange * % 0 1000; curve c t x; plot P c;\
readx q2d_demo_a t x"

q2d -e "delay 2; xrange * 0 10; yrange * -1.2 1.3; curve a t x;\
curve b t y; plot P a b; readx q2d_demo_c t x y"

q2d -e "delay 1; xrange * % 0 10; curve c x y - O; plot P c;\
readx q2d_demo_c x y"

q2d -e "delay 1; curve c x y; plot P c;\
readx q2d_demo_d * x y; show; q"