[pstricks] Generate Table via \readdata
Herbert Voss
Herbert.Voss at FU-Berlin.DE
Mon Apr 20 16:55:27 CEST 2009
Buddy Ledger schrieb:
> I've been trying to develop a macro which will typeset a data file into
> a table. The code below represents my most sucsessful atempt. I want
> to be able to generate a table for any data file which could be used
> with listplot. So far I am having trouble generating the column format
> string for the tabular environment and I cannot dynamically set the
> number of colums via an input argument. I have no doubt these problems
> are due to my limited knowledge of advanced Tex/Latex macro
> programming. Any help with this would be appreciated. My objective is
> to typeset data tables which are in plot format rather than TeX
> format. Possible advanced options would be to only print selected
> columns and possibly provide the column labels in the data file and have
> them typeset in mathmode, or formatting of numerical data. Any
> input/help or simplifications would be appreciated.
>
> \begin{filecontents}{doterrorbar.dat}
>
> 1.00E+001 2.00E+001 3.00E+001 4.00E+001
> 2.00E+001 3.00E+001 4.00E+001 5.00E+001
> 3.00E+001 4.00E+001 5.00E+001 6.00E+001
> 4.00E+001 5.00E+001 6.00E+001 7.00E+001
> \end{filecontents}
important is that you use the star version of filecontents which
supresses the output of the first three comment lines
Herbert
\begin{filecontents*}{doterrorbar.dat}
1.00E+001 2.00E+001 3.00E+001 4.00E+001
2.00E+001 3.00E+001 4.00E+001 5.00E+001
3.00E+001 4.00E+001 5.00E+001 6.00E+001
4.00E+001 5.00E+001 6.00E+001 7.00E+001
\end{filecontents*}
\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage{pstricks-add}
\makeatletter
\def\checkEntries#1 #2#3\@nil{%
\def\@tempA{#3}
\ifx\@tempA\@empty\else
\global\advance\pst at cnta\@ne%
\expandafter\checkEntries#2#3\@nil
\fi}
\def\readLine#1#2{%
\openin1=#1
\read1 to \pst at tempa
\global\pst at cnta=0
\expandafter\checkEntries\pst at tempa\space\@nil
\advance\pst at cnta\@ne
\gdef#2{\the\pst at cnta}\ignorespaces}
\def\fillTab at i#1{\fillTab at ii#1}
\def\fillTab at ii D #1 {%
\global\advance\pst at cntm by \@ne
#1 \ifnum\pst at cntm=\pst at cntn \global\pst at cntm=0 \tabularnewline \else
& \fi
\@ifnextchar D\fillTab at ii{}}
\def\fillTab#1{%
\global\pst at cntm=0
\global\pst at cntn=\dataNo
\expandafter\fillTab at i#1}
\makeatother
\begin{document}
\readLine{doterrorbar.dat}{\dataNo}
\readdata{\data}{doterrorbar.dat}
\begin{tabular}{|*{\dataNo}{r|}}\hline
\fillTab{\data}\\\hline
\end{tabular}
\end{document}
More information about the PSTricks
mailing list