[pstricks] using values read from an external file

Leon Free leon.free at free.fr
Thu Apr 12 14:04:03 CEST 2012

I'd like to produce a sequence of n graphics where graphics[i] depends
on the value a[i] of a parameter a. For some reason, the values
a[1],...,a[n] cannot be computed by latex+dvips directly. In particular,
I want graphics[i] to display the value a[i].

The simplified pstricks pseudocode would look like

1. \multido{\iA=1+1}{n}{
2. \begin{pspicture}
3. \readdata{\data}{mydata.dat}
4. "read the value a[\iA]"
5. \psline(some_coordinates_involving_[\iA])%
6. \listplot[xStart=number_depending_on_a[\iA]]{\data}
7. \rput(some_coordinates){a[\iA]}
8. \end{pspicture}
9. \newpage
10. }

My problem is with line 4. I can think of 2 ways of producing those n
graphics :

1. (a[1],...,a[n]) is a column of the file mydata.dat. After reading
that file (line 3 : \readdata{\data}{mydata}), the latex object \data is
some kind of list which contains the a[i] values with a D separation. Is
it possible to extract the \iA th element from that list at each \iA
\multido step ?

2. a[1],...,a[n] are in a given file a.dat. Is there any latex/pstrick
macro that would read a particular line in an external file and storing
the result in a tex variable ?

As an example, I tried doing something similar to 2 (but more complex
because the a[i] are generated by an external program and read by latex
"on the fly"). Here is my exemple (needs scilab to be run). It does what
I want, but it's really hugly. Compiles with --shell-escape option.



%% macro for executing scilab from within latex
\write18{scilab -nogui -f #1}}


% write the value of \rA in file q.tex
% write the scilab instructions in file scilab.tex : compute a[\rA]
% and write its value in file leftcdf
% scilab execution
% read the value of a[\rA] in leftcdf and put it in \a
    \immediate\read\inputstream to \a
% graphics[\rA] : display the value of a[\rA]
% and draw a silly line of no interest
$\alpha = $ \a \rA

More information about the PSTricks mailing list