Re: xwinplot files

Dr. Guenter Schmidt (gsc@bruker.de)
Fri, 29 Nov 1996 13:33:30 +0000

Julian Keates wrote:
>

> with a file called 'ps2hpgl.ps'. This is in /u/xspec/ghostscript and comes as
> standard with xwinnmr releases. The file contains postscript commands and must

This is not true for XwinNMR 1.3. The Xspec Program is not included.
GhostScript
Version 3.51 is available with XwinNMR but you need The 'pstohpgl.ps'
file. If You
install that file in /u/plot/gs/lib/3.51, The startup script would be:

============================== BEGIN of pstohpgl
==============================
#!/bin/sh

if [ $# -lt 1 -o $# -gt 2 ]; then
echo "Usage: pstohpgl file.ps [file.hpgl]" 1>&2
exit 1
fi

infile=$1

if [ $# -eq 1 ]
then
case "${infile}" in
*.ps) base=`basename ${infile} .ps` ;;
*.cps) base=`basename ${infile} .cps` ;;
*.eps) base=`basename ${infile} .eps` ;;
*.epsf) base=`basename ${infile} .epsf` ;;
*) base=`basename ${infile}` ;;
esac
outfile=${base}.hpgl
else
outfile=$2
fi
export outfile

exec /u/plot/gs/bin/gs -q -dNODISPLAY -dNOPAUSE pstohpgl.ps ${infile} -c
quit 1>&2 > ${outfile}

exit 0

=========================== END OF pstohpgl ===========================

============================== BEGIN of pstohpgl.ps
==============================
%!
%
% pstodmpl.ps - convert a PostScript program into plotter commands for
% a Houston Instruments DMP-4x series D-size pen plotter.
%
% Mark Costlow
% May 27, 1993
%

% Modified by Ed Haymore 8/3/93 to output HPGL.

%
% Pick a scale and rotation. Always leave the first scale (by
2.777778)
% uncommented. It gives you a 34" by 21.5" page to work on (X is the
% long axis, not Y). If the following scale, rotate, and translate
% commands are used, a PostScript program written for a letter-size
page
% will fit on the plotter page with the correct aspect ratio. Note
that
% about 8 inches of the paper will be unused (the price of preserving
the
% aspect ratio).
%
% First, whack the CTM
[1.0 0.0 0.0 1.0 0.0 0.0] setmatrix
% 2.777778 2.777778 scale % 34" by 21.5" page
11.9 11.9 scale % 8.5" by 11" page (hopefully)

% Uncomment these to scale an an 8.5" by 11" page the plotter page,
cenetered.
% 2.5294 2.5294 scale
% -90 rotate
% 8.5 72 mul neg 3 72 mul 2.5294 div translate

% Some helper routinges
/newline { (;\012) print } def
/comma { (,) print } def
/tempstr 30 string def
%
% x y PrintCoord -
%
% Transforms an X,Y pair to device coords, rounds it to nearest
integer,
% then prints the pair with a comma separator.
%
/PrintCoord {
% ( not needed) transform
exch round cvi tempstr cvs print
comma
round cvi tempstr cvs print
} bind def

% Initialize plotter
(IN;SP 1;RO 90) print newline

%
% Send the pen "Home", go into Absolute addressing mode, and specify
% coordinate addressing of .005".
%
% (;: HA EC5) print newline
(PU 0,0) print newline

%
% x y Moveto -
%
% Side effects: Positions plotter pen. Leaves pen raised.
%
/Moveto {
/SavedY exch def
/SavedX exch def
(PU ) print
SavedX SavedY PrintCoord % Print X,Y pair
newline
} bind def

%
% x y Lineto -
%
% Side effects: Draws a line from currentpoint to x,y
%
/Lineto {
(PD ) print
PrintCoord % Print X,Y pair
newline
} bind def

