| 1 |
\documentclass{article} |
| 2 |
|
| 3 |
\usepackage{tabstackengine}[2016-10-04] |
| 4 |
\usepackage{lmodern} |
| 5 |
\usepackage[T1]{fontenc} |
| 6 |
\parskip 1em |
| 7 |
\parindent 0em |
| 8 |
\newcommand\rl{\rule{1em}{0in}} |
| 9 |
\def\rdar{\textsf{readarray}} |
| 10 |
\def\loi{\textsf{listofitems}} |
| 11 |
\def\cmd#1{\texttt{\string\ \unskip#1}} |
| 12 |
\usepackage{readarray,tokcycle} |
| 13 |
\usepackage{verbatimbox} |
| 14 |
\newcommand\bverb[1][]{\begingroup\ifx\relax#1\relax |
| 15 |
\def\tmpA{\allowbreak}\def\tmpB{0}\else |
| 16 |
\def\tmpA{}\def\tmpB{#1}\fi |
| 17 |
\catcode`\%=12 \bverbaux} |
| 18 |
\newcommand\bverbaux[2][\allowbreak\textvisiblespace\allowbreak]{% |
| 19 |
\ttfamily\tokencycle |
| 20 |
{\expandafter\tctestifx\expandafter{\tmpB##1}{\allowbreak} |
| 21 |
{\string##1\tmpA}} |
| 22 |
{\{\processtoks{##1}\}} |
| 23 |
{\tctestifx{\isiteleven##1}{##1} |
| 24 |
{\expandafter\tctestifx\expandafter{\tmpB##1}{\allowbreak} |
| 25 |
{\tcpush{\string##1\isiteleven}}}} |
| 26 |
{#1}#2\endtokencycle\endgroup} |
| 27 |
\def\isiteleven{\tcpeek\zzz\ifcat\noexpand\zzz A\tcpush{\space}\fi} |
| 28 |
\begin{filecontents*}[overwrite]{file1data.txt} |
| 29 |
A111 A112 A113 A114 |
| 30 |
A121 A122 A123 A124 |
| 31 |
A131 A132 A133 A134 |
| 32 |
|
| 33 |
A211 A212 A213 A214 |
| 34 |
A221 A222 A223 A224 |
| 35 |
A231 A232 A233 A234 |
| 36 |
\end{filecontents*} |
| 37 |
\begin{filecontents*}[overwrite]{file2data.txt} |
| 38 |
\def{\dataA}{% |
| 39 |
A111 A112 A113 A114 |
| 40 |
A121 A122 A123 A124 |
| 41 |
A131 A132 A133 A134 |
| 42 |
% |
| 43 |
A211 A212 A213 A214 |
| 44 |
A221 A222 A223 A224 |
| 45 |
A231 A232 A233 A234 |
| 46 |
} |
| 47 |
\end{filecontents*} |
| 48 |
\begin{filecontents*}[overwrite]{file3data.txt} |
| 49 |
\textit{am} , \textit{are}, have \textit{been}, have \textit{been} |
| 50 |
\textit{are}, \textit{are} , have \textit{been}, have \textit{been} |
| 51 |
\textit{is} , \textit{are} , has \textit{been} , have \textit{been} |
| 52 |
|
| 53 |
\textit{was} , \textit{were}, had \textit{been}, had \textit{been} |
| 54 |
\textit{were}, \textit{were}, had \textit{been}, had \textit{been} |
| 55 |
\textit{was} , \textit{were}, had \textit{been}, had \textit{been} |
| 56 |
|
| 57 |
will \textit{be}, will \textit{be}, will have \textit{been}, will have \textit{been} |
| 58 |
will \textit{be}, will \textit{be}, will have \textit{been}, will have \textit{been} |
| 59 |
will \textit{be}, will \textit{be}, will have \textit{been}, will have \textit{been} |
| 60 |
\end{filecontents*} |
| 61 |
|
| 62 |
|
| 63 |
\let\vb\verb |
| 64 |
\def\bs{{\ttfamily\char'134}} |
| 65 |
\reversemarginpar |
| 66 |
\marginparwidth 1.5in |
| 67 |
\newcommand\margcmd[1]{\marginpar{\hfill\ttfamily\char'134#1}} |
| 68 |
|
| 69 |
\begin{document} |
| 70 |
\begin{center} |
| 71 |
\LARGE The {\rdar} Package\\ |
| 72 |
\rule{0em}{.7em}\small Routines for inputting formatted array data and |
| 73 |
recalling it on an element-by-element basis.\\ |
| 74 |
\rule{0em}{2.7em}\large Steven B. Segletes\\ |
| 75 |
[email protected]\\ |
| 76 |
\rule{0em}{1.7em}\readarrayPackageDate\\ |
| 77 |
V\readarrayPackageVersion |
| 78 |
\end{center} |
| 79 |
|
| 80 |
\subsection*{Comments About Version 3.0} |
| 81 |
|
| 82 |
\vspace{-5pt} |
| 83 |
Version 3.0 of \rdar{} introduces several new features. |
| 84 |
Arrays can be initialized with the \vb|\initarray| command, |
| 85 |
rather than being read from a file. |
| 86 |
With \vb|\setvalue|, the tokens of individual |
| 87 |
array cells can be revised on demand. |
| 88 |
The contents of one array can be merged into another |
| 89 |
by way of the \vb|\mergearray| command. |
| 90 |
The \vb|\typesetarray| command allows for versatile ways |
| 91 |
to format your array output, including by way |
| 92 |
of \vb|tabular| environments. |
| 93 |
The way end-of-line characters can be handled on a data-read |
| 94 |
is made more versatile with this package version. |
| 95 |
There are many new things here---check them out.\vspace{-10pt} |
| 96 |
|
| 97 |
|
| 98 |
\subsubsection*{Comments About Version 2.0} |
| 99 |
|
| 100 |
\vspace{-5pt} |
| 101 |
Version 2.0 of the \rdar{} package brought major changes, |
| 102 |
including a \textit{new and improved} syntax. |
| 103 |
Functionally, the data-reading/parsing code of the package |
| 104 |
was revised to use the powerful \loi{} package. |
| 105 |
This has two primary advantages: 1) the data that is read is no |
| 106 |
longer expanded prior to the read, so that macros can be read |
| 107 |
and stored in the data arrays using their unexpanded tokens; and 2) |
| 108 |
list separators other than a space may now be employed |
| 109 |
to parse the data into array cells. |
| 110 |
The user will also note other small changes, such as the fact that errors |
| 111 |
arising from array-boundary violations now appear in the log file |
| 112 |
rather than the document itself.\vspace{-10pt} |
| 113 |
|
| 114 |
\section{Description and Commands} |
| 115 |
|
| 116 |
The {\rdar} package allows for the creation of data arrays (numeric, |
| 117 |
string, or even formatted) using either file contents or \vb|\def| |
| 118 |
format for input, such that the elements of multiple arrays can be |
| 119 |
set and later recalled in an orderly fashion, on a cell-by-cell basis. |
| 120 |
Routines have been developed to support the storage and recall of both |
| 121 |
2-D and 3-D arrays, as well as 1-D file-record arrays.% |
| 122 |
\footnote{ |
| 123 |
Note: for 1-D arrays that are to be simply parsed on the basis of a |
| 124 |
specified separator, the \loi{} package is already prepared |
| 125 |
to do this, without the help of this package. |
| 126 |
} |
| 127 |
|
| 128 |
The commands included in this package help the user to input data, define |
| 129 |
it in terms of array elements, and recall those elements at will. Those |
| 130 |
commands are: |
| 131 |
|
| 132 |
|
| 133 |
\itshape |
| 134 |
\textup{To place file data into a data macro:}\\ |
| 135 |
\rl\vb|\readdef{|filename\vb|}\|data-macro\\ |
| 136 |
\textup{To place file data into a 1-D file-record array:}\\ |
| 137 |
\rl\vb|\readrecordarray{|filename\vb|}\|array-identifier% |
| 138 |
\hfill\textup{(1-D)}\\ |
| 139 |
\textup{To parse a data macro and place the results into a new 2-D or 3-D array:}\\ |
| 140 |
\rl\vb|\readarray\|data-macro\vb|\|array-identifier\vb|[-,|columns\vb|]|% |
| 141 |
\hfill\textup{(2-D)}\\ |
| 142 |
\rl\vb|\readarray\|data-macro\vb|\|array-identifier\vb|[-,|rows\vb|,|columns\vb|]|% |
| 143 |
\hfill\textup{(3-D)}\\ |
| 144 |
\textup{Same as above, with leading/trailing spaces removed from array cells:}\\ |
| 145 |
\rl\vb|\readarray*\|data-macro\vb|\|array-identifier\vb|[-,|columns\vb|]|% |
| 146 |
\hfill\textup{(2-D)}\\ |
| 147 |
\rl\vb|\readarray*\|data-macro\vb|\|array-identifier\vb|[-,|rows\vb|,|columns\vb|]|% |
| 148 |
\hfill\textup{(3-D)}\\ |
| 149 |
\textup{To create a new array, each cell initialized to a default |
| 150 |
value:}\\ |
| 151 |
\rl\vb|\initarray\|array-identifier\vb|[|rows\vb|,|columns\vb|]|% |
| 152 |
\hfill\textup{(2-D)}\\ |
| 153 |
\rl\vb|\initarray\|array-identifier\vb|[|planes\vb|,|rows\vb|,|columns% |
| 154 |
\vb|]|\hfill\textup{(3-D)}\\ |
| 155 |
\textup{To merge each cell of one array into another:}\\ |
| 156 |
\rl\vb|\mergearray\|from-array-id\vb|\|to-array-id\vb|[|row\vb|,|% |
| 157 |
column\vb|]|\hfill\textup{(2-D)}\\ |
| 158 |
\rl\vb|\mergearray\|from-array-id\vb|\|to-array-id\vb|[|plane\vb|,|% |
| 159 |
row\vb|,|column\vb|]|\hfill\textup{(3-D)}\\ |
| 160 |
\textup{To typeset an array:}\\ |
| 161 |
\rl\vb|\typesetarray\|array-identifier\hfill\textup{(2-D/3-D)}\\ |
| 162 |
\textup{Recall (typeset) data from indexed array cell:}\\ |
| 163 |
\rl\vb|\|array-identifier\vb|[|row\vb|,|column\vb|]|% |
| 164 |
\hfill\textup{(2-D)}\\ |
| 165 |
\rl\vb|\|array-identifier\vb|[|plane\vb|,|row\vb|,|column\vb|]|% |
| 166 |
\hfill\textup{(3-D)}\\ |
| 167 |
\textup{To place the actual tokens of an array cell into a macro:}\\ |
| 168 |
\rl\vb|\arraytomacro\|array-identifier\vb|[|row\vb|,|column\vb|]\|macro% |
| 169 |
\hfill\textup{(2-D)}\\ |
| 170 |
\rl\vb|\arraytomacro\|array-identifier\vb|[|plane\vb|,|row\vb|,|column% |
| 171 |
\vb|]\|macro\hfill\textup{(3-D)}\\ |
| 172 |
\textup{To manually (re)set the value of an existing array cell:}\\ |
| 173 |
\rl\vb|\setvalue\|array-identifier\vb|[|row\vb|,|column\vb|]{|% |
| 174 |
value\vb|}|\hfill\textup{(2-D)}\\ |
| 175 |
\rl\vb|\setvalue\|array-identifier\vb|[|plane\vb|,|row\vb|,|column\vb|]{|% |
| 176 |
value\vb|}|\hfill\textup{(3-D)}\\ |
| 177 |
\textup{To change the array-parsing separator for} |
| 178 |
\vb|\readdef| \textup{and/or} \vb|\readarray|\textup{:}\\ |
| 179 |
\rl\vb|\readarraysepchar{|parsing-separator-char\vb|}|\\ |
| 180 |
\textup{To change the default (=9) end-of-line catcode for} |
| 181 |
\vb|\readdef|\textup{:}\\ |
| 182 |
\rl\vb|\readarrayendlinechar=|end-of-line-catcode\\ |
| 183 |
\textup{To redefine default cell initialization for} \vb|\initarray| |
| 184 |
\textup{:}\\ |
| 185 |
\rl\vb|\renewcommand\readarrayinitvalue{|value\vb|}|\\ |
| 186 |
\textup{To redefine default cell format in} \vb|\typesetarray|\textup{:}\\ |
| 187 |
\rl\vb|\renewcommand\typesetcell[1]{|format-for-\#1\vb|}|\\ |
| 188 |
\textup{To redefine default plane, row, column separator formats for} |
| 189 |
\vb|\typesetarray|\textup{:}\\ |
| 190 |
\rl\vb|\renewcommand\typesetplanesepchar{|format\vb|}|\\ |
| 191 |
\rl\vb|\renewcommand\typesetrowsepchar{|format\vb|}|\\ |
| 192 |
\rl\vb|\renewcommand\typesetcolsepchar{|format\vb|}|\\ |
| 193 |
\textup{To select the level of bounds checking on array cell recall:}\\ |
| 194 |
\rl\vb|\nocheckbounds|\hfill OR\hfill% |
| 195 |
\vb|\checkbounds|\hfill OR\hfill% |
| 196 |
\vb|\hypercheckbounds|\\ |
| 197 |
\textup{To ignore blank (or fully commented) records during the |
| 198 |
course of a record-array read (this can be undone with a false |
| 199 |
setting):}\\ |
| 200 |
\rl\vb|\ignoreblankreadarrayrecordstrue| |
| 201 |
\upshape |
| 202 |
|
| 203 |
In these commands, \cmd{}\textit{data-macro} is a control sequence into |
| 204 |
which the contents of \texttt{filename} are set into a \cmd{def}. |
| 205 |
The \cmd{}\textit{array-identifier} is the array into which cell data is |
| 206 |
inserted. |
| 207 |
The starred version of the commands are used if, during the array |
| 208 |
creation, it is desired to automatically excise the array data of |
| 209 |
leading and trailing spaces. |
| 210 |
|
| 211 |
Unlike earlier versions of this package, where error messages were |
| 212 |
output into the typeset document, error messages are now |
| 213 |
set in the log file. |
| 214 |
The level of error messaging is defined by the level of bounds checking, |
| 215 |
with \cmd{hypercheckbounds} providing the |
| 216 |
most intense level of error checking. |
| 217 |
When a bounds-checking error is found in an array invocation, in addition |
| 218 |
to the error message in the log file, a ``?'' is typeset in the document, |
| 219 |
unless bound checking is disabled with \cmd{nocheckbounds}. |
| 220 |
|
| 221 |
|
| 222 |
Several strings of fixed name are defined through the use the |
| 223 |
\cmd{readdef} command, which are accessible to the user: |
| 224 |
|
| 225 |
\itshape |
| 226 |
\rl\vb|\nrows|\\ |
| 227 |
\rl\vb|\ncols|\\ |
| 228 |
\rl\vb|\nrecords|\\ |
| 229 |
\rl\vb|\ArrayRecord[|record\vb|]|% |
| 230 |
\hfill\textup{(to retrieve record from most recent \cmd{readdef})}\upshape |
| 231 |
|
| 232 |
The macros \cmd{nrows} and \cmd{ncols}, which were gleaned from the file |
| 233 |
structure, may be used in the subsequent \cmd{readarray} |
| 234 |
invocation to specify the array dimensions. |
| 235 |
Alternately, those values may be manually overridden by specifying |
| 236 |
the desired values in the \cmd{readarray} invocation. |
| 237 |
Individual records of the original file, from the most recent |
| 238 |
\cmd{readdef}, may be recalled with the |
| 239 |
\cmd{ArrayRecord} macro. |
| 240 |
|
| 241 |
In addition to the strings of fixed name created during the |
| 242 |
\cmd{readdef}, there are various strings created during |
| 243 |
the \cmd{readarray} whose name is a function of the |
| 244 |
\cmd{}\textit{array-identifier}, such as |
| 245 |
|
| 246 |
\itshape |
| 247 |
\rl\vb|\|array-identifier\vb|CELLS|\\ |
| 248 |
\rl\vb|\|array-identifier\vb|PLANES|\\ |
| 249 |
\rl\vb|\|array-identifier\vb|ROWS|\\ |
| 250 |
\rl\vb|\|array-identifier\vb|COLS|\upshape |
| 251 |
|
| 252 |
where \cmd{}\textit{array-identifier} is the name |
| 253 |
you have designated a particular array. |
| 254 |
Their meaning will be discussed later in this document. |
| 255 |
|
| 256 |
|
| 257 |
\section{Data Structure} |
| 258 |
|
| 259 |
The first requirement is to lay out a format for the data interface to |
| 260 |
this package. |
| 261 |
The {\rdar} package is set up to digest data separated by a user-defined |
| 262 |
separator character. |
| 263 |
The default separator is a space character but the separator |
| 264 |
may be specified by way of \vb|\readarraysepchar{|\textit{separator}\vb|}|. |
| 265 |
The format for the data organization to be digested is as follows, |
| 266 |
for 2-D arrays: |
| 267 |
|
| 268 |
\TABstackTextstyle{\tiny} |
| 269 |
\setstackgap{L}{3pt} |
| 270 |
\newcommand\SEP{\,\langle\smash{\raisebox{1pt}{\tabbedCenterstack{s\\e\\p}}}\rangle\,} |
| 271 |
\renewcommand\arraystretch{1.1} |
| 272 |
{\arraycolsep=3pt\relax\small\( |
| 273 |
\begin{array}{lll@{\hspace{2pt}}ll} |
| 274 |
A_{11}\SEP &A_{12}\SEP &A_{13}\SEP & \ldots & A_{1\mathrm{(columns)}} \\ |
| 275 |
A_{21}\SEP &A_{22}\SEP & \ldots && \\ |
| 276 |
\vdots&&&&\\ |
| 277 |
A_{\mathrm{(rows)}1}\SEP &A_{\mathrm{(rows)}2}\SEP &A_{\mathrm{(rows)}3}\SEP & |
| 278 |
\ldots & A_{\mathrm{(rows)}\mathrm{(columns)}} \\ |
| 279 |
\end{array} |
| 280 |
\)} |
| 281 |
|
| 282 |
For 3-D arrays, the following structure is employed: |
| 283 |
|
| 284 |
{\arraycolsep=3pt\relax\small\( |
| 285 |
\begin{array}{lll@{\hspace{2pt}}ll} |
| 286 |
A_{111}\SEP &A_{112}\SEP &A_{113}\SEP & \ldots & A_{11\mathrm{(columns)}} \\ |
| 287 |
A_{121}\SEP &A_{122}\SEP & \ldots && \\ |
| 288 |
\vdots&&&&\\ |
| 289 |
A_{1\mathrm{(rows)}1}\SEP &A_{1\mathrm{(rows)}2}\SEP &A_{1\mathrm{(rows)}3}\SEP & |
| 290 |
\ldots & A_{1\mathrm{(rows)}\mathrm{(columns)}} \\ |
| 291 |
\rlap{\scriptsize$<$blank line$>$}&&&&\\ |
| 292 |
A_{211}\SEP &A_{212}\SEP &A_{213} & \ldots & A_{21\mathrm{(columns)}} \\ |
| 293 |
A_{221}\SEP &A_{222}\SEP & \ldots && \\ |
| 294 |
\vdots&&&&\\ |
| 295 |
A_{2\mathrm{(rows)}1}\SEP &A_{2\mathrm{(rows)}2}\SEP &A_{2\mathrm{(rows)}3}\SEP & |
| 296 |
\ldots & A_{2\mathrm{(rows)}\mathrm{(columns)}} \\ |
| 297 |
&&&&\\ |
| 298 |
\vdots&&&&\\ |
| 299 |
&&&&\\ |
| 300 |
A_{\mathrm{(planes)}11}\SEP &A_{\mathrm{(planes)}12}\SEP &A_{\mathrm{(planes)}13}\SEP & \ldots & A_{\mathrm{(planes)}1\mathrm{(columns)}} \\ |
| 301 |
A_{\mathrm{(planes)}21}\SEP &A_{\mathrm{(planes)}22}\SEP & \ldots && \\ |
| 302 |
\vdots&&&&\\ |
| 303 |
A_{\mathrm{(planes)}\mathrm{(rows)}1}\SEP &A_{\mathrm{(planes)}\mathrm{(rows)}2}\SEP &A_{\mathrm{(planes)}\mathrm{(rows)}3}\SEP & |
| 304 |
\ldots & A_{\mathrm{(planes)}\mathrm{(rows)}\mathrm{(columns)}} \\ |
| 305 |
\end{array} |
| 306 |
\)} |
| 307 |
|
| 308 |
|
| 309 |
Here,\,$\SEP${}\,is the data separator that is used to parse the input. |
| 310 |
Terms like $A_{\mathrm{(plane)}\mathrm{(row)}\mathrm{(column)}}$ refers |
| 311 |
to the \LaTeX{}-formatted data to be associated with the particlar plane, |
| 312 |
row, and column of data. |
| 313 |
Note, that for 3-D arrays, a blank line can be used to signify to the |
| 314 |
parsing algorithm the size of a data plane (alternately, the number of |
| 315 |
rows per data plane can be explicitly provided to the \cmd{readarray} |
| 316 |
command). |
| 317 |
|
| 318 |
\section{Getting Data into Array Structures\label{s:ex}} |
| 319 |
|
| 320 |
One can provide data to be digested by this package in one of two ways: |
| 321 |
either through an external file, or by way of ``cut and paste'' into a |
| 322 |
\vb|\def|. If one chooses the external file approach, the command |
| 323 |
\vb|\readdef|\margcmd{readdef} is the command which can achieve this |
| 324 |
result. The command takes two arguments. The first is the file in |
| 325 |
which the data is stored, while the second is the data macro into which the |
| 326 |
file's data will be placed, for example |
| 327 |
|
| 328 |
\rl\vb|\readdef{data.txt}{\dataA}|\readdef{file1data.txt}{\dataA} |
| 329 |
|
| 330 |
In this case, the contents of the file \vb|data.txt| will be placed |
| 331 |
into the data macro \vb|\dataA|. |
| 332 |
Two alterations to the format occur during this conversion from file |
| 333 |
to \cmd{def}: 1) blank lines in the file are ignored; and |
| 334 |
2) a data separator replaces the end-of-line. |
| 335 |
At this point, the data is still not digested into a 2-D or 3-D data |
| 336 |
``array.'' |
| 337 |
However, two things have been accomplished: 1) the file contents are \cmd{def}'ed |
| 338 |
into the data macro \cmd{dataA}; and 2) they are also placed into a 1-D |
| 339 |
file record array, \cmd{ArrayRecord}. |
| 340 |
|
| 341 |
Regarding the point that end-of-line characters are replaced |
| 342 |
with a data separator, these are controlled by two separate |
| 343 |
mechanisms, each with its own control. |
| 344 |
First, end-of-lines are, by default discarded---this is accomplished |
| 345 |
internally with \rdar{} setting \vb|\endlinechar| equal to 9, |
| 346 |
during the \vb|\readdef|. |
| 347 |
This is not the native \LaTeX{} behavior. |
| 348 |
In \LaTeX{}, end-of-lines are converted into spaces, unless |
| 349 |
preempted with a \vb|%| character or a line-ending control |
| 350 |
sequence. |
| 351 |
To recover the \LaTeX{} way of treating end-of-lines, the |
| 352 |
count \vb|\readarrayendlinechar| is provided, which can |
| 353 |
be set in the manner desired for subsequent invocations |
| 354 |
of \vb|\readdef|. |
| 355 |
For example, \vb|\readarrayendlinechar=5 | will change |
| 356 |
subsequent treatment of end-of-line characters to the normal |
| 357 |
\LaTeX{} treatment. |
| 358 |
|
| 359 |
The second aspect regarding end-of-lines is the data |
| 360 |
separator inserted when the end-of-line is |
| 361 |
reached. This is one of the functions of the |
| 362 |
\vb|\readarraysepchar| macro, the argument to which |
| 363 |
is the separator inserted into the read, when |
| 364 |
end-of-line is encountered during a \vb|\readdef|. |
| 365 |
If you don't want any record separators inserted during |
| 366 |
the \vb|\readdef|, one may set \vb|\readarraysepchar{}|. |
| 367 |
Note, however, that an empty \rdar{} sepchar, while valid |
| 368 |
during a \vb|\readdef|, is meaningless during a |
| 369 |
\vb|\readarray| invocation, since it would like to |
| 370 |
use the sepchar to parse the data. |
| 371 |
Therefore, an empty sepchar should be redefined to |
| 372 |
a meaningful value prior to invoking \vb|\readarray|. |
| 373 |
See section~\ref{s:sepchar} for more information on the |
| 374 |
separator character. |
| 375 |
|
| 376 |
There is no |
| 377 |
\textit{requirement} that the input file be organized with structured rows |
| 378 |
of data corresponding to individual file records, nor that blank |
| 379 |
lines exist between planes of data (if the data is 3-D). |
| 380 |
\textit{However}, there is a reason to do so, nonetheless. |
| 381 |
In particular, for datafiles that are organized in the |
| 382 |
preferred fashion, for example: |
| 383 |
|
| 384 |
\verbfilebox{file1data.txt} |
| 385 |
\rl\theverbbox |
| 386 |
|
| 387 |
a \vb|\readdef| attempts to estimate the number columns, and |
| 388 |
rows-per-plane of the dataset by analyzing the data structure. |
| 389 |
These estimates are given by |
| 390 |
\vb|\ncols|\margcmd{ncols} and \vb|\nrows|\margcmd{nrows}, in this |
| 391 |
case to values of \texttt{\ncols} and \texttt{\nrows}, respectively. |
| 392 |
Such data could prove useful if the array size is not known in advance. |
| 393 |
When \verb|\readdef| is invoked, a string |
| 394 |
\verb|\nrecords|\margcmd{nrecords} will also be set to the number of |
| 395 |
file records processed by the \vb|\readdef| command, in this case, |
| 396 |
to \texttt{\nrecords}. |
| 397 |
Finally, the 1-D file-record array, \cmd{ArrayRecord}\margcmd{ArrayRecord}, |
| 398 |
is created to allow access to the most recently read file records. |
| 399 |
For example, \vb|\ArrayRecord[3]| produces: ``\ArrayRecord[3]''. |
| 400 |
Note, however, that the array, \cmd{ArrayRecord}, will be overwritten on |
| 401 |
the subsequent invocation of \cmd{readdef}. |
| 402 |
|
| 403 |
Because \cmd{ArrayRecord} is only a 1-D file-record array, the |
| 404 |
\textit{actual} array metrics, given by \cmd{ArrayRecordCOLS}, |
| 405 |
\cmd{ArrayRecordROWS}, \cmd{ArrayRecordPLANES}, and |
| 406 |
\cmd{ArrayRecordCELLS} are |
| 407 |
\ArrayRecordCOLS, \ArrayRecordROWS, \ArrayRecordPLANES, and |
| 408 |
\ArrayRecordCELLS, respectively, which do not align with the |
| 409 |
estimations provided by \cmd{ncols} and \cmd{nrows}. |
| 410 |
|
| 411 |
In lieu of \verb|\readdef|, a generally less preferred, but viable way |
| 412 |
to make the data available is to cut and paste into a \vb|\def|. |
| 413 |
However, because a blank line is not permitted as part of the \vb|\def|, |
| 414 |
a filler symbol (\vb|%| or \vb|\relax|) must be used in its place, if it |
| 415 |
is desired to visually separate planes of data, as shown in the |
| 416 |
\verb|\def| example at the top of the following page. Note that the |
| 417 |
\vb|%| is also required at the end of the line containing \vb|\def|, in |
| 418 |
order to guarantee that, in this case, \vb|A111| is the first element of |
| 419 |
data (and not a space separator). However, unlike \vb|\readdef|, this |
| 420 |
definition will neither set the value of \vb|\ncols| nor \vb|\nrows|. |
| 421 |
|
| 422 |
\verbfilebox{file2data.txt} |
| 423 |
\rl\theverbbox |
| 424 |
|
| 425 |
Once the data to be placed into an array is available in a macro, |
| 426 |
by way of either |
| 427 |
\vb|\readdef| or \vb|\def|, the command to digest the data into an |
| 428 |
array is \vb|\readarray| for the case of 2-D or 3-D data. |
| 429 |
For 1-D file-record arrays, in contrast, the \cmd{readrecordarray} |
| 430 |
command is used to go directly from a file into the 1-D array, |
| 431 |
bypassing the intermediate step of a data macro. |
| 432 |
|
| 433 |
\subsection{1-D File-Record Arrays} |
| 434 |
|
| 435 |
If the desire is merely to parse a string of data based on a common |
| 436 |
data separator, such as a comma or any other character, there is |
| 437 |
no need to use the \rdar{} package. |
| 438 |
The \loi{} package, which is employed by \rdar, already has those provisions |
| 439 |
and should be used directly.% |
| 440 |
\begin{verbbox}[\footnotesize] |
| 441 |
\setsepchar{ } |
| 442 |
\readlist\oneDlist{\dataA} |
| 443 |
\oneDlistlen{} list items, 12th item is ``\oneDlist[12]''. |
| 444 |
\end{verbbox} |
| 445 |
\footnote{% |
| 446 |
For a simple 1-D list punctuated by data separators, one may use the |
| 447 |
\loi{} package directly:\\ |
| 448 |
\rl\theverbbox\\ |
| 449 |
which produces the following output: |
| 450 |
\setsepchar{ }% |
| 451 |
\readlist\oneDlist{\dataA}% |
| 452 |
\oneDlistlen{} list items, 12th item is ``\oneDlist[12]''. |
| 453 |
} |
| 454 |
|
| 455 |
On the other hand, if one wishes a 1-D file-record array, in which each |
| 456 |
array element corresponds to the record from a file, then \rdar{} |
| 457 |
can be used. |
| 458 |
The command \cmd{readrecordarray} can be used to stick the individual |
| 459 |
``file records'' from a designated file into a 1-D array. |
| 460 |
|
| 461 |
The \cmd{readrecordarray} command takes two arguments: a file |
| 462 |
name containing data records, and the name of a 1-D record-array |
| 463 |
into which to place the file records. |
| 464 |
|
| 465 |
So, for example, with the invocation of |
| 466 |
\vb|\readrecordarray{data.txt}\oneD|, the data from the file |
| 467 |
\texttt{data.txt} is now saved in the \cmd{oneD} array, and can |
| 468 |
be retrieved, for example, the 3rd record, with \cmd{oneD[3]}, which |
| 469 |
returns \readrecordarray{file1data.txt}\oneD``\oneD[3]''. |
| 470 |
|
| 471 |
If an array name is reutilized, its prior definitions are cleared, |
| 472 |
so that ``old'' data is not inadvertantly retrieved following the |
| 473 |
reutilization. |
| 474 |
|
| 475 |
One option (introduced in v3.1) in this regard is the if-condition% |
| 476 |
\margcmd{ifignoreblank readarrayrecords} |
| 477 |
\bverb[.]{\ifignore.blankreadarrayrecords}, which can take on |
| 478 |
values of either \bverb[\-]{\ignoreblank\-readarrayrecordstrue} or |
| 479 |
\bverb{\ignoreblankreadarrayrecordsfalse}. |
| 480 |
When set to the true condition, ``blank'' records in the input file |
| 481 |
(defined either when the record is actually blank or if the first |
| 482 |
non-blank token in the record is a catcode-14 \verb|%|) will |
| 483 |
be ignored. |
| 484 |
This setting will only affect the record array itself---the result |
| 485 |
of any \cmd{readdef} will be unaffected by this setting, except |
| 486 |
as detailed in the next paragraph. |
| 487 |
|
| 488 |
The only warning to heed when setting |
| 489 |
\bverb[\-]{\ignoreblankreadarrayrecords\-true} is that the first |
| 490 |
blank line in a \bverb{\readdef}'ed file is used to set the value |
| 491 |
of \cmd{nrows}, which can be used to set the row-depth of a 3-D |
| 492 |
array plane within subsequent invocations of \cmd{readarray}. |
| 493 |
Of course, the array plane's row-depth may always be set |
| 494 |
manually, in lieu of using \bverb{\nrows}. |
| 495 |
|
| 496 |
|
| 497 |
\subsection{Creating 2-D and 3-D Arrays from Data} |
| 498 |
|
| 499 |
The \cmd{readarray}\margcmd{readarray} command, used to convert |
| 500 |
raw parsable data into data arrays, |
| 501 |
takes three arguments. |
| 502 |
The first is the data macro into which the unarrayed raw data had |
| 503 |
previously been stuffed (e.g., by way of \cmd{readdef} or \cmd{def}). |
| 504 |
The second is array-identifier macro into which the parsed data is to |
| 505 |
be placed. |
| 506 |
Finally, the last compound argument, enclosed in square brackets, denotes the |
| 507 |
rank and range of the array to be created. |
| 508 |
|
| 509 |
There is a starred version of the command, \cmd{readarray*}, which is used |
| 510 |
to remove leading/trailing spaces from the array elements, when parsed. |
| 511 |
This option, is only relevant when the data separator is not already a |
| 512 |
space. |
| 513 |
|
| 514 |
\subsubsection{2-D Arrays} |
| 515 |
|
| 516 |
\begin{sloppypar} |
| 517 |
For a 2-D array, this last argument of \cmd{readarray} will be |
| 518 |
of the form \vb|[-,<columns>]|. |
| 519 |
If the data had recently been read by way of \vb|\readdef|, the |
| 520 |
string \vb|\ncols| may be used to signify the \vb|<columns>| value. |
| 521 |
The \texttt{-} (or any other character before the initial comma) |
| 522 |
reminds us that the range of row numbers is not specified in advance, |
| 523 |
but is dictated by the length of the data macro containing the raw |
| 524 |
file data. |
| 525 |
For such a 2-D array, only the column range is specified. |
| 526 |
\end{sloppypar} |
| 527 |
|
| 528 |
Consider, for example, the previously discussed file, \texttt{dataA.txt}, |
| 529 |
which had been digested into the data macro \cmd{dataA}. |
| 530 |
One can process that as a 2-D array with an invocation of |
| 531 |
\vb|\readarray\dataA\twoD[-,\ncols]|, since \cmd{ncols} had been |
| 532 |
set to a value of \texttt{\ncols}, based on the prior \cmd{readdef}. |
| 533 |
Thereafter, data may be retieved, for example the 3rd row, 2nd column, |
| 534 |
with \cmd{twoD[3,2]}, to give |
| 535 |
\readarray\dataA\twoD[-,\ncols] |
| 536 |
``\twoD[3,2]''. |
| 537 |
|
| 538 |
The actual array size is given by |
| 539 |
\cmd{twoDROWS}, \cmd{twoDCOLS}, \cmd{twoDCELLS} |
| 540 |
as |
| 541 |
\twoDROWS, \twoDCOLS, and \twoDCELLS, respectively. |
| 542 |
The number of rows in the array is fewer than the number of file records, |
| 543 |
\oneDCELLS, because blank rows in the input file are ignored. |
| 544 |
One should also note that if the end of the data stream results in a |
| 545 |
partial final row of data, the partial row will be discarded. |
| 546 |
|
| 547 |
\subsubsection{3-D Arrays} |
| 548 |
|
| 549 |
For the 3-D case, the only difference in the invocation of |
| 550 |
\vb|\readarray| is in the 3rd argument, in which the |
| 551 |
rank and range of the array is specified. |
| 552 |
This last argument will be of the form |
| 553 |
\vb|[-,<rows>,<columns>]|. |
| 554 |
As before, the \vb|-| denotes the fact that the range of the planes |
| 555 |
of data is unknown before the fact, and governed by the length |
| 556 |
of data in the dataset. |
| 557 |
Only the range of rows and columns are specifiable here. |
| 558 |
If \vb|\readdef| had been used on a properly formed |
| 559 |
input file, both \vb|\nrows| and \vb|\ncols| may be used to supply the |
| 560 |
range arguments of the 3-D array. |
| 561 |
|
| 562 |
For example, using the same \cmd{dataA} dataset, but reading it as a |
| 563 |
3-D array can be accomplished with |
| 564 |
\vb|\readarray\dataA\threeD[-,\nrows,\ncols]|.% |
| 565 |
\readarray\dataA\threeD[-,\nrows,\ncols] |
| 566 |
This results in an array with \threeDPLANES{} planes, |
| 567 |
\threeDROWS{} rows, and \threeDCOLS{} columns |
| 568 |
(\threeDCELLS{} data cells total). |
| 569 |
Data from the 2nd plane, 1st row, 2nd column can be obtained via |
| 570 |
\cmd{threeD[2,1,2]} as ``\threeD[2,1,2]''. |
| 571 |
|
| 572 |
If, perchance, a row or plane is only partially defined by |
| 573 |
\cmd{readarray}, the partial data is discarded from the array. |
| 574 |
|
| 575 |
\subsubsection{Array Parsing Separator\label{s:sepchar}} |
| 576 |
|
| 577 |
While it may be easily envisioned that the array data is numerical, this |
| 578 |
need not be the case. |
| 579 |
The array data may be text, and even formatted text. |
| 580 |
|
| 581 |
A key setting, either when inputting information from a file |
| 582 |
by way of \vb|\readdef| or when parsing a \vb|\def|'ed |
| 583 |
argument into an array by way of \vb|\readarray|, is the |
| 584 |
macro \vb|\readarraysepchar|.\margcmd{readarraysepchar} |
| 585 |
|
| 586 |
The value of \vb|\readarraysepchar| is used in distinct |
| 587 |
ways for \vb|\readdef| and \vb|\readarray|. |
| 588 |
For \vb|\readdef|, the separator is inserted into the |
| 589 |
\vb|\data-macro| |
| 590 |
definition whenever an end-line-char (end of record) |
| 591 |
is encountered. |
| 592 |
For the subsequent \vb|\readarray| (with or without a \vb|*|), the |
| 593 |
\vb|\readarraysepchar| is used to separate the data |
| 594 |
contained in the \vb|\data-macro| into individual cell |
| 595 |
data that will be placed into the \vb|\array-identifier|. |
| 596 |
|
| 597 |
For example, if your data file is comma separated, but the |
| 598 |
last item of data in each record is not followed by a |
| 599 |
trailing comma, setting \vb|\readarraysepchar{,}| will |
| 600 |
assure that the comma gets inserted into the |
| 601 |
\vb|\data-macro| after each record, during the |
| 602 |
\vb|\readdef|. |
| 603 |
This will preclude confusion of the last item of |
| 604 |
each record with the first item of the subsequent |
| 605 |
record when the \vb|\readarray| is executed. |
| 606 |
|
| 607 |
If the trailing comma were present in the data file, |
| 608 |
then \vb|\readarraysepchar{}| could be set for the |
| 609 |
\vb|\readdef|, to avoid inserting an extra comma. |
| 610 |
However, it would have to be reset to a comma before |
| 611 |
executing the \vb|\readarray|, in order to parse |
| 612 |
the data using the comma to separate cell data. |
| 613 |
|
| 614 |
Finally, if one wished to employ lists rather than |
| 615 |
arrays (wherein each row could have a variable |
| 616 |
number of columns, for example), then one could |
| 617 |
set \vb|\readarraysepchar{\\}| prior to the |
| 618 |
\vb|\readdef|, so as to insert a \vb|\\| macro |
| 619 |
between each record. |
| 620 |
Then, if the file data were otherwise comma separated, |
| 621 |
one could use the \loi{} tools rather than \rdar{} |
| 622 |
to absorb the data as a list, rather than an array. |
| 623 |
In this case, \vb|\setsepchar{\\/,}| would set a |
| 624 |
two-tier nested parsing for \loi{}. |
| 625 |
Then, \vb|\readlist\|\textit{listname}\vb|{\|% |
| 626 |
\textit{data-macro}\vb|}| would read the data into |
| 627 |
a list, with a variable column dimension for each row, |
| 628 |
based on the number of commas in each file record. |
| 629 |
|
| 630 |
|
| 631 |
Note also, using the facilities of the underlying \loi{} package, |
| 632 |
that compound separators are possible. |
| 633 |
For example, when employing \vb|\readarray|. |
| 634 |
\textit{either} a comma \textit{or} a period may be used |
| 635 |
for the data parsing, by specifying a |
| 636 |
\textbf{logical-OR} (\vb+||+) separated list: \vb:\readarraysepchar{,||.}:. |
| 637 |
Similarly, a multicharacter separator is possible, so that setting |
| 638 |
\vb|\readarraysepchar{!!}| will cause \cmd{readarray} to look for |
| 639 |
instances of ``!!'' to divide the data into separate array elements. |
| 640 |
|
| 641 |
Consider the following comma-separated input in, let us say, the file |
| 642 |
\textsf{conjugation.txt}. |
| 643 |
|
| 644 |
\verbfilebox[\footnotesize]{file3data.txt} |
| 645 |
\rl\theverbbox |
| 646 |
|
| 647 |
The sequence of commands |
| 648 |
|
| 649 |
\begin{verbbox} |
| 650 |
\readarraysepchar{,} |
| 651 |
\readdef{conjugation.txt}\dataC |
| 652 |
\readarray*\dataC\tobeConjugation[-,\nrows,\ncols] |
| 653 |
\end{verbbox} |
| 654 |
\rl\theverbbox |
| 655 |
\readarraysepchar{,} |
| 656 |
\readdef{file3data.txt}\dataC |
| 657 |
\readarray*\dataC\tobeConjugation[-,\nrows,\ncols] |
| 658 |
|
| 659 |
will read the file into \vb|\dataC|, adding a comma between |
| 660 |
records. |
| 661 |
It will then employ a comma separator to parse the file. |
| 662 |
As a result, it will create a 3-D array using data from the |
| 663 |
\vb|\dataC| macro, and create a parsed array by the name of |
| 664 |
\cmd{tobeConjugation}. |
| 665 |
During the \vb|\readdef|, it will have been gleaned that the file |
| 666 |
is arranged with 4 columns (stored in \vb|\ncols|) and |
| 667 |
3 rows per plane (stored in \vb|\nrows|). |
| 668 |
These row \& column specifications could be manually overridden |
| 669 |
merely by specifying actual numbers in the bracketed argument to |
| 670 |
\vb|\readarray|. |
| 671 |
Leading/trailing spaces will be removed from the data, with the use of the |
| 672 |
star form of the \cmd{readarray} command. |
| 673 |
Data can then be directly accessed, so that, for example |
| 674 |
\cmd{tobeConjugation[1,3,3]} will yield the entry from the |
| 675 |
1st plane, 3rd row, 3rd column as ``\tobeConjugation[1,3,3]''. |
| 676 |
|
| 677 |
The 3-D array metrics are \cmd{tobeConjugationPLANES}, |
| 678 |
\cmd{tobeConjugationROWS}, \cmd{tobeConjugationCOLS}, and |
| 679 |
\cmd{tobeConjugationCELLS}, which are |
| 680 |
here given as \tobeConjugationPLANES, |
| 681 |
\tobeConjugationROWS, \tobeConjugationCOLS, and |
| 682 |
\tobeConjugationCELLS. |
| 683 |
respectively. |
| 684 |
|
| 685 |
\section{Initializing an Array Structure} |
| 686 |
|
| 687 |
With the \vb|readarray| macro described above, data can be |
| 688 |
introduced into an array structure that is specifically created |
| 689 |
to receive the data. |
| 690 |
However, sometimes, an array placeholder must be defined before |
| 691 |
knowing exactly what will eventually reside there. |
| 692 |
For this purpose, that package provides \vb|\initarray|. |
| 693 |
\margcmd{initarray} |
| 694 |
|
| 695 |
With a command like \vb|\initarray\z[3,4]|, a 2-D array identified |
| 696 |
as \vb|\z| is created with 3 rows and 4 columns. |
| 697 |
Each cell is initialized with a standard value (default |
| 698 |
\vb|-|). |
| 699 |
However, the standard initialization value may be changed, |
| 700 |
for example, to a \vb|0| with an invocation of |
| 701 |
\vb|\renewcommand\readarrayinitvalue{0}|.% |
| 702 |
\margcmd{readarrayinitvalue} |
| 703 |
|
| 704 |
\section{Manually Setting Array-Cell Data} |
| 705 |
|
| 706 |
While \vb|\readarray| and \vb|\initarray| are used to create |
| 707 |
new arrays and to populate their cells with content, we here |
| 708 |
examine a way to update or change the content of a single existing |
| 709 |
array cell. |
| 710 |
The command \vb|\setvalue|\margcmd{setvalue} is used to place |
| 711 |
content into an existing array cell. |
| 712 |
Let us assume that the array \vb|\z| was created as a |
| 713 |
2-D array of size 3 rows by 4 columns. |
| 714 |
The command \vb|\setvalue\z[2,3]{xyz}| will replace the |
| 715 |
existing content of the array's 2nd row and 3rd column |
| 716 |
with the tokens \vb|xyz|. |
| 717 |
All other cells in the \vb|\z| array will remain as they |
| 718 |
were; the pre-existing content of cell \vb|\z[2,3]|, once |
| 719 |
replaced, will no longer be available. |
| 720 |
|
| 721 |
|
| 722 |
\section{Merging Data from Separate Arrays} |
| 723 |
|
| 724 |
The command \vb|\setvalue| was described as a way to replace |
| 725 |
the contents of a single cell in an array. |
| 726 |
Here, we describe a way to replace the contents of multiple |
| 727 |
cells at once, in the form of merging two arrays with the |
| 728 |
macro \vb|\mergearray|\margcmd{mergearray}. |
| 729 |
This command sets up a loop of repeated invocations of |
| 730 |
\vb|\setarray|. |
| 731 |
|
| 732 |
Let's assume that we had created arrays |
| 733 |
\vb|\Q[10,10]| and \vb|\R[3,2]|. |
| 734 |
The command |
| 735 |
\vb|\mergarray\R\Q[6,3]| will overlay the contents of |
| 736 |
\vb|\R|'s 3x2 cells into the \vb|\Q| cells, beginning with |
| 737 |
\vb|\Q[6,3]|. |
| 738 |
The overlay will, therefore, include the cells: \vb|[6,3]|, \vb|[6,4]|, |
| 739 |
\vb|[7,3]|, \vb|[7,4]|, \vb|[8,3]|, and \vb|[8,4]|. |
| 740 |
If the overlay of the \textit{from-array} causes the bounds in |
| 741 |
the \textit{to-array} to be exceeded, no copy is made of those |
| 742 |
cells. |
| 743 |
However, a warning will be noted in the log file if error |
| 744 |
checking is enabled. |
| 745 |
|
| 746 |
|
| 747 |
\section{Recalling Cell Data from Array Structures} |
| 748 |
|
| 749 |
\begin{sloppypar} |
| 750 |
While one must specify the number of columns and/or rows associated |
| 751 |
with the \vb|\readarray| invocation, those numbers may not yet |
| 752 |
be known to the user, if the values employed came from the |
| 753 |
\vb|\readdef| estimations of |
| 754 |
\vb|\ncols| and \vb|\nrows|. Therefore, the \cmd{readrray} |
| 755 |
\margcmd{{\rmfamily\itshape array-identifier}CELLS}% |
| 756 |
\margcmd{{\rmfamily\itshape array-identifier}PLANES}% |
| 757 |
\margcmd{{\rmfamily\itshape array-identifier}ROWS}% |
| 758 |
\margcmd{{\rmfamily\itshape array-identifier}COLS}% |
| 759 |
command variants also define the following strings: |
| 760 |
\itshape\vb|\|array-identifier\vb|CELLS|, \vb|\|array-identifier\vb|PLANES|, |
| 761 |
\vb|\|array-identifier\vb|ROWS|{\upshape, and} |
| 762 |
\vb|\|array-identifier\vb|COLS|\upshape, where |
| 763 |
\cmd{array-identifier} is the array name supplied to |
| 764 |
the \cmd{readarray} command. Note, for 3-D arrays, that |
| 765 |
\end{sloppypar} |
| 766 |
|
| 767 |
\rl\itshape\vb|\|array-identifier\vb|CELLS| $=$ \\\rl\quad |
| 768 |
\vb|\|array-identifier\vb|PLANES| $\times$ \vb|\|array-identifier\vb|ROWS| |
| 769 |
$\times$ \vb|\|array-identifier\vb|COLS|\upshape |
| 770 |
|
| 771 |
For the \cmd{tobeConjugation} example of the prior section, |
| 772 |
\tobeConjugationCELLS $=$\tobeConjugationPLANES |
| 773 |
$\times$\tobeConjugationROWS $\times$% |
| 774 |
\tobeConjugationCOLS. Likewise, for 2-D arrays |
| 775 |
|
| 776 |
\rl\itshape\vb|\|array-identifier\vb|CELLS| $=$ \vb|\|array-identifier\vb|ROWS| |
| 777 |
$\times$ \vb|\|array-identifier\vb|COLS|\upshape |
| 778 |
|
| 779 |
To retrieve the data from the array, one merely supplies the |
| 780 |
array name in the form of |
| 781 |
\cmd{}\textit{array-identifier}\margcmd{\rmfamily\itshape array-identifier% |
| 782 |
\upshape\ttfamily[...]}, |
| 783 |
along with the array-cell nomenclature in the form of |
| 784 |
\textit{\texttt{\upshape[}plane\texttt{\upshape,}row\texttt{\upshape,}% |
| 785 |
column\texttt{\upshape]}} for 3-D arrays, |
| 786 |
\textit{\texttt{\upshape[}row\texttt{\upshape,}% |
| 787 |
column\texttt{\upshape]}} for 2-D arrays, and |
| 788 |
\textit{\texttt{\upshape[}row\texttt{\upshape]}} for 1-D arrays. |
| 789 |
|
| 790 |
Thus, in the case of the earlier example involving conjugation of the |
| 791 |
verb \textit{to be}, the second-person future-perfect tense of the verb |
| 792 |
is given by |
| 793 |
|
| 794 |
\rl\cmd{tobeConjugation[3,2,4]} |
| 795 |
|
| 796 |
which yields ``\tobeConjugation[3,2,4]''. |
| 797 |
|
| 798 |
\section{Typesetting Whole Arrays} |
| 799 |
|
| 800 |
Often, one wishes not just to recall the contents of a single |
| 801 |
cell, but to recall a whole array for the purposes of typesetting. |
| 802 |
The command \vb|\typesetarray| does just that. |
| 803 |
Let us create an array \vb|\Q[2,2,2]| whose cell \vb|[i,j,k]| contains |
| 804 |
the tokens ``($i,j,k$)'', where $i$, $j$ and $k$ denote a particular |
| 805 |
plane, row and column of \vb|\Q|. |
| 806 |
If one invokes \vb|\typesetarray\Q|\margcmd{typesetarray}, the default |
| 807 |
dump of the array will be: |
| 808 |
|
| 809 |
\initarray\Q[2,2,2] |
| 810 |
\setvalue\Q[1,1,1]{(1,1,1)} |
| 811 |
\setvalue\Q[1,2,1]{(1,2,1)} |
| 812 |
\setvalue\Q[1,1,2]{(1,1,2)} |
| 813 |
\setvalue\Q[1,2,2]{(1,2,2)} |
| 814 |
\setvalue\Q[2,1,1]{(2,1,1)} |
| 815 |
\setvalue\Q[2,2,1]{(2,2,1)} |
| 816 |
\setvalue\Q[2,1,2]{(2,1,2)} |
| 817 |
\setvalue\Q[2,2,2]{(2,2,2)} |
| 818 |
\typesetarray\Q |
| 819 |
|
| 820 |
The presentation of the array is governed by four defined macros, |
| 821 |
whose definitions can be renewed:\\ |
| 822 |
\vb|\typesetplanesepchar| (default \vb|\\---\\|),\\ |
| 823 |
\vb|\typesetrowsepchar| (default \vb|\\|),\\ |
| 824 |
\vb|\typesetcolsepchar| (default \vb|,|) and\\ |
| 825 |
\vb|\typesetcell|,\\ |
| 826 |
the last of which takes 1 argument (the cell content) and, by |
| 827 |
default, presents it unaltered. |
| 828 |
One can see that the default treatment separates columns with |
| 829 |
a comma, performs a linefeed between each row, and |
| 830 |
inserts an em-dash on a line by itself between each plane, which |
| 831 |
is exactly how \vb|\Q| was presented above. |
| 832 |
|
| 833 |
However, these defaults can be renewed to produce a different |
| 834 |
visual format, for example, that obtainable from a \vb|tabular| |
| 835 |
environment. |
| 836 |
For example, upon issuing these renewals |
| 837 |
\begin{verbatim} |
| 838 |
\renewcommand\typesetplanesepchar{\\\hline} |
| 839 |
\renewcommand\typesetrowsepchar{\\} |
| 840 |
\renewcommand\typesetcolsepchar{&} |
| 841 |
\renewcommand\typesetcell[1]{\scriptsize\textbf{#1}} |
| 842 |
\end{verbatim} |
| 843 |
one may insert the \vb|\typesetarray| inside a \vb|\tabular| |
| 844 |
and it will format according to those rules: |
| 845 |
\begin{verbatim} |
| 846 |
\begin{tabular}{cc} |
| 847 |
\hline |
| 848 |
\typesetarray\Q\\ |
| 849 |
\hline |
| 850 |
\end{tabular} |
| 851 |
\end{verbatim} |
| 852 |
yielding the following output: |
| 853 |
\renewcommand\typesetplanesepchar{\\\hline} |
| 854 |
\renewcommand\typesetrowsepchar{\\} |
| 855 |
\renewcommand\typesetcolsepchar{&} |
| 856 |
\renewcommand\typesetcell[1]{\scriptsize\textbf{#1}} |
| 857 |
\begin{tabular}{cc} |
| 858 |
\hline |
| 859 |
\typesetarray\Q\\ |
| 860 |
\hline |
| 861 |
\end{tabular} |
| 862 |
. |
| 863 |
|
| 864 |
%@@@ |
| 865 |
|
| 866 |
\section{Bounds Checking} |
| 867 |
|
| 868 |
While the user is developing his or her application involving the {\rdar} |
| 869 |
package, there may accidentally arise the unintended circumstance where |
| 870 |
an array element is requested which falls outside the array bounds. |
| 871 |
In general, when a non-existent array element is requested in the |
| 872 |
absence of bounds checking, the call will expand to \cmd{relax}. |
| 873 |
|
| 874 |
The package provides three declarations to set the manner in |
| 875 |
which array bounds are be monitored. |
| 876 |
The setting \cmd{nocheckbounds}\margcmd{nocheckbounds} is used when bounds |
| 877 |
are not to be checked. |
| 878 |
This is the default behavior for \rdar. |
| 879 |
For some bounds checking, \cmd{checkbounds}\margcmd{checkbounds} |
| 880 |
may be set. |
| 881 |
With this setting, bounds violations are noted, but no guidance is |
| 882 |
provided as to the allowable index range for the array. |
| 883 |
However, with \cmd{hypercheckbounds}\margcmd{hypercheckbounds} set, |
| 884 |
full bounds checking is possible. |
| 885 |
With this setting, not only are violations noted, but a description |
| 886 |
of the actual array range is provided. |
| 887 |
|
| 888 |
As of V2.0, bounds violations are noted in the log file, rather than the |
| 889 |
document itself. |
| 890 |
However, if an array bound is violated when bounds checking is turned on, |
| 891 |
a ``?'' shows up in the document itself. |
| 892 |
|
| 893 |
|
| 894 |
\section{Accessing Array Cells if Full Expansion is Required |
| 895 |
(e.g., placed in an \texttt{\bs edef}) } |
| 896 |
|
| 897 |
If full expansion is required of array cell contents (and assuming the cell |
| 898 |
content is expandable), it is advisable to set \cmd{nocheckbounds}% |
| 899 |
, so that the error checking code is not |
| 900 |
included in the expansion. |
| 901 |
Results may be also expanded even with \cmd{checkbounds} |
| 902 |
set, though the error-checking code is part of the expansion. |
| 903 |
However, with \cmd{hypercheckbounds} set, full |
| 904 |
expansion of array cells is no longer possible. |
| 905 |
|
| 906 |
\section{Transfer Array Cell Tokens to Macro} |
| 907 |
|
| 908 |
With the normal use of \cmd{\rmfamily\itshape array-identifier} syntax |
| 909 |
for accessing array cells, |
| 910 |
several levels of expansion are required to directly recover the original |
| 911 |
tokens of the cell, and then only when bounds checking is disabled. |
| 912 |
When the actual unexpanded tokens of cell are required, the use of the |
| 913 |
\cmd{arraytomacro}\margcmd{arraytomacro} command provides the means |
| 914 |
to accomplish this. |
| 915 |
The command takes the array name and index as the initial arguments followed |
| 916 |
by a generic macro name into which to place the unexpanded tokens of the |
| 917 |
indexed array cell. |
| 918 |
|
| 919 |
So, for example \vb|\arraytomacro\tobeConjugation[2,2,3]\thiscell| will |
| 920 |
place the cell's original tokens in the macro \cmd{thiscell}. |
| 921 |
Upon detokenization, the macro \cmd{thiscell} contains |
| 922 |
\arraytomacro\tobeConjugation[2,2,3]\thiscell |
| 923 |
``\texttt{\detokenize\expandafter{\thiscell}}''. |
| 924 |
|
| 925 |
|
| 926 |
\section{Deprecated and Defunct Features} |
| 927 |
|
| 928 |
\textbf{Deprecated} |
| 929 |
|
| 930 |
The following commands are supplied, but are no longer the preferred |
| 931 |
embodiment of package syntax. |
| 932 |
|
| 933 |
\rl\vb|\arraydump|\\ |
| 934 |
\rl\vb|\scalardump| |
| 935 |
|
| 936 |
To replace the function of these, \vb|\typesetarray| is |
| 937 |
the preferred embodiment. |
| 938 |
|
| 939 |
\textbf{Defunct} |
| 940 |
|
| 941 |
The following macros are no longer supported. |
| 942 |
|
| 943 |
\itshape |
| 944 |
\rl\vb|\copyrecords{|array-identifier\vb|}|% |
| 945 |
\\ |
| 946 |
\rl\vb|\readArrayij{\|data-macro\vb|}{|array-identifier\vb|}{|columns\vb|}|% |
| 947 |
\\ |
| 948 |
\rl\vb|\readArrayij*{\|data-macro\vb|}{|array-identifier\vb|}{|columns\vb|}|% |
| 949 |
\\ |
| 950 |
\rl\vb|\readArrayijk{\|data-macro\vb|}{|array-identifier\vb|}{|rows\vb|}{|columns\vb|}|% |
| 951 |
\\ |
| 952 |
\rl\vb|\readArrayijk*{\|data-macro\vb|}{|array-identifier\vb|}{|rows\vb|}{|columns\vb|}|% |
| 953 |
\\ |
| 954 |
\rl\vb|\showrecord[|error\vb|]{|record number\vb|}|\\ |
| 955 |
\rl\vb|\Arrayij[|error\vb|]{|array-identifier\vb|}{|row\vb|}{|column\vb|}|\\ |
| 956 |
\rl\vb|\Arrayijk[|error\vb|]{|array-identifier\vb|}{|plane\vb|}{|row\vb|}{|% |
| 957 |
column\vb|}|\\ |
| 958 |
\rl\vb|\arrayij{|array-identifier\vb|}{|row\vb|}{|column\vb|}|\\ |
| 959 |
\rl\vb|\arrayijk{|array-identifier\vb|}{|plane\vb|}{|row\vb|}{|% |
| 960 |
column\vb|}|\upshape |
| 961 |
\itshape |
| 962 |
\rl\vb|\getargsC{\|macro {\upshape or} string\vb|}|\\ |
| 963 |
\rl\vb|\arg|index\\ |
| 964 |
\rl\vb|\narg|\\ |
| 965 |
\rl\vb|\showargs|% |
| 966 |
\rl\vb|\converttilde|\\ |
| 967 |
\rl\vb|\record|index |
| 968 |
\upshape |
| 969 |
|
| 970 |
|
| 971 |
\section{Acknowledgements} |
| 972 |
|
| 973 |
I am profoundly thankful to Christian Tellechea for using |
| 974 |
my simplistic (read ``deficient'') \textsf{getargs} package to |
| 975 |
inspire his effort in creating the powerful \loi{} package. |
| 976 |
It is precisely the tool I have sought for a long time, and I have |
| 977 |
adapted its use into the workings of this package. |
| 978 |
|
| 979 |
I would like to thank Dr. David Carlisle for his assistance in |
| 980 |
helping the author rewrite the \vb|\getargs| command, originally found |
| 981 |
in the \textsf{stringstrings} package. To distinguish the two versions, |
| 982 |
and in deference to him, it is herein named \vb|\getargsC|. However, |
| 983 |
as of V2.0, its presence is vestigial, having instead been superceded with |
| 984 |
the \loi{} package macros. |
| 985 |
|
| 986 |
I am likewise grateful to Ken Kubota, who suggested moving the |
| 987 |
\vb|\newread| outside of \vb|\readdef|, so as not to prematurely |
| 988 |
exhaust the 16 available file streams. |
| 989 |
|
| 990 |
%\clearpage |
| 991 |
\section{Code Listing} |
| 992 |
|
| 993 |
\verbfilenobox[\footnotesize]{readarray.sty} |
| 994 |
\end{document} |
| 995 |
|
| 996 |
|
| 997 |
|