[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ 16 ] [ 17 ] [ 18 ] [ 19 ] [ 20 ] [ next ]

Debian User Reference Manual
Chapter 11 - Science


author = Andreas Franzen [email protected]

topics = everything in section math

Latest update to this chapter: 9th January 2000


11.1 What this chapter covers

This chapter shows possible ways to use Debian GNU/Linux for scientific research. This means especially how to process measurement data to convert them into papers.

To illustrate these concepts, the package diploma in the section doc of the Debian distribution contains some real world examples.


11.2 Plotting

One important aspect in the scientific use of computers is the graphic representation of data. The most common form is a two-dimensional plot. There are many different ways to create such plots with a Debian system. These include command line tools, programming libraries, scripting language interpreters, and programs with GUIs.

Which of these different approaches is the best one depends both on the problem to solve and on the overall concept. In case the concept is to structure the whole work in a make project, it is important to integrate the conversion of data into diagrams cleanly into the makefile. This means that interactive manipulations are not possible. On the other hand, it can be easier and faster to create a special plot with a GUI driven program.

The classic way to plot data is the command line tool graph. This is included in the package plotutils. It is possible to convert data into publication quality plots just by invoking graph with some command line options to set the axis labels, etc. Interesting is the possiblility to include a huge number of special characters and to output the plot in the file format of the program xfig. Such plots can be rearranged and changed with the GUI driven vector graphics program xfig. The documentation can be accessed by info plotutils.

Another possibility to use the plotutils package to create diagrams is to use graphs metafile format directly. This makes it possible to write and edit plots in a simple graphic description language.

Also, the plotutils package comes with a C library which makes it possible to create graphical output from C programs.

Another very popular way to convert data into plots is the program gnuplot. This program can be used with an interactive interface and also as a scripting language interpreter. The later way makes it possible to include invocations of gnuplot in make projects.

Sometimes, it may be necessary to use the graphic description language Ghostscript directly. For example, if you want to include a grayscale image into a diagram, the rotation angle of this image has to be adjusted some degrees without quality loss, and you have to adjust the raster frequency of the print to get an optimum compromise between reproducability and resolution. In such a case, Ghostscript is a solution. The section on the combination of diagrams and the diploma package give more information on this topic.

The Debian distribution provides also some GUI driven plotting programs. The most useful of these is grace. The X Window binary is xmgrace. It is found in the menu at programs-apps-math-grace. It is also possible to use the package grace for batch processing. Grace project files use a human readable description language. The documentation on grace is in /usr/lib/grace/doc and examples are in /usr/lib/grace/examples.


11.3 Combining diagrams

Sometimes, it is necessary to combine plots produced by plotting programs like graph with additional images. One possible way is to set the output format of graph to fig which creates a .fig file. This can be edited manually with the graphics program xfig. This method has the drawback that every time a change is done to the original plot the additional modifications must be repeated. This is especially annoying when you try to summarize the structure of your work in a makefile. The make command cannot do the additional modifications you did with xfig, when the original plot is updated.

One possibility is to do the creation of the original plot and of the additional figure separately. The manually created figure is saved as an .eps file which is considered as source code in the makefile. The combination of the manually created figure and the original plot is then done by commands within the makefile. Whenever the original plot changes the same manually created figure is added automatically to the now plot.

When you want to combine figures from different sources into one figure to include into e.g. a LaTeX document, the easiest way is to use the .eps format. .eps files are textfiles which have the important possibility to be combined easily into new .eps files.

The programming language for the processing of .eps files included in the Debian GNU/Linux system is Ghostscript. The Ghostscript interpreter is in the package gs in the text section. The binary is also named gs.

For a quick start with Ghostscript, you can open a console window in X Window and just type gs at the shell prompt. Then an additional window with the graphics display will pop up and you will get the GS> prompt at the console. Ghostscript is an interpreted stack oriented programming language. To get an impression of this we will try to compute (3+5)*7 with Ghostscript. The program is simple.

     3 5 add 7 mul =

In detail this means

     3     %Put 3 onto the stack.
     5     %Put 5 onto the stack.
     add   %Take the last two elements from the stack and put
           %the sum onto the stack.
     7     %Put 7 onto the stack.
     mul   %Take the last two elements from the stack and put
           %the product onto the stack.
     =     %Take the last element from the stack and print it
           %at the console.

