Well, I finally got it to work. Typical linux experience, I might add. 
This only took three evenings and the better part of Saturday.
I am proud of the fact that I DIDN'T buy a book about postscript, to add to the
25 books I have on various aspects of linux.
The basic question was how to put several ps files on one page.
The commands mpage and psnup put a multipage ps file onto one page.
The trick was to get multiple ps files into one big file. This must be very
hard to do. I have solved only a very simple problem. Taking multiple plots
from GNUplot and getting them into one big file which psnup and mpage will
handle.
So, the script is attached, in case anyone else has a similar problem.
Actually, it is quite simple, once you dissect out the page breaks of a ps
file.
Joel


#!/bin/bash
# This script "pschain" only works on GNUplots !!!
# Sample command: pschain file1.ps file2.ps file3.ps > big.ps or pschain file*ps > 
big.ps
# This won't really make sense unless you look at the structure of a PostScript file, 
better yet, a postscript file from GNUplot
# Basically, it gets the prolog from the first plot and sends it to stdout
# Then, again from the first file, it gets the final lines after the last showpage 
command, and saves them in $$_suffix ($$=process ID)
#Then, it outputs the current page number
# Then it just reads in the files, stripping off the prolog and the old page number 
after the EndProlog, and strips the  suffix (as I call it) from each file. 
# Each file is processed in a similar fashion
# Then, when all the file are done, it outputs the suffix and the final page number.
# Now you have one big postscript file which can be handled with psnup.
# Very likely, tinkering will be required to make this work with a variety of 
GNUplots, but that should be staighforward.
 
# Get prolog
cat $1 | sed -n "1,/EndProlog/p"
# Get suffix of file
cat $1 | sed -n "{
/showpage/{    #showpage is the last line in a page
:loop
n
/Pages/q       #Pages is the last line in the file.
w "$$"_suffix
bloop
}
}"
j=0   # page counter
while [ "$#" -gt 0 ]
do
j=$((j+1))
echo "%%Page: $j $j"   #put page number at the start of each new page
cat $1 | sed  "1,/EndProlog/d" | \
         sed  -n "2,/showpage/p"   # This removes the prolog and the next line beneath 
it, the page number
shift
done
cat "$$"_suffix
echo "%%Pages: $j"
         

Reply via email to