%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% pst-eqdf.tex --- plotting of differential equations
%% Copyright 2004 Dominique RODRIGUEZ
%%
%% Author          : Dominique RODRIGUEZ (EN) <dominique.rodriguez@waika9.com>
%% Created the     : ven avr  2 22:02:01 CEST 2004
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% HISTORY
%%
%% 2004-04-04 : creation of the file from a first LaTeX protype sty file
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\fileversion{pre-1.0}
\def\filedate{2004/03/21}%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt.
%% adapation de M.Luque juin 2012 pour
%% sauvegarde de tableaux de valeurs
\message{`PST-Equadiff v\fileversion, \filedate\space (Dominique RODRIGUEZ)}%
\csname PSTEquadiffLoaded\endcsname
\let\PSTEquadiffLoaded\endinput
% Require PSTricks and pst-node packages
\ifx\PSTplotLoaded\endinput\else\input pst-plot.tex\fi
%% prologue for postcript
%%\pstheader{pst-eucl.pro}%
% DPC interface to the `keyval' package (until keyval based version of PSTricks)
%\input pst-key.tex
\edef\PstAtCode{\the\catcode`\@}%
\catcode`\@=11\relax
% Definition of the parameters
% ----------------------------
\pst@addfams{pst-eqd}
\define@key[psset]{pst-eqd}{method}{\edef\psk@method{#1}}%
\define@key[psset]{pst-eqd}{whichabs}{\edef\psk@whichabs{#1}}%
\define@key[psset]{pst-eqd}{whichord}{\edef\psk@whichord{#1}}%
\define@key[psset]{pst-eqd}{plotfuncx}{\edef\psk@plotfuncx{#1}}%
\define@key[psset]{pst-eqd}{plotfuncy}{\edef\psk@plotfuncy{#1}}%
\define@key[psset]{pst-eqd}{tabname}{\edef\psk@tabname{#1}}%
\define@key[psset]{pst-eqd}{filename}{\edef\psk@filename{#1}}%
\newif\ifPst@buildvector%
\define@key[psset]{pst-eqd}{buildvector}[true]{\@nameuse{Pst@buildvector#1}}%
\newif\ifPst@saveData%
\define@key[psset]{pst-eqd}{saveData}[true]{\@nameuse{Pst@saveData#1}}%
\psset{method=default, whichabs=default, whichord=default, filename=datas.dat,
  plotfuncx=default, plotfuncy=default, buildvector=false,tabname=tabValues,saveData=false}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SpecialCoor%% for using polar coordinates, node position, ...
\psset{dimen=middle}% remark of ML
\def\@undef{undef}%
\def\@default{default}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% #1-#2 x range
%% #3 initial value of y (which is a vector)
%% #4 value of the dérivative (y and t can be used)
\def\psequadiff{\def\pst@par{}\pst@object{psequadiff}}
\def\psequadiff@i#1#2#3#4{%
  \pst@killglue
  \begingroup
    \use@par
%    \@nameuse{beginplot@\psplotstyle}%
  \addto@pscode{%
    /x #1 def
    /x1 #2 def
    /y [ #3 ] def
    /ylength y length def
    /addvect
     { /len exch def 1 1 len
       { /i exch def len i sub 2 add -1 roll add len 2 mul i sub 1 roll } for } def
    /dx x1 x sub \psk@plotpoints div def
    /mulvect { exch 1 index { dup 4 -1 roll mul 2 index 2 add 1 roll } repeat pop pop } def
    /divvect { exch 1 index { dup 4 -1 roll exch div 2 index 2 add 1 roll } repeat pop pop } def
    /k0 0 def /k1 0 def /k2 0 def /k3 0 def
  \ifPst@algebraic /F@pstplot (#4) AlgParser cvx def \fi
   /Func {
      \ifPst@algebraic F@pstplot ylength array astore
      \else
        \ifPst@buildvector\else y aload pop \fi #4
        \ifPst@buildvector\else ylength array astore \fi
      \fi
    } def
    /xy {
  \ifx\psk@method\@default%
      \ifx\psk@plotfuncx\@default
        \ifx\psk@whichabs\@default x \else y \psk@whichabs\space get \fi%
      \else\psk@plotfuncx\space\fi%
      \pst@number\psxunit mul
      y /y Func { dx mul } forall y aload pop ylength addvect ylength array astore def
      \ifx\psk@plotfuncy\@default
        \ifx\psk@whichord\@default 0 \else\psk@whichord\space\fi get %
      \else\psk@plotfuncy\space\fi
  \else%
      \ifx\psk@plotfuncx\@default
        \ifx\psk@whichabs\@default x \else y \psk@whichabs\space get \fi%
      \else\psk@plotfuncx\space\space\fi%
      y /k0 Func { dx mul } forall ylength array astore def %% y
      dup aload pop k0 { 2 div } forall ylength addvect ylength array astore /y exch def %
      x dup dx 2 div add /x exch def %% y x
      /k1 Func { dx mul } forall ylength array astore def %% y x
      exch dup aload pop k1 { 2 div } forall ylength addvect y astore pop %% x y
      /k2 Func { dx mul } forall ylength array astore def %% x y
      dup aload pop k2 aload pop ylength addvect y astore pop exch dup dx add /x exch def %% y x
      /k3 Func { dx mul } forall ylength array astore def %% y x
      /x exch def %% y
      dup aload pop k0 aload pop k1 aload pop k2 aload pop ylength addvect
      2 ylength mulvect ylength addvect k3 aload pop ylength addvect
      6 ylength divvect ylength addvect y astore pop
      \ifx\psk@plotfuncy\@default
        \ifx\psk@whichord\@default 0 \else\psk@whichord\space\fi get %
      \else\psk@plotfuncy\space\fi
  \fi
    } def}%
\addto@pscode{%
/\psk@tabname [
  \psk@plotpoints {
        xy
        /x x dx add
         def
     } repeat
      /x x1 def
      xy
    ] def
\ifPst@saveData
/fichierpoints (\psk@filename) (w) file def
0 2 \psk@tabname\space length 2 sub  {/i exch def
    /xi \psk@tabname\space i get def
    /yi \psk@tabname\space i 1 add get def
      fichierpoints xi 15 string cvs writestring
      fichierpoints 32 write %% espace
      fichierpoints yi 15 string cvs writestring
      fichierpoints 32 write %% espace
      fichierpoints 10 write %% CR
} for
fichierpoints closefile
\fi
    }%
%\psdot[linecolor=white,dotsize=0.001](0,0)
  \endgroup
  \ignorespaces}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
