Contents of file 'epsimg/epsimg.tex':
1 \input cwebmac
2 % File: epsimg.w [CWEB source code]
3 % Last change: February 21, 2004
4 % Author: Fredrik Jonsson
5 % Description: CWEB source code for the EPSIMG program. Given a matrix of
6 % numerical values stored in a regular ASCII text file, the
7 % EPSIMG program creates a grey-scale Encapsulated PostScript
8 % image of the matrix using its elements as specification of
9 % the brightness of the corresponding pixels in the image.
10 % For information on the CWEB programming language, see
11 % http://www.literateprogramming.com.
12 % Compilation: Compile this program by using the enclosed Makefile, or use
13 % the blocks of the Makefile as listed in section five of the
14 % documentation (file epsimg.ps or epsimg.pdf). The C source
15 % code (as generated from this CWEB code) conforms to the ANSI
16 % standard for the C programming language (which is equivalent
17 % to the ISO C89 standard for C).
18 %
19 % Copyright (C) 2004, Fredrik Jonsson
20 %
21 \def\version{1.6}
22 \def\lastrevdate{February 21, 2004}
23 \input epsf
24 \font\eightcmr=cmr8
25 \font\tensc=cmcsc10
26 \font\eightcmssq=cmssq8
27 \font\eightcmssqi=cmssqi8
28 \font\twentycmcsc=cmcsc10 at 20 truept
29 \def\epsimg{{\eightcmr EPSIMG\spacefactor1000}}
30 \def\CEE{{\eightcmr C\spacefactor1000}} % The C programming language
31 \def\CWEB{{\eightcmr CWEB\spacefactor1000}} % The CWEB programming language
32 \def\MATLAB{{\eightcmr MATLAB\spacefactor1000}} % The MATLAB ditto
33 \def\endalg{\vrule height 1.4ex width .6ex depth .4ex} % Rectangular bullet
34 %
35 % Define a handy macro for listing the steps of an algorithm.
36 %
37 \newdimen\aitemindent \aitemindent=26pt
38 \newdimen\aitemleftskip \aitemleftskip=36pt
39 \def\aitem[#1]{\smallbreak\noindent\hbox to 10pt{}%
40 \hbox to\aitemindent{\bf #1\hfill}%
41 \hangindent\aitemleftskip\ignorespaces}
42 %
43 % Define a handy macro for the list of program revisions.
44 %
45 \newdimen\citemindent \citemindent=80pt
46 \newdimen\citemleftskip \citemleftskip=90pt
47 \def\citem[#1]{\smallbreak\noindent\hbox to 10pt{}%
48 \hbox to\citemindent{\bf #1\hfill}%
49 \hangindent\citemleftskip\ignorespaces}
50 %
51 % Define a handy macro for listing of operator descriptions.
52 %
53 \newdimen\oitemindent \oitemindent=66pt
54 \newdimen\oitemleftskip \oitemleftskip=76pt
55 \def\oitem[#1]{\smallbreak\noindent\hbox to 10pt{}%
56 \hbox to\oitemindent{\bf #1\hfill}%
57 \hangindent\oitemleftskip\ignorespaces}
58
59 \datethis
60
61
62 \N{1}{1}Introduction.
63 \vskip 120pt
64 \centerline{\twentycmcsc Epsimg}
65 \vskip 20pt
66 \centerline{Creates grey-scale Encapsulated PostScript images of matrices
67 of numerical data}
68 \vskip 2pt
69 \centerline{(Version \version\ of \lastrevdate)}
70 \vskip 10pt
71 \centerline{Written by Fredrik Jonsson}
72 \vskip 80pt
73 \noindent
74 Given a matrix of floating-point numbers stored in a regular ASCII text file,
75 this \CWEB\footnote{${}^\dagger$}{For information on the \CWEB\ programming
76 language by Donald E.~Knuth, as well as samples of \CWEB\ programs, see
77 {\tt http://www-cs-faculty.stanford.edu/\~\ \kern -5pt knuth/cweb.html}.
78 For general information on literate programming, see
79 {\tt http://www.literateprogramming.com}.} program creates a grey-scale
80 Encapsulated PostScript (EPS) image of the matrix using its elements as
81 specification of the brightness of the corresponding pixels in the image.
82
83 I do by no means claim to have written a program that generates fully optimized
84 Encapsulated PostScript. The output images are in many cases large, and can
85 in many cases be considerably reduced in size, in particular for binary or
86 few-level grayscale images, for which run-length encoding easily can be
87 applied. (In run-length encoding a long row of
88 identical pixels is parametrized as a loop, without the need of individual
89 specification of each pixel.) However, for my purposes it works fine, since
90 I often only is concerned with the evaluation of gray-scale images, generated
91 by mathematical means and often with no a priori specification of the number
92 of intensity levels.
93
94 Of course, there are other ways of generating Encapsulated PostScript images
95 of sampled of simulated data, as for example using the {\tt image()} function
96 of \MATLAB. An advantage with using a stand-alone program, however, is that
97 it is easily incorporated in scripts for batch processing. In addition, the
98 \epsimg\ program is provided free of charge.
99 \bigskip
100 \noindent Copyright \copyright\ Fredrik Jonsson, 2004.
101 All rights reserved.
102 \vfill
103
104 \fi
105
106 \N{1}{2}Revision history of the program.
107 \medskip
108
109 \citem[2004-01-26]{[v.1.0]} {\tt <jonsson@uni-wuppertal.de>}\hfill\break
110 First properly working version of the \epsimg\ program. I have now for a
111 longer time had in my mind that it would be useful to write a stand-alone
112 program that is capable of generating Encapsulated PostScript images of
113 data matrices, in similar to the {\tt image()} built-in function of \MATLAB.
114 In particular, I have lately encountered some problems involving the optical
115 analysis of diffraction patterns, and in order to visualize my generated data
116 (without having to use \MATLAB\ every time) I this evening started the coding
117 in \CWEB.
118
119 \citem[2004-01-27]{[v.1.1]} {\tt <jonsson@uni-wuppertal.de>}\hfill\break
120 Continued with cleaning up the code and adding some features, such as the
121 possibility of letting the program add a frame outlining the bounding box
122 of the Encapsulated PostScript image, and a scaling of the $x$- or $y$-axis
123 to leave the aspect ratio of the square pixels invariant even for non-square
124 input matrices. Also changed the precision of the coordinates and gray scale
125 specifications in order to get really smooth images. However, there still seem
126 to remain some bug that causes the program to refuse to accept data files
127 containing lines with trailing blank spaces and additional line feeds.
128 [Coding finished at 00:45, 2004-01-28]
129
130 \citem[2004-01-28]{[v.1.2]} {\tt <jonsson@uni-wuppertal.de>}\hfill\break
131 This morning fixed the remaining bug from yesterday, and wrote a basic example
132 ({\tt example1}) as a block in the {\tt Makefile}, using AWK to generate a
133 simple interference pattern that is visualized with the help of the \epsimg\
134 program. Also wrote blocks that provide a proper rescaling of the image
135 width or height whenever either the width or height is larger than their
136 respective maximum values. Wrote an example ({\tt example2}) in the
137 {\tt Makefile} that illustrates this automatic rescaling of the image.
138
139 \citem[2004-01-30]{[v.1.3]} {\tt <jonsson@uni-wuppertal.de>}\hfill\break
140 This evening (time is now 01:55 Saturday morning) I started to sketch on
141 a partitioning scheme for the reduction of data neccessary to save to disk.
142 For many of my diffraction images, there are large areas that are of equal
143 shade, and since they have considerable extent in the $x$- as well as
144 $y$-direction, a run-length encoding (of the type used in the ancient program
145 for generation of fractals that I wrote together with Tommy Ekola in 1996)
146 of the Encapsulated PostScript will not fix the problem to any greater extent.
147 Therefore, I started formulating a recursive scheme for the partitioning of
148 data into smaller and smaller sub-blocks of the user-supplied matrix, which
149 I for the sake of simplicity so far have assumed to be square, of size
150 $[2^M\times 2^M]$ for some integer $M$.
151 Wrote a MetaPost figure {\tt matfig.mp} that illustrates the partition scheme.
152
153 \citem[2004-02-07]{[v.1.4]} {\tt <jonsson@uni-wuppertal.de>}\hfill\break
154 [Athens, Greece] Noticed that when viewed using Ghostview, the figures could
155 not be zoomed properly. This was corrected by letting the program explicitly
156 state {\tt \%\%!PS-Adobe-2.0 EPSF-1.2}, and by also explicitly stating the
157 number of pages (that is to say, one) of the figure in the Encapsulated
158 PostScript preamble, using {\tt \%\%Pages: 1}.
159
160 \citem[2004-02-20]{[v.1.5]} {\tt <jonsson@uni-wuppertal.de>}\hfill\break
161 [\"Ostergarn, Gotland] Added the command-line options
162 {\tt --commmented\_postscript} and {\tt --uncommmented\_postscript},
163 explicitly forcing the program either to include comments on PostScript
164 routines directly into the generated code (default),
165 or forcing the program to suppress these comments (giving a slightly reduced
166 size on disk).
167
168 \citem[2004-02-21]{[v.1.6]} {\tt <jonsson@uni-wuppertal.de>}\hfill\break
169 [\"Ostergarn, Gotland] Wrote the final blocks of a major revision of the
170 program, concerning the algorithm for generation of individual pixels.
171 While the program previously explicitly stated the pixel boundaries as paths,
172 I have now replaced this by a PostScript routine {\tt drawpixel} that takes
173 a pixel bounding box given by the lower left and upper right corners
174 $(\langle\PB{\\{llx}}\rangle,\langle\PB{\\{lly}}\rangle)$ and
175 $(\langle\PB{\\{urx}}\rangle,\langle\PB{\\{ury}}\rangle)$ and draws and fills
176 the pixel
177 with a specified gray value.
178 The syntax for this PostScript routine is (in the PostScript language)
179 simply {\tt drawpixel} $\langle\PB{\\{llx}}\rangle$ $\langle\PB{\\{lly}}%
180 \rangle$
181 $\langle\PB{\\{urx}}\rangle$ $\langle\PB{\\{ury}}\rangle$ $\langle\PB{\|w}%
182 \rangle$, where
183 $\langle\PB{\|w}\rangle\in[0,1]$ is the whiteness of the actual pixel.
184 I did, however, keep the possibility of generating the previous, more extensive
185 form of PostScript, and in order to be able to switch the program into
186 either mode, the options {\tt --compactified\_pixelcode} and
187 {\tt --extensive\_pixelcode} were added as parts of the startup syntax.
188 When applied to the previously written example with a $64\times64$-sized
189 matrix of real numbers, the size of the generated was radically reduced
190 from 590.3 kB to 152.4 kB, hence corresponding to a reduction by 74\%!
191 However, there still remain to optimize the code, especially to write
192 PostScript routines that takes the image matrix and automatically loops
193 over the indices, instead of the current approach, where the bounding box
194 of each individual pixel still is specified in the code. (The image generated
195 by the {\tt image()} routine of \MATLAB\ is still considerably smaller in
196 size than what the now optimized algorithm provides; so far the generated
197 PostScript takes approximately 37 byte per pixel, which is far too much
198 even for ``educational purpose''.)
199 What remains now is to also include the more clever partitioning of the
200 image for cases with many adjacent pixels of identical gray value.
201 \medskip
202 \centerline{\epsfxsize=40.0mm\epsfbox{examples/example1-compact.eps}}
203 \medskip\nobreak
204 \centerline{Figure R1. The example $64\times64$ image used in evaluating
205 size reduction 2004-02-21.}
206
207 \fi
208
209 \N{1}{3}Compiling the source code. The program is written in \CWEB, generating
210 ANSI-C conforming source code and documentation as \TeX-source, and is to
211 be compiled using the enclosed Makefile, leaving an executable
212 file {\tt epsimg}\footnote{$\dagger$}{On platforms running Windows NT,
213 Windows 2000, or any other operating system by Microsoft, the executable
214 file will instead automatically be called {\tt epsimg.exe}.} and a
215 PostScript file {\tt epsimg.ps} (the document you currently are reading),
216 which contains the full documentation of the program:
217 \bigskip
218 {\obeyspaces\obeylines\tt
219 ~ \#
220 ~ \# Makefile designed for use with ctangle, cweave, gcc, and plain TeX.
221 ~ \#
222 ~ \# Copyright (C) 2004, Fredrik Jonsson <jonsson@uni-wuppertal.de>
223 ~ \#
224 ~ CTANGLE = ctangle
225 ~ CC = gcc
226 ~ CCOPTS = -O2 -Wall -ansi -pedantic \# follow ISO C89 (ANSI) strictly
227 ~ LNOPTS = -lm
228 ~ CWEAVE = cweave
229 ~ TEX = tex
230 ~ DVIPS = dvips
231 ~ DVIPSOPT = -ta4 -D1200
232 ~ ~
233 ~ all: epsimg.exe epsimg.ps
234 ~ ~
235 ~ epsimg.exe: epsimg.o \# generate the executable file
236 ~ \$(CC) \$(CCOPTS) -o epsimg epsimg.o \$(LNOPTS)
237 ~ ~
238 ~ epsimg.o: epsimg.c \# generate the object file
239 ~ \$(CC) \$(CCOPTS) -c epsimg.c
240 ~ ~
241 ~ epsimg.c: epsimg.w \# generate C code from the CWEB source
242 ~ \$(CTANGLE) epsimg
243 ~ ~
244 ~ epsimg.ps: epsimg.dvi \# generate the PostScript documentation
245 ~ \$(DVIPS) \$(DVIPSOPT) epsimg.dvi -o epsimg.ps
246 ~ ~
247 ~ epsimg.dvi: epsimg.tex \# generate the device-independent documentation
248 ~ \$(TEX) epsimg.tex
249 ~ ~
250 ~ epsimg.tex: epsimg.w \# generate plain TeX code from the CWEB source
251 ~ \$(CWEAVE) epsimg
252 ~ ~
253 ~ clean:
254 ~ ~ -rm -Rf *.c *.o *.exe *.aux *.log *.toc *.idx *.scn *.tex *.dvi}
255 \bigskip
256
257 \fi
258
259 \N{1}{4}Running the program. The program is entirely controlled by the command
260 line options supplied when invoking the program, and the syntax is simply:
261 \medskip
262 {\obeyspaces\obeylines\tt
263 ~ epsimg -i <infile> -o <outfile>
264 }
265 \medskip
266 \noindent
267 where {\tt <infile>} is a regular text file containing the matrix of numerical
268 data, and {\tt <outfile>} is the name of the Encapsulated PostScript image
269 that is to be generated.
270 Instead of {\tt -i} and {\tt -o}, the switches can equivalently be specified
271 in their longer forms {\tt --inputfile} and {\tt --outputfile}, respectively.
272
273 Several options may additionally be specified; to see a listing of all
274 available options, simply invoke \epsimg\ with the help switch {\tt -h}
275 (or, equivalently, {\tt --help} in a longer form), as
276 \medskip
277 {\obeyspaces\obeylines\tt
278 ~ epsimg -h
279 }
280 \medskip
281 \noindent
282
283
284 \fi
285
286 \N{1}{5}Compressing the size of the generated Encapsulated Postscript.
287 In a general sense, the input to the \epsimg\ program is just an arbitrary
288 matrix of numbers, with no a priori assumption on their individual values
289 or their ordering.
290 In many images, however, there are large areas of equal colour (or brightness,
291 if we stick to the fact that the \epsimg\ program primarily is designed for
292 the visualization of gray scale images), and instead of sequentially writing
293 a large list of identical squares, of the same shading but slightly displaced
294 with respect to one another, one may start thinking that there must be a more
295 efficient method of saving the image to file.
296
297 One possibility is to check the structure sequentially in the order the squares
298 are written, and in case many boxes of the same shade appear, say in the
299 row direction of the supplied matrix, a rectangle with this shade and with
300 a length corresponding to the number of equal squares is to be drawn instead.
301 This, however, may be an inefficient method as well, since any directionality
302 in the image in the column direction of the matrix will be left unnoticed.
303 In addition, if there are large fields of equal shade, a lot of neighbouring
304 rows should be possible to further reduce, for example by instead drawing
305 general rectangles which no longer need to be of the same height as the
306 basic pixels.
307
308 The question therefore arises: Would it not be possible to make a relatively
309 simple divide-and-conquer description of the matrix, partitioning the matrix
310 into rectangular building blocks of equal shade?
311 In Fig.~1, on possibility of a partitioning scheme for the reduction of the
312 data needed to save to disk is illustrated.
313 \bigskip
314 \centerline{\epsfxsize=107.55mm\epsfbox{matfig/matfig.1}}\medskip\nobreak
315 \centerline{Figure 1. A possible partitioning scheme for square matrices
316 of size $[2^M\times 2^M]$.}
317
318
319 \fi
320
321 \N{1}{6}The main program. Here follows the general outline of the main program.
322
323 For the flags that are internally used, for the settings of desired program
324 actions, the significance of the flags are:
325 \PB{\.{COMPACTIFIED\_PIXELCODE}} If set to a positive nonzero integer value,
326 this flag causes the program to generate a
327 compactified PostScript code for the definitions of the individual boxes
328 of the image, i.e. the individual pixels.
329
330 In order to have one single and generic output stream, the \PB{\.{OUTSTREAM}}
331 definition provides an easy solution to switching the output from file
332 to terminal output, depending on which options that are detected at the
333 command line during startup of the program.
334
335 \Y\B\8\#\&{include} \.{<math.h>}\6
336 \8\#\&{include} \.{<stdio.h>}\6
337 \8\#\&{include} \.{<stddef.h>}\6
338 \8\#\&{include} \.{<stdlib.h>}\6
339 \8\#\&{include} \.{<string.h>}\6
340 \8\#\&{include} \.{<time.h>}\C{ to get automatically generated timestamp in EPS
341 header }\6
342 \8\#\&{include} \.{<ctype.h>}\C{ to access \PB{\\{isalnum}(\,)} }\6
343 \8\#\&{define} \.{VERSION\_NUMBER} \5\.{"1.6"}\6
344 \8\#\&{define} \.{A4\_PAGE\_WIDTH} \5(\T{594})\C{ A4 page width in pt (1/72 in)
345 }\6
346 \8\#\&{define} \.{A4\_PAGE\_HEIGHT} \5(\T{841})\C{ A4 page height in pt (1/72
347 in) }\6
348 \8\#\&{define} \.{MAXIMUM\_IMAGE\_WIDTH} \5${}(\.{A4\_PAGE\_WIDTH}-\T{144}{}$)%
349 \C{ 1.0 inch default margin }\6
350 \8\#\&{define} \.{MAXIMUM\_IMAGE\_HEIGHT} \5${}(\.{A4\_PAGE\_HEIGHT}-%
351 \T{144}{}$)\C{ 1.0 inch default margin }\6
352 \8\#\&{define} \.{DEFAULT\_IMAGE\_WIDTH} \5${}(\T{0.8}*\.{MAXIMUM\_IMAGE%
353 \_WIDTH}){}$\6
354 \8\#\&{define} \.{DEFAULT\_IMAGE\_XCENTER} \5${}(\.{A4\_PAGE\_WIDTH}/\T{2}){}$\6
355 \8\#\&{define} \.{DEFAULT\_IMAGE\_YCENTER} \5${}(\.{A4\_PAGE\_HEIGHT}/\T{2}){}$%
356 \6
357 \8\#\&{define} \.{DEFAULT\_LINETHICKNESS} \5\T{1}\C{ default line thickness in
358 pt (1/72 in) }\6
359 \8\#\&{define} \.{OUTSTREAM} \5${}(\\{outfile\_specified}\?\\{fpout}:%
360 \\{stdout}){}$\6
361 \8\#\&{define} \.{SUCCESS} \5\T{0}\C{ Return code for successful program
362 termination }\6
363 \8\#\&{define} \.{FAILURE} \5\T{1}\C{ Return code for program termination
364 caused by failure }\6
365 \8\#\&{define} \.{COMPACTIFIED\_PIXELCODE} \5\T{1}\6
366 \8\#\&{define} \.{EXTENSIVE\_PIXELCODE} \5\T{2}\6
367 \X7:Global variables\X\6
368 \X8:Subroutines\X\7
369 \&{int} \\{main}(\&{int} \\{argc}${},\39{}$\&{char} ${}{*}\\{argv}[\,]){}$\1\1%
370 \2\2\6
371 ${}\{{}$\1\6
372 \X16:Local variables\X\6
373 \X17:Parse command line\X\6
374 \X19:Open files\X\6
375 \X20:Load text file into image matrix\X\6
376 \X21:Normalize image matrix\X\6
377 \X22:Initialize parameters of Encapsulated PostScript image\X\6
378 \X23:Write preamble of Encapsulated PostScript image\X\6
379 \X24:Write body of Encapsulated PostScript image\X\6
380 \X27:Write closing of Encapsulated PostScript image\X\6
381 \X28:Deallocate image matrix\X\6
382 \X29:Close files\X\6
383 \&{return} (\.{SUCCESS});\6
384 \4${}\}{}$\2\par
385 \fi
386
387 \N{1}{7}Declaration of global variables. The only global variables allowed in
388 my programs are \PB{\\{optarg}}, which is the string of characters that
389 specified
390 the call from the command line, and \PB{\\{progname}}, which simply is the
391 string
392 containing the name of the program, as it was invoked from the command line.
393
394 \Y\B\4\X7:Global variables\X${}\E{}$\6
395 \&{extern} \&{char} ${}{*}\\{optarg}{}$;\C{ command line string }\6
396 \&{char} ${}{*}\\{progname}{}$;\C{ name of the program as invoked from command
397 line }\par
398 \U6.\fi
399
400 \N{1}{8}Declarations of subroutines used by the program.
401
402 \Y\B\4\X8:Subroutines\X${}\E{}$\6
403 \X9:Display help message\X\6
404 \X10:Routine for allocation of double vectors\X\6
405 \X11:Routine for allocation of double matrices\X\6
406 \X12:Routine for deallocation of double vectors\X\6
407 \X13:Routine for deallocation of double matrices\X\6
408 \X14:Routine for loading matrix data from text file\X\6
409 \X15:Routine for unloading matrix data previously loaded from text file\X\par
410 \U6.\fi
411
412 \M{9}Routine for displaying a help message at the screen.
413
414 \Y\B\4\X9:Display help message\X${}\E{}$\6
415 \&{void} \\{showsomehelp}(\&{void})\1\1\2\2\6
416 ${}\{{}$\1\6
417 ${}\\{fprintf}(\\{stderr},\39\.{"Usage:\ \%s\ -i\ infile}\)\.{\ [options]\ [-o\
418 outfi}\)\.{le]\\n"},\39\\{progname});{}$\6
419 ${}\\{fprintf}(\\{stderr},\39\.{"Options:\\n"});{}$\6
420 ${}\\{fprintf}(\\{stderr},\39\.{"\ \ -i,\ --inputfile\ <}\)\.{str>\ \ \
421 Specifies\ the}\)\.{\ file\ where\ to\ find\ }\)\.{the\ intensity\\n"}\.{"\ \ \
422 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ response\ for\ }\)\.{the\
423 actual\ property.}\)\.{\\n"});{}$\6
424 ${}\\{fprintf}(\\{stderr},\39\.{"\ \ -o,\ --outputfile\ }\)\.{<str>\ \
425 Specifies\ the}\)\.{\ file\ where\ to\ save\ }\)\.{the\ trans-\\n"}\.{"\ \ \ \ %
426 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ mitted\ optica}\)\.{l\ pulse\
427 shape.\ Whene}\)\.{ver\ this\\n"});{}$\6
428 ${}\\{fprintf}(\\{stderr},\39\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ %
429 \ \ \ \ \ \ option\ is\ not}\)\.{\ present\ at\ the\ comm}\)\.{and\ line,\\n"}%
430 \.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ the\ generated}\)%
431 \.{\ time\ series\ will\ be}\)\.{\ written\\n"}\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ %
432 \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ to\ standard\ t}\)\.{erminal\ output\ inste}\)%
433 \.{ad,\ in\\n"}\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \
434 which\ case\ an}\)\.{y\ set\ verbose\ mode\ w}\)\.{ill\ be\ turned\\n"}\.{"\ \ %
435 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ off\ (see\ -v\ o}\)%
436 \.{ption).\\n"});{}$\6
437 ${}\\{fprintf}(\\{stderr},\39\.{"\ \ -s,\ --sequential\ }\)\.{\ \ \ \ \ \ \
438 Toggle\ sequen}\)\.{tial\ mode.\ Default:\ }\)\.{off.\\n"}\.{"\ \ \ \ \ \ \ \ \
439 \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ When\ generati}\)\.{ng\ the\
440 Encapsulated\ }\)\.{PostScript,\\n"}\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }%
441 \)\.{\ \ \ \ \ \ \ in\ sequential}\)\.{\ mode,\ the\ data\\n"});{}$\6
442 ${}\\{fprintf}(\\{stderr},\39\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ %
443 \ \ \ \ \ \ is\ scanned\ co}\)\.{lumn/row-wise,\ with\ }\)\.{an\ individual%
444 \\n"}\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ pixel\
445 written}\)\.{\ for\ each\ data\ point}\)\.{\ of\ the\ input\\n"}\.{"\ \ \ \ \ \
446 \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ matrix.\ In\ th}\)\.{is\ mode\
447 the\ program\ }\)\.{will\ ignore\\n"}\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
448 }\)\.{\ \ \ \ \ \ \ any\ possibili}\)\.{ties\ of\ reducing\ the}\)\.{\ data\
449 through\\n"}\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ a\
450 more\ effici}\)\.{ent\ partitioning\ of\ }\)\.{the\ input\\n"}\.{"\ \ \ \ \ \ \
451 \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ matrix.\\n"});{}$\6
452 ${}\\{fprintf}(\\{stderr},\39\.{"\ \ -v,\ --verbose\ \ \ \ }\)\.{\ \ \ \ \ \ \
453 Toggle\ verbos}\)\.{e\ mode.\ If\ no\ output}\)\.{\ filename\ was\\n"}\.{"\ \ \
454 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ specified\ at\ }\)\.{the\
455 command\ line,\ ve}\)\.{rbose\ mode\\n"}\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
456 \ }\)\.{\ \ \ \ \ \ \ will\ automati}\)\.{cally\ be\ turned\ off,}\)\.{\ in\
457 order\ for\\n"}\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \
458 output\ messag}\)\.{es\ not\ to\ interfere\ }\)\.{with\ the\\n"}\.{"\ \ \ \ \ \
459 \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ \ \ generated\ Enc}\)\.{apsulated\
460 PostScript}\)\.{\ code.\\n"}\.{"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\)\.{\ \
461 \ \ \ \ \ Default:\ off\\}\)\.{n"});{}$\6
462 ${}\\{fprintf}(\\{stderr},\39\.{"\ \ -h,\ --help\ \ \ \ \ \ \ }\)\.{\ Display\
463 this\ help\ m}\)\.{essage\ and\ exit\ clea}\)\.{n\\n"});{}$\6
464 ${}\\{fprintf}(\\{stderr},\39\.{"Copyright\ (C)\ 2004\ }\)\.{Fredrik\ Jonsson\
465 <jon}\)\.{sson@uni-wuppertal.d}\)\.{e>\\n"});{}$\6
466 \4${}\}{}$\2\par
467 \U8.\fi
468
469 \M{10}The \PB{\\{dvector}(\,)} routine allocate a real-valued vector of double
470 precision,
471 with vector index ranging from \PB{\\{nl}} to \PB{\\{nh}}.
472
473 \Y\B\4\X10:Routine for allocation of double vectors\X${}\E{}$\6
474 \&{double} ${}{*}{}$\\{dvector}(\&{long} \\{nl}${},\39{}$\&{long} \\{nh})\1\1\2%
475 \2\6
476 ${}\{{}$\1\6
477 \&{double} ${}{*}\|v;{}$\7
478 ${}\|v\K{}$(\&{double} ${}{*}){}$ \\{malloc}${}((\&{size\_t})((\\{nh}-\\{nl}+%
479 \T{2})*\&{sizeof}(\&{double})));{}$\6
480 \&{if} ${}(\R\|v){}$\5
481 ${}\{{}$\1\6
482 ${}\\{fprintf}(\\{stderr},\39\.{"Error:\ Allocation\ f}\)\.{ailure\ in\
483 dvector()\\}\)\.{n"});{}$\6
484 \\{exit}(\.{FAILURE});\6
485 \4${}\}{}$\2\6
486 \&{return} \|v${}-\\{nl}+\T{1};{}$\6
487 \4${}\}{}$\2\par
488 \U8.\fi
489
490 \M{11}The \PB{\\{dmatrix}(\,)} routine allocate a real-valued matrix of double
491 precision,
492 with row index ranging from \PB{\\{nrl}} to \PB{\\{nrh}}, and column index
493 ranging from
494 \PB{\\{ncl}} to \PB{\\{nch}}.
495
496 \Y\B\4\X11:Routine for allocation of double matrices\X${}\E{}$\6
497 \&{double} ${}{*}{*}{}$\\{dmatrix}(\&{long} \\{nrl}${},\39{}$\&{long} %
498 \\{nrh}${},\39{}$\&{long} \\{ncl}${},\39{}$\&{long} \\{nch})\1\1\2\2\6
499 ${}\{{}$\1\6
500 \&{long} \|i${},{}$ \\{nrow}${}\K\\{nrh}-\\{nrl}+\T{1},{}$ \\{ncol}${}\K%
501 \\{nch}-\\{ncl}+\T{1};{}$\6
502 \&{double} ${}{*}{*}\|m;{}$\7
503 ${}\|m\K{}$(\&{double} ${}{*}{*}){}$ \\{malloc}${}((\&{size\_t})((\\{nrow}+%
504 \T{1})*{}$\&{sizeof}(\&{double} ${}{*})));{}$\6
505 \&{if} ${}(\R\|m){}$\5
506 ${}\{{}$\1\6
507 ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Allocation\ fail}\)\.{ure\ 1\ in\
508 dmatrix()\ r}\)\.{outine!\\n"},\39\\{progname});{}$\6
509 \\{exit}(\.{FAILURE});\6
510 \4${}\}{}$\2\6
511 ${}\|m\MRL{+{\K}}\T{1};{}$\6
512 ${}\|m\MRL{-{\K}}\\{nrl};{}$\6
513 ${}\|m[\\{nrl}]\K{}$(\&{double} ${}{*}){}$ \\{malloc}${}((\&{size\_t})((%
514 \\{nrow}*\\{ncol}+\T{1})*\&{sizeof}(\&{double})));{}$\6
515 \&{if} ${}(\R\|m[\\{nrl}]){}$\5
516 ${}\{{}$\1\6
517 ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Allocation\ fail}\)\.{ure\ 2\ in\
518 dmatrix()\ r}\)\.{outine!\\n"},\39\\{progname});{}$\6
519 \\{exit}(\.{FAILURE});\6
520 \4${}\}{}$\2\6
521 ${}\|m[\\{nrl}]\MRL{+{\K}}\T{1};{}$\6
522 ${}\|m[\\{nrl}]\MRL{-{\K}}\\{ncl};{}$\6
523 \&{for} ${}(\|i\K\\{nrl}+\T{1};{}$ ${}\|i\Z\\{nrh};{}$ ${}\|i\PP){}$\1\5
524 ${}\|m[\|i]\K\|m[\|i-\T{1}]+\\{ncol};{}$\2\6
525 \&{return} \|m;\6
526 \4${}\}{}$\2\par
527 \U8.\fi
528
529 \M{12}The \PB{\\{free\_dvector}(\,)} routine release the memory occupied by the
530 real-valued vector \PB{$\|v[\\{nl}\MRL{{.}{.}}\\{nh}]$}.
531
532 \Y\B\4\X12:Routine for deallocation of double vectors\X${}\E{}$\6
533 \&{void} \\{free\_dvector}(\&{double} ${}{*}\|v,\39{}$\&{long} \\{nl}${},\39{}$%
534 \&{long} \\{nh})\1\1\2\2\6
535 ${}\{{}$\1\6
536 \\{free}((\&{char} ${}{*})(\|v+\\{nl}-\T{1}));{}$\6
537 \4${}\}{}$\2\par
538 \U8.\fi
539
540 \M{13}The \PB{\\{free\_dmatrix}(\,)} routine release the memory occupied by the
541 real-valued matrix \PB{$\|m[\\{nrl}\MRL{{.}{.}}\\{nrh}][\\{ncl}\MRL{{.}{.}}%
542 \\{nch}]$}.
543
544 \Y\B\4\X13:Routine for deallocation of double matrices\X${}\E{}$\6
545 \&{void} \\{free\_dmatrix}(\&{double} ${}{*}{*}\|m,\39{}$\&{long} \\{nrl}${},%
546 \39{}$\&{long} \\{nrh}${},\39{}$\&{long} \\{ncl}${},\39{}$\&{long} \\{nch})\1\1%
547 \2\2\6
548 ${}\{{}$\1\6
549 \\{free}((\&{char} ${}{*})(\|m[\\{nrl}]+\\{ncl}-\T{1}));{}$\6
550 \\{free}((\&{char} ${}{*})(\|m+\\{nrl}-\T{1}));{}$\6
551 \4${}\}{}$\2\par
552 \U8.\fi
553
554 \M{14}The \PB{\\{load\_matrix}(\,)} routine takes as input a character string
555 \PB{\\{inputfilename}}, specifying a regular text file of ASCII data stored
556 as a matrix, and returns a pointer \PB{\|m} to a matrix of double precision,
557 containing the numerical values as appearing if the text file.
558 The routine also automatically scans the input matrix size, and returns the
559 number of rows in \PB{\\{nr}} and the number of columns in \PB{\\{nc}}.
560 The number of columns is determined as the number of elements in the first
561 row of data of the supplied text file. All subsequent rows are assumed to
562 contain exactly the same number of elements; if this is not the case, an
563 error message will be displayed on standard terminal output.
564 The minimum and maximum elements found in the matrix are returned in the
565 variables \PB{\\{min}} and \PB{\\{max}}, respectively.
566
567 Example of usage:
568 \medskip
569 {\obeyspaces\obeylines\tt
570 ~ double **imagematrix,min,max;
571 ~ long int nr,nc;
572 ~ imagematrix=load\_matrix("image.dat",\&nr,\&nc,\&min,\&max);
573 ~ fprintf(stdout,"Detected \%ld rows and \%ld columns of data.\\n",nr,nc);
574 ~ fprintf(stdout,"Minimum element: \%f\\n",min);
575 ~ fprintf(stdout,"Maximum element: \%f\\n",max);
576 }
577 \bigskip
578
579 \Y\B\4\X14:Routine for loading matrix data from text file\X${}\E{}$\6
580 \&{char} \\{validchar}(\&{char} \\{ch})\1\1\2\2\6
581 ${}\{{}$\1\6
582 \&{return} ${}(\\{isalnum}(\\{ch})\V(\\{ch}\E\.{'+'})\V(\\{ch}\E\.{'-'})\V(%
583 \\{ch}\E\.{'.'}));{}$\6
584 \4${}\}{}$\2\7
585 \&{double} ${}{*}{*}{}$\\{load\_matrix}(\&{char} \\{inputfilename}[\,]${},%
586 \39{}$\&{long} ${}{*}\\{nr},\39{}$\&{long} ${}{*}\\{nc},\39{}$\&{double} ${}{*}%
587 \\{min},\39{}$\&{double} ${}{*}\\{max}){}$\1\1\2\2\6
588 ${}\{{}$\1\6
589 \&{FILE} ${}{*}\\{fpin}\K\NULL;{}$\6
590 \&{char} \\{tmpch};\6
591 \&{long} \|j${},{}$ \|k${},{}$ \\{nrt}${},{}$ \\{nct};\6
592 \&{double} \\{tmpd}${},{}$ ${}{*}{*}\|m,{}$ \\{tmin}${},{}$ \\{tmax};\7
593 \&{if} ${}((\\{fpin}\K\\{fopen}(\\{inputfilename},\39\.{"r"}))\E\NULL){}$\5
594 ${}\{{}$\1\6
595 ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Could\ not\ open\ }\)\.{file\ \%s\ for\
596 reading!}\)\.{\\n"},\39\\{progname},\39\\{inputfilename});{}$\6
597 \\{exit}(\.{FAILURE});\6
598 \4${}\}{}$\2\6
599 ${}\\{fseek}(\\{fpin},\39\T{0\$L},\39\.{SEEK\_SET});{}$\6
600 ${}\\{fscanf}(\\{fpin},\39\.{"\%lf"},\39{\AND}\\{tmpd});{}$\6
601 ${}\\{tmin}\K\\{tmpd}{}$;\C{ initialize memory for minimum element }\6
602 ${}\\{tmax}\K\\{tmpd}{}$;\C{ initialize memory for maximum element }\6
603 ${}\\{fseek}(\\{fpin},\39\T{0\$L},\39\.{SEEK\_SET});{}$\6
604 ${}\\{nct}\K\T{0}{}$;\C{ initialize column counter }\6
605 \&{while} ${}((\\{tmpch}\K\\{getc}(\\{fpin}))\I\.{'\\n'}){}$\5
606 ${}\{{}$\C{ determine column size \PB{\\{nc}} }\1\6
607 ${}\\{ungetc}(\\{tmpch},\39\\{fpin});{}$\6
608 \&{while} ${}((\\{tmpch}\K\\{getc}(\\{fpin}))\E\.{'\ '}){}$\1\5
609 ;\C{ get rid of any leading blanks }\2\6
610 ${}\\{ungetc}(\\{tmpch},\39\\{fpin});{}$\6
611 \&{while} ${}(\\{validchar}(\\{tmpch}\K\\{getc}(\\{fpin}))){}$\1\5
612 ;\C{ scan pass field for valid char }\2\6
613 ${}\\{ungetc}(\\{tmpch},\39\\{fpin});{}$\6
614 ${}\\{nct}\PP;{}$\6
615 \&{while} ${}((\\{tmpch}\K\\{getc}(\\{fpin}))\E\.{'\ '}){}$\1\5
616 ;\C{ get read of any trailing blanks }\2\6
617 ${}\\{ungetc}(\\{tmpch},\39\\{fpin});{}$\6
618 \4${}\}{}$\2\6
619 ${}\\{fseek}(\\{fpin},\39\T{0\$L},\39\.{SEEK\_SET});{}$\6
620 ${}\\{nrt}\K\T{0}{}$;\C{ initialize row counter }\6
621 \&{while} ${}((\\{tmpch}\K\\{getc}(\\{fpin}))\I\.{EOF}){}$\5
622 ${}\{{}$\C{ determine row size \PB{\\{nr}} }\1\6
623 ${}\\{ungetc}(\\{tmpch},\39\\{fpin});{}$\6
624 \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\\{nct};{}$ ${}\|k\PP){}$\1\5
625 ${}\\{fscanf}(\\{fpin},\39\.{"\%lf"},\39{\AND}\\{tmpd});{}$\2\6
626 ${}\\{nrt}\PP;{}$\6
627 ${}\\{tmpch}\K\\{getc}(\\{fpin});{}$\6
628 \&{while} ${}((\\{tmpch}\E\.{'\ '})\V(\\{tmpch}\E\.{'\\n'})){}$\1\5
629 ${}\\{tmpch}\K\\{getc}(\\{fpin});{}$\2\6
630 \&{if} ${}(\\{tmpch}\I\.{EOF}){}$\1\5
631 ${}\\{ungetc}(\\{tmpch},\39\\{fpin});{}$\2\6
632 \4${}\}{}$\2\6
633 ${}\|m\K\\{dmatrix}(\T{1},\39\\{nrt},\39\T{1},\39\\{nct});{}$\6
634 ${}\\{fseek}(\\{fpin},\39\T{0\$L},\39\.{SEEK\_SET});{}$\6
635 \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nrt};{}$ ${}\|j\PP){}$\5
636 ${}\{{}$\C{ for all rows, ... }\1\6
637 \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\\{nct};{}$ ${}\|k\PP){}$\5
638 ${}\{{}$\C{ and for all columns, ... }\1\6
639 ${}\\{fscanf}(\\{fpin},\39\.{"\%lf"},\39{\AND}\\{tmpd});{}$\6
640 ${}\|m[\|j][\|k]\K\\{tmpd};{}$\6
641 \&{if} ${}(\\{tmpd}<\\{tmin}){}$\1\5
642 ${}\\{tmin}\K\\{tmpd};{}$\2\6
643 \&{else} \&{if} ${}(\\{tmpd}>\\{tmax}){}$\1\5
644 ${}\\{tmax}\K\\{tmpd};{}$\2\6
645 \4${}\}{}$\2\6
646 \4${}\}{}$\2\6
647 \\{fclose}(\\{fpin});\6
648 ${}{*}\\{nr}\K\\{nrt};{}$\6
649 ${}{*}\\{nc}\K\\{nct};{}$\6
650 ${}{*}\\{min}\K\\{tmin};{}$\6
651 ${}{*}\\{max}\K\\{tmax};{}$\6
652 \&{return} \|m;\6
653 \4${}\}{}$\2\par
654 \U8.\fi
655
656 \M{15}The \PB{\\{unload\_matrix}(\,)} routine simply releases memory previously
657 allocated
658 by the \PB{\\{load\_matrix}(\,)} routine.
659
660 \Y\B\4\X15:Routine for unloading matrix data previously loaded from text file%
661 \X${}\E{}$\6
662 \&{void} \\{unload\_matrix}(\&{double} ${}{*}{*}\|m,\39{}$\&{long} \\{nr}${},%
663 \39{}$\&{long} \\{nc})\1\1\2\2\6
664 ${}\{{}$\1\6
665 ${}\\{free\_dmatrix}(\|m,\39\T{1},\39\\{nr},\39\T{1},\39\\{nc}){}$;\C{ yes, it
666 is this simple... }\6
667 \4${}\}{}$\2\par
668 \U8.\fi
669
670 \N{1}{16}Declaration of local variables of the \PB{\\{main}} program.
671
672 \Y\B\4\X16:Local variables\X${}\E{}$\6
673 \&{double} ${}{*}{*}\\{imagematrix},{}$ \\{min}${},{}$ \\{max}${},{}$ %
674 \\{dx}${},{}$ \\{dy}${},{}$ \\{llx}${},{}$ \\{lly}${},{}$ \\{urx}${},{}$ %
675 \\{ury};\6
676 \&{double} \\{imagewidth}${},{}$ \\{imageheight}${},{}$ \\{imagexcenter}${},{}$
677 \\{imageycenter};\6
678 \&{double} \\{linethickness}${}\K\.{DEFAULT\_LINETHICKNESS};{}$\6
679 \&{time\_t} \\{now}${}\K\\{time}(\NULL);{}$\6
680 \&{long} \&{int} \|j${},{}$ \|k${},{}$ \\{nr}${},{}$ \\{nc};\6
681 \&{int} \\{no\_arg}${},{}$ \\{bbllx}${},{}$ \\{bblly}${},{}$ \\{bburx}${},{}$ %
682 \\{bbury};\6
683 \&{FILE} ${}{*}\\{fpout}\K\NULL;{}$\6
684 \&{char} \\{inputfilename}[\T{256}]${}\K\.{""},{}$ \\{outputfilename}[%
685 \T{256}]${}\K\.{""};{}$\6
686 \&{short} \\{verbose}${}\K\T{0},{}$ \\{write\_floatform}${}\K\T{0},{}$ \\{write%
687 \_frame}${}\K\T{1};{}$\6
688 \&{short} \\{infile\_specified}${}\K\T{0},{}$ \\{outfile\_specified}${}\K%
689 \T{0},{}$ \\{parse\_data\_sequentially}${}\K\T{1};{}$\6
690 \&{short} \\{write\_title}${}\K\T{0};{}$\6
691 \&{short} \\{pixel\_generation\_mode}${}\K\.{COMPACTIFIED\_PIXELCODE};{}$\6
692 \&{short} \\{comments\_in\_postscript}${}\K\T{1}{}$;\par
693 \U6.\fi
694
695 \N{1}{17}Parsing command line options. All input parameters are passed to the
696 program through command line options and arguments to the program.
697 The syntax of command line options is listed
698 whenever the program is invoked without any options, or if the {\tt --help}
699 option is specified at startup.
700
701 \Y\B\4\X17:Parse command line\X${}\E{}$\6
702 ${}\{{}$\1\6
703 ${}\\{progname}\K\\{argv}[\T{0}];{}$\6
704 ${}\\{no\_arg}\K\\{argc};{}$\6
705 \&{while} ${}(\MM\\{argc}){}$\5
706 ${}\{{}$\1\6
707 \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-o"})\V\R%
708 \\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--outputfile"})){}$\5
709 ${}\{{}$\1\6
710 ${}\MM\\{argc};{}$\6
711 ${}\\{strcpy}(\\{outputfilename},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
712 ${}\\{outfile\_specified}\K\T{1};{}$\6
713 \4${}\}{}$\2\6
714 \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-i"})\V%
715 \R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--inputfile"})){}$\5
716 ${}\{{}$\1\6
717 ${}\MM\\{argc};{}$\6
718 ${}\\{strcpy}(\\{inputfilename},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
719 ${}\\{infile\_specified}\K\T{1};{}$\6
720 \4${}\}{}$\2\6
721 \&{else} \&{if} ${}((\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-f"}))%
722 \V(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--floatform"}))){}$\5
723 ${}\{{}$\1\6
724 ${}\\{write\_floatform}\K(\\{write\_floatform}\?\T{0}:\T{1});{}$\6
725 \&{if} (\\{verbose})\1\5
726 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Using\ floating\ }\)\.{number\ output.%
727 \\n"},\39\\{progname});{}$\2\6
728 \4${}\}{}$\2\6
729 \&{else} \&{if} ${}((\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-r"}))%
730 \V(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--writeframe"}))){}$\5
731 ${}\{{}$\1\6
732 ${}\\{write\_frame}\K(\\{write\_frame}\?\T{0}:\T{1});{}$\6
733 \4${}\}{}$\2\6
734 \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
735 \.{"--commmented\_postsc}\)\.{ript"})){}$\5
736 ${}\{{}$\1\6
737 ${}\\{comments\_in\_postscript}\K\T{1};{}$\6
738 \4${}\}{}$\2\6
739 \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
740 \.{"--uncommmented\_post}\)\.{script"})){}$\5
741 ${}\{{}$\1\6
742 ${}\\{comments\_in\_postscript}\K\T{0};{}$\6
743 \4${}\}{}$\2\6
744 \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
745 \.{"--compactified\_pixe}\)\.{lcode"})){}$\5
746 ${}\{{}$\1\6
747 ${}\\{pixel\_generation\_mode}\K\.{COMPACTIFIED\_PIXELCODE};{}$\6
748 \4${}\}{}$\2\6
749 \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
750 \.{"--extensive\_pixelco}\)\.{de"})){}$\5
751 ${}\{{}$\1\6
752 ${}\\{pixel\_generation\_mode}\K\.{EXTENSIVE\_PIXELCODE};{}$\6
753 \4${}\}{}$\2\6
754 \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-v"})\V%
755 \R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--verbose"})){}$\5
756 ${}\{{}$\1\6
757 ${}\\{verbose}\K(\\{verbose}\?\T{0}:\T{1});{}$\6
758 \4${}\}{}$\2\6
759 \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-s"})\V%
760 \R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--sequential"})){}$\5
761 ${}\{{}$\1\6
762 ${}\\{parse\_data\_sequentially}\K(\\{parse\_data\_sequentially}\?\T{0}:%
763 \T{1});{}$\6
764 \4${}\}{}$\2\6
765 \&{else}\5
766 ${}\{{}$\1\6
767 ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Unknown\ option\ }\)\.{'\%s'.\\n"},\39%
768 \\{progname},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
769 \\{exit}(\.{FAILURE});\6
770 \4${}\}{}$\2\6
771 \4${}\}{}$\2\6
772 \&{if} ${}(\R\\{outfile\_specified}){}$\1\5
773 ${}\\{verbose}\K\T{0}{}$;\C{ terminal output EPS should be clean }\2\6
774 \4${}\}{}$\2\par
775 \U6.\fi
776
777 \N{1}{18}Opening and closing files for data output.
778
779 \fi
780
781 \M{19}Open files for reading and writing.
782
783 \Y\B\4\X19:Open files\X${}\E{}$\6
784 ${}\{{}$\1\6
785 \&{if} (\\{outfile\_specified})\5
786 ${}\{{}$\1\6
787 \&{if} ${}((\\{fpout}\K\\{fopen}(\\{outputfilename},\39\.{"w"}))\E\NULL){}$\5
788 ${}\{{}$\1\6
789 ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Could\ not\ open\ }\)\.{file\ \%s\ for\
790 writing!}\)\.{\\n"},\39\\{progname},\39\\{outputfilename});{}$\6
791 \\{exit}(\.{FAILURE});\6
792 \4${}\}{}$\2\6
793 ${}\\{fseek}(\\{fpout},\39\T{0\$L},\39\.{SEEK\_SET});{}$\6
794 \4${}\}{}$\2\6
795 \&{else}\5
796 ${}\{{}$\1\6
797 \&{if} (\\{verbose})\1\5
798 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ No\ output\ file\ }\)\.{specified.\
799 (Writing\ }\)\.{to\ stdout).\\n"},\39\\{progname});{}$\2\6
800 \4${}\}{}$\2\6
801 \4${}\}{}$\2\par
802 \U6.\fi
803
804 \M{20}Loading the text file into memory. In this first step, the specified
805 input
806 text file is opened, and is loaded into memory allocated by the \PB{%
807 \\{dmatrix}}
808 routine. The memory area is accessed via the pointer \PB{${*}{*}%
809 \\{imagematrix}$}, which
810 is the basic variable used later on by the blocks that write the Encapsulated
811 PostScript image to file. After the data is loaded, the input file is closed.
812
813 \Y\B\4\X20:Load text file into image matrix\X${}\E{}$\6
814 ${}\{{}$\1\6
815 \&{if} (\\{infile\_specified})\5
816 ${}\{{}$\1\6
817 \&{if} (\\{verbose})\1\5
818 ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Loading\ data\ fr}\)\.{om\ file\ \%s.%
819 \\n"},\39\\{progname},\39\\{inputfilename});{}$\2\6
820 ${}\\{imagematrix}\K\\{load\_matrix}(\\{inputfilename},\39{\AND}\\{nr},\39{%
821 \AND}\\{nc},\39{\AND}\\{min},\39{\AND}\\{max});{}$\6
822 \&{if} (\\{verbose})\5
823 ${}\{{}$\1\6
824 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Detected\ \%ld\ ro}\)\.{ws\ and\ \%ld\
825 columns\ o}\)\.{f\ data\ in\ file\ '\%s'.}\)\.{\\n"},\39\\{progname},\39\\{nr},%
826 \39\\{nc},\39\\{inputfilename});{}$\6
827 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Maximum\ element}\)\.{\ in\ '\%s':\ \%f%
828 \\n"},\39\\{progname},\39\\{inputfilename},\39\\{max});{}$\6
829 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Minimum\ element}\)\.{\ in\ '\%s':\ \%f%
830 \\n"},\39\\{progname},\39\\{inputfilename},\39\\{min});{}$\6
831 \4${}\}{}$\2\6
832 \4${}\}{}$\2\6
833 \&{else}\5
834 ${}\{{}$\1\6
835 ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error:\ Specify\ }\)\.{an\ input\
836 filename.\\n}\)\.{"},\39\\{progname});{}$\6
837 \\{showsomehelp}(\,);\6
838 \\{exit}(\.{FAILURE});\6
839 \4${}\}{}$\2\6
840 \4${}\}{}$\2\par
841 \U6.\fi
842
843 \M{21}Normalize the image matrix. In order to write a properly scaled
844 Encapsulated
845 PostScript image to file, the loaded data need to be normalized, so that the
846 elements arenumerical values between 0 and 1.
847
848 \Y\B\4\X21:Normalize image matrix\X${}\E{}$\6
849 ${}\{{}$\1\6
850 \&{if} (\\{verbose})\1\5
851 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Normalizing\ ima}\)\.{ge\ matrix.\\n"},%
852 \39\\{progname});{}$\2\6
853 \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nr};{}$ ${}\|j\PP){}$\5
854 ${}\{{}$\C{ for all rows, ... }\1\6
855 \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\\{nc};{}$ ${}\|k\PP){}$\5
856 ${}\{{}$\C{ and for all columns, ... }\1\6
857 ${}\\{imagematrix}[\|j][\|k]\K\\{imagematrix}[\|j][\|k]-\\{min};{}$\6
858 ${}\\{imagematrix}[\|j][\|k]\K\\{imagematrix}[\|j][\|k]/(\\{max}-\\{min});{}$\6
859 \4${}\}{}$\2\6
860 \4${}\}{}$\2\6
861 \4${}\}{}$\2\par
862 \U6.\fi
863
864 \M{22}Initialize the parameters to be used for the Encapsulated PostScript
865 image.
866 The parameters to be set prior to the calculation of positioning of the
867 individual pixels of the image are the corner coordinates for the bounding box.
868 The $x$-height and $y$-width of the image are generally scaled such that
869 the aspect ratio of the image is left invariant under scaling of any of the
870 coordinate axes.
871
872 By default, the program will use the width as reference for scaling the height
873 of the image, to give an aspect ratio (height/width) that leaves the individual
874 pixels as squares. If, however, the program finds that the calculated image
875 height exceed the maximum allowed, then the height will be fixed to its maximum
876 value, instead scaling the width of the image (to still give an equal aspect
877 ratio).
878
879 The values here used for the maximum extents of the picture are based on that
880 for an A4 paper, the limiting bounding box is between the lower left corner
881 at~$(0,0)$ pt and upper right corner at~$(594,841)$ pt.
882
883 \bigskip
884 \centerline{\epsfxsize=114.58mm\epsfbox{pagelayt/pagelayt.1}}\medskip\nobreak
885 \centerline{Figure 2. The page layout and definitions as used for the
886 initialization of the Encapsulated PostScript image.}
887
888
889 \Y\B\4\X22:Initialize parameters of Encapsulated PostScript image\X${}\E{}$\6
890 ${}\{{}$\1\6
891 ${}\\{imagewidth}\K((\&{double})(\.{DEFAULT\_IMAGE\_WIDTH}));{}$\6
892 ${}\\{imageheight}\K{}$(((\&{double}) \\{nr})${}/{}$((\&{double}) %
893 \\{nc}))${}*((\&{double})(\.{DEFAULT\_IMAGE\_WIDTH}));{}$\6
894 ${}\\{imagexcenter}\K\.{DEFAULT\_IMAGE\_XCENTER};{}$\6
895 ${}\\{imageycenter}\K\.{DEFAULT\_IMAGE\_YCENTER};{}$\6
896 \&{if} ${}(\\{imageheight}>\.{MAXIMUM\_IMAGE\_HEIGHT}){}$\5
897 ${}\{{}$\1\6
898 \&{if} (\\{verbose})\5
899 ${}\{{}$\1\6
900 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Warning.\ I\ foun}\)\.{d\ that\ the\
901 height\ of}\)\.{\ "},\39\\{progname});{}$\6
902 ${}\\{fprintf}(\\{stdout},\39\.{"the\ image\ exceeds\ i}\)\.{ts\ maximum%
903 \\n"});{}$\6
904 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ value\ of\ \%d\ pt.}\)\.{\\n"},\39%
905 \\{progname},\39{}$((\&{int}) \.{MAXIMUM\_IMAGE\_HEIGHT}));\6
906 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Will\ now\ instea}\)\.{d\ scale\ the\
907 width\ of}\)\.{\ the\ image.\\n"},\39\\{progname});{}$\6
908 \4${}\}{}$\2\6
909 ${}\\{imageheight}\K\.{MAXIMUM\_IMAGE\_HEIGHT};{}$\6
910 ${}\\{imagewidth}\K{}$(((\&{double}) \\{nc})${}/{}$((\&{double}) \\{nr}))${}*%
911 \\{imageheight};{}$\6
912 \4${}\}{}$\2\6
913 \&{else}\5
914 ${}\{{}$\1\6
915 \&{if} (\\{verbose})\5
916 ${}\{{}$\1\6
917 ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Image\ height\ au}\)\.{tomatically\
918 scaled\ t}\)\.{o\ "},\39\\{progname});{}$\6
919 ${}\\{fprintf}(\\{stdout},\39\.{"width\ (to\ give\ equa}\)\.{l\ aspect\ ratio).%
920 \\n"});{}$\6
921 \4${}\}{}$\2\6
922 \4${}\}{}$\2\6
923 ${}\\{bbllx}\K\\{imagexcenter}-\\{imagewidth}/\T{2.0};{}$\6
924 ${}\\{bblly}\K\\{imageycenter}-\\{imageheight}/\T{2.0};{}$\6
925 ${}\\{bburx}\K\\{imagexcenter}+\\{imagewidth}/\T{2.0};{}$\6
926 ${}\\{bbury}\K\\{imageycenter}+\\{imageheight}/\T{2.0};{}$\6
927 \4${}\}{}$\2\par
928 \U6.\fi
929
930 \M{23}Write the leading blocks of Encapsulated PostScript code.
931 If the flag \PB{\\{pixel\_generation\_mode}} is set to \PB{\.{COMPACTIFIED}%
932 \.{PIXELCODE}}, then
933 an additional routine for the generation of the individual pixels will be
934 added just after the comments in the preamble; otherwise, the generated code
935 will be self-contained in the sense that the individual pixels are defined
936 as free-standing drawing statements in the code.
937 Notice that the type of output stream (terminal output or file pointer,
938 depending on the options present at the command line at startup of the
939 program) is determined by the current definition provided by \PB{%
940 \.{OUTSTREAM}}.
941 Notice that the string returned by the \PB{\\{ctime}(\,)} routine ends with a
942 linefeeed.
943
944 The blocks dealing with the definition of the PostScript routine for a
945 more ``compactified'' output code clearly deserves some more detailed
946 description.
947 The syntax for drawing an individual pixel, determined by the bounding box
948 given by its lower left and upper right corners $(x_{\rm ll},y_{\rm ll})$
949 and $(x_{\rm ur},y_{\rm ur})$ is\par\medskip
950 {\narrower\narrower{\tt /drawpixel} $\langle\PB{\\{llx}}\rangle$ $\langle\PB{%
951 \\{lly}}\rangle$
952 $\langle\PB{\\{urx}}\rangle$ $\langle\PB{\\{ury}}\rangle$ $\langle\PB{\|w}%
953 \rangle$,\par}
954 \medskip\noindent
955 where $\PB{\\{llx}}=x_{\rm ll}$, $\PB{\\{lly}}=y_{\rm ll}$,
956 $\PB{\\{urx}}=x_{\rm ur}$, and $\PB{\\{ury}}=y_{\rm ur}$.
957 This definition is illustrated in Fig.~3 below.
958 In this description of the syntax, $\PB{\|w}\in[0,1]$ is the whiteness value of
959 the pixel, with 0 corresponding to black, and 1 corresponding to white.
960 \bigskip
961 \centerline{\epsfxsize=45.0mm\epsfbox{pixbb/pixbb.1}}\medskip\nobreak
962 \centerline{Figure 3. Illustration of the definition of a pixel in terms
963 of its lower left and upper right corners.}
964 \bigskip
965 In the PostScript routine {\tt /drawpixel}, the following commands of the
966 PostScript languange are used for manipulation of the stack:
967 \medskip
968 \oitem[{\tt dup}]{Duplicates the bottom element in the stack, and then pushes
969 it into the stack. This operation is similar to the ENTER as used in reverse
970 polish notation employed in, for example, Hewlett--Packard calculators.}
971
972 \oitem[{\tt exch}]{Interchanges the two bottom-most elements in the stack.
973 This operation is identical to SWAP.}
974
975 \oitem[$\langle m\rangle$ $\langle n\rangle$ {\tt roll}]{Rolls down the~$m$
976 bottom-most elements of the stack $n$ times, that is to say, applying cyclic
977 permutation $n$ times on the first $m$ elements.
978 In analogy with the ROLLD operation of reverse polish notation of
979 Hewlett--Packard calculators, this is identical to executing the operation
980 ``$m$ ROLLD'' exactly $n$ times.
981 Notice that $\langle m\rangle$ $\langle m\rangle$ {\tt roll} always just gives
982 the identity operation on the stack for arbitrary $m$ (of course provided
983 that~$m$ is not greater than the number of elements that currently are present
984 in the stack).
985
986 \Y\B\4\X23:Write preamble of Encapsulated PostScript image\X${}\E{}$\6
987 ${}\{{}$\1\6
988 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%!PS-Adobe-2.0\ EPS}\)\.{F-1.2\\n"});{}$%
989 \6
990 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%BoundingBox:\ \%d}\)\.{\ \%d\ \%d\ %
991 \%d\\n"},\39\\{bbllx},\39\\{bblly},\39\\{bburx},\39\\{bbury});{}$\6
992 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%Creator:\ epsimg}\)\.{\ \%s"},\39%
993 \.{VERSION\_NUMBER});{}$\6
994 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ Copyright\ (C)\ 2004}\)\.{\ Fredrik\
995 Jonsson\\n"});{}$\6
996 \&{if} (\\{outfile\_specified})\1\5
997 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%Title:\ \%s\\n"},\39%
998 \\{outputfilename});{}$\2\6
999 \&{else}\1\5
1000 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%Title:\ (image\ w}\)\.{ritten\ to\
1001 stdout)\\n"});{}$\2\6
1002 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%CreationDate:\ \%}\)\.{s"},\39%
1003 \\{ctime}({\AND}\\{now}));{}$\6
1004 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%Pages:\ 1\\n"});{}$\6
1005 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%EndProlog\\n"});{}$\6
1006 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%Pages:\ 1\\n"});{}$\6
1007 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%Page:\ 1\ 1\\n"});{}$\6
1008 \&{if} ${}(\\{pixel\_generation\_mode}\E\.{COMPACTIFIED\_PIXELCODE}){}$\5
1009 ${}\{{}$\1\6
1010 \&{if} (\\{comments\_in\_postscript})\5
1011 ${}\{{}$\1\6
1012 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\\n"});{}$\6
1013 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\ Routine\ for\ dupl}\)\.{icating\ the\
1014 bottom-m}\)\.{ost\ pair"});{}$\6
1015 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ of\ elements\ in\ the}\)\.{\
1016 stack."});{}$\6
1017 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\\n"});{}$\6
1018 \4${}\}{}$\2\6
1019 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"/dupc\ \{dup\ 3\ 2\ roll}\)\.{\ dup\ 4\ 1\
1020 roll\ exch\}\ }\)\.{bind\ def"});{}$\6
1021 \&{if} (\\{comments\_in\_postscript})\5
1022 ${}\{{}$\1\6
1023 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\\n"});{}$\6
1024 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\ Routine\ for\ calc}\)\.{ulating\ the\
1025 lower\ ri}\)\.{ght\ corner"});{}$\6
1026 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ coordinates\ of\ the}\)\.{\ pixel.%
1027 \\n"});{}$\6
1028 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\ The\ syntax\ is\ si}\)\.{mply\ '<llx>%
1029 \ <lly>\ <u}\)\.{rx>\ <ury>\ "});{}$\6
1030 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ lrc',\ where\ (<llx>}\)\.{,<lly>)%
1031 \\n"});{}$\6
1032 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\ and\ (<urx>,<ury>}\)\.{)\ are\
1033 the"});{}$\6
1034 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ lower\ left\ and\ upp}\)\.{er\ right\
1035 corner\ coor}\)\.{dinates\\n"});{}$\6
1036 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\ of\ the\ pixel.\ Th}\)\.{e\ resulting%
1037 \ (<lrx>,<}\)\.{lry>)\ pair"});{}$\6
1038 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ are\ after\ the\ calc}\)\.{ulation\\n\%\%%
1039 \ pushed\ o}\)\.{nto\ the"});{}$\6
1040 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ stack,\ preserving\ }\)\.{the\ previously%
1041 \ prese}\)\.{nt\ stack"});{}$\6
1042 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ at\ above\\n\%\%\ level}\)\.{s.\\n"});{}$%
1043 \6
1044 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\\n"});{}$\6
1045 \4${}\}{}$\2\6
1046 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"/lrc\ \{4\ 1\ roll\ dup\ }\)\.{5\ 2\ roll\
1047 dup\ 5\ -1\ ro}\)\.{ll\ exch"});{}$\6
1048 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ 4\ 2\ roll\ 6\ 2\ roll\}}\)\.{\ bind\ def%
1049 \\n"});{}$\6
1050 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"/ulc\ \{4\ 3\ roll\ dup\ }\)\.{5\ 2\ roll\
1051 dup\ 6\ -1\ ro}\)\.{ll\ exch\}"});{}$\6
1052 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ bind\ def\\n"});{}$\6
1053 \&{if} (\\{comments\_in\_postscript})\5
1054 ${}\{{}$\1\6
1055 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\\n"});{}$\6
1056 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\ Routine\ for\ draw}\)\.{ing\
1057 individual\ pixel}\)\.{s\\n"});{}$\6
1058 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\\n"});{}$\6
1059 \4${}\}{}$\2\6
1060 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"/pixelstack\ \{lrc\ 6\ }\)\.{2\ roll\ ulc\
1061 4\ 2\ roll\ }\)\.{8\ 4\ roll"});{}$\6
1062 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ dupc\ 10\ 2\ roll\}\ bi}\)\.{nd\ def%
1063 \\n"});{}$\6
1064 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"/drawpixel\ \{setgray}\)\.{\ pixelstack\
1065 newpath\ }\)\.{moveto\ lineto\\n"});{}$\6
1066 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ lineto\ lineto\ line}\)\.{to\ closepath\
1067 fill\}\ b}\)\.{ind\ def\\n"});{}$\6
1068 \&{if} (\\{comments\_in\_postscript})\5
1069 ${}\{{}$\1\6
1070 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\\n"});{}$\6
1071 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\ The\ dp\ routine\ i}\)\.{s\
1072 short-hand\ for\ dra}\)\.{wpixel\\n"});{}$\6
1073 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\\n"});{}$\6
1074 \4${}\}{}$\2\6
1075 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"/dp\ \{drawpixel\}\ bin}\)\.{d\ def%
1076 \\n"});{}$\6
1077 \4${}\}{}$\2\6
1078 \4${}\}{}$\2\par
1079 \U6.\fi
1080
1081 \M{24}Write the body of Encapsulated PostScript code.
1082
1083 \Y\B\4\X24:Write body of Encapsulated PostScript image\X${}\E{}$\6
1084 ${}\{{}$\1\6
1085 \&{if} (\\{parse\_data\_sequentially})\5
1086 ${}\{{}$\1\6
1087 \X25:Write body of sequential Encapsulated PostScript image\X\6
1088 \4${}\}{}$\2\6
1089 \&{else}\5
1090 ${}\{{}$\1\6
1091 \X26:Write body of partitioned Encapsulated PostScript image\X\6
1092 \4${}\}{}$\2\6
1093 \4${}\}{}$\2\par
1094 \U6.\fi
1095
1096 \M{25}Write sequential body of Encapsulated PostScript code.
1097 The {\tt moveto} sets the current starting point of each pixel.
1098 The path of the boundary of each pixel is traversed in counter-clockwise
1099 direction, starting in the lower left corner of each pixel.
1100 Here \PB{$(\\{llx},\\{lly})$} give the $(x,y)$-coordinates of the lower left
1101 corner of
1102 the pixel, while \PB{$(\\{urx},\\{ury})$} give the $(x,y)$-coordinates of the
1103 upper right
1104 corner.
1105
1106 \Y\B\4\X25:Write body of sequential Encapsulated PostScript image\X${}\E{}$\6
1107 ${}\{{}$\1\6
1108 ${}\\{dx}\K((\&{double})(\\{bburx}-\\{bbllx}))/{}$((\&{double}) \\{nc});\6
1109 ${}\\{dy}\K((\&{double})(\\{bbury}-\\{bblly}))/{}$((\&{double}) \\{nr});\6
1110 \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nr};{}$ ${}\|j\PP){}$\5
1111 ${}\{{}$\1\6
1112 ${}\\{lly}\K{}$((\&{double}) \\{bblly})${}+((\&{double})(\|j-\T{1}))*\\{dy};{}$%
1113 \6
1114 ${}\\{ury}\K\\{lly}+\\{dy}*(\T{1.0}+\T{8.0\_-2});{}$\6
1115 ;\6
1116 \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\\{nc};{}$ ${}\|k\PP){}$\5
1117 ${}\{{}$\1\6
1118 ${}\\{llx}\K\\{bbllx}+((\&{double})(\|k-\T{1})*\\{dx});{}$\6
1119 ${}\\{urx}\K\\{llx}+\\{dx}*(\T{1.0}+\T{8.0\_-2});{}$\6
1120 \&{if} ${}(\\{pixel\_generation\_mode}\E\.{COMPACTIFIED\_PIXELCODE}){}$\5
1121 ${}\{{}$\1\6
1122 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%1.2f\ \%1.2f\ \%1.2f\ \%}\)\.{1.2f\ %
1123 \%1.3f\ dp\\n"},\39\\{llx},\39\\{lly},\39\\{urx},\39\\{ury},\39\\{imagematrix}[%
1124 \|j][\|k]);{}$\6
1125 \4${}\}{}$\2\6
1126 \&{else}\5
1127 ${}\{{}$\1\6
1128 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%1.3f\ setgray\\n"},\39\\{imagematrix}[%
1129 \|j][\|k]);{}$\6
1130 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"newpath\ \%1.2f\ \%1.2f}\)\.{\ moveto\\n"},%
1131 \39\\{llx},\39\\{lly});{}$\6
1132 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ \%1.2f\ \%1.2f\ lineto}\)\.{"},\39%
1133 \\{urx},\39\\{lly});{}$\6
1134 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ \%1.2f\ \%1.2f\ lineto}\)\.{\\n"},\39%
1135 \\{urx},\39\\{ury});{}$\6
1136 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ \%1.2f\ \%1.2f\ lineto}\)\.{"},\39%
1137 \\{llx},\39\\{ury});{}$\6
1138 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ \%1.2f\ \%1.2f\ lineto}\)\.{\ closepath\
1139 fill\\n"},\39\\{llx},\39\\{lly});{}$\6
1140 \4${}\}{}$\2\6
1141 \4${}\}{}$\2\6
1142 \4${}\}{}$\2\6
1143 \&{if} ${}(\T{0}\E\T{1}){}$\5
1144 ${}\{{}$\C{ for debugging purposes only }\1\6
1145 \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nr};{}$ ${}\|j\PP){}$\5
1146 ${}\{{}$\1\6
1147 \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\\{nc};{}$ ${}\|k\PP){}$\5
1148 ${}\{{}$\1\6
1149 ${}\\{fprintf}(\\{stdout},\39\.{"\%2.4f\ \ "},\39\\{imagematrix}[\|j][\|k]);{}$%
1150 \6
1151 \4${}\}{}$\2\6
1152 ${}\\{fprintf}(\\{stdout},\39\.{"\\n"});{}$\6
1153 \4${}\}{}$\2\6
1154 \4${}\}{}$\2\6
1155 \4${}\}{}$\2\par
1156 \U24.\fi
1157
1158 \M{26}Write partitioned body of Encapsulated PostScript code.
1159
1160 \Y\B\4\X26:Write body of partitioned Encapsulated PostScript image\X${}\E{}$\6
1161 ${}\{{}$\1\6
1162 ${}\\{fprintf}(\\{stdout},\39\.{"Not\ yet\ finished\ wi}\)\.{th\ non-sequential%
1163 \ pa}\)\.{rtitioning\ of\ data\\n}\)\.{"});{}$\6
1164 ${}\\{exit}({-}\T{1});{}$\6
1165 \4${}\}{}$\2\par
1166 \U24.\fi
1167
1168 \M{27}Write the blocks ending the Encapsulated PostScript code.
1169
1170 \Y\B\4\X27:Write closing of Encapsulated PostScript image\X${}\E{}$\6
1171 ${}\{{}$\1\6
1172 \&{if} (\\{write\_frame})\5
1173 ${}\{{}$\C{ write frame corresponding to bounding box }\1\6
1174 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"0\ setgray\ 0\ \%1.2f\ d}\)\.{transform\
1175 truncate\ "},\39\\{linethickness});{}$\6
1176 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"idtransform\ setline}\)\.{width\ pop%
1177 \\n"});{}$\6
1178 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ []\ 0\ setdash\ 1\ set}\)\.{linejoin\ 10\
1179 setmiter}\)\.{limit\\n"});{}$\6
1180 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"newpath\ \%d\ \%d\ movet}\)\.{o\\n"},\39%
1181 \\{bbllx},\39\\{bblly});{}$\6
1182 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ \%d\ \%d\ lineto"},\39\\{bburx},\39%
1183 \\{bblly});{}$\6
1184 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ \%d\ \%d\ lineto\\n"},\39\\{bburx},\39%
1185 \\{bbury});{}$\6
1186 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ \%d\ \%d\ lineto"},\39\\{bbllx},\39%
1187 \\{bbury});{}$\6
1188 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\ \%d\ \%d\ lineto\ close}\)\.{path\ stroke%
1189 \\n"},\39\\{bbllx},\39\\{bblly});{}$\6
1190 \4${}\}{}$\2\6
1191 \&{if} (\\{write\_title})\5
1192 ${}\{{}$\1\6
1193 ${}\\{fprintf}(\\{stderr},\39\.{"Still\ to\ be\ finishe}\)\.{d!!\\n"});{}$\6
1194 ${}\\{exit}({-}\T{1});{}$\6
1195 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%IncludeResource:\ }\)\.{font\ Helvetica%
1196 \\n"});{}$\6
1197 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"/Helvetica\ /Windows}\)\.{Latin1Encoding\
1198 120\ F}\)\.{MSR\\n"});{}$\6
1199 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"2345\ 2372\ moveto\\n"});{}$\6
1200 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"(Intensity\ distribu}\)\.{tion\ in\
1201 observation\ }\)\.{plane)\ s\\n"});{}$\6
1202 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"504\ 2372\ moveto\ -90}\)\.{\ rotate%
1203 \\n"});{}$\6
1204 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"(y\ [)\ s\\n"});{}$\6
1205 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"90\ rotate\\n"});{}$\6
1206 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%IncludeResource:\ }\)\.{font\ Symbol%
1207 \\n"});{}$\6
1208 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"/Symbol\ /WindowsLat}\)\.{in1Encoding\ 120\
1209 FMSR}\)\.{\\n"});{}$\6
1210 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"504\ 2540\ moveto\ -90}\)\.{\ rotate%
1211 \\n"});{}$\6
1212 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"(m)\ s\\n"});{}$\6
1213 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"90\ rotate\\n"});{}$\6
1214 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"504\ 2372\ moveto\ -90}\)\.{\ rotate%
1215 \\n"});{}$\6
1216 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"(])\ s\\n"}){}$;\C{ AND SO ON, IN THIS
1217 STYLE .... }\6
1218 \4${}\}{}$\2\6
1219 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"showpage\\n"});{}$\6
1220 ${}\\{fprintf}(\.{OUTSTREAM},\39\.{"\%\%\%\%EOF\\n"});{}$\6
1221 \4${}\}{}$\2\par
1222 \U6.\fi
1223
1224 \M{28}Deallocate memory occupied by the image matrix.
1225
1226 \Y\B\4\X28:Deallocate image matrix\X${}\E{}$\6
1227 ${}\{{}$\1\6
1228 ${}\\{unload\_matrix}(\\{imagematrix},\39\\{nr},\39\\{nc});{}$\6
1229 \4${}\}{}$\2\par
1230 \U6.\fi
1231
1232 \M{29}Close all open files.
1233
1234 \Y\B\4\X29:Close files\X${}\E{}$\6
1235 ${}\{{}$\1\6
1236 \\{fclose}(\\{fpout});\6
1237 \4${}\}{}$\2\par
1238 \U6.\fi
1239
1240 \N{1}{30}Index.
1241 \fi
1242
1243 \inx
1244 \fin
1245 \con
1246
Generated by ::viewsrc::