# pgfplotstable: read gnuplot generated table and typeset

I am new to pgfplotstable, I am trying to read gnuplot exported table in pgfplotstable.

gnuplot script:

set samples 91
set table "file.dat"
set angles degrees
plot [0:90] sin(x),cos(x),tan(x);
unset table


gnuplot table file.dat is given below (5 points given to be concise):

# Curve 0 of 3, 91 points
# Curve title: "sin(x)"
# x y type
0  0  i
1  0.0174524  i
2  0.0348995  i
3  0.052336  i
4  0.0697565  i
5  0.0871557  i

# Curve 1 of 3, 91 points
# Curve title: "cos(x)"
# x y type
0  1  i
1  0.999848  i
2  0.999391  i
3  0.99863  i
4  0.997564  i
5  0.996195  i

# Curve 2 of 3, 91 points
# Curve title: "tan(x)"
# x y type
0  0  i
1  0.0174551  i
2  0.0349208  i
3  0.0524078  i
4  0.0699268  i
5  0.0874887  i


Note: It's possible to read table header and format (all data arranged in columns) given below compared to the above case (all data arranged sequentially)

# A B C
1 2 3
4 5 7
8 9 10


Question

Is it possible to read custom format ASCII file in pgfplotstable by \pgfplotstableset{} or any other workarounds in gnuplot to make it read well and typeset in pgfplotstable?

-

Initially I thought you wanted to plot the data but reading your question again it seems you just want to set it as a table using pgfplotstable you can do something like this although I'm not sure pgfplotstable is really helping in this case, by the time you've re-arranged the data to be read by \pgfplotstabletypeset you could simply write it as a longtable, however...

[update for non integer first column]

\documentclass{article}
\usepackage{pgfplotstable,longtable,array}

\begin{document}
\makeatletter

\def\loopb#1\repeatb{\def\iterateb{#1\relax\expandafter\iterateb\fi}%
\iterateb \let\iterateb\relax}
\let\repeatb\fi

\begingroup

\count@\z@
\catcode\#12
\catcode\*=6

\def\tstrelax{\relax}
\def\tsti{i}

\def\ca*1# Curve*2 of *3,*4 points*5!!{%
\def\cnum{*2}\def\ctot{*3}\def\cpoints{*4}}

\def\cb*1# Curve title: "*2"*3!!{%
\def\title{*2}}

\def\cc*1 *2 *3 *4!!{%
\def\x{*1}\def\y{*2}\def\ci{*3}}

\openin\myin=file.dat

\@tempcnta\z@

\loop
\ifeof\myin\else
\expandafter\ifx\expandafter\par\tmp
\else
\expandafter\cb\tmp# Curve title: "\relax"!!%
\ifx\title\tstrelax
\expandafter\ca\tmp# Curve of \relax, points!!%
\ifx\ctot\tstrelax
\expandafter\cc\tmp. . . !!%
\ifx\ci\tsti
\expandafter\edef\csname my-\the\@tempcnta-\the\@tempcntb\endcsname{\ifnum\@tempcnta=1 \x\space\fi\y}
\fi
\else
\let\total\ctot
\let\points\cpoints
\@tempcntb\z@
\fi
\else
\expandafter\let\csname my-\the\@tempcnta-title\endcsname\title
\fi
\fi
\repeat

{\let\\\relax

\gdef\mytable{}
\gdef\row{x}
\@tempcnta\z@
\loop
\xdef\row{\row\space \csname my-\the\@tempcnta-title\endcsname}
\ifnum\@tempcnta<\total
\repeat
\xdef\mytable{\row\space\\\space}

\@tempcntb\z@
\loopb
\xdef\row{}
\@tempcnta\z@
\loop
\xdef\row{\row\space \csname my-\the\@tempcnta-\the\@tempcntb\endcsname}
\ifnum\@tempcnta<\total
\repeat
\xdef\mytable{\mytable\row\space\\\space}
\ifnum\@tempcntb<\points
\repeatb

\show\mytable
\xdef\tmp{\noexpand\pgfplotstabletypeset[row sep=\noexpand\\, begin table=\noexpand\begin{longtable},
end table=\noexpand\end{longtable}
sci,precision=5]{\mytable}}
}

\endgroup

\tmp

\end{document}

-
How to extend on Eg: # Curve 2 of 6(data_sets), 991(numb_pnts) points to typeset with five significant digits after decimal ? – texenthusiast Apr 16 '13 at 21:50
@texenthusiast changing the end of the code to sci,precision=5]{\mytable} does something – David Carlisle Apr 16 '13 at 22:01

Although not a great low level TeX answer like above, surprisingly overlooked previously and found today that using pgfplotstable options ignore chars={\i} to read full gnuplot table file.dat in two columns and select equal part entry of to rearrange two columns into equal rows of 3 columns. But could not find pgfplotstable options to read multiple headers("sin(x)","cos(x)" and "tan(x)") automatically.

\documentclass[12pt]{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{longtable}
\pgfplotstableset{begin table=\begin{longtable},end table=\end{longtable},%
every head row/.style={before row=\toprule,after row=\midrule},%
every last row/.style={after row=\bottomrule},%
every even row/.style={before row={\rowcolor[gray]{.8}}}%
}
\begin{document}
\pgfplotstabletypeset[columns={0,1,1,1},%
display columns/0/.style={select equal part entry of={0}{3},column name=$x$},%
display columns/1/.style={select equal part entry of={0}{3},column name=$sin(x)$},%
display columns/2/.style={select equal part entry of={1}{3},column name=$cos(x)$},%
display columns/3/.style={select equal part entry of={2}{3},column name=$tan(x)$},%
precision=5,ignore chars={\i}]{file.dat}
\end{document}

-