[pstricks] using values read from an external file
Leon Free
leon.free at free.fr
Thu Apr 12 14:04:03 CEST 2012
Hi,
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])%
(some_other_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.
lf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{article}
\usepackage{multido,pstricks}
\begin{document}
%% macro for executing scilab from within latex
\newcommand{\scilab}[1]{%
\write18{scilab -nogui -f #1}}
\newwrite\tempfile
\newwrite\ttempfile
\multido{\rA=.05+.5}{4}{
%
% write the value of \rA in file q.tex
%
\immediate\openout\tempfile=q
\immediate\write\tempfile{\rA}
\immediate\closeout\tempfile
%
% write the scilab instructions in file scilab.tex : compute a[\rA]
% and write its value in file leftcdf
%
\openout\ttempfile=scilab
\write\ttempfile{q=fscanfMat('q.tex');}
\write\ttempfile{a=1-cdfnor("PQ",q,0,1);}
\write\ttempfile{fprintfMat('leftcdf',a);}
\write\ttempfile{quit;}
\closeout\ttempfile
%
% scilab execution
%
\scilab{scilab.tex}
%
% read the value of a[\rA] in leftcdf and put it in \a
%
\newread\inputstream
\immediate\openin\inputstream=leftcdf
\immediate\read\inputstream to \a
\immediate\closein\inputstream
%
% graphics[\rA] : display the value of a[\rA]
% and draw a silly line of no interest
%
\begin{pspicture}(-5,5)
$\alpha = $ \a \rA
\psline(\a,1)(\rA,1)
\end{pspicture}
\newpage
}
\end{document}
More information about the PSTricks
mailing list