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

Alan Ristow Alan.Ristow at ece.gatech.edu
Sun Apr 27 05:56:07 CEST 2003


[Denis -- sorry if you receive this twice, I'm temporarily using an email
system I'm unfamiliar with to reply to messages and it is behaving
differently than I am accustomed to....]

> What \readdata do is to concatenate in a
> macro the coordinates, suppressing the original delimiters and
> introducing a "D" Postscript operator before each of them. For
> instance, with the "data.dat" file that I use for my tests here, the
> macro resulting of \readdata will contain:
>  D 1.2 D 2.3 D 2.7 D -1.1 D 2 D 2 D 4.5 D 0.7539 D 1.7 D 3.9 D 1 D 4.6
> D
>
> -0.43 D 3 D 3.98 D -0.7 D -0.7 D -0.4

Thanks -- in retrospect, this should have been clear from looking at
pst-plot.tex. I don't know why it was not, but I understand now.

>   But if this way is not relevant for what you want to do and if you
> want to
> manage the coordinates by yourself at the TeX level, you have only to
> parse the macro resulting from \readdata (what you seemed to want.) I
> give you an example where you have just to define the \DoCoordinate
> macro to specify what to do with each pair of coordinates (in my
> examples, I just print them or put a dot at the position of the
> coordinate.)

Your example was most helpful. The first of my projects is a routine for
making bar charts, and with your help I have made it work quite well by
defining the plotting command as:

\def\psbarchart#1{%
  \expandafter\CountDataPoints#1%
  \expandafter\GetCoordinates#1%
}

with usage as:

\readdata{\Data}{data.dat}
\psbarchart{\Data}

\CountDataPoints counts the number of values in the data supplied and
increments a counter, while \GetCoordinates is defined in a similar
manner to your example. Then I altered your \DoCoordinate to draw the
bars of the bar chart. As I said, this works quite well.

However, I have defined some keys and would like to be able to use
\psbarchart as I do other pst objects. After scanning some of the other
pst-*.tex files, I have determined that the proper way to do this should
be:

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

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

Thanks again for your help!

Alan Ristow






More information about the PSTricks mailing list