www.pudn.com > object pascal±àÒëÆ÷Ô´Âë.rar > arrayabs.tex


\section*{Array types} 
The array type mechanism of Pascal has been extended to 
provide better support for data parallel programming in general, 
and SIMD image processing in particular. 
Data parallel programming can be built up from certain underlying 
abstractions\cite{Ewing}: 
\begin{itemize} 
\item operations on whole arrays 
\item array slicing 
\item conditional operations 
\item reduction operations 
\item scan operations 
\item data reorganisation 
\end{itemize} 
 
\subsection*{Dynamic Arrays} 
 
A dynamic array is an array whose bounds are determined at run time. Operations 
on dynamic arrays are essential in general purpose image processing software since 
the size of an image loaded from a file may not be known at compile time. 
 
Pascal 90\cite{ISO90} introduced the notion of schematic or parameterised types 
as a means of creating dynamic arrays. Thus where \textbf{r} is some integral 
type one can write  
 
\textbf{type z(a,b:r)=array{[}a..b{]} of t;} 
 
If \textbf{p:\textasciicircum{}z}, then  
 
\textbf{new(p,n,m)} 
 
where \textbf{n,m:r} initialises \textbf{p} to point to an array of bounds \textbf{n..m}. 
The bounds of the array can then be accessed as \textbf{p\textasciicircum{}.a, 
p\textasciicircum{}.b}. Vector Pascal incorporates this notation from Pascal 
90 for dynamic arrays  
\footnote{ 
It should be noted that the use of schematic array types preserves the semantic distinction 
present in Standard Pascal, between assigning a pointer to an array, and assigining an array itself. 
This distinction is confused with the "open array" construct allowed by Delphi and Free Pascal. 
}. 
\subsection*{Indexed Ranges} 
 
Image processing applications often have to deal with regions of interest, rectangular 
sub-images within a larger image. Vector Pascal extends the array abstraction to 
define sub-ranges of arrays. A sub-range  of an array variable are denoted by the variable followed 
by a range expression in brackets. 
 
%\vspace{0.3cm} 
%{\centering \begin{tabular}{|c|c|} 
%\hline  
%& 
% '{[}' {[}',' {]}{*} '{]}'\\ 
%\hline  
%\end{tabular}\par} 
%\vspace{0.3cm} 
 
%\vspace{0.3cm} 
%{\centering \begin{tabular}{|c|c|} 
%\hline  
%& 
% '..' \\ 
%\hline  
%\end{tabular}\par} 
%\vspace{0.3cm} 
 
The expressions within the range expression must conform to the index type of 
the array variable. The type of a range expression \textbf{a{[}i..j{]}} where 
\textbf{a: array{[}p..q{]} of t} is \textbf{array{[}0..j-i{]} of t.} 
 
Examples 
 
\textbf{dataset{[}i..i+2{]}:=blank;} 
 
\textbf{twoDdata{[}2..3,5..6{]}:=twoDdata{[}4..5,11..12{]}{*}0.5;} 
 
Subranges may be passed in as actual parameters to procedures whose corresponding 
formal parameters are declared as variables of a schematic type. Hence given 
the following declarations: 
 
\textbf{type image(miny,maxy,minx,maxx:integer)=array{[}miny..maxy,minx..maxx{]} 
of pixel;} 
 
\textbf{procedure invert(var im:image);begin im:= - im; end;} 
 
\textbf{var screen:array{[}0..319,0..199{]} of pixel;} 
 
then the following statement would be valid: 
 
\textbf{invert(screen{[}40..60,20..30{]});} 
 
 
 
 An array may be indexed 
by another array. If \textbf{x:array{[}t0{]} of t1} and \textbf{y:array{[}t1{]} 
of t2}, then \textbf{y{[}x{]}} denotes the virtual array of type \textbf{array{[}t0{]} 
of t2} such that \textbf{y{[}x{]}{[}i{]}=y{[}x{[}i{]}{]}}. This construct is 
useful for performing permutations.  
%To fully understand the following example 
%refer to sections \ref{iota},\ref{implicitindices}. 
 
 
\paragraph{Example} 
 
Given the declarations 
 
\textbf{const perm:array{[}0..3{]} of integer=(3,1,2,0);} 
 
\textbf{var ma,m0:array{[}0..3{]} of integer; } 
 
then the statements 
 
\textbf{m0:= (iota 0)+1;} 
 
%\textbf{write('m0=');for j:=0 to 3 do write(m0{[}j{]});writeln;} 
 
\textbf{ma:=m0{[}perm{]}; } 
 
%\textbf{write('perm=');for j:=0 to 3 do write(perm{[}j{]});writeln; } 
 
%\textbf{writeln('ma:=m0{[}perm{]}');for j:=0 to 3 do write(ma{[}j{]});writeln;} 
 
would set the variables such that  
 
\begin{verbatim} 
m0=	1 	2 	3 	4 
perm=	3	1	2	0 
ma=	4	2	3	1 
\end{verbatim}