From b6aea40f0cbaf1008c78115ead2666210aebb165 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 26 Mar 2013 21:30:29 +0000 Subject: readarray (26mar13) git-svn-id: svn://tug.org/texlive/trunk@29518 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/readarray/readarray.sty | 198 +++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 Master/texmf-dist/tex/latex/readarray/readarray.sty (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 new file mode 100644 index 00000000000..8978292ad13 --- /dev/null +++ b/Master/texmf-dist/tex/latex/readarray/readarray.sty @@ -0,0 +1,198 @@ +\ProvidesPackage{readarray} +[2013/03/25 v1.0 +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 +% http://www.latex-project.org/lppl.txt +% and version 1.3c or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% This work has the LPPL maintenance status `maintained'. +% +% The Current Maintainer of this work is Steven B. Segletes. +% +\usepackage{ifthen} +\usepackage{ifnextok} +% +\newcounter{@index} +\newcounter{@plane} +\newcounter{@row} +\newcounter{@col} +\newcounter{use@args} +\def\the@rule{\rule{.8ex}{1.6ex}}% +% +\newcommand\readArrayijk[4]{% + \getargsC{#1}% + \setcounter{@plane}{\numexpr(\narg/#4/#3)}% + \setcounter{use@args}{\numexpr\arabic{@plane}*#3*#4}% + \ifthenelse{\arabic{use@args} > \narg}{% + \addtocounter{@plane}{-1}% + \setcounter{use@args}{\numexpr\arabic{@plane}*#3*#4}% + }{}% + \expandafter\edef\csname#2PLANES\endcsname{\arabic{@plane}}% + \expandafter\edef\csname#2ROWS\endcsname{#3}% + \expandafter\edef\csname#2COLS\endcsname{#4}% + \expandafter\edef\csname#2CELLS\endcsname{\arabic{use@args}}% + \setcounter{@index}{0}% + \setcounter{@plane}{1}% + \setcounter{@row}{1}% + \setcounter{@col}{0}% + \whiledo{\value{@index} < \value{use@args}}{% + \addtocounter{@index}{1}% + \addtocounter{@col}{1}% + \ifthenelse{\value{@col} > #4}% + {\addtocounter{@row}{1}% + \addtocounter{@col}{-#4}}% + {}% + \ifthenelse{\value{@row} > #3}% + {\addtocounter{@plane}{1}% + \addtocounter{@row}{-#3}}% + {}% + \expandafter\protected@edef% + \csname#2X\roman{@plane}X\roman{@row}X\roman{@col}\endcsname% + {\expandafter\csname arg\roman{@index}\endcsname}% + }% +} +% +\newcommand\readArrayij[3]{% + \getargsC{#1}% + \setcounter{@row}{\numexpr(\narg/#3)}% + \setcounter{use@args}{\numexpr\arabic{@row}*#3}% + \ifthenelse{\arabic{use@args} > \narg}{% + \addtocounter{@row}{-1}% + \setcounter{use@args}{\numexpr\arabic{@row}*#3}% + }{}% + \expandafter\edef\csname#2ROWS\endcsname{\arabic{@row}}% + \expandafter\edef\csname#2COLS\endcsname{#3}% + \expandafter\edef\csname#2CELLS\endcsname{\arabic{use@args}}% + \setcounter{@index}{0}% + \setcounter{@row}{1}% + \setcounter{@col}{0}% + \whiledo{\value{@index} < \value{use@args}}{% + \addtocounter{@index}{1}% + \addtocounter{@col}{1}% + \ifthenelse{\value{@col} > #3}% + {\addtocounter{@row}{1}% + \addtocounter{@col}{-#3}}% + {}% + \expandafter\protected@edef% + \csname#2X\roman{@row}X\roman{@col}\endcsname% + {\expandafter\csname arg\roman{@index}\endcsname}% + }% +} +% +\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}} +\def\colmessage#1#2{{\tiny COL=#2 exceeds limit for #1}} +% +\newcommand\Arrayijk[5][$]{% + \setcounter{@plane}{#3}% + \setcounter{@row}{#4}% + \setcounter{@col}{#5}% + \ifthenelse{\value{@plane}<1 \OR \value{@row}<1 \OR \value{@col}<1}{% + \if$#1\nonposmessage\else#1\fi}{% + \ifthenelse{#3 > \csname#2PLANES\endcsname}{% + \if$#1\planemessage{#2}{#3}\else#1\fi}{% + \ifthenelse{#4 > \csname#2ROWS\endcsname}{% + \if$#1\rowmessage{#2}{#4}\else#1\fi}{% + \ifthenelse{#5 > \csname#2COLS\endcsname}{% + \if$#1\colmessage{#2}{#5}\else#1\fi}{% + \csname#2X\roman{@plane}X\roman{@row}X\roman{@col}\endcsname}% + }% + }% + }% +} +% +\newcommand\Arrayij[4][$]{% + \setcounter{@row}{#3}% + \setcounter{@col}{#4}% + \ifthenelse{\value{@row}<1 \OR \value{@col}<1}{% + \if$#1\nonposmessage\else#1\fi}{% + \ifthenelse{#3 > \csname#2ROWS\endcsname}{% + \if$#1\rowmessage{#2}{#3}\else#1\fi}{% + \ifthenelse{#4 > \csname#2COLS\endcsname}{% + \if$#1\colmessage{#2}{#4}\else#1\fi}{% + \csname#2X\roman{@row}X\roman{@col}\endcsname}% + }% + }% +} +% +\newcommand\readdef[2]{% +\def\first@row{T}% +\def\first@plane{T}% +\catcode\endlinechar=10\relax% +\def#2{}% +\newread\file% +\openin\file=#1% +\loop\unless\ifeof\file% + \read\file to\fileline % Reads a line of the file into \fileline% + \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}% + \else% + \if T\first@plane\getargsC{\fileline}\ifthenelse{\equal{\narg}{1}}{% + \edef\nrows{\arabic{@row}}\def\first@plane{F}}{% + \addtocounter{@row}{1}}% + \fi + \fi% +\repeat% +\closein\file% +\catcode\endlinechar=5\relax% +} +% +\newcommand\showargs[1][0]{% + narg=\narg:~% + \the@rule% + \setcounter{arg@index}{0}% + \setcounter{break@count}{0}% + \whiledo{\value{arg@index} < \narg}{% + \addtocounter{arg@index}{1}% + \addtocounter{break@count}{1}% + \csname arg\roman{arg@index}\endcsname% + \the@rule% + \ifthenelse{\equal{#1}{\value{break@count}}}{% + \ifthenelse{\equal{\value{arg@index}}{\narg}}{}{% + \newline\the@rule\addtocounter{break@count}{-#1}}% + }% + {}% + }% + \setcounter{arg@index}{0}% +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% The \getargsC macro mimics the behavior of the \getargs macro +% of the stringstrings package, but runs faster, and can handle +% arbitrary tokens. For the development of \getargsC, significant +% assistance was provided by David Carlisle, for which the author is +% most appreciative. +% http://tex.stackexchange.com/questions/101604/ +% parsing-strings-containing-diacritical-marks-macros +% +\def\string@end{$\SaveHardspace} +\def\converttilde{F} +\newcounter{arg@index} +\newcounter{break@count} +\let\SaveHardspace~%%% +% +\def\getargsC#1{% + \if T\converttilde\def~{ }\else\catcode`~=12\fi + \protected@edef\the@string{#1}% + \setcounter{arg@index}{0}% + \lowercase{\expandafter\parse@Block\the@string} \string@end + \let~\SaveHardspace% + \catcode`~=13 +} +% +\def\parse@Block#1 {% + \stepcounter{arg@index}% + \@namedef{arg\roman{arg@index}}{#1}% + \futurelet\tmp\parse@Block@} +% +\def\parse@Block@{% +\ifx\tmp\string@end\edef\narg{\thearg@index}\expandafter\@gobble +\else\expandafter\parse@Block\fi} +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\endinput + + -- cgit v1.2.3