From 2c744df230bea4ca067782081c0fe56c5e9820de Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 19 Apr 2013 23:41:18 +0000 Subject: readarray (19apr13) git-svn-id: svn://tug.org/texlive/trunk@30048 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/readarray/readarray.sty | 38 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'Master/texmf-dist/tex/latex/readarray') diff --git a/Master/texmf-dist/tex/latex/readarray/readarray.sty b/Master/texmf-dist/tex/latex/readarray/readarray.sty index ccdc9a7cb36..535e4b76bc6 100644 --- a/Master/texmf-dist/tex/latex/readarray/readarray.sty +++ b/Master/texmf-dist/tex/latex/readarray/readarray.sty @@ -1,5 +1,5 @@ \ProvidesPackage{readarray} -[2013/04/02 v1.01 +[2013/04/18 v1.1 Routines for inputting array data and recalling it on an element-by-element basis. Currently supports 2-D and 3-D array] % The latest version of this license is in @@ -13,6 +13,7 @@ element-by-element basis. Currently supports 2-D and 3-D array] % % Revisions: % v1.01 Documentation revision +% v1.1 Added \csname record\roman{@row}\endcsname to \readdef \usepackage{ifthen} \usepackage{ifnextok} % @@ -21,6 +22,7 @@ element-by-element basis. Currently supports 2-D and 3-D array] \newcounter{@row} \newcounter{@col} \newcounter{use@args} +\newcounter{@record} \def\the@rule{\rule{.8ex}{1.6ex}}% % \newcommand\readArrayijk[4]{% @@ -64,6 +66,7 @@ element-by-element basis. Currently supports 2-D and 3-D array] \addtocounter{@row}{-1}% \setcounter{use@args}{\numexpr\arabic{@row}*#3}% }{}% + \expandafter\edef\csname#2PLANES\endcsname{1}% \expandafter\edef\csname#2ROWS\endcsname{\arabic{@row}}% \expandafter\edef\csname#2COLS\endcsname{#3}% \expandafter\edef\csname#2CELLS\endcsname{\arabic{use@args}}% @@ -83,6 +86,9 @@ element-by-element basis. Currently supports 2-D and 3-D array] }% } % +\def\nonposrecordmessage{{\tiny Only positive showrecords permitted}} +\def\recordmessage#1{{\tiny RECORD=#1 exceeds records read}} +% \def\nonposmessage{{\tiny Only positive array indices permitted}} \def\planemessage#1#2{{\tiny PLANE=#2 exceeds limit for #1}} \def\rowmessage#1#2{{\tiny ROW=#2 exceeds limit for #1}} @@ -120,15 +126,40 @@ element-by-element basis. Currently supports 2-D and 3-D array] }% } % +\newcommand\copyrecords[1]{% + \setcounter{@record}{0}% + \whiledo{\value{@record} < \nrecords}{% + \addtocounter{@record}{1}% + \expandafter\protected@edef\csname#1X\roman{@record}Xi\endcsname{% + \csname record\roman{@record}\endcsname}% + }% + \expandafter\edef\csname#1PLANES\endcsname{1}% + \expandafter\edef\csname#1ROWS\endcsname{\nrecords}% + \expandafter\edef\csname#1COLS\endcsname{1}% + \expandafter\edef\csname#1CELLS\endcsname{\nrecords}% +} +% +\newcommand\showrecord[2][$]{% + \setcounter{@record}{#2}% + \ifthenelse{\value{@record}<1}{% + \if$#1\nonposrecordmessage\else#1\fi}{% + \ifthenelse{#2 > \nrecords}{% + \if$#1\recordmessage{#2}\else#1\fi}{% + \csname record\roman{@record}\endcsname}% + }% +} +% \newcommand\readdef[2]{% \def\first@row{T}% \def\first@plane{T}% \catcode\endlinechar=10\relax% \def#2{}% +\setcounter{@record}{0}% \newread\file% \openin\file=#1% \loop\unless\ifeof\file% \read\file to\fileline % Reads a line of the file into \fileline% + \addtocounter{@record}{1}% \protected@edef#2{#2\fileline}% \if T\first@row\getargsC{#2}\setcounter{@col}{\numexpr(\narg-1)}% \edef\ncols{\arabic{@col}}\def\first@row{F}\setcounter{@row}{1}% @@ -136,9 +167,12 @@ element-by-element basis. Currently supports 2-D and 3-D array] \if T\first@plane\getargsC{\fileline}\ifthenelse{\equal{\narg}{1}}{% \edef\nrows{\arabic{@row}}\def\first@plane{F}}{% \addtocounter{@row}{1}}% - \fi + \fi% \fi% + \expandafter\protected@edef\csname record\roman{@record}\endcsname{% + \fileline}% \repeat% +\edef\nrecords{\arabic{@record}}% \closein\file% \catcode\endlinechar=5\relax% } -- cgit v1.2.3