I would like to conditionally print something in a report, based on whether there was a non-zero data point or not (for this example, \DepthOne and \DepthThree are to be tested).
I start by reading values in from a csv table using \csvreader, and then I assign these a label using \newcommand.
Then I apply a test on the label using \ifnum. The behaviour in the implementation below is not what I hoped for. For instance, I get missing number, treated as zero errors and weird output preceding the sentence.
Also, oddly one of the labels I assigned (\SampleName) doesn't seem to persist.
Is it possible to do what I am attempting, and what is the right way to go about this?
\documentclass[10pt]{report}
\usepackage{csvsimple}
\usepackage{filecontents}
\newcommand*{\ThisRock}{examplecsv}
% Make up some data in a CSV file called examplecsv.csv
\begin{filecontents*}{\ThisRock.csv}
SampleName,Depth1,DepthTwo,Depth3
ROCK001,48,52,0
\end{filecontents*}
% Pick out specific data in the file and create labels for them to be read by latex
\newcommand*{\SampleName}{\csvreader{\ThisRock.csv}{1=\SampleName}{\SampleName}}
\newcommand*{\DepthOne}{\csvreader{\ThisRock.csv}{2=\Depth1}{\Depth1}}
\newcommand*{\DepthTwo}{\csvreader{\ThisRock.csv}{3=\DepthTwo}{\DepthTwo}}
\newcommand*{\DepthThree}{\csvreader{\ThisRock.csv}{4=\Depth3}{\Depth3}}
\begin{document}
% Show the data (normally this is underwater)
\csvautotabular{examplecsv.csv} \\
% Expect this to print the sentence twice fully (first time is okay, second time incomplete?)
The rock sampled was called \SampleName. \\
The rock sampled was called \SampleName. \\
% Because there is some non-zero data for the first sample, expect this to print the sentence
\ifnum\ifnum\DepthOne>0 1\else0\fi
=1 %
\noindent The first sample hole was drilled to \DepthOne~mm\\
\else
\\
\fi
% Because the data is zero for the third sample, expect this not to print the sentence
\ifnum\ifnum\DepthThree>0 1\else0\fi
=1 %
\noindent The third sample hole was drilled to \DepthThree~mm\\
\else
\\
\fi
\end{document}




\DepthOneetc. aren't expandable apparently, so\ifnum\Depth...will fail -- it can't evaluate the test,\cvsreaderis not expandable since it has an optional first argument, so\DepthOneetc. can't be expanded as well – Feb 09 '17 at 22:55\ifcvsstrequaletc. (see the manual please) are more useful? I can't test right now... it's late and I am tired! – Feb 09 '17 at 22:59readarraypackage, as an alternative. – Steven B. Segletes Feb 10 '17 at 02:45