%
% x1 y1 x2 y2 x3 y3 Curveto -
%
% Side effects: Draws a curve (NOT IMPLEMENTED)
%
/Curveto {
(I shouldn't be in Curveto, but I am!) print
pop pop pop pop pop pop
} bind def

%
% - Closepath -
%
% Side-effects: closes the path
%
/Closepath {
(PD ) print
SavedX SavedY PrintCoord % Print X,Y pair
newline
} def

%
% After considerable futzing around with strokepath, clip clippath,
etc., I
% have determined that there is no good way to intersect the current
path
% with the clipping region since pathforall refuses to do it for me.
The
% only way I can think of to get clipping to work will be to do the
clipping
% "by hand". This *might* be possible with PSL2's "infill" type
functions.
%
/EmitPath {
flattenpath
gsave
%clip clippath
matrix setmatrix

/Moveto load
/Lineto load
/Curveto load
/Closepath load
pathforall
flush
grestore
} bind def

/stroke {
EmitPath currentpoint newpath moveto
} def

/fill {
EmitPath currentpoint newpath moveto
} def

/show {
true charpath fill
} bind def

% redefine showpage
/showpage {
% Send the pen home
(PU 0,0;PG) print newline flush
} bind def

%
% END of pstodmpl.ps
%
%

% setrgbcolor.ps
%
% A replacement for PostScript's setrgbcolor operator. It works by
using
% a table of plotter pens which holds the pens' approximate RGB values.
% When the new setrgbcolor is called, it compares its arguments (an RGB
% triple) to each of the pens in the table, and returns the pen with
the
% "closest" color. "Closest" is defined as the smallest Euclidean
distance
% in the RGB color cube.
%
% To use this code:
%
% 1. Add any pens you have to PenDict, with their RGB colors. You
may
% to store a "pen number" in the array instead of (or in
addition
% to) the name string which is stored now. Note that if you
have
% more than 20 pens you need to increase the size of PenDict.
%
% 2. Add code in the setrgbcolor proc which emits plotter
pen-change
% commands, or whatever you need to have happen when a color
change
% occurs. Right now it just prints out the name and RGB values
of
% the pen it chose.
%

/PenDict 20 dict def
PenDict begin
% /black [0.0 0.0 0.0 (1)] def
% /white [1.0 1.0 1.0 (1)] def % Gets plotted as black
% /red [1.0 0.0 0.0 (2)] def
% /orange [0.3 0.3 0.3 (3)] def % I don't know what orange is in
rgb
% /green [0.0 1.0 0.0 (4)] def
% /ltblue [0.0 0.0 1.0 (5)] def
% /dkblue [0.0 0.0 0.5 (6)] def
% /purple [1.0 0.0 1.0 (7)] def

% Definitions for MATLAB colors
/black [0.0 0.0 0.0 (1)] def
/white [1.0 1.0 1.0 (1)] def % Gets plotted as black
/red [1.0 0.0 0.0 (2)] def
/orange [1.0 1.0 0.0 (3)] def % MATLAB's yellow
/green [0.0 1.0 0.0 (4)] def
/ltblue [0.0 1.0 1.0 (5)] def % MATLAB's cyan
/dkblue [0.0 0.0 1.0 (6)] def % MATLAB's blue
/purple [1.0 0.0 1.0 (7)] def % MATLAB's magenta
end

%
% [r g b] [r g b] distance DISTANCE
%
/distance {
/c1 exch def
/c2 exch def

/sum 0.0 def

c1 0 get c2 0 get sub dup mul sum add /sum exch def
c1 1 get c2 1 get sub dup mul sum add /sum exch def
c1 2 get c2 2 get sub dup mul sum add /sum exch def

sum sqrt
} def

%
% red green blue findclosest -
%
/findclosest {
/b exch def
/g exch def
/r exch def

/closest 3 sqrt def
PenDict {
[r g b] distance dup closest lt { % Distance less than closes so far?
/closest exch def
/closest_color exch def
} {
pop pop
} ifelse
} forall
closest_color % return the name of the closest colored pen
} def

%
% red green blue setrgbcolor -
%
/setrgbcolor {
findclosest /pen exch def % Find pen with closest color
/pen PenDict pen get def % Dig that pen out of the pen table

%
% Change the following code to emit plotter commands which effect
% a pen change
%
% (Chose color [) print

% pen 0 get =string cvs print ( ) print
% pen 1 get =string cvs print ( ) print
% pen 2 get =string cvs print (] - ") print
% pen 3 get print ("\n) print flush

(SP ) print
pen 3 get print newline flush

} def
=========================== END OF pstohpgl.ps
===========================
> be used as part of the ghostscript command line. To make this easier, we use it
> in a unix shell script (called ps2hpgl in /usr/local/bin):
>

>
> This is run with the command:
>
> ps2hpgl myfile.ps myfile.hpgl
>
> In addition, you'll (sometimes) need to type 'quit' after entering this command
> to terminate ghostscript.
>
> We use this method regularly. Although large, the hpgl files load perfectly
> into
> word 6 and 7 and are fully scalable, without sacrificing resolution.
>
> Hope this helps.
>
> Julian Keates.
>

-- 
   ...     ...         Dr. Guenter Schmidt  	E-Mail: gsc@bruker.de
  .    * .    .        - Software Department
   .   . .   .         Bruker Analytik GmbH	Phone: +49 7243-504-443
   B R U K E R         Rudolf Plank - Str. 23
  .   . .   .          D-76275 Ettlingen	Fax:   +49 7243-504-480
  .    * .    .     
   ...     ...