jonsson.eu

EpsImg

Given a matrix of floating-point numbers stored in a regular ASCII text file,
the EpsImg program creates a grey-scale Encapsulated PostScript (EPS) image
of the matrix using its elements as specification of the brightness of the
corresponding pixels in the image.
For an extensive description of the algorithms used in the program, supported
command-line options and syntax, as well as the full documentation of the
source, see epsimg.pdf.
[193 kB, 28 pages].

Summary of the program

As for this program, I do by no means claim to have optimized
the generated Encapsulated PostScript.
The output images are in many cases large, and could in many cases be
considerably reduced in size, in particular for binary or few-level
grayscale images for which run-length encoding easily can be applied.
(In run-length encoding a long row of identical pixels is parametrized
as a loop, without the need of individual specification of each pixel.)
However, for my purposes it works fine, since I often only is concerned
with the evaluation of gray-scale images, generated by mathematical means
and often with no a priori specification of the number of intensity levels.

Of course, there are other ways of generating Encapsulated PostScript images
of sampled of simulated data, as for example using the image()
function of MATLAB. However, an advantage with using a stand-alone program
is that it is easily incorporated in scripts for batch processing.
In addition, the EpsImg program is provided free of charge.

Figure 1.
Example of application of the EpsImg program, in this particular case for the
visualization of a two-dimensional artificially generated interference pattern.
The numerical data for the image was generated by an AWK script and stored
in an ASCII file example1.dat.
The Encapsulated PostScript image was then generated by a call of the EpsImg
program, with command-line parameters of the form epsimg -i example1.dat
-o example1.eps, to leave the image file
example1.eps.

Current revision

Source files

epsimg.pdf
[193 kB]
Documentation of the EpsImg program in Portable Document Format (PDF)
[2], generated from the PostScript [4]
documentation.

epsimg.w
[42 kB]
The CWEB [1] master source code for the EpsImg program.
From this master, the ANSI-C (ISO C90) source code for the program and TeX
code for the documentation is extracted using the CTANGLE and CWEAVE
compilers, respectively.
[ download |
view source ]

Makefile
[2 kB]
The Makefile for compilation of the executable file, as well as generation
of the documentation of the program. Extracts the C and TeX code from the
CWEB source, and compiles the C and TeX code into binary executable and
PostScript, respectively.
To compile the executable and documentation, simply run 'make' in the
directory containing the source files and this Makefile.
[ download |
view source ]

epsimg.ps
[646 kB]
PostScript [4] documentation of the EpsImg program,
generated from the TeX-code, which in turn is generated from the CWEB master
source code.

Compilation

The program is written in CWEB [1], generating
ANSI C (ISO C99) conforming source code and documentation as plain
TeX-source, and is to be compiled using the sequences as outlined in the
enclosed
Makefile, which
essentially executes two major calls. First, the CTANGLE program parses the
CWEB source file
epsimg.w,
to extract a C source
file epsimg.c
which may be compiled into an executable program using any
ANSI C conformant compiler. The output source file
epsimg.c
includes #line specifications so that any debugging conveniently
can be done in terms of line numbers in the original CWEB source file
epsimg.w.
Second, the CWEAVE program parses the same CWEB source file
to extract a plain TeX file
epsimg.tex
which may be compiled into a PostScript [7] or
PDF [6] document.
The document file
epsimg.tex
takes appropriate care of typographic details like page layout and text
formatting, and supplies extensive cross-indexing information which is
gathered automatically.
In addition to extracting the documentary text, CWEAVE also includes the
source code in cross-referenced blocks corresponding to the descriptors as
entered in the CWEB source code.

Having executed make (or gmake for the
GNU enthusiast) in the same
directory where the files
epsimg.w,
and Makefile,
are located, one is left with the executable file epsimg, being
the ready-to-use compiled program, and the PostScript [7]
file epsimg.ps (or PDF
[6] file epsimg.pdf)
which contains the full documentation of the program.
Notice that on platforms running any operating system by Microsoft, the
executable file will instead automatically be named epsimg.exe.
This convention also applies to programs compiled under the UNIX-like
environment CYGWIN.

References

[3]
For information on the TeX typesetting system, as well as on the dvips
program, see for example the website of the TeX Users Group, at
http://www.tug.org

[4]
For information on the PostScript programming language, see for example the
PostScript area on the website of Adobe Systems Inc., at
http://www.adobe.com/products/postscript/ or the reference book
"PostScript Language - Tutorial and Cookbook" (Adison-Wesley, Reading,
Massachusetts, 1985), ISBN 0-201-10179-3.