%
%%%%%%%%% The following gives an example of the use of this graphing routine.
% B. Harbourne, 10-2002.
%Revised: March 22, 2003


%\def\mydata{?}   specify the file to read the data to be plotted from
%                 each line of this file should be of the form "\ptplt x y" where x y 
%                 are the x and y values of a point to be graphed
%\def\xscale{?}   ? should be equal to width/(xmax - xmin), where width = actual width on page in pts
%\def\yscale{?}   ? should be equal to height/(ymax - ymin), where height = actual height on page in pts
%\def\xmin{?}     ? should be the least x-coord of among data points that you want on your graph
%\def\ymin{?}     ? should be the least y-coord of among data points that you want on your graph
%\def\xmax{?}     ? should be the greatest x-coord of among data points that you want on your graph
%\def\ymax{?}     ? should be the greatest y-coord of among data points that you want on your graph
% WARNING: Because TeX uses integer arithmetic (TeX has no floating point) scaling which
%  is too large or too small won't work. Also, because there is a maximum size in pts in TeX, data 
%  values bigger than 15000 or so don't work. When such data or scaling is needed, it can be handled
%  by preprocessing the data. For example, to graph data where the coordinates lie in the range
%  of 20000 where say the scaling factors are .01, instead change the coordinate to 2000.0 and the scale to .1. 
%\penwidth?pt     ? should be how wide each plotted point should be, in absolute units (i.e., is unaffected by xscale or yscale)
%\penheight?pt    ? should be how tall each plotted point should be, in absolute units (i.e., is unaffected by xscale or yscale)

%\vskip1in\hskip2in\hbox{\vbox{       %Change the 1in and 2in to move the graph around on the page.
%\parindent0in                        %Leave this alone
%\putinaxes
%\putinticx 5 1 1                     %This puts in a tic mark for horizontal axis; see below for documentation
%\putinticy 5 0 1 1                   %Likewise for vertical axis
%                                     Put in one tic mark command for each tic mark to be included on graph
%\input\mydata                        
%\myput 3.14 .2  {inflection point}   %This puts the text "inflection point" on the graph at the coords (3.14,.2)
%                                     See more below.
%\putincaption 0 20 {{\bf Figure 1.} Blah blah.} %This puts a caption on the figure. See more below.
%}}


\newdimen\myx
\newdimen\myht
\newdimen\mywdth
\newdimen\myhtB
\newdimen\mydepth
\newdimen\xm
\newdimen\ym
\newdimen\xM
\newdimen\yM
\newdimen\mywidth
\newdimen\mylength
\newdimen\myheight
\newdimen\penwidth
\newdimen\penheight
\newdimen\myskip

%\ptplt plots a data point
% #1 = x coord of data point  #2 = y coord of data point 
\def\ptplt #1 #2 {\myskip\baselineskip\baselineskip0pt{
\xm\xmin pt
\ym\ymin pt
\xM\xmax pt
\yM\ymax pt
\myheight\ym\multiply\myheight by-1\advance\myheight by\yM
\myheight\yscale\myheight
\myx#1 pt
\myht#2 pt
\ifdim\myx<\xm \else \ifdim\myx>\xM \else \ifdim\myht<\ym \else \ifdim\myht>\yM \else 
\advance\myx by -\xm \advance\myht by -\ym 
\myx\xscale\myx\myht\yscale\myht 
\multiply\myht by-1\advance\myht by\myheight
\hbox to0in{\vbox to0in{\hbox to0in{\hbox to\myx{\hfil}\vbox{\vbox to\myht{\vss}\vrule depth\penheight width\penwidth\vss}\hss}\vss}\hss}
\fi\fi\fi\fi}\baselineskip\myskip}

%\segplt plots a vertical line segment 
% #1 = height of segment #2 = x coord of bottom of segment  #3 = y coord of bottom of segment 
\def\segplt #1 #2 #3 {\myskip\baselineskip\baselineskip0pt{
\xm\xmin pt
\ym\ymin pt
\xM\xmax pt
\yM\ymax pt
\myheight\ym\multiply\myheight by-1\advance\myheight by\yM
\myheight\yscale\myheight
\mylength#1 pt
\myx#2 pt
\myht#3 pt
\myhtB\mylength\advance\myhtB by\myht
\ifdim\myht<\ym \myht\ym\fi
\ifdim\myhtB>\yM \myhtB\yM\fi
\ifdim\myhtB<\myht \mylength0pt\else \mylength\myhtB\advance\mylength by-\myht\fi
\ifdim\myx<\xm \else \ifdim\myx>\xM \else \ifdim\myhtB<\ym \else \ifdim\myht>\yM \else 
\advance\myx by -\xm \advance\myhtB by -\ym 
\myx\xscale\myx\myhtB\yscale\myhtB\mylength\yscale\mylength
\multiply\myhtB by-1\advance\myhtB by\myheight
\hbox to0in{\vbox to0in{\hbox to0in{\hbox to\myx{\hfil}\vbox{\vbox to\myhtB{\vss}\vrule depth\mylength width\penwidth\vss}\hss}\vss}\hss}
\fi\fi\fi\fi}\baselineskip\myskip}

