OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / 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.3 2001/02/17 07:46:19 ghowlett 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.4 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 create \fIvecName \fR?\fIvecName\fR...? ?\fIswitches\fR? 
269 .sp
270 \fBvector destroy \fIvecName \fR?\fIvecName\fR...?
271 .sp
272 \fBvector expr \fIexpression\fR
273 .sp
274 \fBvector names \fR?\fIpattern\fR...?
275 .BE
276 .SH DESCRIPTION
277 The \fBvector\fR command creates a vector of floating point
278 values.  The vector's components can be manipulated in three ways:
279 through a Tcl array variable, a Tcl command, or the C API.
280 .SH INTRODUCTION
281 A vector is simply an ordered set of numbers.  The components of a
282 vector are real numbers, indexed by counting numbers.
283 .PP
284 Vectors are common data structures for many applications.  For
285 example, a graph may use two vectors to represent the X-Y
286 coordinates of the data plotted.  The graph will automatically
287 be redrawn when the vectors are updated or changed. By using vectors, 
288 you can separate
289 data analysis from the graph widget.  This makes it easier, for
290 example, to add data transformations, such as splines.  It's possible
291 to plot the same data to in multiple graphs, where each graph presents
292 a different view or scale of the data.
293 .PP
294 You could try to use Tcl's associative arrays as vectors.  Tcl arrays
295 are easy to use.  You can access individual elements randomly by
296 specifying the index, or the set the entire array by providing a list
297 of index and value pairs for each element.  The disadvantages of 
298 associative arrays as vectors lie in the fact they are implemented as
299 hash tables.
300 .TP 2
301 \(bu 
302 There's no implied ordering to the associative arrays.  If you used
303 vectors for plotting, you would want to insure the second component
304 comes after the first, an so on.  This isn't possible since arrays
305 are actually hash tables.  For example, you can't get a range of
306 values between two indices.  Nor can you sort an array.
307 .TP 2
308 \(bu
309 Arrays consume lots of memory when the number of elements becomes
310 large (tens of thousands).  This is because each element's index and
311 value are stored as strings in the hash table.
312 .TP 2
313 \(bu 
314 The C programming interface is unwieldy.  Normally with vectors, you
315 would like to view the Tcl array as you do a C array, as an array of
316 floats or doubles.  But with hash tables, you must convert both the
317 index and value to and from decimal strings, just to access
318 an element in the array.  This makes it cumbersome to perform operations on
319 the array as a whole.
320 .PP
321 The \fBvector\fR command tries to overcome these disadvantages while
322 still retaining the ease of use of Tcl arrays.  The \fBvector\fR
323 command creates both a new Tcl command and associate array which are
324 linked to the vector components.  You can randomly access vector
325 components though the elements of array.  Not have all indices are
326 generated for the array, so printing the array (using the \fBparray\fR
327 procedure) does not print out all the component values.  You can use
328 the Tcl command to access the array as a whole.  You can copy, append,
329 or sort vector using its command.  If you need greater performance, or
330 customized behavior, you can write your own C code to manage vectors.
331 .SH EXAMPLE
332 You create vectors using the \fBvector\fR command and its \fBcreate\fR
333 operation.
334 .CS
335 # Create a new vector. 
336 vector create y(50)
337 .CE
338 This creates a new vector named \f(CWy\fR.  It has fifty components, by
339 default, initialized to \f(CW0.0\fR.  In addition, both a Tcl command
340 and array variable, both named \f(CWy\fR, are created.  You can use
341 either the command or variable to query or modify components of the
342 vector.
343 .CS
344 # Set the first value. 
345 set y(0) 9.25
346 puts "y has [y length] components"
347 .CE
348 The array \f(CWy\fR can be used to read or set individual components of
349 the vector.  Vector components are indexed from zero.  The array index
350 must be a number less than the number of components.  For example,
351 it's an error if you try to set the 51st element of \f(CWy\fR.
352 .CS
353 # This is an error. The vector only has 50 components.
354 set y(50) 0.02
355 .CE
356 You can also specify a range of indices using a colon (:) to separate
357 the first and last indices of the range.
358 .CS
359 # Set the first six components of y 
360 set y(0:5) 25.2
361 .CE
362 If you don't include an index, then it will default to the first
363 and/or last component of the vector.
364 .CS
365 # Print out all the components of y 
366 puts "y = $y(:)"
367 .CE
368 There are special non-numeric indices.  The index \f(CWend\fR, specifies
369 the last component of the vector.  It's an error to use this index if
370 the vector is empty (length is zero).  The index \f(CW++end\fR can be
371 used to extend the vector by one component and initialize it to a specific 
372 value.  You can't read from the array using this index, though.
373 .CS
374 # Extend the vector by one component.
375 set y(++end) 0.02
376 .CE
377 The other special indices are \f(CWmin\fR and \f(CWmax\fR.  They return the
378 current smallest and largest components of the vector.  
379 .CS
380 # Print the bounds of the vector
381 puts "min=$y(min) max=$y(max)"
382 .CE
383 To delete components from a vector, simply unset the corresponding
384 array element. In the following example, the first component of
385 \f(CWy\fR is deleted.  All the remaining components of \f(CWy\fR will be
386 moved down by one index as the length of the vector is reduced by
387 one.
388 .CS
389 # Delete the first component
390 unset y(0)
391 puts "new first element is $y(0)"
392 .CE
393 The vector's Tcl command can also be used to query or set the vector.
394 .CS
395 # Create and set the components of a new vector
396 vector create x
397 x set { 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 }
398 .CE
399 Here we've created a vector \f(CWx\fR without a initial length specification.
400 In this case, the length is zero.  The \fBset\fR operation resets the vector,
401 extending it and setting values for each new component.  
402 .PP
403 There are several operations for vectors.  The \fBrange\fR operation
404 lists the components of a vector between two indices.
405 .CS
406 # List the components 
407 puts "x = [x range 0 end]"
408 .CE
409 You can search for a particular value using the \fBsearch\fR
410 operation.  It returns a list of indices of the components with the
411 same value.  If no component has the same value, it returns \f(CW""\fR.
412 .CS
413 # Find the index of the biggest component
414 set indices [x search $x(max)]
415 .CE
416 Other operations copy, append, or sort vectors.  You can append
417 vectors or new values onto an existing vector with the \fBappend\fR
418 operation.
419 .CS
420 # Append assorted vectors and values to x
421 x append x2 x3 { 2.3 4.5 } x4
422 .CE
423 The \fBsort\fR operation sorts the vector.  If any additional vectors
424 are specified, they are rearranged in the same order as the vector.
425 For example, you could use it to sort data points represented by x and
426 y vectors.
427 .CS
428 # Sort the data points
429 x sort y
430 .CE
431 The vector \f(CWx\fR is sorted while the components of \f(CWy\fR are 
432 rearranged so that the original x,y coordinate pairs are retained.
433 .PP
434 The \fBexpr\fR operation lets you perform arithmetic on vectors.  
435 The result is stored in the vector.
436 .CS
437 # Add the two vectors and a scalar
438 x expr { x + y }
439 x expr { x * 2 }
440 .CE
441 When a vector is modified, resized, or deleted, it may trigger
442 call-backs to notify the clients of the vector.  For example, when a
443 vector used in the \fBgraph\fR widget is updated, the vector
444 automatically notifies the widget that it has changed.  The graph can
445 then redrawn itself at the next idle point.  By default, the
446 notification occurs when Tk is next idle.  This way you can modify the
447 vector many times without incurring the penalty of the graph redrawing
448 itself for each change.  You can change this behavior using the
449 \fBnotify\fR operation.
450 .CS
451 # Make vector x notify after every change
452 x notify always
453         ...
454 # Never notify
455 x notify never
456         ...
457 # Force notification now
458 x notify now
459 .CE
460 To delete a vector, use the \fBvector delete\fR command.  
461 Both the vector and its corresponding Tcl command are destroyed.
462 .CS
463 # Remove vector x
464 vector destroy x
465 .CE
466 .SH SYNTAX
467 Vectors are created using the \fBvector create\fR operation.  
468 Th \fBcreate\fR operation can be invoked in one of three forms:
469 .TP
470 \fBvector create \fIvecName\fR
471 This creates a new vector \fIvecName\fR which initially has no components.
472 .TP
473 \fBvector create \fIvecName\fR(\fIsize\fR)
474 This second form creates a new vector which will contain \fIsize\fR
475 number of components.  The components will be indexed starting from
476 zero (0). The default value for the components is \f(CW0.0\fR.
477 .TP
478 \fBvector create \fIvecName\fR(\fIfirst\fR:\fIlast\fR)
479 The last form creates a new vector of indexed \fIfirst\fR through
480 \fIlast\fR.  \fIFirst\fR and \fIlast\fR can be any integer value
481 so long as \fIfirst\fR is less than \fIlast\fR.
482 .PP
483 Vector names must start with a letter and consist of letters, digits,
484 or underscores.  
485 .CS
486 # Error: must start with letter
487 vector create 1abc
488 .CE
489 You can automatically generate vector names using the
490 "\f(CW#auto\fR" vector name.  The \fBcreate\fR operation will generate a 
491 unique vector name.
492 .CS
493 set vec [vector create #auto]
494 puts "$vec has [$vec length] components"
495 .CE
496 .SS VECTOR INDICES
497 Vectors are indexed by integers.  You can access the individual vector
498 components via its array variable or Tcl command.  The string
499 representing the index can be an integer, a numeric expression, a
500 range, or a special keyword.
501 .PP
502 The index must lie within the current range of the vector, otherwise
503 an an error message is returned.  Normally the indices of a vector
504 are start from 0.  But you can use the \fBoffset\fR operation to
505 change a vector's indices on-the-fly.
506 .CS
507 puts $vecName(0)
508 vecName offset -5
509 puts $vecName(-5)
510 .CE
511 You can also use numeric expressions as indices.  The result
512 of the expression must be an integer value.  
513 .CS
514 set n 21
515 set vecName($n+3) 50.2
516 .CE
517 The following special non-numeric indices are available: \f(CWmin\fR, \f(CWmax\fR, \f(CWend\fR, and
518 \f(CW++end\fR.  
519 .CS
520 puts "min = $vecName($min)"
521 set vecName(end) -1.2
522 .CE
523 The indices \f(CWmin\fR and \f(CWmax\fR will return the minimum and maximum
524 values of the vector.  The index \f(CWend\fR returns the value of the 
525 last component in the vector.  The index \f(CW++end\fR is used to append
526 new value onto the vector.  It automatically extends the vector by
527 one component and sets its value.
528 .CS
529 # Append an new component to the end
530 set vecName(++end) 3.2
531 .CE
532 A range of indices can be indicated by a colon (:).  
533 .CS
534 # Set the first six components to 1.0
535 set vecName(0:5) 1.0
536 .CE
537 If no index is supplied the first or last component is assumed.
538 .CS
539 # Print the values of all the components
540 puts $vecName(:)
541 .CE
542 .SH VECTOR OPERATIONS
543 .TP
544 \fBvector create \fIvecName\fR?(\fIsize\fR)?... \fR?\fIswitches\fR? 
545 The \fBcreate\fR operation creates a new vector \fIvecName\fR.  Both a
546 Tcl command and array variable \fIvecName\fR are also created.  The
547 name \fIvecName\fR must be unique, so another Tcl command or array
548 variable can not already exist in that scope.  You can access the
549 components of the vector using its variable.  If you change a value in
550 the array, or unset an array element, the vector is updated to reflect
551 the changes.  When the variable \fIvecName\fR is unset, the vector and
552 its Tcl command are also destroyed.
553 .sp
554 The vector has optional switches that affect how the vector is created. They
555 are as follows:
556 .RS
557 .TP
558 \fB\-variable \fIvarName\fR
559 Specifies the name of a Tcl variable to be mapped to the vector. If
560 the variable already exists, it is first deleted, then recreated. 
561 If \fIvarName\fR is the empty string, then no variable will be mapped.
562 You can always map a variable back to the vector using the vector's 
563 \fBvariable\fR operation.
564 .TP
565 \fB\-command \fIcmdName\fR
566 Maps a Tcl command to the vector. The vector can be accessed using 
567 \fIcmdName\fR and one of the vector instance operations.  
568 A Tcl command by that name cannot already exist.
569 If \fIcmdName\fR is the empty string, no command mapping
570 will be made.
571 .TP
572 \fB\-watchunset \fIboolean\fR
573 Indicates that the vector should automatically delete itself if
574 the variable associated with the vector is unset.  By default,
575 the vector will not be deleted.  This is different from previous
576 releases.  Set \fIboolean\fR to "true" to get the old behavior.
577 .RE
578 .TP
579 \fBvector destroy \fIvecName\fR \fR?\fIvecName...\fR?
580 .TP
581 \fBvector expr \fIexpression\fR
582 .RS
583 All binary operators take vectors as operands (remember that numbers
584 are treated as one-component vectors).  The exact action of binary
585 operators depends upon the length of the second operand.  If the
586 second operand has only one component, then each element of the first
587 vector operand is computed by that value.  For example, the expression
588 "x * 2" multiples all elements of the vector x by 2.  If the second
589 operand has more than one component, both operands must be the same
590 length.  Each pair of corresponding elements are computed.  So "x + y"
591 adds the the first components of x and y together, the second, and so on.
592 .sp
593 The valid operators are listed below, grouped in decreasing order
594 of precedence:
595 .TP 20
596 \fB\-\0\0!\fR
597 Unary minus and logical NOT.  The unary minus flips the sign of each
598 component in the vector.  The logical not operator returns a vector of
599 whose values are 0.0 or 1.0.  For each non-zero component 1.0 is returned,
600 0.0 otherwise.
601 .TP 20
602 \fB^\fR
603 Exponentiation.  
604 .TP 20
605 \fB*\0\0/\0\0%\fR
606 Multiply, divide, remainder.  
607 .TP 20
608 \fB+\0\0\-\fR
609 Add and subtract.  
610 .TP 20
611 \fB<<\0\0>>\fR
612 Left and right shift.  Circularly shifts the values of the vector 
613 (not implemented yet).
614 .TP 20
615 \fB<\0\0>\0\0<=\0\0>=\fR
616 Boolean less, greater, less than or equal, and greater than or equal.
617 Each operator returns a vector of ones and zeros.  If the condition is true, 
618 1.0 is the component value, 0.0 otherwise.
619 .TP 20
620 \fB==\0\0!=\fR
621 Boolean equal and not equal.
622 Each operator returns a vector of ones and zeros.  If the condition is true, 
623 1.0 is the component value, 0.0 otherwise.
624 .TP 20
625 \fB|\fR
626 Bit-wise OR.  (Not implemented).
627 .TP 20
628 \fB&&\fR
629 Logical AND.  Produces a 1 result if both operands are non-zero, 0 otherwise.
630 .TP 20
631 \fB||\fR
632 Logical OR.  Produces a 0 result if both operands are zero, 1 otherwise.
633 .TP 20
634 \fIx\fB?\fIy\fB:\fIz\fR
635 If-then-else, as in C.  (Not implemented yet).
636 .LP
637 See the C manual for more details on the results produced by each
638 operator.  All of the binary operators group left-to-right within the
639 same precedence level.  
640 .sp
641 Several mathematical functions are supported for vectors.  Each of
642 the following functions invokes the math library function of the same name;
643 see the manual entries for the library functions for details on what
644 they do.  The operation is applied to all elements of the vector
645 returning the results. 
646 .CS
647 .ta 3c 6c 9c
648 \fBacos\fR      \fBcos\fR       \fBhypot\fR     \fBsinh\fR 
649 \fBasin\fR      \fBcosh\fR      \fBlog\fR       \fBsqrt\fR 
650 \fBatan\fR      \fBexp\fR       \fBlog10\fR     \fBtan\fR  
651 \fBceil\fR      \fBfloor\fR     \fBsin\fR       \fBtanh\fR 
652 .CE
653 Additional functions are:
654 .TP 1i
655 \fBabs\fR
656 Returns the absolute value of each component.
657 .TP 1i
658 \fBrandom\fR
659 Returns a vector of non-negative values uniformly distributed 
660 between [0.0, 1.0) using \fIdrand48\fR.
661 The seed comes from the internal clock of the machine or may be 
662 set manual with the srandom function.
663 .TP 1i
664 \fBround\fR
665 Rounds each component of the vector.
666 .TP 1i
667 \fBsrandom\fR
668 Initializes the random number generator using \fIsrand48\fR.
669 The high order 32-bits are set using the integral portion of the first 
670 vector component. All other components are ignored.  The low order 16-bits 
671 are set to an arbitrary value.
672 .PP
673 The following functions return a single value.
674 .TP 1i
675 \fBadev\fR 
676 Returns the average deviation (defined as the sum of the absolute values 
677 of the differences between component and the mean, divided by the length
678 of the vector).
679 .TP 1i
680 \fBkurtosis\fR
681 Returns the degree of peakedness (fourth moment) of the vector.
682 .TP 1i
683 \fBlength\fR
684 Returns the number of components in the vector.
685 .TP 1i
686 \fBmax\fR
687 Returns the vector's maximum value.
688 .TP 1i
689 \fBmean\fR
690 Returns the mean value of the vector.
691 .TP 1i
692 \fBmedian\fR
693 Returns the median of the vector.
694 .TP 1i
695 \fBmin\fR
696 Returns the vector's minimum value.
697 .TP 1i
698 \fBq1\fR
699 Returns the first quartile of the vector.
700 .TP 1i
701 \fBq3\fR
702 Returns the third quartile of the vector.
703 .TP 1i
704 \fBprod\fR 
705 Returns the product of the components.
706 .TP 1i
707 \fBsdev\fR 
708 Returns the standard deviation (defined as the square root of the variance)
709 of the vector.
710 .TP 1i
711 \fBskew\fR 
712 Returns the skewness (or third moment) of the vector.  This characterizes
713 the degree of asymmetry of the vector about the mean.
714 .TP 1i
715 \fBsum\fR 
716 Returns the sum of the components.
717 .TP 1i
718 \fBvar\fR
719 Returns the variance of the vector. The sum of the squared differences 
720 between each component and the mean is computed.  The variance is 
721 the sum divided by the length of the vector minus 1.
722 .PP
723 The last set returns a vector of the same length as the argument.
724 .TP 1i
725 \fBnorm\fR 
726 Scales the values of the vector to lie in the range [0.0..1.0].
727 .TP 1i
728 \fBsort\fR
729 Returns the vector components sorted in ascending order.
730 .RE
731 .TP
732 \fBvector names \fR?\fIpattern\fR?
733 .SH INSTANCE OPERATIONS
734 You can also use the vector's Tcl command to query or modify it.  The
735 general form is
736 .DS
737 \fIvecName \fIoperation\fR \fR?\fIarg\fR?...
738 .DE
739 Both \fIoperation\fR and its arguments determine the exact behavior of
740 the command.  The operations available for vectors are listed below.
741 .TP
742 \fIvecName \fBappend\fR \fIitem\fR ?\fIitem\fR?...
743 Appends the component values from \fIitem\fR to \fIvecName\fR.
744 \fIItem\fR can be either the name of a vector or a list of numeric
745 values.
746 .TP
747 \fIvecName \fBbinread\fR \fIchannel\fR ?\fIlength\fR? ?\fIswitches\fR? 
748 Reads binary values from a Tcl channel. Values are either appended
749 to the end of the vector or placed at a given index (using the
750 \fB\-at\fR option), overwriting existing values.  Data is read until EOF
751 is found on the channel or a specified number of values \fIlength\fR 
752 are read (note that this is not necessarily the same as the number of 
753 bytes). The following switches are supported:
754 .RS
755 .TP
756 \fB\-swap\fR
757 Swap bytes and words.  The default endian is the host machine.
758 .TP
759 \fB\-at \fIindex\fR
760 New values will start at vector index \fIindex\fR.  This will
761 overwrite any current values.
762 .TP
763 \fB\-format\fR \fIformat\fR
764 Specifies the format of the data.  \fIFormat\fR can be one of the
765 following: "i1", "i2", "i4", "i8", "u1, "u2", "u4", "u8", "r4",
766 "r8", or "r16".  The number indicates the number of bytes
767 required for each value.  The letter indicates the type: "i" for signed,
768 "u" for unsigned, "r" or real.  The default format is "r16".
769 .RE
770 .TP
771 \fIvecName \fBclear\fR 
772 Clears the element indices from the array variable associated with
773 \fIvecName\fR.  This doesn't affect the components of the vector.  By
774 default, the number of entries in the Tcl array doesn't match the
775 number of components in the vector.  This is because its too expensive
776 to maintain decimal strings for both the index and value for each
777 component.  Instead, the index and value are saved only when you read
778 or write an element with a new index.  This command removes the index
779 and value strings from the array.  This is useful when the vector is
780 large.
781 .TP
782 \fIvecName \fBdelete\fR \fIindex\fR ?\fIindex\fR?...
783 Deletes the \fIindex\fRth component from the vector \fIvecName\fR.
784 \fIIndex\fR is the index of the element to be deleted.  This is the
785 same as unsetting the array variable element \fIindex\fR.  The vector
786 is compacted after all the indices have been deleted.
787 .TP
788 \fIvecName \fBdup\fR \fIdestName\fR 
789 Copies \fIvecName\fR to \fIdestName\fR. \fIDestName\fR is the name of a
790 destination vector.  If a vector \fIdestName\fR already exists, it is
791 overwritten with the components of \fIvecName\fR.  Otherwise a 
792 new vector is created.
793 .TP
794 \fIvecName \fBexpr\fR \fIexpression\fR
795 Computes the expression and resets the values of the vector accordingly.
796 Both scalar and vector math operations are allowed.  All values in
797 expressions are either real numbers or names of vectors.  All numbers
798 are treated as one component vectors.
799 .TP
800 \fIvecName \fBlength\fR ?\fInewSize\fR?
801 Queries or resets the number of components in \fIvecName\fR.
802 \fINewSize\fR is a number specifying the new size of the vector.  If
803 \fInewSize\fR is smaller than the current size of \fIvecName\fR,
804 \fIvecName\fR is truncated.  If \fInewSize\fR is greater, the vector
805 is extended and the new components are initialized to \f(CW0.0\fR.  If
806 no \fInewSize\fR argument is present, the current length of the vector
807 is returned.
808 .TP
809 \fIvecName \fBmerge\fR \fIsrcName\fR ?\fIsrcName\fR?...
810 Merges the named vectors into a single vector.  The resulting 
811 vector is formed by merging the components of each source vector 
812 one index at a time.
813 .TP
814 \fIvecName \fBnotify\fR \fIkeyword\fR
815 Controls how vector clients are notified of changes to the vector.  
816 The exact behavior is determined by \fIkeyword\fR.
817 .RS
818 .TP 0.75i
819 \f(CWalways\fR 
820 Indicates that clients are to be notified immediately whenever the
821 vector is updated.
822 .TP
823 \f(CWnever\fR
824 Indicates that no clients are to be notified.
825 .TP
826 \f(CWwhenidle\fR
827 Indicates that clients are to be notified at the next idle point
828 whenever the vector is updated.
829 .TP
830 \f(CWnow\fR
831 If any client notifications is currently pending, they are notified
832 immediately.
833 .TP
834 \f(CWcancel\fR
835 Cancels pending notifications of clients using the vector.
836 .TP
837 \f(CWpending\fR
838 Returns \f(CW1\fR if a client notification is pending, and \f(CW0\fR otherwise.
839 .RE
840 .TP
841 \fIvecName \fBoffset\fR ?\fIvalue\fR?
842 Shifts the indices of the vector by the amount specified by \fIvalue\fR.
843 \fIValue\fR is an integer number.  If no \fIvalue\fR argument is 
844 given, the current offset is returned.
845 .TP
846 \fIvecName \fBpopulate\fR \fIdestName\fR ?\fIdensity\fR?
847 Creates a vector \fIdestName\fR which is a superset of \fIvecName\fR.
848 \fIDestName\fR will include all the components of \fIvecName\fR, in
849 addition the interval between each of the original components will
850 contain a \fIdensity\fR number of new components, whose values are
851 evenly distributed between the original components values.  This is
852 useful for generating abscissas to be interpolated along a spline.
853 .TP
854 \fIvecName \fBrange\fR \fIfirstIndex\fR ?\fIlastIndex\fR?...
855 Returns a list of numeric values representing the vector components
856 between two indices. Both \fIfirstIndex\fR and \fIlastIndex\fR are 
857 indices representing the range of components to be returned. If 
858 \fIlastIndex\fR is less than \fIfirstIndex\fR, the components are
859 listed in reverse order.
860 .TP
861 \fIvecName \fBsearch\fR \fIvalue\fR ?\fIvalue\fR?  
862 Searches for a value or range of values among the components of
863 \fIvecName\fR.  If one \fIvalue\fR argument is given, a list of
864 indices of the components which equal \fIvalue\fR is returned.  If a
865 second \fIvalue\fR is also provided, then the indices of all
866 components which lie within the range of the two values are returned.
867 If no components are found, then \f(CW""\fR is returned.
868 .TP
869 \fIvecName \fBset\fR \fIitem\fR
870 Resets the components of the vector to \fIitem\fR. \fIItem\fR can
871 be either a list of numeric expressions or another vector.
872 .TP
873 \fIvecName \fBseq\fR \fIstart\fR ?\fIfinish\fR? ?\fIstep\fR?
874 Generates a sequence of values starting with the value \fIstart\fR.
875 \fIFinish\fR indicates the terminating value of the sequence.  
876 The vector is automatically resized to contain just the sequence.
877 If three arguments are present, \fIstep\fR designates the interval.  
878 .sp
879 With only two arguments (no \fIfinish\fR argument), the sequence will
880 continue until the vector is filled.  With one argument, the interval 
881 defaults to 1.0.
882 .TP
883 \fIvecName \fBsort\fR ?\fB-reverse\fR? ?\fIargName\fR?...  
884 Sorts the vector \fIvecName\fR in increasing order.  If the
885 \fB-reverse\fR flag is present, the vector is sorted in decreasing
886 order.  If other arguments \fIargName\fR are present, they are the
887 names of vectors which will be rearranged in the same manner as
888 \fIvecName\fR.  Each vector must be the same length as \fIvecName\fR.
889 You could use this to sort the x vector of a graph, while still
890 retaining the same x,y coordinate pairs in a y vector.
891 .TP
892 \fIvecName \fBvariable\fR \fIvarName\fR
893 Maps a Tcl variable to the vector, creating another means for 
894 accessing the vector.  The variable \fIvarName\fR can't already 
895 exist. This overrides any current variable mapping the vector
896 may have.
897 .RE
898 .SH C LANGUAGE API
899 You can create, modify, and destroy vectors from C code, using 
900 library routines.  
901 You need to include the header file \f(CWblt.h\fR. It contains the
902 definition of the structure \fBBlt_Vector\fR, which represents the
903 vector.  It appears below.
904 .CS
905 \fRtypedef struct {
906     double *\fIvalueArr\fR; 
907     int \fInumValues\fR;    
908     int \fIarraySize\fR;    
909     double \fImin\fR, \fImax\fR;  
910 } \fBBlt_Vector\fR;
911 .CE
912 The field \fIvalueArr\fR points to memory holding the vector
913 components.  The components are stored in a double precision array,
914 whose size size is represented by \fIarraySize\fR.  \fINumValues\fR is
915 the length of vector.  The size of the array is always equal to or
916 larger than the length of the vector.  \fIMin\fR and \fImax\fR are
917 minimum and maximum component values.
918 .SH LIBRARY ROUTINES
919 The following routines are available from C to manage vectors.
920 Vectors are identified by the vector name.
921 .PP
922 \fBBlt_CreateVector\fR 
923 .RS .25i
924 .TP 1i
925 Synopsis:
926 .CS 
927 int \fBBlt_CreateVector\fR (\fIinterp\fR, \fIvecName\fR, \fIlength\fR, \fIvecPtrPtr\fR)
928 .RS 1.25i
929 Tcl_Interp *\fIinterp\fR;
930 char *\fIvecName\fR;
931 int \fIlength\fR;
932 Blt_Vector **\fIvecPtrPtr\fR;
933 .RE
934 .CE
935 .TP
936 Description:
937 Creates a new vector \fIvecName\fR\fR with a length of \fIlength\fR.
938 \fBBlt_CreateVector\fR creates both a new Tcl command and array 
939 variable \fIvecName\fR.  Neither a command nor variable named 
940 \fIvecName\fR can already exist.  A pointer to the vector is 
941 placed into \fIvecPtrPtr\fR.
942 .TP
943 Results:
944 Returns \f(CWTCL_OK\fR if the vector is successfully created.  If
945 \fIlength\fR is negative, a Tcl variable or command \fIvecName\fR
946 already exists, or memory cannot be allocated for the vector, then
947 \f(CWTCL_ERROR\fR is returned and \fIinterp->result\fR will contain an
948 error message.
949 .RE
950 .sp
951 .PP
952 \fBBlt_DeleteVectorByName\fR 
953 .RS .25i
954 .TP 1i
955 Synopsis:
956 .CS
957 int \fBBlt_DeleteVectorByName\fR (\fIinterp\fR, \fIvecName\fR)
958 .RS 1.25i
959 Tcl_Interp *\fIinterp\fR;
960 char *\fIvecName\fR;
961 .RE
962 .CE
963 .TP 1i
964 Description:
965 Removes the vector \fIvecName\fR.  \fIVecName\fR is the name of a vector
966 which must already exist.  Both the Tcl command and array variable
967 \fIvecName\fR are destroyed.  All clients of the vector will be notified
968 immediately that the vector has been destroyed.
969 .TP
970 Results:
971 Returns \f(CWTCL_OK\fR if the vector is successfully deleted.  If
972 \fIvecName\fR is not the name a vector, then \f(CWTCL_ERROR\fR is returned
973 and \fIinterp->result\fR will contain an error message.
974 .RE
975 .sp
976 .PP
977 \fBBlt_DeleteVector\fR 
978 .RS .25i
979 .TP 1i
980 Synopsis:
981 .CS
982 int \fBBlt_DeleteVector\fR (\fIvecPtr\fR)
983 .RS 1.25i
984 Blt_Vector *\fIvecPtr\fR;
985 .RE
986 .CE
987 .TP 1i
988 Description:
989 Removes the vector pointed to by \fIvecPtr\fR.  \fIVecPtr\fR is a
990 pointer to a vector, typically set by \fBBlt_GetVector\fR or
991 \fBBlt_CreateVector\fR.  Both the Tcl command and array variable of
992 the vector are destroyed.  All clients of the vector will be notified
993 immediately that the vector has been destroyed.
994 .TP
995 Results:
996 Returns \f(CWTCL_OK\fR if the vector is successfully deleted.  If
997 \fIvecName\fR is not the name a vector, then \f(CWTCL_ERROR\fR is returned
998 and \fIinterp->result\fR will contain an error message.
999 .RE
1000 .sp
1001 .PP
1002 \fBBlt_GetVector\fR 
1003 .RS .25i
1004 .TP 1i
1005 Synopsis:
1006 .CS
1007 int \fBBlt_GetVector\fR (\fIinterp\fR, \fIvecName\fR, \fIvecPtrPtr\fR)
1008 .RS 1.25i
1009 Tcl_Interp *\fIinterp\fR;
1010 char *\fIvecName\fR;
1011 Blt_Vector **\fIvecPtrPtr\fR;
1012 .RE
1013 .CE
1014 .TP 1i
1015 Description:
1016 Retrieves the vector \fIvecName\fR.  \fIVecName\fR is the name of a
1017 vector which must already exist.  \fIVecPtrPtr\fR will point be set to
1018 the address of the vector.
1019 .TP
1020 Results:
1021 Returns \f(CWTCL_OK\fR if the vector is successfully retrieved.  If
1022 \fIvecName\fR is not the name of a vector, then \f(CWTCL_ERROR\fR is
1023 returned and \fIinterp->result\fR will contain an error message.
1024 .RE
1025 .sp
1026 .PP
1027 \fBBlt_ResetVector\fR 
1028 .PP
1029 .RS .25i
1030 .TP 1i
1031 Synopsis:
1032 .CS
1033 int \fBBlt_ResetVector\fR (\fIvecPtr\fR, \fIdataArr\fR, 
1034         \fInumValues\fR, \fIarraySize\fR, \fIfreeProc\fR)
1035 .RS 1.25i
1036 Blt_Vector *\fIvecPtr\fR;
1037 double *\fIdataArr\fR;
1038 int *\fInumValues\fR;
1039 int *\fIarraySize\fR;
1040 Tcl_FreeProc *\fIfreeProc\fR;
1041 .RE
1042 .CE
1043 .TP
1044 Description: 
1045 Resets the components of the vector pointed to by \fIvecPtr\fR.
1046 Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
1047 notifications to its clients. \fIDataArr\fR is the array of doubles
1048 which represents the vector data. \fINumValues\fR is the number of
1049 elements in the array. \fIArraySize\fR is the actual size of the array
1050 (the array may be bigger than the number of values stored in
1051 it). \fIFreeProc\fP indicates how the storage for the vector component
1052 array (\fIdataArr\fR) was allocated.  It is used to determine how to
1053 reallocate memory when the vector is resized or destroyed.  It must be
1054 \f(CWTCL_DYNAMIC\fR, \f(CWTCL_STATIC\fR, \f(CWTCL_VOLATILE\fR, or a pointer
1055 to a function to free the memory allocated for the vector array. If
1056 \fIfreeProc\fR is \f(CWTCL_VOLATILE\fR, it indicates that \fIdataArr\fR
1057 must be copied and saved.  If \fIfreeProc\fR is \f(CWTCL_DYNAMIC\fR, it
1058 indicates that \fIdataArr\fR was dynamically allocated and that Tcl
1059 should free \fIdataArr\fR if necessary.  \f(CWStatic\fR indicates that
1060 nothing should be done to release storage for \fIdataArr\fR.
1061 .TP
1062 Results:
1063 Returns \f(CWTCL_OK\fR if the vector is successfully resized.  If
1064 \fInewSize\fR is negative, a vector \fIvecName\fR does not exist, or
1065 memory cannot be allocated for the vector, then \f(CWTCL_ERROR\fR is
1066 returned and \fIinterp->result\fR will contain an error message.
1067 .RE
1068 .sp
1069 .PP
1070 \fBBlt_ResizeVector\fR 
1071 .RS .25i
1072 .TP 1i
1073 Synopsis:
1074 .CS
1075 int \fBBlt_ResizeVector\fR (\fIvecPtr\fR, \fInewSize\fR)
1076 .RS 1.25i
1077 Blt_Vector *\fIvecPtr\fR;
1078 int \fInewSize\fR;
1079 .RE
1080 .CE
1081 .TP
1082 Description:
1083 Resets the length of the vector pointed to by \fIvecPtr\fR to
1084 \fInewSize\fR.  If \fInewSize\fR is smaller than the current size of
1085 the vector, it is truncated.  If \fInewSize\fR is greater, the vector
1086 is extended and the new components are initialized to \f(CW0.0\fR.
1087 Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
1088 notifications.
1089 .TP
1090 Results:
1091 Returns \f(CWTCL_OK\fR if the vector is successfully resized.  If
1092 \fInewSize\fR is negative or memory can not be allocated for the vector, 
1093 then \f(CWTCL_ERROR\fR is returned and \fIinterp->result\fR will contain 
1094 an error message.
1095 .sp
1096 .PP
1097 \fBBlt_VectorExists\fR 
1098 .RS .25i
1099 .TP 1i
1100 Synopsis:
1101 .CS
1102 int \fBBlt_VectorExists\fR (\fIinterp\fR, \fIvecName\fR)
1103 .RS 1.25i
1104 Tcl_Interp *\fIinterp\fR;
1105 char *\fIvecName\fR;
1106 .RE
1107 .CE
1108 .TP
1109 Description:
1110 Indicates if a vector named \fIvecName\fR exists in \fIinterp\fR.
1111 .TP
1112 Results:
1113 Returns \f(CW1\fR if a vector \fIvecName\fR exists and \f(CW0\fR otherwise.
1114 .RE
1115 .sp
1116 .PP
1117 If your application needs to be notified when a vector changes, it can
1118 allocate a unique \fIclient identifier\fR for itself.  Using this
1119 identifier, you can then register a call-back to be made whenever the
1120 vector is updated or destroyed.  By default, the call-backs are made at
1121 the next idle point.  This can be changed to occur at the time the
1122 vector is modified.  An application can allocate more than one
1123 identifier for any vector.  When the client application is done with
1124 the vector, it should free the identifier.
1125 .PP
1126 The call-back routine must of the following type.
1127 .CS
1128 .RS
1129 .sp
1130 typedef void (\fBBlt_VectorChangedProc\fR) (Tcl_Interp *\fIinterp\fR, 
1131 .RS .25i
1132 ClientData \fIclientData\fR, Blt_VectorNotify \fInotify\fR);
1133 .RE
1134 .sp
1135 .RE
1136 .CE
1137 .fi
1138 \fIClientData\fR is passed to this routine whenever it is called.  You
1139 can use this to pass information to the call-back.  The \fInotify\fR 
1140 argument indicates whether the vector has been updated of destroyed. It
1141 is an enumerated type.
1142 .CS
1143 .RS
1144 .sp
1145 typedef enum {
1146     \f(CWBLT_VECTOR_NOTIFY_UPDATE\fR=1,
1147     \f(CWBLT_VECTOR_NOTIFY_DESTROY\fR=2
1148 } \fBBlt_VectorNotify\fR;
1149 .sp
1150 .RE
1151 .CE
1152 .PP
1153 \fBBlt_AllocVectorId\fR
1154 .RS .25i
1155 .TP 1i
1156 Synopsis:
1157 .CS
1158 Blt_VectorId \fBBlt_AllocVectorId\fR (\fIinterp\fR, \fIvecName\fR)
1159 .RS 1.25i
1160 Tcl_Interp *\fIinterp\fR;
1161 char *\fIvecName\fR;
1162 .RE
1163 .CE
1164 .TP
1165 Description:
1166 Allocates an client identifier for with the vector \fIvecName\fR.
1167 This identifier can be used to specify a call-back which is triggered
1168 when the vector is updated or destroyed.
1169 .TP
1170 Results:
1171 Returns a client identifier if successful.  If \fIvecName\fR is not
1172 the name of a vector, then \f(CWNULL\fR is returned and
1173 \fIinterp->result\fR will contain an error message.
1174 .RE
1175 .sp
1176 .PP
1177 \fBBlt_GetVectorById\fR 
1178 .RS .25i
1179 .TP 1i
1180 Synopsis:
1181 .CS
1182 int \fBBlt_GetVector\fR (\fIinterp\fR, \fIclientId\fR, \fIvecPtrPtr\fR)
1183 .RS 1.25i
1184 Tcl_Interp *\fIinterp\fR;
1185 Blt_VectorId \fIclientId\fR;
1186 Blt_Vector **\fIvecPtrPtr\fR;
1187 .RE
1188 .CE
1189 .TP 1i
1190 Description:
1191 Retrieves the vector used by \fIclientId\fR.  \fIClientId\fR is a valid
1192 vector client identifier allocated by \fBBlt_AllocVectorId\fR.
1193 \fIVecPtrPtr\fR will point be set to the address of the vector.
1194 .TP
1195 Results:
1196 Returns \f(CWTCL_OK\fR if the vector is successfully retrieved.  
1197 .RE
1198 .sp
1199 .PP
1200 \fBBlt_SetVectorChangedProc\fR
1201 .RS .25i
1202 .TP 1i
1203 Synopsis:
1204 .CS
1205 void \fBBlt_SetVectorChangedProc\fR (\fIclientId\fR, \fIproc\fR, \fIclientData\fR);
1206 .RS 1.25i
1207 Blt_VectorId \fIclientId\fR;
1208 Blt_VectorChangedProc *\fIproc\fR;
1209 ClientData *\fIclientData\fR;
1210 .RE
1211 .CE
1212 .TP
1213 Description: 
1214 Specifies a call-back routine to be called whenever the vector
1215 associated with \fIclientId\fR is updated or deleted.  \fIProc\fR is a
1216 pointer to call-back routine and must be of the type
1217 \fBBlt_VectorChangedProc\fR.  \fIClientData\fR is a one-word value to
1218 be passed to the routine when it is invoked. If \fIproc\fR is
1219 \f(CWNULL\fR, then the client is not notified.
1220 .TP
1221 Results:
1222 The designated call-back procedure will be invoked when the vector is 
1223 updated or destroyed.
1224 .RE
1225 .sp
1226 .PP
1227 \fBBlt_FreeVectorId\fR
1228 .RS .25i
1229 .TP 1i
1230 Synopsis:
1231 .CS
1232 void \fBBlt_FreeVectorId\fR (\fIclientId\fR);
1233 .RS 1.25i
1234 Blt_VectorId \fIclientId\fR;
1235 .RE
1236 .CE
1237 .TP
1238 Description: 
1239 Frees the client identifier.  Memory allocated for the identifier 
1240 is released.  The client will no longer be notified when the
1241 vector is modified.
1242 .TP
1243 Results:
1244 The designated call-back procedure will be no longer be invoked when
1245 the vector is updated or destroyed.
1246 .RE
1247 .sp
1248 .PP
1249 \fBBlt_NameOfVectorId\fR
1250 .RS .25i
1251 .TP 1i
1252 Synopsis:
1253 .CS
1254 char *\fBBlt_NameOfVectorId\fR (\fIclientId\fR);
1255 .RS 1.25i
1256 Blt_VectorId \fIclientId\fR;
1257 .RE
1258 .CE
1259 .TP
1260 Description: 
1261 Retrieves the name of the vector associated with the client identifier
1262 \fIclientId\fR.  
1263 .TP
1264 Results:
1265 Returns the name of the vector associated with \fIclientId\fR.  If
1266 \fIclientId\fR is not an identifier or the vector has been destroyed, 
1267 \f(CWNULL\fR is returned.
1268 .RE
1269 .sp
1270 .PP
1271 \fBBlt_InstallIndexProc\fR
1272 .RS .25i
1273 .TP 1i
1274 Synopsis:
1275 .CS
1276 void \fBBlt_InstallIndexProc\fR (\fIindexName\fR, \fIprocPtr\fR)
1277 .RS 1.25i
1278 char *\fIindexName\fR;
1279 Blt_VectorIndexProc *\fIprocPtr\fR;
1280 .RE
1281 .CE
1282 .TP
1283 Description: 
1284 Registers a function to be called to retrieved the index \fIindexName\fR
1285 from the vector's array variable.  
1286 .sp
1287 typedef double Blt_VectorIndexProc(Vector *vecPtr);
1288 .sp
1289 The function will be passed a pointer to the vector.  The function must
1290 return a double representing the value at the index.
1291 .TP
1292 Results:
1293 The new index is installed into the vector.
1294 .RE
1295 .RE
1296 .SH C API EXAMPLE
1297 The following example opens a file of binary data and stores it in an
1298 array of doubles. The array size is computed from the size of the
1299 file. If the vector "data" exists, calling \fBBlt_VectorExists\fR,
1300 \fBBlt_GetVector\fR is called to get the pointer to the vector.
1301 Otherwise the routine \fBBlt_CreateVector\fR is called to create a new
1302 vector and returns a pointer to it. Just like the Tcl interface, both
1303 a new Tcl command and array variable are created when a new vector is
1304 created. It doesn't make any difference what the initial size of the
1305 vector is since it will be reset shortly. The vector is updated when
1306 \fBlt_ResetVector\fR is called.  Blt_ResetVector makes the changes
1307 visible to the Tcl interface and other vector clients (such as a graph
1308 widget).
1309 .sp
1310 .CS
1311 #include <tcl.h>
1312 #include <blt.h>                                
1313 ...
1314 Blt_Vector *vecPtr;
1315 double *newArr;
1316 FILE *f;
1317 struct stat statBuf;
1318 int numBytes, numValues;
1319
1320 f = fopen("binary.dat", "r");
1321 fstat(fileno(f), &statBuf);
1322 numBytes = (int)statBuf.st_size;
1323
1324 /* Allocate an array big enough to hold all the data */
1325 newArr = (double *)malloc(numBytes);
1326 numValues = numBytes / sizeof(double);
1327 fread((void *)newArr, numValues, sizeof(double), f);
1328 fclose(f);
1329
1330 if (Blt_VectorExists(interp, "data"))  {
1331     if (Blt_GetVector(interp, "data", &vecPtr) != TCL_OK) {
1332         return TCL_ERROR;
1333     }
1334 } else {
1335    if (Blt_CreateVector(interp, "data", 0, &vecPtr) != TCL_OK) {
1336         return TCL_ERROR;
1337    }
1338 }
1339 /* 
1340  * Reset the vector. Clients will be notified when Tk is idle. 
1341  * TCL_DYNAMIC tells the vector to free the memory allocated 
1342  * if it needs to reallocate or destroy the vector.
1343  */
1344 if (Blt_ResetVector(vecPtr, newArr, numValues, numValues, 
1345         TCL_DYNAMIC) != TCL_OK) {
1346     return TCL_ERROR;
1347 }
1348 .CE
1349 .SH "INCOMPATIBILITIES"
1350 In previous versions, if the array variable isn't global 
1351 (i.e. local to a Tcl procedure), the vector is automatically 
1352 destroyed when the procedure returns.
1353 .CS
1354 proc doit {} {
1355     # Temporary vector x
1356     vector x(10)
1357     set x(9) 2.0
1358       ...
1359 }
1360 .CE
1361 .PP
1362 This has changed.  Variables are not automatically destroyed when
1363 their variable is unset.  You can restore the old behavior by
1364 setting the "-watchunset" switch.
1365 .CE
1366 .SH KEYWORDS
1367 vector, graph, widget