%%=========================================
%% This is file 'pst-2dplot.sty'
%% It provides the pst-2dplot package.
%% ------------------------------------
%% Author: Farshid Delgosha
%% E-mail: fdelgosha@gmail.com
%%=========================================

\ProvidesPackage{pst-2dplot}[2008/12/26 by Farshid Delgosha]

\csname PSTiidpLoaded\endcsname
\def\fileversion{1.5}
\def\filedate{2008/12/26}
\message{`pst-2dplot' v\fileversion, \filedate\space (Farshid Delgosha)}

\ifx\PSTricksLoaded\endinput\else\input pstricks \fi
\ifx\PSTplotLoaded\endinput\else \input pst-plot \fi
\ifx\MultidoLoaded\endinput\else \input multido  \fi
\ifx\XKeyValLoaded\endinput\else \input xkeyval \fi
%\ifx\PSTricksAddLoaded\endinput\else \input pstricks-add \fi



%--- internal macros -------------------------------------
\newdimen\iidp@SubDiv@dimenA
\newdimen\iidp@SubDiv@dimenB
%
\def\pst@SubDiv#1#2#3#4#5{%
\pssetlength{\iidp@SubDiv@dimenA}{#1 pt}%
\psaddtolength{\iidp@SubDiv@dimenA}{-#2 pt}%
\pssetlength{\iidp@SubDiv@dimenB}{#3 pt}%
\psaddtolength{\iidp@SubDiv@dimenB}{-#4 pt}%
\pst@divide{\iidp@SubDiv@dimenA}{\iidp@SubDiv@dimenB}#5%
}
%--- end internal macros ---------------------------------



%--- keys ------------------------------------------------
\define@key{pstgraph}{xmin}{\def\iidp@graph@xmin{#1}}
\define@key{pstgraph}{xmax}{\def\iidp@graph@xmax{#1}}
\define@key{pstgraph}{ymin}{\def\iidp@graph@ymin{#1}}
\define@key{pstgraph}{ymax}{\def\iidp@graph@ymax{#1}}
\define@key{pstgraph}{xgriddiv}{\def\iidp@graph@xgriddiv{#1}}
\define@key{pstgraph}{ygriddiv}{\def\iidp@graph@ygriddiv{#1}}
\define@key{pstgraph}{gridstyle}{\def\iidp@graph@gridstyle{#1}}
\define@key{pstgraph}{gridcolor}{\def\iidp@graph@gridcolor{#1}}
\define@key{pstgraph}{gridwidth}{\def\iidp@graph@gridwidth{#1}}
\define@key{pstgraph}{xticksize}{\def\iidp@graph@xticksize{#1}}
\define@key{pstgraph}{yticksize}{\def\iidp@graph@yticksize{#1}}
\define@key{pstgraph}{xtagsep}{\def\iidp@graph@xtagsep{#1}}
\define@key{pstgraph}{ytagsep}{\def\iidp@graph@ytagsep{#1}}
\define@key{pstgraph}{xtagformat}{\def\iidp@graph@xtagformat{#1}}
\define@key{pstgraph}{ytagformat}{\def\iidp@graph@ytagformat{#1}}
\define@key{pstgraph}{xlabel}{\def\iidp@graph@xlabel{#1}}
\define@key{pstgraph}{ylabel}{\def\iidp@graph@ylabel{#1}}
\define@key{pstgraph}{xlabelsep}{\def\iidp@graph@xlabelsep{#1}}
\define@key{pstgraph}{ylabelsep}{\def\iidp@graph@ylabelsep{#1}}
\define@key{pstgraph}{framewidth}{\def\iidp@graph@framewidth{#1}}
\define@key{pstgraph}{framecolor}{\def\iidp@graph@framecolor{#1}}
%--- end keys --------------------------------------------


%--- initial key values ----------------------------------
\setkeys{pstgraph}{%
xmin=0,xmax=1,ymin=0,ymax=1,%
xgriddiv=1,ygriddiv=1,gridstyle=solid,gridcolor=gray,gridwidth=.5pt,%
xticksize=.1,yticksize=.1,xtagsep=.2,ytagsep=.2,xtagformat=\scriptstyle,ytagformat=\scriptstyle,%
xlabel={},ylabel={},xlabelsep=.55,ylabelsep=.75,framewidth=1pt,framecolor=black%
}
%--- end initial key values ------------------------------


%--- pstgraph --------------------------------------------
\def\iidp@graph@gridDx{}
\def\iidp@graph@gridDy{}
\newcount\iidp@graph@grid
\def\iidp@graph@Dx{}
\def\iidp@graph@Dy{}
\newdimen\iidp@graph@pstgraph@dimen
\def\iidp@graph@xscale{}
\def\iidp@graph@yscale{}
%%-------------------------------
\def\pstgraph{\@ifnextchar[{\pst@graph}{\pst@graph[]}}
\def\pst@graph[#1](#2,#3){%
\setkeys{pstgraph}{#1}%
\pspicture(-\iidp@graph@xlabelsep,-\iidp@graph@ylabelsep)(#2,#3)%
\def\iidp@graph@xframe{#2}
\def\iidp@graph@yframe{#3}
%
\newpsstyle{grid@style}{linestyle=\iidp@graph@gridstyle,linecolor=\iidp@graph@gridcolor,linewidth=\iidp@graph@gridwidth}
%
\pst@divide{\iidp@graph@xframe pt}{\iidp@graph@xgriddiv pt}\iidp@graph@gridDx
\iidp@graph@grid=\iidp@graph@xgriddiv\relax
\advance\iidp@graph@grid\@ne
\pst@SubDiv{\iidp@graph@xmax}{\iidp@graph@xmin}{\iidp@graph@xgriddiv}{0}\iidp@graph@Dx
\multido{\rx=0+\iidp@graph@gridDx,\rlab=\iidp@graph@xmin+\iidp@graph@Dx}{\the\iidp@graph@grid}{%
\rput(\rx,0){\psline[style=grid@style](0,-\iidp@graph@xticksize)(0,#3)}%
\rput[t](\rx,-\iidp@graph@xtagsep){$\iidp@graph@xtagformat\rlab$}%
}
%
\pst@divide{\iidp@graph@yframe pt}{\iidp@graph@ygriddiv pt}\iidp@graph@gridDy
\iidp@graph@grid=\iidp@graph@ygriddiv\relax
\advance\iidp@graph@grid\@ne
\pst@SubDiv{\iidp@graph@ymax}{\iidp@graph@ymin}{\iidp@graph@ygriddiv}{0}\iidp@graph@Dy
\multido{\ry=0+\iidp@graph@gridDy,\rlab=\iidp@graph@ymin+\iidp@graph@Dy}{\the\iidp@graph@grid}{%
\rput(0,\ry){\psline[style=grid@style](-\iidp@graph@yticksize,0)(#2,0)}%
\rput[r](-\iidp@graph@ytagsep,\ry){$\iidp@graph@ytagformat\rlab$}%
}
%
\pst@SubDiv{\iidp@graph@xframe}{0}{\iidp@graph@xmax}{\iidp@graph@xmin}\iidp@graph@xscale
\pst@SubDiv{\iidp@graph@yframe}{0}{\iidp@graph@ymax}{\iidp@graph@ymin}\iidp@graph@yscale
}
%%-------------------------------
\def\endpstgraph{%
\psframe[framearc=0,linewidth=\iidp@graph@framewidth,linecolor=\iidp@graph@framecolor,linestyle=solid,dimen=middle]%
(0,0)(\iidp@graph@xframe,\iidp@graph@yframe)%
%
\pssetlength{\iidp@graph@pstgraph@dimen}{\iidp@graph@xframe}%
\pssetlength{\iidp@graph@pstgraph@dimen}{.5\iidp@graph@pstgraph@dimen}%
\rput[t](\iidp@graph@pstgraph@dimen,-\iidp@graph@xlabelsep){\iidp@graph@xlabel}%
%
\pssetlength{\iidp@graph@pstgraph@dimen}{\iidp@graph@yframe}%
\pssetlength{\iidp@graph@pstgraph@dimen}{.5\iidp@graph@pstgraph@dimen}%
\rput[b]{90}(-\iidp@graph@ylabelsep,\iidp@graph@pstgraph@dimen){\iidp@graph@ylabel}%
\endpspicture}
%--- end pstgraph ----------------------------------------


%--- setpstgraph -----------------------------------------
\def\setpstgraph#1{\setkeys{pstgraph}{#1}}
%--- end setpstgraph -------------------------------------


%--- pstlabel --------------------------------------------
\def\pstlabel#1#2{\setkeys{pstgraph}{xlabel=#1,ylabel=#2}}
%--- end pstlabel ----------------------------------------


%--- pstfileplot -----------------------------------------
\def\pstfileplot{\@ifnextchar[{\pst@fileplot}{\pst@fileplot[]}}
\def\pst@fileplot[#1]#2{%
\ifx\empty#1\empty%
\fileplot[xunit=\iidp@graph@xscale,yunit=\iidp@graph@yscale]{#2}%
\else%
\fileplot[xunit=\iidp@graph@xscale,yunit=\iidp@graph@yscale,#1]{#2}%
\fi%
}
%--- end pstfileplot -------------------------------------