[Fwd: Re: [pstricks] Accessing data in files on disk]

Denis Girou Denis.Girou at idris.fr
Tue Apr 29 00:17:20 CEST 2003


>>>>> "Alan.Ristow" == Alan Ristow <Alan.Ristow at ece.gatech.edu> writes:

    Alan.Ristow> \def\psbarchart{\def\pst at par{}\pst at object{psbarchart}}
    Alan.Ristow>   \def\psbarchart at i#1{%
    Alan.Ristow>     \expandafter\CountDataPoints#1%
    Alan.Ristow>     \expandafter\GetCoordinates#1%
    Alan.Ristow>   }

    Alan.Ristow> However, this fails to work. \CountDataPoints gets executed, but
    Alan.Ristow> \GetCoordinates does not. My guess is that \psbarchart at i needs to be
    Alan.Ristow> preceeded by \expandafter when it is called, but that the calling
    Alan.Ristow> mechanism provided by \pst at object does not do this. I'm still working on
    Alan.Ristow> my TeX programming skills, though, so I'm not quite sure how to proceed
    Alan.Ristow> here. Suggestions?

  Well... This is only because my \GetCoordinates macro was not robust (that
is to say badly tested / written...) A \relax was missing. This version seems
better...  Nevertheless, always try to give a _minimal_ and _complete_ test
file. This save time for others and is simpler than to guess what you are
using.

\begin{filecontents}{data.dat}
(1.2,2.3)
(2.7,-1.1) (2,2)       (4.5,0.7539)
(1.7,3.9)  (1,4.6)
(-0.43,3)  (3.98,-0.7) (-0.7,-0.4)
\end{filecontents}

\documentclass[a4paper]{article}

\usepackage{pst-plot}

\makeatletter

\def\CountDataPoints#1{\expandafter\CountDataPoints at i#1 \relax}

\def\CountDataPoints at i #1{\CountDataPoints at ii#1}

\def\CountDataPoints at ii#1 #2 #3 #4 {%
\advance\pst at cnta\@ne
\@ifnextchar D{\CountDataPoints at ii}{}}

\def\GetCoordinates#1{\expandafter\GetCoordinates at i#1 \relax}

\def\GetCoordinates at i #1{\GetCoordinates at ii#1}

\def\GetCoordinates at ii#1 #2 #3 #4 {%
\DoCoordinate{#2}{#4}%
\@ifnextchar D{\GetCoordinates at ii}{}}

\def\psbarchart{\def\pst at par{}\pst at object{psbarchart}}

\def\psbarchart at i#1{%
\pst at cnta=\z@
\CountDataPoints{#1}%
\typeout{Number of points: \the\pst at cnta}%
\GetCoordinates{#1}}

\makeatother

\pagestyle{empty}

\begin{document}

\readdata{\Data}{data.dat}

\def\DoCoordinate#1#2{\typeout{New point: (#1,#2)}}

\psbarchart{\Data}

\end{document}


D.G.



More information about the PSTricks mailing list