1

I get a code from @DavidCarlisle, that generate output-txt-files, and I want to put all the outputfiles in a pgfplotstable together.
So I try adding
\ifnum\the\filecount=1 \pgfplotstableread[col sep=comma]{data1.txt}{\main} \else {.........} \fi

But this gives only some strange Omegas and \pgfplotstabletypeset[col sep=comma]{\main} does not work.

What have I to do?

enter image description here

\documentclass[a4paper]{article}
\usepackage{pgfplotstable}

\newcount\filecount
\newwrite\cisout
\begin{document}

{
\endlinechar=\newlinechar%
\filecount=1 %
\def\aaa{file number \the\filecount}%
\loop%
\immediate\openout\cisout=data\the\filecount.txt %
\immediate\write\cisout{%
111, 222,   \aaa 
}%
\immediate\closeout\cisout %
\advance\filecount by 1 %
\ifnum\filecount<5 %
\ifnum\the\filecount=1 \pgfplotstableread[col sep=comma]{data1.txt}{\main} \else\fi
\repeat %
}%

\section{pgfplotstable Test - bad}
%\pgfplotstabletypeset[col sep=comma]{\main}
\dots and some bad Omegas above\dots

\section{input Test - good}
\input{data1.txt}
\input{data3.txt}
\end{document}
11
  • \pgfplotstableread[col sep=comma,header=false]{data1.txt}{\main} \pgfplotstabletypeset[col sep=comma,string type]{\main} works for me.
    – user194703
    Dec 5, 2019 at 15:03
  • \ifnum\the\filecount=1 \pgfplotstableread[col sep=comma]{data1.txt}{\main} \else\fi is never going to be true as you start with filecount=1 and you increment it two lines above this test so it will never be less than 2. Dec 5, 2019 at 15:09
  • @DavidCarlisle, @ Schrödinger'scat I am not able to fix it.
    – cis
    Dec 5, 2019 at 15:15
  • you haven't said what you want to do, do you just want to read the first file or read them all? Either way move the tableread command to before the \advance\filecount, but after the \closeout. Also why write the data to the filesystem then read it back isn't that just making things slow for no reason? Dec 5, 2019 at 15:21
  • I need a method to create a pgfplotstable by rows - the code here is only the MWE-base for that. So for the problem here: I need a pgfplotstable with all the outpufiles as rows. I think I have done what you said and moved \pgfplotstableread to serveral positions. But something is not going to work at mine.
    – cis
    Dec 5, 2019 at 15:27

2 Answers 2

2

You're doing \ifnum\filecount=1 when the counter has already been advanced, so the code for \pgfplotstableread is never executed.

Besides, even if you manage to execute it, the whole \loop is in a group, so \main will be forgotten at the end of the group.

The Omegas were produced because \fi was not followed by %.

Here's a working code, although it's not clear what your aim is.

\documentclass[a4paper]{article}
\usepackage{pgfplotstable}

\newcount\filecount
\newwrite\cisout

\begin{document}

\filecount=1
\def\aaa{file number \the\filecount}%
\loop
\immediate\openout\cisout=data\the\filecount.txt
\immediate\write\cisout{%
111, 222,   \aaa
}
\immediate\closeout\cisout
\ifnum\the\filecount=1 \pgfplotstableread[col sep=comma]{data1.txt}{\main}\fi
\advance\filecount by 1
\ifnum\filecount<5
\repeat

\section{pgfplotstable Test - bad}

\pgfplotstabletypeset[col sep=comma]{\main}

\section{input Test - good}
\input{data1.txt}
\input{data3.txt}
\end{document}

enter image description here

6
  • Oh... Could you add please that every row, the loop creates, is added to \main? I got the next problem with \pgfplotstablevertcat{\main}{\temp} after "\else"
    – cis
    Dec 5, 2019 at 17:32
  • @cis Why not writing a single file?
    – egreg
    Dec 5, 2019 at 17:57
  • Yes, Mr. Carlisle ask the same; but I do not know how to do that with "openout-write-loop-..." command. With other words: I don not know, how to create '1' textfile and add rows per loop.
    – cis
    Dec 5, 2019 at 19:16
  • Ouuhh and very important: I need for my algorithm the content of previous rows to be computated in later rows!!!
    – cis
    Dec 5, 2019 at 19:21
  • Thank you very much. I think, it is better to close here. I will make a follow-up question. ;)
    – cis
    Dec 6, 2019 at 10:44
1

Ultimately, is this what you are trying to achieve?

\documentclass[a4paper]{article}
\usepackage{pgfplotstable}

\newcount\filecount
\newwrite\cisout
\begin{document}

{
\filecount=0
\immediate\openout\cisout=data1.txt
\immediate\write\cisout{a, b, c}% write header
\loop\ifnum\filecount<5
  \advance\filecount by 1
  \immediate\write\cisout{111, 222, \the\filecount }%
\repeat% no \fi needed
\immediate\closeout\cisout

\pgfplotstableread[col sep=comma]{data1.txt}{\main}%

\pgfplotstabletypeset\main
\end{document}

demo


This version uses \foreach.

\documentclass[a4paper]{article}
\usepackage{pgfplotstable}

\newwrite\cisout

\begin{document}
\immediate\openout\cisout=data1.txt
\immediate\write\cisout{a, b, c}% write header
\foreach \i in {1,..., 5}%
  {\immediate\write\cisout{111, 222, \i }}%
\immediate\closeout\cisout

\pgfplotstableread[col sep=comma]{data1.txt}{\main}%

\pgfplotstabletypeset\main
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .