NArray: Multidimensional Numeric Arrays in Tcl
Version 0.15
Note: this is alpha software. Things are likely to change. If
you have any comments or suggestions please send them to
slshen@lbl.gov. See the file NEWS for a list of recent
changes.
In Brief
NArray is an extension to help Tcl cope with large in-memory numeric
arrays. NArray's require only a few more bytes than the storage
required by the array. In addition to providing array referencing
and setting, narray allows functions to be mapped over each element
of the array. These functions are compiled into byte code for
performance about 100x faster than straight tcl and only 5-10x slower
than C. (These numbers are ball-park figures, actual results depend
on the situation.)
If you have netCDF, then
narray's can be saved to and loaded from netCDF files.
An Example
Here's a example:
% narray create cube 64 64 64 ;# cube is an 64x64x64 float array
cube
% cube status ;# 64x64x64 * sizeof(float) = 1MB
1024.12KB used, debug 0
% cube aref 0 0 0 ;# return the element (0,0,0)
0
% cube aset 0 0 0 10 ;# set (0,0,0) to 10
10
% cube map { [] += 5; } ;# add 5 to each element
% cube aref 0 0 0 ;# (0,0,0) is now 15
15
% cube vset sum 0 ;# set the variable sum to 0
0
% cube map { sum += []; } ;# sum the elements
% cube vref sum ;# get the value of the variable sum
1.31073e+06 ;# the sum of the elements is 1310730
% expr 64*64*64*5+10 ;# just checking...
1310730
You can also bind other arrays to variables in the narray language,
call functions, call tcl, etc. See the man page and other examples
for more information.
Online Demonstration
If you'd like to get the feel of narray's without the bother of
compiling the thing then you may enter expressions
into a restricted Tcl interpreter through a form. You might need
to take a look at the narray man page. You
can also cut and paste the following examples into the form:
Where to Get It
The current version of the software should be available on harbor.ecn.purdue.edu
in the usual place, or in ftp://overload.lbl.gov/pub/narray/.
Sam Shen, slshen@lbl.gov
Last modified: Tue Dec 6 19:49:41 1994