%%=========================================
%% This is file 'pst-2dplot.sty'
%% It provides the pst-2dplot package.
%% ------------------------------------
%% Author: Farshid Delgosha
%%         326004 Georgia Tech Station
%%         Atlanta, GA 30332-1085
%%         U.S.A.
%% E-mail: delgosha@ieee.org
%%=========================================

\ProvidesPackage{pst-2dplot}[2006/08/20 Version 1.0 by Farshid Delgosha]
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\typeout{%
*****************************************************^^J%
Package `pst-2dplot' (Version 1.0) -- 22 January 2007 --^^J%
Author: Farshid Delgosha (delgosha@ieee.org)^^J%
*****************************************************}

\def\fileversion{1.0}
\def\filedate{2007/01/22}

\csname PSTtwoDPlotLoaded\endcsname
\let\PSTtwoDPlotLoaded\endinput



\RequirePackage{xkeyval,calc}
\RequirePackage{pstricks-add}



%-----------------------------------------------
% PSTAXES local variables
%-----------------------------------------------
\def\@pstaxes@xmin{0}
\def\@pstaxes@ymin{0}
\def\@pstaxes@xmax{1}
\def\@pstaxes@ymax{1}
\def\@pstaxes@xbox{1}
\def\@pstaxes@ybox{1}
\def\@pstaxes@gridwidth{.5pt}
\def\@pstaxes@gridcolor{gray}
\def\@pstaxes@gridstyle{solid}
\def\@pstaxes@xgriddiv{1}
\def\@pstaxes@ygriddiv{1}
\def\@pstaxes@xticksize{.1}
\def\@pstaxes@yticksize{.1}
\def\@pstaxes@xlabel{}
\def\@pstaxes@ylabel{}
\def\@pstaxes@xtagsep{.4}
\def\@pstaxes@ytagsep{.5}
\def\@pstaxes@xlabelsep{.8}
\def\@pstaxes@ylabelsep{1}
%-----------------------------------------------


%-----------------------------------------------
% assign PSTAXES local variables
%-----------------------------------------------
\define@key{pstaxes}{xmin}{\renewcommand\@pstaxes@xmin{#1}}
\define@key{pstaxes}{ymin}{\renewcommand\@pstaxes@ymin{#1}}
\define@key{pstaxes}{xmax}{\renewcommand\@pstaxes@xmax{#1}}
\define@key{pstaxes}{ymax}{\renewcommand\@pstaxes@ymax{#1}}
\define@key{pstaxes}{xbox}{\renewcommand\@pstaxes@xbox{#1}}
\define@key{pstaxes}{ybox}{\renewcommand\@pstaxes@ybox{#1}}
\define@key{pstaxes}{gridwidth}{\renewcommand\@pstaxes@gridwidth{#1}}
\define@key{pstaxes}{gridcolor}{\renewcommand\@pstaxes@gridcolor{#1}}
\define@key{pstaxes}{gridstyle}{\renewcommand\@pstaxes@gridstyle{#1}}
\define@key{pstaxes}{xgriddiv}{\renewcommand\@pstaxes@xgriddiv{#1}}
\define@key{pstaxes}{ygriddiv}{\renewcommand\@pstaxes@ygriddiv{#1}}
\define@key{pstaxes}{xticksize}{\renewcommand\@pstaxes@xticksize{#1}}
\define@key{pstaxes}{yticksize}{\renewcommand\@pstaxes@yticksize{#1}}
\define@key{pstaxes}{xlabel}{\renewcommand\@pstaxes@xlabel{#1}}
\define@key{pstaxes}{ylabel}{\renewcommand\@pstaxes@ylabel{#1}}
\define@key{pstaxes}{xlabelsep}{\renewcommand\@pstaxes@xlabelsep{#1}}
\define@key{pstaxes}{ylabelsep}{\renewcommand\@pstaxes@ylabelsep{#1}}
\define@key{pstaxes}{xtagsep}{\renewcommand\@pstaxes@xtagsep{#1}}
\define@key{pstaxes}{ytagsep}{\renewcommand\@pstaxes@ytagsep{#1}}
%-----------------------------------------------



%-----------------------------------------------
% PSTAXES internal variables
%-----------------------------------------------
\newcounter{@pstaxes@grid}
\def\@pstaxes@dx{1}
\def\@pstaxes@dy{1}
\def\@pstaxes@Dx{1}
\def\@pstaxes@Dy{1}
\def\@pstaxes@pos{1}
\newlength{\@pstaxes@xrange}
\newlength{\@pstaxes@yrange}
\newlength{\@pstaxes@XunitTemp}
\newlength{\@pstaxes@YunitTemp}
%-----------------------------------------------



%-----------------------------------------------
% PSTAXES environment
%-----------------------------------------------
\newenvironment{pstaxes}[1][]{
   \setkeys{pstaxes}{#1}
   \begin{pspicture}(-\@pstaxes@xtagsep,-\@pstaxes@ytagsep)(\@pstaxes@xbox,\@pstaxes@ybox)
      \setlength{\@pstaxes@xrange}{\@pstaxes@xmax pt - \@pstaxes@xmin pt}
      \setlength{\@pstaxes@yrange}{\@pstaxes@ymax pt - \@pstaxes@ymin pt}

      \setcounter{@pstaxes@grid}{\@pstaxes@xgriddiv}
      \addtocounter{@pstaxes@grid}{1}
      \pst@divide{\@pstaxes@xbox pt}{\@pstaxes@xgriddiv pt}\@pstaxes@dx
      \pst@divide{\@pstaxes@xrange}{\@pstaxes@xgriddiv pt}\@pstaxes@Dx
      \multido{\rx=0+\@pstaxes@dx,\rX=\@pstaxes@xmin+\@pstaxes@Dx}{\the@pstaxes@grid}%
              {\psline[linecolor=\@pstaxes@gridcolor,linewidth=\@pstaxes@gridwidth,linestyle=\@pstaxes@gridstyle]
                      (\rx,-\@pstaxes@xticksize)(\rx,\@pstaxes@ybox)
               \rput[t](\rx,-\@pstaxes@xtagsep){$\rX$}}

      \setcounter{@pstaxes@grid}{\@pstaxes@ygriddiv}
      \addtocounter{@pstaxes@grid}{1}
      \pst@divide{\@pstaxes@ybox pt}{\@pstaxes@ygriddiv pt}\@pstaxes@dy
      \pst@divide{\@pstaxes@yrange}{\@pstaxes@ygriddiv pt}\@pstaxes@Dy
      \multido{\ry=0+\@pstaxes@dy,\rY=\@pstaxes@ymin+\@pstaxes@Dy}{\the@pstaxes@grid}%
              {\psline[linecolor=\@pstaxes@gridcolor,linewidth=\@pstaxes@gridwidth,linestyle=\@pstaxes@gridstyle]
                      (-\@pstaxes@yticksize,\ry)(\@pstaxes@xbox,\ry)
               \rput[r](-\@pstaxes@ytagsep,\ry){$\rY$}}

      \setlength{\@pstaxes@XunitTemp}{\psxunit}
      \setlength{\@pstaxes@YunitTemp}{\psyunit}
      \psset{xunit=\@pstaxes@xbox,yunit=\@pstaxes@ybox}
}
{
      \psset{xunit=\@pstaxes@XunitTemp,yunit=\@pstaxes@YunitTemp}
      \psframe[linecolor=black,linestyle=solid](\@pstaxes@xbox,\@pstaxes@ybox)

      \pst@divide{\@pstaxes@xbox pt}{2pt}\@pstaxes@pos
      \rput[t](\@pstaxes@pos,-\@pstaxes@xlabelsep){\@pstaxes@xlabel}

      \pst@divide{\@pstaxes@ybox pt}{2pt}\@pstaxes@pos
      \rput[b]{90}(-\@pstaxes@ylabelsep,\@pstaxes@pos){\@pstaxes@ylabel}
   \end{pspicture}
}
%-----------------------------------------------



%-----------------------------------------------
% Commands
%-----------------------------------------------
\newcommand{\pstaxessetup}[1]{\setkeys{pstaxes}{#1}}
\newcommand{\pstxlabel}[1]{\setkeys{pstaxes}{xlabel=#1}}
\newcommand{\pstylabel}[1]{\setkeys{pstaxes}{ylabel=#1}}
%-----------------------------------------------
