[metapost] problems with memory in metapost

Nelson H. F. Beebe beebe at math.utah.edu
Mon May 10 22:48:43 CEST 2010


A reader posted an observation about redundant PostScript code in an
example like this:

>   newpath 414.37424 124.80127 moveto
>   416.37424 122.80127 lineto
>   418.37424 124.80127 lineto
>   416.37424 126.80127 lineto
>   closepath stroke

One simple solution in the Unix world is to filter the PostScript file
with the "uniq" program, which drops duplicate adjacent lines:

% uniq < oldfile.eps > newfile.eps

For gnuplot output using the default "with points" style, I use this
little awk program, which does not require the duplicates to be
adjacent:

% cat squeeze-eps.awk
### ====================================================================
### Reduce the size of gnuplot error plot files by removing duplicate
### "x y Pls" lines.
###
### Usage:
###	awk -f squeeze-eps.awk file.eps > new-file.eps
###
### [19-Jan-2010]
### ====================================================================

(NF == 3) && ($3 == "Pls")	{ if ($0 in Pls) next ; Pls[$0] = 1 }

				{ print }

You can squeeze that down to one line (and hide it in a alias or shell
script) if you prefer:

	awk '(NF == 3) && ($3 == "Pls")	{ if ($0 in Pls) next ; Pls[$0] = 1 } { print }' file.eps > new-file.eps

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe at math.utah.edu  -
- 155 S 1400 E RM 233                       beebe at acm.org  beebe at computer.org -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------


More information about the metapost mailing list