This is related to a previous question I asked - Plotting data blocks of varying length using PGFPlots and gnuplot.
Here is a minimum working example:
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass[a4paper,12pt]{article}
\usepackage{pgfplots,filecontents}
\begin{filecontents*}{data.csv}
"Amplitude","notes: data set 1",
X,Y,
1,1,
2,2,
3,3,
4,4,
"Amplitude","notes: data set 2",
X,Y,
1,7,
2,6,
3,5,
4,4,
5,3,
6,2,
7,1,
"CH1","notes: data set 1",
"CH1","notes: data set 2",
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis} [width=0.5\textwidth,height=7cm,
]
\addplot gnuplot [raw gnuplot, mark=none, black]{
set datafile separator comma;
plot "<(sed -n '3,6p' data.csv)" using 1:2 with lines;
};
\addplot gnuplot [raw gnuplot, mark=none, red]{
set datafile separator comma;
plot "<(sed -n '10,16p' data.csv)" using 1:2 with lines;
};
\end{axis}
\end{tikzpicture}
\end{document}
My question is, is there a way to get TeX to locate the blank lines in the .csv
file? Using datatool
or something like that? If I could get locations of the blank lines, it could tell me that (a) there are two data sets, and (b) I could work out the length of each data set.
In this example, the blank lines are at line 7 and line 17. So data set 1 goes from line 3 to 6 (7-1) and data set 2 goes from 10 (7+3) to 16 (17-1). This would enable me to automatically generate the gnuplot
commands and enable me to answer Plotting data blocks of varying length using PGFPlots and gnuplot.
\readdef
from my other answer appears to skip over blank lines in the input, and so is unable to detect them explicitly. – Steven B. Segletes May 1 at 3:03