1 # pm3dCompress.awk - (c) Petr Mikulik; 1996/1997/1999/2002
3 # This awk script tries to compress a postscript file created by pm3d or
4 # gnuplot with pm3d splotting mode (limits: compresses only the first pm3d
5 # splot map there if in multiplot mode).
9 # Copy this file into a directory listed in your AWKPATH
11 # awk -f pm3dCompress.awk _original_.ps >reduced.ps
13 # Hint: make a script file/abbreviation/alias, e.g. under VMS
14 # pm3dcompress:=="$disk:[dir]gawk.exe -f disk:[dir]pm3dCompress.awk"
16 # Note: use GNU awk whenever possible (HP awk does not have /dev/stderr, for
20 # Strategy: this program browses the given .ps file and makes a list of all
21 # frequently used chains of postscript commands. If this list is not too large,
22 # then it replaces these chains by abbreviated commands.
23 # This may reduce the size of the postscript file about 50 %, which is not
24 # so bad if you want to store these files for a later use (and with the same
25 # functionality, of course).
28 # (c) Petr Mikulik, mikulik@physics.muni.cz, http://www.sci.muni.cz/~mikulik/
30 # Distribution policy: this file must be distributed together with the
31 # whole stuff of pm3d or gnuplot program.
33 # This is version: 2. 3. 2002
34 # 2. 3. 2002 - updated because of stroke in /g definition
35 # 15. 1. 1999 - new staff in pm3d and gnuplot/pm3d
37 # 16. 3. 1997 - first (?) version
43 print "pm3dCompress.awk --- (c) Petr Mikulik, Brno. Version 2. 3. 2002" >err
44 print "Compression of pm3d .ps files. See the header of this file for more info." >err
45 print "Usage: awk -f pm3dCompress.awk inp_file.ps >out_file.ps" >err
49 print "Please wait, it may take a while (input file "ARGV[1]" is read twice)." >err
50 while ($1!="%pm3d_map_begin")
52 print "No pm3d piece found in the input file, exiting." >err
57 while ($1!="%pm3d_map_end") {
59 print "Corrupted pm3d block---end not found, exiting." >err
63 S=substr($0,i,length($0)) # M including
64 # is this string defined?
65 for (i=0; i<nList && List[i]!=S; i++);
66 if (i==nList) { # string is not in the list
69 print "Defining more than 300 strings makes no sense, I think. Exiting, sorry." >err
75 print "List of frequent strings contains "nList" elements." >err
77 # now read the same file again the 3d part:
79 while ($1!="%pm3d_map_begin") {
81 print $0", compressed by pm3dCompress.awk"
82 else if ($1=="/pmdict") {
88 # now print the list as a new definition
89 print "\t\t\t\t\t%pm3dCompress definitions"
90 for (i=0; i<nList; i++)
91 print "/X"i" {"List[i]"} def"
92 for (i=0; i<nList; i++) {
94 sub("N ","2 index g N ",S)
95 print "/x"i" {"S"} def"
97 print "\n"PrintMapping"\n"
99 # now substitute the new definitions:
100 while ($1!="%pm3d_map_end") {
101 getline <ARGV[1]; i=index($0,"N");
103 S=substr($0,i,length($0)) # M including
104 # find the definition in the list
105 for (m=0; m<nList && List[m]!=S; m++);
107 if (index(S," g ")) {
117 # read the rest of the file
118 flag = (getline <ARGV[1] );
119 while (flag>0) { print; flag = (getline <ARGV[1] ); }
123 # eof pm3dCompress.awk