%\rectplt plots a rectangle
% #1 = x coord of bottom of segment,  #2 = y coord of bottom of segment 
% #3 = width of rectangle, #4 = height of rectangle 
\def\rectplt #1 #2 #3 #4 {\myskip\baselineskip\baselineskip0pt{
\xm\xmin pt
\ym\ymin pt
\xM\xmax pt
\yM\ymax pt
\myheight\ym\multiply\myheight by-1\advance\myheight by\yM
\myheight\yscale\myheight
\mylength#4 pt
\myx#1 pt
\myht#2 pt
\mywdth#3 pt
\penwidth\xscale\mywdth 
\myhtB\mylength\advance\myhtB by\myht
\ifdim\myht<\ym \myht\ym\fi
\ifdim\myhtB>\yM \myhtB\yM\fi
\ifdim\myhtB<\myht \mylength0pt\else \mylength\myhtB\advance\mylength by-\myht\fi
\ifdim\myx<\xm \else \ifdim\myx>\xM \else \ifdim\myhtB<\ym \else \ifdim\myht>\yM \else 
\advance\myx by -\xm \advance\myhtB by -\ym 
\myx\xscale\myx\myhtB\yscale\myhtB\mylength\yscale\mylength
\multiply\myhtB by-1\advance\myhtB by\myheight
\hbox to0in{\vbox to0in{\hbox to0in{\hbox to\myx{\hfil}\vbox{\vbox to\myhtB{\vss}\vrule depth\mylength width \penwidth \vss}\hss}\vss}\hss}
\fi\fi\fi\fi}\baselineskip\myskip}

%The command \plt 11 23 34 means that for n=23 points, the range of
%multiplicities is 34 <= m <= 34+11. Although this is a range of length 11,
%it is 11+1 data points. To account for the 12th point, we would want
%\segplt 12 23 34, so \plt is defined to increase the first parameter by 1, but otherwise
%to be the same as \segplt.

\newcount\mynumber
\def\plt #1 #2 #3 {\mynumber #1\advance\mynumber by1\segplt {\mynumber} #2 #3 }

% #1 = x coord of data point;  #2 = y coord of data point;
% #3 = text to be put on graph at (#1,#2)
\def\myput #1 #2 #3 {\myskip\baselineskip\baselineskip0pt{
\xm\xmin pt
\ym\ymin pt
\xM\xmax pt
\yM\ymax pt
\myheight\ym\multiply\myheight by-1\advance\myheight by\yM
\myheight\yscale\myheight
\myx#1 pt
\myht#2 pt
\ifdim\myx<\xm \else \ifdim\myx>\xM \else \ifdim\myht<\ym \else \ifdim\myht>\yM \else 
\advance\myx by -\xm \advance\myht by -\ym 
\myx\xscale\myx\myht\yscale\myht 
\multiply\myht by-1\advance\myht by\myheight
\hbox to0in{\vbox to0in{\hbox to0in{\hbox to\myx{\hfil}\vbox{\vbox to\myht{\vss}#3\vss}\hss}\vss}\hss}
\fi\fi\fi\fi}\baselineskip\myskip}

%#1 = name of horiz axis; #2 = name of vertical axis
\def\putinaxes #1 #2 {{\xm\xmin pt
\xM\xmax pt
\advance\xM by -\xm 
\xM\xscale\xM
\penwidth\xM
\ptplt {\xmin} 0 
\vskip5pt\myput {\xmax} 0 {#1} 
\vskip-5pt}
{\ym\ymin pt\yM\ymax pt
\myput 0 {\ymax} {\hbox to0in{\hss #2\  }}
\advance\yM by -\ym 
\yM\yscale\yM
\penheight\yM
\vskip-\yM
\ptplt 0 {\ymin} 
\vskip\yM}}

% #1 = height of tic mark in pt's; #2 = x coord of tic mark;
% #3 = text to be put on graph by tic mark
\def\putinticx #1 #2 #3 {{\penheight#1pt\ptplt #2 0
\vskip\penheight\myput #2 0 #3  
\vskip-\penheight}}

% #1 = width of tic mark in pt's; #2 x-coord of tic mark #3 = y coord of tic mark;
% #4 = text to be put on graph by tic mark
\def\putinticy #1 #2 #3 #4 {{\penwidth#1pt\ptplt {#2} #3
\myput 0 #3 {\hskip-\penwidth \hbox to0in{\hss #4\  }}
}}

% #1 is a horizontal shift in pt's: it moves the caption left but also widens
% the caption in an attempt to keep it centered (but this is only apparent if the caption is 
% long enough; a short caption will just appear to move left by the amount #1);
% #2 is a vertical shift in pt's: it moves the caption down; #3 is the caption text
\def\putincaption #1 #2 #3 {\xm\xmin pt
\ym\ymin pt
\xM\xmax pt
\yM\ymax pt
\mywidth\xm\multiply\mywidth by-1\advance\mywidth by\xM
\mywidth\xscale\mywidth
\advance\mywidth by #1pt\advance\mywidth by #1pt\relax
{\vskip#2 pt\myput {\xmin} {\ymin} {\hskip-#1pt\hbox{\hsize\mywidth\hfil\vbox{#3}\hfil}} \vskip-#2pt}}




%