# NoSetrgbcolorIDL.awk by Petr Mikulik. Version 1. 6. 1998 # The PS output of IDL is really awful! # 1. All letters (of text) are made of lines, really stupid idea! Why they # do not use postscript fonts?! # 2. There is a lot of x x x setrgbcolor (x is number) in black&white # figures. # 3. There are trailing zeros in numbers! # This script replaces # 1. "x x x setrgbcolor" strings by "x K" string, # 2. "x y z setrgbcolor" strings by "x y z k" with new definition # "/k{setrgbcolor}bdef" # 3. "0.000" by "0", and trailing zeros in decimal numbers # This results in an enourmous reduction of the .ps file size (here I can # see 25--30%, which are megabytes for large files.) BEGIN { kAddDef=1 } # update title $1=="%%Title:" { print $0 ", sized reduced by P.M.'s NoSetrgbcolorIDL.awk" next } # add definition "/k { setrgbcolor } bdef" into the dictionary kAddDef && ($0 ~ "/K") { i=index($0,"/K") $0=substr($0,1,i-1) "\n\t/k{setrgbcolor}bdef\n" substr($0,i) print kAddDef=0 next } # replace "0.000" by "0" #$0 ~ "0.000" { #for (i=1; i<=NF; i++) # if ($i=="0.000") $i="0" #} # deleted trailing zeros after decimal point (in real numbers) { for (i=1; i<=NF; i++) if ($i+0==$i) $i+=0 } # skip lines without "setrgbcolor" #index($0,"setrgbcolor")==0 { print; next } $0 !~ "setrgbcolor" { print; next } # there is setrgbcolor command there, so abbreviate it { for (i=4; i<=NF; i++) { # setrgbcolor can be at least at 4th column if ($i=="setrgbcolor") if ($(i-1)==$(i-2) && $(i-2)==$(i-3) ) { # all 3 RGB values are the same, so replace "x x x setrgbcolor" by "x setgray" $(i-2)="K" # "K" is an IDL abbreviation for "setgray" k=i+1 for (a=i-1; k<=NF; a++) { $a=$k; k++ } NF-=2 } else # RGB values are different, so abbreviate "rgbcolor" to "k" $i="k" } print } # eof NoSetrgbcolorIDL.awk