#!/usr/bin/perl # Perl script to change the colors in the Postscript files output # by gnuplot (for example when using octave). # Because there is no corresponding terminal option (as for example # with terminal png) to set up the colors, this Perl script is used. # # Alexander Klink 2005, public domain # # Usage: set the $linecolor0 to $linecolor8 variables below to fit # your taste (values from 0 to 1 in RGB are used here) and run # gnuplot_ps_colorchange # The script will then output the changed file into $linecolorb = "0 0 0"; $linecolora = "0 0 0"; $linecolor0 = "1 0 0"; $linecolor1 = "0 1 0"; $linecolor2 = "0 0 1"; $linecolor3 = "1 0 1"; $linecolor4 = "0 1 1"; $linecolor5 = "1 1 0"; $linecolor6 = "0 0 0"; $linecolor7 = "1 0.3 0"; $linecolor8 = "0.5 0.5 0.5"; ### You should not need to change anything below this line ### $outfilename = $ARGV[0]; $outfilename =~ s/\.eps$/_colorchanged\.eps/; open(PS, "<$ARGV[0]") || die('Could not open input file.'); open(OUT, ">$outfilename") || die('Could not open output file.'); while () { # read in file if (/^\/LT/) { # the line starts with /LT # color substitutions s/\/LTb { BL \[\] 0 0 0 DL } def/\/LTb { BL \[\] $linecolorb DL } def/; s/\/LTa { AL \[1 udl mul 2 udl mul\] 0 setdash 0 0 0 setrgbcolor } def/\/LTa { AL \[1 udl mul 2 udl mul\] 0 setdash $linecolora setrgbcolor } def/; s/\/LT0 { PL \[\] 1 0 0 DL } def/\/LT0 { PL \[\] $linecolor0 DL } def/; s/\/LT1 { PL \[4 dl 2 dl\] 0 1 0 DL } def/\/LT1 { PL \[4 dl 2 dl\] $linecolor1 DL } def/; s/\/LT2 { PL \[2 dl 3 dl\] 0 0 1 DL } def/\/LT2 { PL \[2 dl 3 dl\] $linecolor2 DL } def/; s/\/LT3 { PL \[1 dl 1.5 dl\] 1 0 1 DL } def/\/LT3 { PL \[1 dl 1.5 dl\] $linecolor3 DL } def/; s/\/LT4 { PL \[5 dl 2 dl 1 dl 2 dl\] 0 1 1 DL } def/\/LT4 { PL \[5 dl 2 dl 1 dl 2 dl\] $linecolor4 DL } def/; s/\/LT5 { PL \[4 dl 3 dl 1 dl 3 dl\] 1 1 0 DL } def/\/LT5 { PL \[4 dl 3 dl 1 dl 3 dl\] $linecolor5 DL } def/; s/\/LT6 { PL \[2 dl 2 dl 2 dl 4 dl\] 0 0 0 DL } def/\/LT6 { PL \[2 dl 2 dl 2 dl 4 dl\] $linecolor6 DL } def/; s/\/LT7 { PL \[2 dl 2 dl 2 dl 2 dl 2 dl 4 dl\] 1 0.3 0 DL } def/\/LT7 { PL \[2 dl 2 dl 2 dl 2 dl 2 dl 4 dl\] $linecolor7 DL } def/; s/\/LT8 { PL \[2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl\] 0.5 0.5 0.5 DL } def/\/LT8 { PL \[2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl\] $linecolor8 DL } def/; } print OUT $_; } close(PS); close(OUT);