After every command you can type pstack to see the current content of the stack. Then we will try to write a line on the graphics display.

     newpath         %Start a new path.
     100 200 moveto  %Move the graphics cursor to x=100, y=200.
     150 210 lineto  %Add a line to the position x=150, y=210.
     stroke          %Draw the current path.

You can leave the Ghostscript interpreter by typing quit.

These examples should have given you an idea of the concept of the Ghostscript languge. All .eps files and .ps files are text files which contain Ghostscript programs. Often these programs are nearly unreadable because in a very big header many short abbreviations are defined which are used throughout the following program. Fortunately, you do not need to lock into the program which describes a figure to include it into another .eps file. The general difference between .ps files and .eps files is that .ps files usually describe whole documents of many pages while .eps files always contain only one figure.

Files in the .eps format may or may not contain a showpage command at the end of the file. Without this command sending the file to a printer won't give you a hardcopy. When it is possible to see the figure with gv with the right papersize set and printing does not work, just adding a showpage command to the end of the file often helps.

The following example shows an .eps file which contains the line of the previous example.

     %!PS-Adobe-3.0 EPSF-3.0
     newpath
     100 200 moveto
     150 210 lineto
     stroke
     showpage
     quit

When you save this as test.eps and start gv test.eps, you can see a small window with the line from the left lower to the right upper corner. The program gv is included in the package gv in the section text of Debian GNU/Linux. The first line of the example indicates the file format. The second line gives the bounding box. This is a rectangle which contains the drawing. When you position the mouse cursor onto the line, you can see the coordinates of the mouse cursor. The origin is the lower left corner of the printing area, e.g. the paper sheet of a printer. x counts positive to the right and y positive upwards. On paper the units are points. One point equals 25.4/72mm. When your lpr command is set up to print .ps files you can just sent the example file with lpr test.eps to the printer and you will get a line on the paper at the according coordinates. The command showpage tells the printer to actually print the page. This is common but not necessary at the end of .eps files. If an .eps file is included in another file, showpage commands must be disabled. Otherwise, the printer would print the page and start a new one at each occurence of these included showpage commands.

Now, we will combine two .eps files into a new .eps file. We plot the following data points

     0 0
     1 1
     2 4
     3 9

and put the Debian logo from http://www.debian.org in the left top corner of the plot. The Debian logo is downloaded as logo-50.jpg. The plot is in plot.eps. This is created by the following command.

     echo '0 0 1 1 2 4 3 9' | graph -T ps > plot.eps

The graph command is contained in the plotutils package in section math of the Debian distribution.

The following script inserts the logo into the plot and saves the combined figure in figure.eps.

     #!/bin/bash
     convert logo-50.jpg logo-50.eps     #Convert the .jpg file
                                         #into an .eps file.
     cat head.asc plot.eps separation.asc logo-50.eps tail.asc > figure.eps

The command convert is contained in the package imagemagick in section graphics. The file head.asc contains

     %!PS-Adobe-3.0 EPSF-3.0
     %%BoundingBox: 107 195 492 580
     save gsave /showpage {} def

The first line says it is an .eps file. The second line is the bounding box. Because the logo is inserted into the plot this is the same as the boundig box of plot.eps. The third line saves the virtual memory and the graphics state, thus, any modifications done inside the .eps files can be restored. Finally, the showpage command is redefined into nothing. The file separation.asc contains

     grestore restore
     save gsave /showpage {} def
     185 400 translate
     2 2 scale

The graphics state and virtual memory are restored and saved again. The logo is scaled by factor 2 in both x and y direction and then translated 185 points to the right and 400 points upwards to fit into the plot. It is also possible to rotate with the rotation angle and the command rotate. The order of the commands is essential. 2 2 scale 10 10 translate means that the origin of the original image is at 20, 20 afterwards. The content of the file tail.asc is

     grestore restore
     showpage
     quit

This closes the .eps file.

Examples of the handling of .eps files are in the package diploma in section doc.


[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ 16 ] [ 17 ] [ 18 ] [ 19 ] [ 20 ] [ next ]

Debian User Reference Manual


version 0.1, 17 June 2006

Ardo van Rangelrooij [email protected]
Jason D. Waterman [email protected]
Thalia L. Hooker [email protected]
Havoc Pennington [email protected]
Oliver Elphick - Maintainer [email protected]
Bruce Evry [email protected]
Karl-Heinz Zimmer [email protected]
Andreas Franzen [email protected]