OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / man / mann / vector.n
1 '\"
2 '\" Copyright 1991-1997 by Lucent Technologies, Inc.
3 '\"
4 '\" Permission to use, copy, modify, and distribute this software and its
5 '\" documentation for any purpose and without fee is hereby granted, provided
6 '\" that the above copyright notice appear in all copies and that both that the
7 '\" copyright notice and warranty disclaimer appear in supporting documentation,
8 '\" and that the names of Lucent Technologies any of their entities not be used
9 '\" in advertising or publicity pertaining to distribution of the software
10 '\" without specific, written prior permission.
11 '\"
12 '\" Lucent Technologies disclaims all warranties with regard to this software,
13 '\" including all implied warranties of merchantability and fitness.  In no event
14 '\" shall Lucent Technologies be liable for any special, indirect or
15 '\" consequential damages or any damages whatsoever resulting from loss of use,
16 '\" data or profits, whether in an action of contract, negligence or other
17 '\" tortuous action, arising out of or in connection with the use or performance
18 '\" of this software.  
19 '\"
20 '\" Vector command created by George Howlett.
21 '\"
22 '\" The definitions below are for supplemental macros used in Tcl/Tk
23 '\" manual entries.
24 '\"
25 '\" .AP type name in/out ?indent?
26 '\"     Start paragraph describing an argument to a library procedure.
27 '\"     type is type of argument (int, etc.), in/out is either "in", "out",
28 '\"     or "in/out" to describe whether procedure reads or modifies arg,
29 '\"     and indent is equivalent to second arg of .IP (shouldn't ever be
30 '\"     needed;  use .AS below instead)
31 '\"
32 '\" .AS ?type? ?name?
33 '\"     Give maximum sizes of arguments for setting tab stops.  Type and
34 '\"     name are examples of largest possible arguments that will be passed
35 '\"     to .AP later.  If args are omitted, default tab stops are used.
36 '\"
37 '\" .BS
38 '\"     Start box enclosure.  From here until next .BE, everything will be
39 '\"     enclosed in one large box.
40 '\"
41 '\" .BE
42 '\"     End of box enclosure.
43 '\"
44 '\" .CS
45 '\"     Begin code excerpt.
46 '\"
47 '\" .CE
48 '\"     End code excerpt.
49 '\"
50 '\" .VS ?version? ?br?
51 '\"     Begin vertical sidebar, for use in marking newly-changed parts
52 '\"     of man pages.  The first argument is ignored and used for recording
53 '\"     the version when the .VS was added, so that the sidebars can be
54 '\"     found and removed when they reach a certain age.  If another argument
55 '\"     is present, then a line break is forced before starting the sidebar.
56 '\"
57 '\" .VE
58 '\"     End of vertical sidebar.
59 '\"
60 '\" .DS
61 '\"     Begin an indented unfilled display.
62 '\"
63 '\" .DE
64 '\"     End of indented unfilled display.
65 '\"
66 '\" .SO
67 '\"     Start of list of standard options for a Tk widget.  The
68 '\"     options follow on successive lines, in four columns separated
69 '\"     by tabs.
70 '\"
71 '\" .SE
72 '\"     End of list of standard options for a Tk widget.
73 '\"
74 '\" .OP cmdName dbName dbClass
75 '\"     Start of description of a specific option.  cmdName gives the
76 '\"     option's name as specified in the class command, dbName gives
77 '\"     the option's name in the option database, and dbClass gives
78 '\"     the option's class in the option database.
79 '\"
80 '\" .UL arg1 arg2
81 '\"     Print arg1 underlined, then print arg2 normally.
82 '\"
83 '\" RCS: @(#) $Id: man.macros,v 1.1.1.1 2009/05/09 16:27:42 pcmacdon Exp $
84 '\"
85 '\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
86 .if t .wh -1.3i ^B
87 .nr ^l \n(.l
88 .ad b
89 '\"     # Start an argument description
90 .de AP
91 .ie !"\\$4"" .TP \\$4
92 .el \{\
93 .   ie !"\\$2"" .TP \\n()Cu
94 .   el          .TP 15
95 .\}
96 .ta \\n()Au \\n()Bu
97 .ie !"\\$3"" \{\
98 \&\\$1  \\fI\\$2\\fP    (\\$3)
99 .\".b
100 .\}
101 .el \{\
102 .br
103 .ie !"\\$2"" \{\
104 \&\\$1  \\fI\\$2\\fP
105 .\}
106 .el \{\
107 \&\\fI\\$1\\fP
108 .\}
109 .\}
110 ..
111 '\"     # define tabbing values for .AP
112 .de AS
113 .nr )A 10n
114 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
115 .nr )B \\n()Au+15n
116 .\"
117 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
118 .nr )C \\n()Bu+\\w'(in/out)'u+2n
119 ..
120 .AS Tcl_Interp Tcl_CreateInterp in/out
121 '\"     # BS - start boxed text
122 '\"     # ^y = starting y location
123 '\"     # ^b = 1
124 .de BS
125 .br
126 .mk ^y
127 .nr ^b 1u
128 .if n .nf
129 .if n .ti 0
130 .if n \l'\\n(.lu\(ul'
131 .if n .fi
132 ..
133 '\"     # BE - end boxed text (draw box now)
134 .de BE
135 .nf
136 .ti 0
137 .mk ^t
138 .ie n \l'\\n(^lu\(ul'
139 .el \{\
140 .\"     Draw four-sided box normally, but don't draw top of
141 .\"     box if the box started on an earlier page.
142 .ie !\\n(^b-1 \{\
143 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
144 .\}
145 .el \}\
146 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
147 .\}
148 .\}
149 .fi
150 .br
151 .nr ^b 0
152 ..
153 '\"     # VS - start vertical sidebar
154 '\"     # ^Y = starting y location
155 '\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
156 .de VS
157 .if !"\\$2"" .br
158 .mk ^Y
159 .ie n 'mc \s12\(br\s0
160 .el .nr ^v 1u
161 ..
162 '\"     # VE - end of vertical sidebar
163 .de VE
164 .ie n 'mc
165 .el \{\
166 .ev 2
167 .nf
168 .ti 0
169 .mk ^t
170 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
171 .sp -1
172 .fi
173 .ev
174 .\}
175 .nr ^v 0
176 ..
177 '\"     # Special macro to handle page bottom:  finish off current
178 '\"     # box/sidebar if in box/sidebar mode, then invoked standard
179 '\"     # page bottom macro.
180 .de ^B
181 .ev 2
182 'ti 0
183 'nf
184 .mk ^t
185 .if \\n(^b \{\
186 .\"     Draw three-sided box if this is the box's first page,
187 .\"     draw two sides but no top otherwise.
188 .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
189 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
190 .\}
191 .if \\n(^v \{\
192 .nr ^x \\n(^tu+1v-\\n(^Yu
193 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
194 .\}
195 .bp
196 'fi
197 .ev
198 .if \\n(^b \{\
199 .mk ^y
200 .nr ^b 2
201 .\}
202 .if \\n(^v \{\
203 .mk ^Y
204 .\}
205 ..
206 '\"     # DS - begin display
207 .de DS
208 .RS
209 .nf
210 .sp
211 ..
212 '\"     # DE - end display
213 .de DE
214 .fi
215 .RE
216 .sp
217 ..
218 '\"     # SO - start of list of standard options
219 .de SO
220 .SH "STANDARD OPTIONS"
221 .LP
222 .nf
223 .ta 4c 8c 12c
224 .ft B
225 ..
226 '\"     # SE - end of list of standard options
227 .de SE
228 .fi
229 .ft R
230 .LP
231 See the \\fBoptions\\fR manual entry for details on the standard options.
232 ..
233 '\"     # OP - start of full description for a single option
234 .de OP
235 .LP
236 .nf
237 .ta 4c
238 Command-Line Name:      \\fB\\$1\\fR
239 Database Name:  \\fB\\$2\\fR
240 Database Class: \\fB\\$3\\fR
241 .fi
242 .IP
243 ..
244 '\"     # CS - begin code excerpt
245 .de CS
246 .RS
247 .nf
248 .ta .25i .5i .75i 1i
249 .ft CW
250 .sp
251 ..
252 '\"     # CE - end code excerpt
253 .de CE
254 .fi
255 .RE
256 .ft R
257 .sp
258 ..
259 .de UL
260 \\$1\l'|0\(ul'\\$2
261 ..
262 .TH vector n 2.5 BLT "BLT Built-In Commands"
263 .BS
264 '\" Note:  do not modify the .SH NAME line immediately below!
265 .SH NAME
266 vector \-  Vector data type for Tcl
267 .SH SYNOPSIS
268 \fBvector configure \fIoption value ...\fR
269 .sp
270 \fBvector create \fIvecName \fR?\fIvecName\fR...? ?\fIswitches\fR? 
271 .sp
272 \fBvector destroy \fIvecName \fR?\fIvecName\fR...?
273 .sp
274 \fBvector expr \fIexpression\fR
275 .sp
276 \fBvector names \fR?\fIpattern\fR...?
277 .sp
278 \fBvector op\fR \fIoperation vecName\fR ?\fIarg\fR?...
279 .BE
280 .SH DESCRIPTION
281 The \fBvector\fR command creates a vector of floating point
282 values.  The vector's components can be manipulated in three ways:
283 through a Tcl array variable, a Tcl command, or the C API.
284 .SH INTRODUCTION
285 A vector is simply an ordered set of numbers.  The components of a
286 vector are real numbers, indexed by counting numbers.
287 .PP
288 Vectors are common data structures for many applications.  For
289 example, a graph may use two vectors to represent the X-Y
290 coordinates of the data plotted.  The graph will automatically
291 be redrawn when the vectors are updated or changed. By using vectors, 
292 you can separate
293 data analysis from the graph widget.  This makes it easier, for
294 example, to add data transformations, such as splines.  It's possible
295 to plot the same data to in multiple graphs, where each graph presents
296 a different view or scale of the data.
297 .PP
298 You could try to use Tcl's associative arrays as vectors.  Tcl arrays
299 are easy to use.  You can access individual elements randomly by
300 specifying the index, or the set the entire array by providing a list
301 of index and value pairs for each element.  The disadvantages of 
302 associative arrays as vectors lie in the fact they are implemented as
303 hash tables.
304 .TP 2
305 \(bu 
306 There's no implied ordering to the associative arrays.  If you used
307 vectors for plotting, you would want to insure the second component
308 comes after the first, an so on.  This isn't possible since arrays
309 are actually hash tables.  For example, you can't get a range of
310 values between two indices.  Nor can you sort an array.
311 .TP 2
312 \(bu
313 Arrays consume lots of memory when the number of elements becomes
314 large (tens of thousands).  This is because each element's index and
315 value are stored as strings in the hash table.
316 .TP 2
317 \(bu 
318 The C programming interface is unwieldy.  Normally with vectors, you
319 would like to view the Tcl array as you do a C array, as an array of
320 floats or doubles.  But with hash tables, you must convert both the
321 index and value to and from decimal strings, just to access
322 an element in the array.  This makes it cumbersome to perform operations on
323 the array as a whole.
324 .PP
325 The \fBvector\fR command tries to overcome these disadvantages while
326 still retaining the ease of use of Tcl arrays.  The \fBvector\fR
327 command creates both a new Tcl command and associate array which are
328 linked to the vector components.  You can randomly access vector
329 components though the elements of array.  Not all indices are
330 generated for the array, so printing the array (using the \fBparray\fR
331 procedure) does not print out all the component values.  You can use
332 the Tcl command to access the array as a whole.  You can copy, append,
333 or sort vector using its command.  If you need greater performance, or
334 customized behavior, you can write your own C code to manage vectors.
335 .SH EXAMPLE
336 You create vectors using the \fBvector\fR command and its \fBcreate\fR
337 operation.
338 .CS
339 # Create a new vector. 
340 vector create y(50)
341 .CE
342 This creates a new vector named \fBy\fR.  It has fifty components, by
343 default, initialized to \fB0.0\fR.  In addition, both a Tcl command
344 and array variable, both named \fBy\fR, are created.  You can use
345 either the command or variable to query or modify components of the
346 vector.
347 .CS
348 # Set the first value. 
349 set y(0) 9.25
350 puts "y has [y length] components"
351 .CE
352 The array \fBy\fR can be used to read or set individual components of
353 the vector.  Vector components are indexed from zero.  The array index
354 must be a number less than the number of components.  For example,
355 it's an error if you try to set the 51st element of \fBy\fR.
356 .CS
357 # This is an error. The vector only has 50 components.
358 set y(50) 0.02
359 .CE
360 You can also specify a range of indices using a colon (:) to separate
361 the first and last indices of the range.
362 .CS
363 # Set the first six components of y 
364 set y(0:5) 25.2
365 .CE
366 If you don't include an index, then it will default to the first
367 and/or last component of the vector.
368 .CS
369 # Print out all the components of y 
370 puts "y = $y(:)"
371 .CE
372 There are special non-numeric indices.  The index \fBend\fR, specifies
373 the last component of the vector.  It's an error to use this index if
374 the vector is empty (length is zero).  The index \fB++end\fR can be
375 used to extend the vector by one component and initialize it to a specific 
376 value.  You can't read from the array using this index, though.
377 .CS
378 # Extend the vector by one component.
379 set y(++end) 0.02
380 .CE
381 The other special indices are \fBmin\fR and \fBmax\fR.  They return the
382 current smallest and largest components of the vector.  
383 .CS
384 # Print the bounds of the vector
385 puts "min=$y(min) max=$y(max)"
386 .CE
387 To delete components from a vector, simply unset the corresponding
388 array element. In the following example, the first component of
389 \fBy\fR is deleted.  All the remaining components of \fBy\fR will be
390 moved down by one index as the length of the vector is reduced by
391 one.
392 .CS
393 # Delete the first component
394 unset y(0)
395 puts "new first element is $y(0)"
396 .CE
397 The vector's Tcl command can also be used to query or set the vector.
398 .CS
399 # Create and set the components of a new vector
400 vector create x
401 x set { 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 }
402 .CE
403 Here we've created a vector \fBx\fR without a initial length specification.
404 In this case, the length is zero.  The \fBset\fR operation resets the vector,
405 extending it and setting values for each new component.  
406 .PP
407 There are several operations for vectors.  The \fBrange\fR operation
408 lists the components of a vector between two indices.
409 .CS
410 # List the components 
411 puts "x = [x range 0 end]"
412 .CE
413 You can search for a particular value using the \fBsearch\fR
414 operation.  It returns a list of indices of the components with the
415 same value.  If no component has the same value, it returns \fB""\fR.
416 .CS
417 # Find the index of the biggest component
418 set indices [x search $x(max)]
419 .CE
420 Other operations copy, append, or sort vectors.  You can append
421 vectors or new values onto an existing vector with the \fBappend\fR
422 operation.
423 .CS
424 # Append assorted vectors and values to x
425 x append x2 x3 { 2.3 4.5 } x4
426 .CE
427 The \fBsort\fR operation sorts the vector.  If any additional vectors
428 are specified, they are rearranged in the same order as the vector.
429 For example, you could use it to sort data points represented by x and
430 y vectors.
431 .CS
432 # Sort the data points
433 x sort y
434 .CE
435 The vector \fBx\fR is sorted while the components of \fBy\fR are 
436 rearranged so that the original x,y coordinate pairs are retained.
437 .PP
438 The \fBexpr\fR operation lets you perform arithmetic on vectors.  
439 The result is stored in the vector.
440 .CS
441 # Add the two vectors and a scalar
442 x expr { x + y }
443 x expr { x * 2 }
444 .CE
445 When a vector is modified, resized, or deleted, it may trigger
446 call-backs to notify the clients of the vector.  For example, when a
447 vector used in the \fBgraph\fR widget is updated, the vector
448 automatically notifies the widget that it has changed.  The graph can
449 then redrawn itself at the next idle point.  By default, the
450 notification occurs when Tk is next idle.  This way you can modify the
451 vector many times without incurring the penalty of the graph redrawing
452 itself for each change.  You can change this behavior using the
453 \fBnotify\fR operation.
454 .CS
455 # Make vector x notify after every change
456 x notify always
457         ...
458 # Never notify
459 x notify never
460         ...
461 # Force notification now
462 x notify now
463
464 # Set Tcl callback for update of Tktable widget .t.
465 x notify callback {.t conf -padx [.t cget -padx]; .t reread}
466
467 .CE
468 To delete a vector, use the \fBvector delete\fR command.  
469 Both the vector and its corresponding Tcl command are destroyed.
470 .CS
471 # Remove vector x
472 vector destroy x
473 .CE
474 The psuedo vector \fBlast\fR can be used at the end of an
475 expression to implement running totals.
476 During execution it resolves to the result from the previous
477 vector element evaluation.
478 .CS
479 vector create A(10)
480 vector create B(10)
481 vector create S(10)
482 vector create T(10)
483 S expr A+B
484 T expr S+last; # Running total
485 .CE
486 .SH SYNTAX
487 Vectors are created using the \fBvector create\fR operation.  
488 Th \fBcreate\fR operation can be invoked in one of three forms:
489 .TP
490 \fBvector create \fIvecName\fR
491 This creates a new vector \fIvecName\fR which initially has no components.
492 .TP
493 \fBvector create \fIvecName\fR(\fIsize\fR)
494 This second form creates a new vector which will contain \fIsize\fR
495 number of components.  The components will be indexed starting from
496 zero (0). The default value for the components is \fB0.0\fR.
497 .TP
498 \fBvector create \fIvecName\fR(\fIrows,columns\fR)
499 This form allows creation of a matrix with the specified columns and
500 \fIrows*columns\fR elements.
501 See the \fImatrix\fR section for more details.
502 .TP
503 \fBvector create \fIvecName\fR(\fIfirst\fR:\fIlast\fR)
504 The last form creates a new vector of indexed \fIfirst\fR through
505 \fIlast\fR.  \fIFirst\fR and \fIlast\fR can be any integer value
506 so long as \fIfirst\fR is less than \fIlast\fR.
507 .PP
508 Vector names must start with a letter and consist of letters, digits,
509 or underscores.  
510 .CS
511 # Error: must start with letter
512 vector create 1abc
513 .CE
514 You can automatically generate vector names using the
515 "\fB#auto\fR" vector name.  The \fBcreate\fR operation will generate a 
516 unique vector name.
517 .CS
518 set vec [vector create #auto]
519 puts "$vec has [$vec length] components"
520 .CE
521 .SS VECTOR INDICES
522 Vectors are indexed by integers.  You can access the individual vector
523 components via its array variable or Tcl command.  The string
524 representing the index can be an integer, a numeric expression, a
525 range, or a special keyword.
526 .PP
527 The index must lie within the current range of the vector, otherwise
528 an an error message is returned.  Normally the indices of a vector
529 are start from 0.  But you can use the \fBoffset\fR operation to
530 change a vector's indices on-the-fly.
531 .CS
532 puts $vecName(0)
533 vecName offset -5
534 puts $vecName(-5)
535 .CE
536 When \fImatrix numcols\fR is > 1, 2D indexes are supported using
537 ROW,COL form.
538 .CS
539 vecName matrix numcols 3
540 puts vecName(0,2)
541 .CE
542 You can also use numeric expressions as indices.  The result
543 of the expression must be an integer value.  
544 .CS
545 set n 21
546 set vecName($n+3) 50.2
547 .CE
548 The following special non-numeric indices are available: \fBmin\fR, \fBmax\fR, \fBend\fR, and
549 \fB++end\fR.  
550 .CS
551 puts "min = $vecName($min)"
552 set vecName(end) -1.2
553 .CE
554 The indices \fBmin\fR and \fBmax\fR will return the minimum and maximum
555 values of the vector.  Also available are: \fBprod\fR,  \fBsum\fR, 
556 and \fBmean\fR.
557 The index \fBend\fR returns the value of the 
558 last component in the vector.
559 he index \fBend,0\fR returns the value of the 
560 last row in column 0 of the vector.
561 The index \fB++end\fR is used to append
562 new value onto the vector.  It automatically extends the vector by
563 numcols and sets its value.
564 .CS
565 # Append an new component to the end
566 set vecName(++end) 3.2
567 .CE
568 A range of indices can be indicated by a colon (:).  
569 .CS
570 # Set the first six components to 1.0
571 set vecName(0:5) 1.0
572 .CE
573 If no index is supplied the first or last component is assumed.
574 .CS
575 # Print the values of all the components
576 puts $vecName(:)
577 .CE
578 .SH VECTOR OPERATIONS
579 .TP
580 \fBvector configure \fI? -flush bool -watchunset bool -oldcreate bool -maxsize int -novariable bool -nocommand bool?\fR
581 The \fBconfigure\fR operation sets the default options used
582 in creating vectors: these options are global to the interpreter.
583 The \fI\-maxsize\fR option, when non-zero, limits creation size.
584 The \fI\-oldcreate\fR enable the creation shortcut: \fBvector vec1 vec2 ...\fR.
585 See the create command for details on the others.
586 By default, these are all disabled or zero.
587 .RE
588 .TP
589 \fBvector create \fIvecName\fR?(\fIsize\fR)?... \fR?\fIswitches\fR? 
590 The \fBcreate\fR operation creates a new vector \fIvecName\fR. The
591 \fIsize\fR may be an integer, a START:END range or ROW,COL (see matrix).
592 This creates both a
593 Tcl command and array variable called \fIvecName\fR.  The
594 name \fIvecName\fR must be unique, so another Tcl command or array
595 variable can not already exist in the current scope.  You may access the
596 components of the vector using the  variable.  If you change a value in
597 the array, or unset an array element, the vector is updated to reflect
598 the changes.  When the variable \fIvecName\fR is unset, the vector and
599 its Tcl command are also destroyed.
600 .sp
601 The vector has optional switches that affect how the vector is created. They
602 are as follows:
603 .RS
604 .TP
605 \fB\-variable \fIvarName\fR
606 Specifies the name of a Tcl variable to be mapped to the vector. If
607 the variable already exists, it is first deleted, then recreated. 
608 If \fIvarName\fR is the empty string, then no variable will be mapped.
609 You can always map a variable back to the vector using the vector's 
610 \fBvariable\fR operation.
611 .TP
612 \fB\-command \fIcmdName\fR
613 Maps a Tcl command to the vector. The vector can be accessed using 
614 \fIcmdName\fR and one of the vector instance operations.  
615 A Tcl command by that name cannot already exist.
616 If \fIcmdName\fR is the empty string, no command mapping
617 will be made.
618 .TP
619 \fB\-watchunset \fIboolean\fR
620 Indicates that the vector should automatically delete itself if
621 the variable associated with the vector is unset.  By default,
622 the vector will not be deleted.  This is different from previous
623 releases.  Set \fIboolean\fR to "true" to get the old behavior.
624 .TP
625 \fB\-flush \fIboolean\fR
626 Indicates that the vector should automatically flush the cached
627 variable elements which unsets all the elements of the Tcl array
628 variable associated with the vector, freeing memory associated 
629 with the variable. This includes both the hash table and the hash keys.
630 The down side is that this effectively flushes the caching of vector
631 elements in the array.  This means that the subsequent reads
632 of the array will require a decimal to string conversion.
633 By default, flushing is disabled.
634 .RE
635 .TP
636 \fBvector destroy \fIvecName\fR \fR?\fIvecName...\fR?
637 Destroy vectors.
638 .TP
639 \fBvector expr \fIexpression\fR
640 .RS
641 All binary operators take vectors as operands (remember that numbers
642 are treated as one-component vectors).The exact action of binary
643 operators depends upon the length of the second operand.  If the
644 second operand has only one component, then each element of the first
645 vector operand is computed by that value.  For example, the expression
646 "x * 2" multiples all elements of the vector x by 2.  If the second
647 operand has more than one component, both operands must be the same
648 length.  Each pair of corresponding elements are computed.  So "x + y"
649 adds the the first components of x and y together, the second, and so on.
650 .sp
651 The valid operators are listed below, grouped in decreasing order
652 of precedence:
653 .TP 20
654 \fB\-\0\0!\fR
655 Unary minus and logical NOT.  The unary minus flips the sign of each
656 component in the vector.  The logical not operator returns a vector of
657 whose values are 0.0 or 1.0.  For each non-zero component 1.0 is returned,
658 0.0 otherwise.
659 .TP 20
660 \fB^\fR
661 Exponentiation.  
662 .TP 20
663 \fB*\0\0/\0\0%\fR
664 Multiply, divide, remainder.  
665 .TP 20
666 \fB+\0\0\-\fR
667 Add and subtract.  
668 .TP 20
669 \fB<<\0\0>>\fR
670 Left and right shift.  Circularly shifts the values of the vector 
671 .TP 20
672 \fB<\0\0>\0\0<=\0\0>=\fR
673 Boolean less, greater, less than or equal, and greater than or equal.
674 Each operator returns a vector of ones and zeros.  If the condition is true, 
675 1.0 is the component value, 0.0 otherwise.
676 .TP 20
677 \fB==\0\0!=\fR
678 Boolean equal and not equal.
679 Each operator returns a vector of ones and zeros.  If the condition is true, 
680 1.0 is the component value, 0.0 otherwise.
681 .TP 20
682 \fB&&\fR
683 Logical AND.  Produces a 1 result if both operands are non-zero, 0 otherwise.
684 .TP 20
685 \fB||\fR
686 Logical OR.  Produces a 0 result if both operands are zero, 1 otherwise.
687 .TP 20
688 \fIx\fB?\fIy\fB:\fIz\fR
689 If-then-else, as in C.
690 .LP
691 .sp
692 See the C manual for more details on the results produced by each
693 operator.  All of the binary operators group left-to-right within the
694 same precedence level.  
695 .sp
696 Several mathematical functions are supported for vectors.  Each of
697 the following functions invokes the math library function of the same name;
698 see the manual entries for the library functions for details on what
699 they do.  The operation is applied to all elements of the vector
700 returning the results.   All functions take a vector operand.
701 If no vector operand is used in the call, the current
702 vector is assumed. eg.
703 .CS
704 vector create aVec
705 aVec seq 0 100
706 aVec expr {2*abs(aVec)-1}
707 aVec length 100
708 aVec expr {2*row()}
709 vector expr {2*row()} ; # ERROR!
710 .CE
711 .CS
712 .ta 3c 6c 9c
713 \fBacos\fR      \fBcos\fR       \fBhypot\fR     \fBsinh\fR 
714 \fBasin\fR      \fBcosh\fR      \fBlog\fR       \fBsqrt\fR 
715 \fBatan\fR      \fBexp\fR       \fBlog10\fR     \fBtan\fR  
716 \fBceil\fR      \fBfloor\fR     \fBsin\fR       \fBtanh\fR 
717 .CE
718 Additional functions are:
719 .TP 1i
720 \fBabs\fR
721 Returns the absolute value of each component.
722 .TP 1i
723 \fBrandom\fR
724 Returns a vector of non-negative values uniformly distributed 
725 between [0.0, 1.0) using \fIdrand48\fR.
726 The seed comes from the internal clock of the machine or may be 
727 set manual with the srandom function.
728 .TP 1i
729 \fBround\fR
730 Rounds each component of the vector.
731 .TP 1i
732 \fBsrandom\fR
733 Initializes the random number generator using \fIsrand48\fR.
734 The high order 32-bits are set using the integral portion of the first 
735 vector component. All other components are ignored.  The low order 16-bits 
736 are set to an arbitrary value.
737 .PP
738 The following functions return a single value.
739 .TP 1i
740 \fBadev\fR 
741 Returns the average deviation (defined as the sum of the absolute values 
742 of the differences between component and the mean, divided by the length
743 of the vector).
744 .TP 1i
745 \fBkurtosis\fR
746 Returns the degree of peakedness (fourth moment) of the vector.
747 .TP 1i
748 \fBlength\fR
749 Returns the number of components in the vector.
750 .TP 1i
751 \fBmax\fR
752 Returns the vector's maximum value.
753 .TP 1i
754 \fBmean\fR
755 Returns the mean value of the vector.
756 .TP 1i
757 \fBmedian\fR
758 Returns the median of the vector.
759 .TP 1i
760 \fBmin\fR
761 Returns the vector's minimum value.
762 .TP 1i
763 \fBq1\fR
764 Returns the first quartile of the vector.
765 .TP 1i
766 \fBq3\fR
767 Returns the third quartile of the vector.
768 .TP 1i
769 \fBprod\fR 
770 Returns the product of the components.
771 .TP 1i
772 \fBsdev\fR 
773 Returns the standard deviation (defined as the square root of the variance)
774 of the vector.
775 .TP 1i
776 \fBskew\fR 
777 Returns the skewness (or third moment) of the vector.  This characterizes
778 the degree of asymmetry of the vector about the mean.
779 .TP 1i
780 \fBsum\fR 
781 Returns the sum of the components.
782 .TP 1i
783 \fBvar\fR
784 Returns the variance of the vector. The sum of the squared differences 
785 between each component and the mean is computed.  The variance is 
786 the sum divided by the length of the vector minus 1.
787 .PP
788 This last set of functions returns a vector of the same length as the argument.
789 .TP 1i
790 \fBinvert\fR
791 Returns vector with elements in reversed order.
792 .TP 1i
793 \fBnorm\fR 
794 Scales the values of the vector to lie in the range [0.0..1.0].
795 .TP 1i
796 \fBrow\fR 
797 Psuedo function to get the current row.
798 .TP 1i
799 \fBsort\fR
800 Returns the vector components sorted in ascending order.
801 .TP 1i
802 \fBshift(nVec,N)\fR
803 This is the only function taking a second arg.
804 It provides a version of \fInvec\fR shifted by N places.
805 When N is a scalar or vector with only one element,
806 shift fills vacant area with 0. Otherwise the second element of
807 \fInVec\fR is used for the fill value.
808 One use for this is providing running totals.
809 .RE
810 .TP
811 \fBvector names \fR?\fIpattern\fR?
812 Return names of all defined vectors.
813 .RE
814 .TP
815 \fBvector op\fR \fIoperation vecName\fR ?\fIarg\fR?...
816 Invoke instance operation.  Supported operations are defined in the next section.
817 Op is the only way to invoke instance operation sub-commands
818 when -command is defined as empty in
819 a vector.  It also allows writing vector code that is checkable
820 by a syntax checkers.  eg.
821 .CS
822
823 vector create v1
824 v1 op append {1 2 3}
825 v1 op modify 1 2.1
826
827 .CE
828 .RE
829 .SH INSTANCE OPERATIONS
830 You can also use the vector's Tcl command to query or modify it.  The
831 general form is
832 .DS
833 \fIvecName \fIoperation\fR \fR?\fIarg\fR?...
834 .DE
835 Note this is equivalent to the form:
836 .DS
837 \fBvector op\fR \fIoperation vecName\fR ?\fIarg\fR?...
838 .DE
839 Both \fIoperation\fR and its arguments determine the exact behavior of
840 the command.  The operations available for vectors are listed below.
841 .TP
842 \fIvecName \fB+\fR \fIitem\fR
843 \fIvecName \fB-\fR \fIitem\fR
844 \fIvecName \fB*\fR \fIitem\fR
845 \fIvecName \fB/\fR \fIitem\fR
846 Perform binary op and return result as a list.
847 .TP
848 \fIvecName \fBappend\fR \fIitem\fR ?\fIitem\fR?...
849 Appends the component values from \fIitem\fR to \fIvecName\fR.
850 \fIItem\fR can be either the name of a vector or a list of numeric
851 values.
852 .TP
853 \fIvecName \fBbinread\fR \fIchannel\fR ?\fIlength\fR? ?\fIswitches\fR? 
854 Reads binary values from a Tcl channel. Values are either appended
855 to the end of the vector or placed at a given index (using the
856 \fB\-at\fR option), overwriting existing values.  Data is read until EOF
857 is found on the channel or a specified number of values \fIlength\fR 
858 are read (note that this is not necessarily the same as the number of 
859 bytes). The following switches are supported:
860 .RS
861 .TP
862 \fB\-swap\fR
863 Swap bytes and words.  The default endian is the host machine.
864 .TP
865 \fB\-at \fIindex\fR
866 New values will start at vector index \fIindex\fR.  This will
867 overwrite any current values.
868 .TP
869 \fB\-format\fR \fIformat\fR
870 Specifies the format of the data.  \fIFormat\fR can be one of the
871 following: "i1", "i2", "i4", "i8", "u1, "u2", "u4", "u8", "r4",
872 "r8", or "r16".  The number indicates the number of bytes
873 required for each value.  The letter indicates the type: "i" for signed,
874 "u" for unsigned, "r" or real.  The default format is "r16".
875 .RE
876 .TP
877 \fIvecName \fBbinwrite\fR \fIchannel\fR ?\fIlength\fR? ?\fI\-at index\fR? 
878 Like \fBbinread\fR, but writes data.
879 .TP
880 \fIvecName \fBclear\fR 
881 Clears the element indices from the array variable associated with
882 \fIvecName\fR.  This doesn't affect the components of the vector.  By
883 default, the number of entries in the Tcl array doesn't match the
884 number of components in the vector.  This is because its too expensive
885 to maintain decimal strings for both the index and value for each
886 component.  Instead, the index and value are saved only when you read
887 or write an element with a new index.  This command removes the index
888 and value strings from the array.  This is useful when the vector is
889 large.
890 .TP
891 \fIvecName \fBdelete\fR \fIindex\fR ?\fIindex\fR?...
892 Deletes the \fIindex\fRth component from the vector \fIvecName\fR.
893 \fIIndex\fR is the index of the element to be deleted.  This is the
894 same as unsetting the array variable element \fIindex\fR.  The vector
895 is compacted after all the indices have been deleted.
896 .TP
897 \fIvecName \fBdup\fR \fIdestName\fR 
898 Copies \fIvecName\fR to \fIdestName\fR. \fIDestName\fR is the name of a
899 destination vector.  If a vector \fIdestName\fR already exists, it is
900 overwritten with the components of \fIvecName\fR.  Otherwise a 
901 new vector is created.
902 .TP
903 \fIvecName \fBexpr\fR \fIexpression\fR
904 Computes the expression and resets the values of the vector accordingly.
905 Both scalar and vector math operations are allowed.  All values in
906 expressions are either real numbers or names of vectors.  All numbers
907 are treated as one component vectors.
908 .TP
909 \fIvecName \fBindex\fR \fIindex\fR ?\fIvalue\fR?...
910 Get/set individual vector values.  This provides element
911 updating when \fI\-variable\fR is set to empty.
912 .TP
913 \fIvecName \fBinsert\fR \fIindex\fR \fIitem\fR ?\fIitem\fR?...
914 Inserts the component values from \fIitem\fR to \fIvecName\fR at
915 \fIindex\fR \fIItem\fR can be either the name of a vector or
916 a list of numeric values.
917 .TP
918 \fIvecName \fBlength\fR ?\fInewSize\fR?
919 Queries or resets the number of components in \fIvecName\fR.
920 \fINewSize\fR is a number specifying the new size of the vector.  If
921 \fInewSize\fR is smaller than the current size of \fIvecName\fR,
922 \fIvecName\fR is truncated.  If \fInewSize\fR is greater, the vector
923 is extended and the new components are initialized to \fB0.0\fR.  If
924 no \fInewSize\fR argument is present, the current length of the vector
925 is returned.
926 .TP
927 \fIvecName \fBmatrix \fI ...\fR
928 Matrix provides a 2D array view into 1D data.  It provides indexing operations
929 in ROW,COL form making it suitable for use with TkTable.
930 Data storage remains unchanged: vectors are still just a single long array.
931 For example, here are two ways to create a 3 column by 10 row matrix:
932 .CS
933
934 vector create aVec(10,3)
935 vector create bVec(30)
936 bVec matrix numcols 3
937 set aVec(0,0) 99
938 set bVec(29,2) -99
939 aVec append {5 6 7}; # aVec now has 11 rows.
940 aVec append 1 2;     # Now aVec has 13 rows!
941
942 .CE
943 Note that data is appended only in increments of numcols.
944 Elements 0-2 make up the first row, 3-5 the second, etc.
945 Elements will appear only in increments of the column size.
946 .RS
947 .TP 0.75i
948 \fIvecName \fBmatrix copy \fIdstcolumn\fR \fIsrccolumn\fR \fI?srcVec?\fR  
949 Copy a column of element values
950 to column \fIdstcolumn\fR from \fIsrccolumn\fR.
951 If vector \fIsrcVec\fR is given, and not the same as \fIvecName\fR, the
952 columns numbers must be different.
953 If the \fIsrcVec\fR column is longer, \fIvecName\fR will be extended.
954 If shorter, remaining destination values are not overwritten.
955 .TP
956 \fIvecName \fBmatrix delete \fIcolumn\fR.
957 Delete elements in a column.
958 Note that \fBnumcols\fR, which must be greater than 1, will be decremented.
959 .TP
960 \fIvecName \fBmatrix get \fIcolumn\fR
961 Get the element in a column:  this number must be
962 less than \fBnumcols\fR.
963 Note that \fBnumcols\fR must be non-zero.
964 .TP
965 \fIvecName \fBmatrix insert \fIcolumn\fR \fI?initvalue?\fR .
966 Insert a new column of elements at column (default 0).
967 The new column is initialized
968 with \fIinitvalue\fR, or \fI0.0\fR if not specified.
969 Note that \fBnumcols\fR will be incremented.
970 .TP
971 \fIvecName \fBmatrix multiply \fIsrcVec\fR ?\fIdstVec\fR? 
972 Perform matrix multiplication using \fBsrcVec\fR,
973 placing results either in \fBdstVec\fR, or returned as a list.
974 The numrows of \fIsrcVec\fR must equal numcols in
975 \fIvecName\fR.  One application for multiply is coordinate transformation.
976 .TP
977 \fIvecName \fBmatrix numcols \fI?size?\fR
978 Get or set the number of columns for a vectors data.  Values >1 enable
979 array variables to accept 2d matrix indexes.
980 For example with a numcols of 10, \fB$vec1(1,2)\fR refers to the
981 13th element in the vector. A vectors size is also constrained
982 to multiples of numcols, as is it's offset.
983 By default, numcols is 1.
984 .TP
985 \fIvecName \fBmatrix numrows \fI?size?\fR
986 Get or set the length of rows in a columns for a vector.
987 By default, this is just the \fIvector length/numcols\fR.
988 Setting this value simply provides a convenient way to increase or decrease
989 the vector size by multiples of \fInumcols\fR.
990 .TP
991 \fIvecName \fBmatrix set \fIcolumn\fR \fI?valuelist?\fR
992 Set value  elements in a column:  this number must be
993 less than \fBnumcols\fR.  The \fIvaluelist\fR is a list values.
994 If this list is shorter than the column, it's last
995 value is used for all remaining columns. The column gets set to
996 the values of \fIitem\fR, or \fI0.0\fR by default.
997 .TP
998 \fIvecName \fBmatrix shift \fIcolumn\fR \fIamount\fR ?\fIstartoffset\fR?
999 Shifts the values of a column by integer in\fIamount\fR.  A negative
1000 value shifts upward.
1001 The \fIstartoffset\fR indicates where to start shifting from.
1002 .TP
1003 \fIvecName \fBmatrix sort \fIcolumn\fR \fI?-reverse?\fR
1004 Sort the vector by the given column.
1005 .TP
1006 \fIvecName \fBmatrix transpose\fR
1007 Transpose all columns with rows in matrix.
1008 Note that this is a no-op if \fBnumcols\fR is 1.  Otherwise,
1009 numcols will change to \fBvectorLength/numcols\fR.
1010 .RE
1011 .TP
1012 \fIvecName \fBmerge\fR \fIsrcName\fR ?\fIsrcName\fR?...
1013 Merges the named vectors into a single vector.  The resulting 
1014 vector is formed by merging the components of each source vector 
1015 one index at a time.
1016 .TP
1017 \fIvecName \fBnotify\fR ?\fIkeyword\fR? ?\fIscript\fR?
1018 Queries or controls how vector clients are notified of changes
1019 to the vector.  Also allows setting a notifier callback.
1020 The exact behavior is determined by \fIkeyword\fR.
1021 .RS
1022 .TP 0.75i
1023 \fBalways\fR 
1024 Indicates that clients are to be notified immediately whenever the
1025 vector is updated.
1026 .TP
1027 \fBnever\fR
1028 Indicates that no clients are to be notified.
1029 .TP
1030 \fBwhenidle\fR
1031 Indicates that clients are to be notified at the next idle point
1032 whenever the vector is updated.
1033 .TP
1034 \fBnow\fR
1035 If any client notifications is currently pending, they are notified
1036 immediately.
1037 .TP
1038 \fBcancel\fR
1039 Cancels pending notifications of clients using the vector.
1040 .TP
1041 \fBpending\fR
1042 Returns \fB1\fR if a client notification is pending, and \fB0\fR otherwise.
1043 .TP
1044 \fBcallback\fR ?\fIscript\fR?
1045 Query or set a Tcl callback script that is evaluated when a vector is updated.
1046 .RE
1047 .TP
1048 \fIvecName \fBpopulate\fR \fIdestName\fR ?\fIdensity\fR?
1049 Creates a vector \fIdestName\fR which is a superset of \fIvecName\fR.
1050 \fIDestName\fR will include all the components of \fIvecName\fR, in
1051 addition the interval between each of the original components will
1052 contain a \fIdensity\fR number of new components, whose values are
1053 evenly distributed between the original components values.  This is
1054 useful for generating abscissas to be interpolated along a spline.
1055 .TP
1056 \fIvecName \fBrange\fR \fIfirstIndex\fR ?\fIlastIndex\fR?...
1057 Returns a list of numeric values representing the vector components
1058 between two indices. Both \fIfirstIndex\fR and \fIlastIndex\fR are 
1059 indices representing the range of components to be returned. If 
1060 \fIlastIndex\fR is less than \fIfirstIndex\fR, the components are
1061 listed in reverse order.
1062 .TP
1063 \fIvecName \fBsearch\fR \fIvalue\fR ?\fIvalue\fR?  
1064 Searches for a value or range of values among the components of
1065 \fIvecName\fR.  If one \fIvalue\fR argument is given, a list of
1066 indices of the components which equal \fIvalue\fR is returned.  If a
1067 second \fIvalue\fR is also provided, then the indices of all
1068 components which lie within the range of the two values are returned.
1069 If no components are found, then \fB""\fR is returned.
1070 .TP
1071 \fIvecName \fBset\fR \fIitem\fR
1072 Resets the components of the vector to \fIitem\fR. \fIItem\fR can
1073 be either a list of numeric expressions or another vector.
1074 .TP
1075 \fIvecName \fBseq\fR \fIstart\fR ?\fIfinish\fR? ?\fIstep\fR?
1076 Generates a sequence of values starting with the value \fIstart\fR.
1077 \fIFinish\fR indicates the terminating value of the sequence.  
1078 The vector is automatically resized to contain just the sequence.
1079 If three arguments are present, \fIstep\fR designates the interval.  
1080 .sp
1081 With only two arguments (no \fIfinish\fR argument), the sequence will
1082 continue until the vector is filled.  With one argument, the interval 
1083 defaults to 1.0.
1084 .TP
1085 \fIvecName \fBsort\fR ?\fB-reverse\fR? ?\fIargName\fR?...  
1086 Sorts the vector \fIvecName\fR in increasing order.  If the
1087 \fB-reverse\fR flag is present, the vector is sorted in decreasing
1088 order.  If other arguments \fIargName\fR are present, they are the
1089 names of vectors which will be rearranged in the same manner as
1090 \fIvecName\fR.  Each vector must be the same length as \fIvecName\fR.
1091 You could use this to sort the x vector of a graph, while still
1092 retaining the same x,y coordinate pairs in a y vector.
1093 .TP
1094 \fIvecName \fBsplit\fR \fIdstName\fR ?\fIdstName\fR?...
1095 Split the vector into a multiple vectors.  The resulting 
1096 N vectors each contain the mod-Nth element from source.
1097 .TP
1098 \fIvecName \fBvariable\fR \fIvarName\fR
1099 Maps a Tcl variable to the vector, creating another means for 
1100 accessing the vector.  The variable \fIvarName\fR can't already 
1101 exist. This overrides any current variable mapping the vector
1102 may have.
1103 .RE
1104 .SH C LANGUAGE API
1105 You can create, modify, and destroy vectors from C code, using 
1106 library routines.  
1107 You need to include the header file \fBblt.h\fR. It contains the
1108 definition of the structure \fBBlt_Vector\fR, which represents the
1109 vector.  It appears below.
1110 .CS
1111 \fRtypedef struct {
1112     double *\fIvalueArr\fR; 
1113     int \fInumValues\fR;    
1114     int \fIarraySize\fR;    
1115     double \fImin\fR, \fImax\fR;  
1116 } \fBBlt_Vector\fR;
1117 .CE
1118 The field \fIvalueArr\fR points to memory holding the vector
1119 components.  The components are stored in a double precision array,
1120 whose size size is represented by \fIarraySize\fR.  \fINumValues\fR is
1121 the length of vector.  The size of the array is always equal to or
1122 larger than the length of the vector.  \fIMin\fR and \fImax\fR are
1123 minimum and maximum component values.
1124 .SH LIBRARY ROUTINES
1125 The following routines are available from C to manage vectors.
1126 Vectors are identified by the vector name.
1127 .PP
1128 \fBBlt_CreateVector\fR 
1129 .RS .25i
1130 .TP 1i
1131 Synopsis:
1132 .CS 
1133 int \fBBlt_CreateVector\fR (\fIinterp\fR, \fIvecName\fR, \fIlength\fR, \fIvecPtrPtr\fR)
1134 .RS 1.25i
1135 Tcl_Interp *\fIinterp\fR;
1136 char *\fIvecName\fR;
1137 int \fIlength\fR;
1138 Blt_Vector **\fIvecPtrPtr\fR;
1139 .RE
1140 .CE
1141 .TP
1142 Description:
1143 Creates a new vector \fIvecName\fR\fR with a length of \fIlength\fR.
1144 \fBBlt_CreateVector\fR creates both a new Tcl command and array 
1145 variable \fIvecName\fR.  Neither a command nor variable named 
1146 \fIvecName\fR can already exist.  A pointer to the vector is 
1147 placed into \fIvecPtrPtr\fR.
1148 .TP
1149 Results:
1150 Returns \fBTCL_OK\fR if the vector is successfully created.  If
1151 \fIlength\fR is negative, a Tcl variable or command \fIvecName\fR
1152 already exists, or memory cannot be allocated for the vector, then
1153 \fBTCL_ERROR\fR is returned and \fIinterp->result\fR will contain an
1154 error message.
1155 .RE
1156 .sp
1157 .PP
1158 \fBBlt_DeleteVectorByName\fR 
1159 .RS .25i
1160 .TP 1i
1161 Synopsis:
1162 .CS
1163 int \fBBlt_DeleteVectorByName\fR (\fIinterp\fR, \fIvecName\fR)
1164 .RS 1.25i
1165 Tcl_Interp *\fIinterp\fR;
1166 char *\fIvecName\fR;
1167 .RE
1168 .CE
1169 .TP 1i
1170 Description:
1171 Removes the vector \fIvecName\fR.  \fIVecName\fR is the name of a vector
1172 which must already exist.  Both the Tcl command and array variable
1173 \fIvecName\fR are destroyed.  All clients of the vector will be notified
1174 immediately that the vector has been destroyed.
1175 .TP
1176 Results:
1177 Returns \fBTCL_OK\fR if the vector is successfully deleted.  If
1178 \fIvecName\fR is not the name a vector, then \fBTCL_ERROR\fR is returned
1179 and \fIinterp->result\fR will contain an error message.
1180 .RE
1181 .sp
1182 .PP
1183 \fBBlt_DeleteVector\fR 
1184 .RS .25i
1185 .TP 1i
1186 Synopsis:
1187 .CS
1188 int \fBBlt_DeleteVector\fR (\fIvecPtr\fR)
1189 .RS 1.25i
1190 Blt_Vector *\fIvecPtr\fR;
1191 .RE
1192 .CE
1193 .TP 1i
1194 Description:
1195 Removes the vector pointed to by \fIvecPtr\fR.  \fIVecPtr\fR is a
1196 pointer to a vector, typically set by \fBBlt_GetVector\fR or
1197 \fBBlt_CreateVector\fR.  Both the Tcl command and array variable of
1198 the vector are destroyed.  All clients of the vector will be notified
1199 immediately that the vector has been destroyed.
1200 .TP
1201 Results:
1202 Returns \fBTCL_OK\fR if the vector is successfully deleted.  If
1203 \fIvecName\fR is not the name a vector, then \fBTCL_ERROR\fR is returned
1204 and \fIinterp->result\fR will contain an error message.
1205 .RE
1206 .sp
1207 .PP
1208 \fBBlt_GetVector\fR 
1209 .RS .25i
1210 .TP 1i
1211 Synopsis:
1212 .CS
1213 int \fBBlt_GetVector\fR (\fIinterp\fR, \fIvecName\fR, \fIvecPtrPtr\fR)
1214 .RS 1.25i
1215 Tcl_Interp *\fIinterp\fR;
1216 char *\fIvecName\fR;
1217 Blt_Vector **\fIvecPtrPtr\fR;
1218 .RE
1219 .CE
1220 .TP 1i
1221 Description:
1222 Retrieves the vector \fIvecName\fR.  \fIVecName\fR is the name of a
1223 vector which must already exist.  \fIVecPtrPtr\fR will point be set to
1224 the address of the vector.
1225 .TP
1226 Results:
1227 Returns \fBTCL_OK\fR if the vector is successfully retrieved.  If
1228 \fIvecName\fR is not the name of a vector, then \fBTCL_ERROR\fR is
1229 returned and \fIinterp->result\fR will contain an error message.
1230 .RE
1231 .sp
1232 .PP
1233 \fBBlt_ResetVector\fR 
1234 .PP
1235 .RS .25i
1236 .TP 1i
1237 Synopsis:
1238 .CS
1239 int \fBBlt_ResetVector\fR (\fIvecPtr\fR, \fIdataArr\fR, 
1240         \fInumValues\fR, \fIarraySize\fR, \fIfreeProc\fR)
1241 .RS 1.25i
1242 Blt_Vector *\fIvecPtr\fR;
1243 double *\fIdataArr\fR;
1244 int *\fInumValues\fR;
1245 int *\fIarraySize\fR;
1246 Tcl_FreeProc *\fIfreeProc\fR;
1247 .RE
1248 .CE
1249 .TP
1250 Description: 
1251 Resets the components of the vector pointed to by \fIvecPtr\fR.
1252 Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
1253 notifications to its clients. \fIDataArr\fR is the array of doubles
1254 which represents the vector data. \fINumValues\fR is the number of
1255 elements in the array. \fIArraySize\fR is the actual size of the array
1256 (the array may be bigger than the number of values stored in
1257 it). \fIFreeProc\fP indicates how the storage for the vector component
1258 array (\fIdataArr\fR) was allocated.  It is used to determine how to
1259 reallocate memory when the vector is resized or destroyed.  It must be
1260 \fBTCL_DYNAMIC\fR, \fBTCL_STATIC\fR, \fBTCL_VOLATILE\fR, or a pointer
1261 to a function to free the memory allocated for the vector array. If
1262 \fIfreeProc\fR is \fBTCL_VOLATILE\fR, it indicates that \fIdataArr\fR
1263 must be copied and saved.  If \fIfreeProc\fR is \fBTCL_DYNAMIC\fR, it
1264 indicates that \fIdataArr\fR was dynamically allocated and that Tcl
1265 should free \fIdataArr\fR if necessary.  \fBStatic\fR indicates that
1266 nothing should be done to release storage for \fIdataArr\fR.
1267 .TP
1268 Results:
1269 Returns \fBTCL_OK\fR if the vector is successfully resized.  If
1270 \fInewSize\fR is negative, a vector \fIvecName\fR does not exist, or
1271 memory cannot be allocated for the vector, then \fBTCL_ERROR\fR is
1272 returned and \fIinterp->result\fR will contain an error message.
1273 .RE
1274 .sp
1275 .PP
1276 \fBBlt_ResizeVector\fR 
1277 .RS .25i
1278 .TP 1i
1279 Synopsis:
1280 .CS
1281 int \fBBlt_ResizeVector\fR (\fIvecPtr\fR, \fInewSize\fR)
1282 .RS 1.25i
1283 Blt_Vector *\fIvecPtr\fR;
1284 int \fInewSize\fR;
1285 .RE
1286 .CE
1287 .TP
1288 Description:
1289 Resets the length of the vector pointed to by \fIvecPtr\fR to
1290 \fInewSize\fR.  If \fInewSize\fR is smaller than the current size of
1291 the vector, it is truncated.  If \fInewSize\fR is greater, the vector
1292 is extended and the new components are initialized to \fB0.0\fR.
1293 Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
1294 notifications.
1295 .TP
1296 Results:
1297 Returns \fBTCL_OK\fR if the vector is successfully resized.  If
1298 \fInewSize\fR is negative or memory can not be allocated for the vector, 
1299 then \fBTCL_ERROR\fR is returned and \fIinterp->result\fR will contain 
1300 an error message.
1301 .sp
1302 .PP
1303 \fBBlt_VectorExists\fR 
1304 .RS .25i
1305 .TP 1i
1306 Synopsis:
1307 .CS
1308 int \fBBlt_VectorExists\fR (\fIinterp\fR, \fIvecName\fR)
1309 .RS 1.25i
1310 Tcl_Interp *\fIinterp\fR;
1311 char *\fIvecName\fR;
1312 .RE
1313 .CE
1314 .TP
1315 Description:
1316 Indicates if a vector named \fIvecName\fR exists in \fIinterp\fR.
1317 .TP
1318 Results:
1319 Returns \fB1\fR if a vector \fIvecName\fR exists and \fB0\fR otherwise.
1320 .RE
1321 .sp
1322 .PP
1323 If your application needs to be notified when a vector changes, it can
1324 allocate a unique \fIclient identifier\fR for itself.  Using this
1325 identifier, you can then register a call-back to be made whenever the
1326 vector is updated or destroyed.  By default, the call-backs are made at
1327 the next idle point.  This can be changed to occur at the time the
1328 vector is modified.  An application can allocate more than one
1329 identifier for any vector.  When the client application is done with
1330 the vector, it should free the identifier.
1331 .PP
1332 The call-back routine must of the following type.
1333 .CS
1334 .RS
1335 .sp
1336 typedef void (\fBBlt_VectorChangedProc\fR) (Tcl_Interp *\fIinterp\fR, 
1337 .RS .25i
1338 ClientData \fIclientData\fR, Blt_VectorNotify \fInotify\fR);
1339 .RE
1340 .sp
1341 .RE
1342 .CE
1343 .fi
1344 \fIClientData\fR is passed to this routine whenever it is called.  You
1345 can use this to pass information to the call-back.  The \fInotify\fR 
1346 argument indicates whether the vector has been updated of destroyed. It
1347 is an enumerated type.
1348 .CS
1349 .RS
1350 .sp
1351 typedef enum {
1352     \fBBLT_VECTOR_NOTIFY_UPDATE\fR=1,
1353     \fBBLT_VECTOR_NOTIFY_DESTROY\fR=2
1354 } \fBBlt_VectorNotify\fR;
1355 .sp
1356 .RE
1357 .CE
1358 .PP
1359 \fBBlt_AllocVectorId\fR
1360 .RS .25i
1361 .TP 1i
1362 Synopsis:
1363 .CS
1364 Blt_VectorId \fBBlt_AllocVectorId\fR (\fIinterp\fR, \fIvecName\fR)
1365 .RS 1.25i
1366 Tcl_Interp *\fIinterp\fR;
1367 char *\fIvecName\fR;
1368 .RE
1369 .CE
1370 .TP
1371 Description:
1372 Allocates an client identifier for with the vector \fIvecName\fR.
1373 This identifier can be used to specify a call-back which is triggered
1374 when the vector is updated or destroyed.
1375 .TP
1376 Results:
1377 Returns a client identifier if successful.  If \fIvecName\fR is not
1378 the name of a vector, then \fBNULL\fR is returned and
1379 \fIinterp->result\fR will contain an error message.
1380 .RE
1381 .sp
1382 .PP
1383 \fBBlt_GetVectorById\fR 
1384 .RS .25i
1385 .TP 1i
1386 Synopsis:
1387 .CS
1388 int \fBBlt_GetVector\fR (\fIinterp\fR, \fIclientId\fR, \fIvecPtrPtr\fR)
1389 .RS 1.25i
1390 Tcl_Interp *\fIinterp\fR;
1391 Blt_VectorId \fIclientId\fR;
1392 Blt_Vector **\fIvecPtrPtr\fR;
1393 .RE
1394 .CE
1395 .TP 1i
1396 Description:
1397 Retrieves the vector used by \fIclientId\fR.  \fIClientId\fR is a valid
1398 vector client identifier allocated by \fBBlt_AllocVectorId\fR.
1399 \fIVecPtrPtr\fR will point be set to the address of the vector.
1400 .TP
1401 Results:
1402 Returns \fBTCL_OK\fR if the vector is successfully retrieved.  
1403 .RE
1404 .sp
1405 .PP
1406 \fBBlt_SetVectorChangedProc\fR
1407 .RS .25i
1408 .TP 1i
1409 Synopsis:
1410 .CS
1411 void \fBBlt_SetVectorChangedProc\fR (\fIclientId\fR, \fIproc\fR, \fIclientData\fR);
1412 .RS 1.25i
1413 Blt_VectorId \fIclientId\fR;
1414 Blt_VectorChangedProc *\fIproc\fR;
1415 ClientData *\fIclientData\fR;
1416 .RE
1417 .CE
1418 .TP
1419 Description: 
1420 Specifies a call-back routine to be called whenever the vector
1421 associated with \fIclientId\fR is updated or deleted.  \fIProc\fR is a
1422 pointer to call-back routine and must be of the type
1423 \fBBlt_VectorChangedProc\fR.  \fIClientData\fR is a one-word value to
1424 be passed to the routine when it is invoked. If \fIproc\fR is
1425 \fBNULL\fR, then the client is not notified.
1426 .TP
1427 Results:
1428 The designated call-back procedure will be invoked when the vector is 
1429 updated or destroyed.
1430 .RE
1431 .sp
1432 .PP
1433 \fBBlt_FreeVectorId\fR
1434 .RS .25i
1435 .TP 1i
1436 Synopsis:
1437 .CS
1438 void \fBBlt_FreeVectorId\fR (\fIclientId\fR);
1439 .RS 1.25i
1440 Blt_VectorId \fIclientId\fR;
1441 .RE
1442 .CE
1443 .TP
1444 Description: 
1445 Frees the client identifier.  Memory allocated for the identifier 
1446 is released.  The client will no longer be notified when the
1447 vector is modified.
1448 .TP
1449 Results:
1450 The designated call-back procedure will be no longer be invoked when
1451 the vector is updated or destroyed.
1452 .RE
1453 .sp
1454 .PP
1455 \fBBlt_NameOfVectorId\fR
1456 .RS .25i
1457 .TP 1i
1458 Synopsis:
1459 .CS
1460 char *\fBBlt_NameOfVectorId\fR (\fIclientId\fR);
1461 .RS 1.25i
1462 Blt_VectorId \fIclientId\fR;
1463 .RE
1464 .CE
1465 .TP
1466 Description: 
1467 Retrieves the name of the vector associated with the client identifier
1468 \fIclientId\fR.  
1469 .TP
1470 Results:
1471 Returns the name of the vector associated with \fIclientId\fR.  If
1472 \fIclientId\fR is not an identifier or the vector has been destroyed, 
1473 \fBNULL\fR is returned.
1474 .RE
1475 .sp
1476 .PP
1477 \fBBlt_InstallIndexProc\fR
1478 .RS .25i
1479 .TP 1i
1480 Synopsis:
1481 .CS
1482 void \fBBlt_InstallIndexProc\fR (\fIindexName\fR, \fIprocPtr\fR)
1483 .RS 1.25i
1484 char *\fIindexName\fR;
1485 Blt_VectorIndexProc *\fIprocPtr\fR;
1486 .RE
1487 .CE
1488 .TP
1489 Description: 
1490 Registers a function to be called to retrieved the index \fIindexName\fR
1491 from the vector's array variable.  
1492 .sp
1493 typedef double Blt_VectorIndexProc(Vector *vecPtr);
1494 .sp
1495 The function will be passed a pointer to the vector.  The function must
1496 return a double representing the value at the index.
1497 .TP
1498 Results:
1499 The new index is installed into the vector.
1500 .RE
1501 .RE
1502 .SH C API EXAMPLE
1503 The following example opens a file of binary data and stores it in an
1504 array of doubles. The array size is computed from the size of the
1505 file. If the vector "data" exists, calling \fBBlt_VectorExists\fR,
1506 \fBBlt_GetVector\fR is called to get the pointer to the vector.
1507 Otherwise the routine \fBBlt_CreateVector\fR is called to create a new
1508 vector and returns a pointer to it. Just like the Tcl interface, both
1509 a new Tcl command and array variable are created when a new vector is
1510 created. It doesn't make any difference what the initial size of the
1511 vector is since it will be reset shortly. The vector is updated when
1512 \fBlt_ResetVector\fR is called.  Blt_ResetVector makes the changes
1513 visible to the Tcl interface and other vector clients (such as a graph
1514 widget).
1515 .sp
1516 .CS
1517 #include <tcl.h>
1518 #include <blt.h>                                
1519 ...
1520 Blt_Vector *vecPtr;
1521 double *newArr;
1522 FILE *f;
1523 struct stat statBuf;
1524 int numBytes, numValues;
1525
1526 f = fopen("binary.dat", "r");
1527 fstat(fileno(f), &statBuf);
1528 numBytes = (int)statBuf.st_size;
1529
1530 /* Allocate an array big enough to hold all the data */
1531 newArr = (double *)malloc(numBytes);
1532 numValues = numBytes / sizeof(double);
1533 fread((void *)newArr, numValues, sizeof(double), f);
1534 fclose(f);
1535
1536 if (Blt_VectorExists(interp, "data"))  {
1537     if (Blt_GetVector(interp, "data", &vecPtr) != TCL_OK) {
1538         return TCL_ERROR;
1539     }
1540 } else {
1541    if (Blt_CreateVector(interp, "data", 0, &vecPtr) != TCL_OK) {
1542         return TCL_ERROR;
1543    }
1544 }
1545 /* 
1546  * Reset the vector. Clients will be notified when Tk is idle. 
1547  * TCL_DYNAMIC tells the vector to free the memory allocated 
1548  * if it needs to reallocate or destroy the vector.
1549  */
1550 if (Blt_ResetVector(vecPtr, newArr, numValues, numValues, 
1551         TCL_DYNAMIC) != TCL_OK) {
1552     return TCL_ERROR;
1553 }
1554 .CE
1555 .SH "INCOMPATIBILITIES"
1556 In previous versions, if the array variable isn't global 
1557 (i.e. local to a Tcl procedure), the vector is automatically 
1558 destroyed when the procedure returns.
1559 .CS
1560 proc doit {} {
1561     # Temporary vector x
1562     vector x(10)
1563     set x(9) 2.0
1564       ...
1565 }
1566 .CE
1567 .PP
1568 This has changed.  Variables are not automatically destroyed when
1569 their variable is unset.  You can restore the old behavior by
1570 setting the "-watchunset" switch.
1571 .CE
1572 .SH KEYWORDS
1573 vector, graph, widget