[pstricks] Generate Table via \readdata
Buddy Ledger
buddyledger at gmail.com
Wed Apr 22 03:22:28 CEST 2009
Herbert
I've run into the mysterious extra column/row before. For some reason
when I write it like this (see below) it works fine. It seems to me
that \@ifnextchar D{do something}{do nothing} really doesn't do nothing
if next char is not D. Therfore if you write \@ifnextchar D{do
something}{do something else} the problem is resolved. I am just
guessing however.
\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage{pst-func}
\usepackage{filecontents}% allows overwriting
\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*}
\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 {%
\makebox[5em]{\psPrintValue{#1}}
\@ifnextchar D{%
\global\advance\pst at cntm by \@ne
\ifnum\pst at cntm>\dataNo
\global\pst at cntm=\@ne
\\\hline \else & \fi
\fillTab at ii}{\\\hline}}
\def\fillTab#1{%
\global\pst at cntm=\@ne
\expandafter\fillTab at i#1}
\makeatother
\parindent=0pt
\begin{document}
\readLine{doterrorbar.dat}{\dataNo}
\readdata{\data}{doterrorbar.dat}
the data:\\
\ttfamily|\data|
\bigskip
\begin{tabular}{|*{\dataNo}{r|}}\hline
\fillTab{\data}
\end{tabular}
\end{document}
More information about the PSTricks
mailing list