Search code examples
gnuplotpostscript

How to combine the output of child scripts from the parent script in gnuplot?


I have a parent gnuplot script that calls a child gnuplot script depending on certain conditions. I want to combine the output graphs of the child scripts into a single .eps file. How do I go about doing this?

As an example, my parent script is:

set terminal postscript
set output "combined.eps"    
if (there_is_s == 1) call "child.gplot" "0"
if (there_is_p == 1) call "child.gplot" "1"

Where there_is_s and there_is_p are conditions that I've defined earlier in the parent script.

My child script child.gplot is:

set terminal postscript
set output "child".ARG1.".eps"
#plot graph here

I basically want the 2 graphs of the child scripts into a combined .eps file, one on each page, while using this method it creates 5 different plots child1.eps etc.

I tried removing the option to set terminal as postscript in the child script, but that just gives me a single graph corresponding to child0.eps, while child1.eps is nowhere to be found. Thanks for the help!


Solution

  • You cannot have multiple pages in an EPS file. EPS graphics are intended for inclusion on a page, and as such they may not include the PostScript operator showpage which is used to end one page and start another.

    So you either need to follow the URL in the comment from Wrzlpmft and create a PostScript file instead of an EPS (assuming gnuplot is capable of such a thing, the link is for PDF output), or you need to combine the EPS files yourself into a PostScript program.

    If you want to do the latter then you need to read the DSC comments from the EPS files (lines beginning %%), find the BoundingBox comments, Insert ahead of the EPS a requested media size for the area of the BoundingBox (using the setpagedevice operator), translate the EPS content onto the media if the lower left co-ordinate is not 0,0 (using the translate operator) and put a showpage after the EPS content. Then do the same with the second EPS file and concatenate the two results.