File: Blt_Vector.man3

package info (click to toggle)
blt 2.5.3%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 24,980 kB
  • sloc: ansic: 133,725; tcl: 17,680; sh: 2,722; makefile: 813; cpp: 370
file content (500 lines) | stat: -rw-r--r-- 14,652 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
'\"
'\" Copyright 1991-1997 by Lucent Technologies, Inc.
'\"
'\" Permission to use, copy, modify, and distribute this software and its
'\" documentation for any purpose and without fee is hereby granted, provided
'\" that the above copyright notice appear in all copies and that both that the
'\" copyright notice and warranty disclaimer appear in supporting documentation,
'\" and that the names of Lucent Technologies any of their entities not be used
'\" in advertising or publicity pertaining to distribution of the software
'\" without specific, written prior permission.
'\"
'\" Lucent Technologies disclaims all warranties with regard to this software,
'\" including all implied warranties of merchantability and fitness.  In no event
'\" shall Lucent Technologies be liable for any special, indirect or
'\" consequential damages or any damages whatsoever resulting from loss of use,
'\" data or profits, whether in an action of contract, negligence or other
'\" tortuous action, arising out of or in connection with the use or performance
'\" of this software.  
'\"
'\" Vector command created by George Howlett.
'\"
.so man.macros
.TH Blt_Vector 3 BLT_VERSION BLT "Blt Library Procedures"
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
Blt_Vector \- Vector data object.

.SH C LANGUAGE API
You can create, modify, and destroy vectors from C code, using 
library routines.  
You need to include the header file \fBblt.h\fR. It contains the
definition of the structure \fBBlt_Vector\fR, which represents the
vector.  It appears below.
.sp
.CS
\fRtypedef struct {
    double *\fIvalueArr\fR; 
    int \fInumValues\fR;    
    int \fIarraySize\fR;    
    double \fImin\fR, \fImax\fR;  
} \fBBlt_Vector\fR;
.CE
.sp
The field \fIvalueArr\fR points to memory holding the vector
components.  The components are stored in a double precision array,
whose size size is represented by \fIarraySize\fR.  \fINumValues\fR is
the length of vector.  The size of the array is always equal to or
larger than the length of the vector.  \fIMin\fR and \fImax\fR are
minimum and maximum component values.
.SH LIBRARY ROUTINES
The following routines are available from C to manage vectors.
Vectors are identified by the vector name.
.PP
\fBBlt_CreateVector\fR 
.RS .25i
.TP 1i
Synopsis:
.CS 
int \fBBlt_CreateVector\fR (\fIinterp\fR, \fIvecName\fR, \fIlength\fR, \fIvecPtrPtr\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
int \fIlength\fR;
Blt_Vector **\fIvecPtrPtr\fR;
.RE
.CE
.TP
Description:
Creates a new vector \fIvecName\fR\fR with a length of \fIlength\fR.
\fBBlt_CreateVector\fR creates both a new Tcl command and array 
variable \fIvecName\fR.  Neither a command nor variable named 
\fIvecName\fR can already exist.  A pointer to the vector is 
placed into \fIvecPtrPtr\fR.
.TP
Results:
Returns \fBTCL_OK\fR if the vector is successfully created.  If
\fIlength\fR is negative, a Tcl variable or command \fIvecName\fR
already exists, or memory cannot be allocated for the vector, then
\fBTCL_ERROR\fR is returned and \fIinterp->result\fR will contain an
error message.
.RE
.sp
.PP
\fBBlt_DeleteVectorByName\fR 
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_DeleteVectorByName\fR (\fIinterp\fR, \fIvecName\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
.RE
.CE
.TP 1i
Description:
Removes the vector \fIvecName\fR.  \fIVecName\fR is the name of a vector
which must already exist.  Both the Tcl command and array variable
\fIvecName\fR are destroyed.  All clients of the vector will be notified
immediately that the vector has been destroyed.
.TP
Results:
Returns \fBTCL_OK\fR if the vector is successfully deleted.  If
\fIvecName\fR is not the name a vector, then \fBTCL_ERROR\fR is returned
and \fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_DeleteVector\fR 
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_DeleteVector\fR (\fIvecPtr\fR)
.RS 1.25i
Blt_Vector *\fIvecPtr\fR;
.RE
.CE
.TP 1i
Description:
Removes the vector pointed to by \fIvecPtr\fR.  \fIVecPtr\fR is a
pointer to a vector, typically set by \fBBlt_GetVector\fR or
\fBBlt_CreateVector\fR.  Both the Tcl command and array variable of
the vector are destroyed.  All clients of the vector will be notified
immediately that the vector has been destroyed.
.TP
Results:
Returns \fBTCL_OK\fR if the vector is successfully deleted.  If
\fIvecName\fR is not the name a vector, then \fBTCL_ERROR\fR is returned
and \fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_GetVector\fR 
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_GetVector\fR (\fIinterp\fR, \fIvecName\fR, \fIvecPtrPtr\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
Blt_Vector **\fIvecPtrPtr\fR;
.RE
.CE
.TP 1i
Description:
Retrieves the vector \fIvecName\fR.  \fIVecName\fR is the name of a
vector which must already exist.  \fIVecPtrPtr\fR will point be set to
the address of the vector.
.TP
Results:
Returns \fBTCL_OK\fR if the vector is successfully retrieved.  If
\fIvecName\fR is not the name of a vector, then \fBTCL_ERROR\fR is
returned and \fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_ResetVector\fR 
.PP
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_ResetVector\fR (\fIvecPtr\fR, \fIdataArr\fR, 
	\fInumValues\fR, \fIarraySize\fR, \fIfreeProc\fR)
.RS 1.25i
Blt_Vector *\fIvecPtr\fR;
double *\fIdataArr\fR;
int *\fInumValues\fR;
int *\fIarraySize\fR;
Tcl_FreeProc *\fIfreeProc\fR;
.RE
.CE
.TP
Description: 
Resets the components of the vector pointed to by \fIvecPtr\fR.
Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
notifications to its clients. \fIDataArr\fR is the array of doubles
which represents the vector data. \fINumValues\fR is the number of
elements in the array. \fIArraySize\fR is the actual size of the array
(the array may be bigger than the number of values stored in
it). \fIFreeProc\fP indicates how the storage for the vector component
array (\fIdataArr\fR) was allocated.  It is used to determine how to
reallocate memory when the vector is resized or destroyed.  It must be
\fBTCL_DYNAMIC\fR, \fBTCL_STATIC\fR, \fBTCL_VOLATILE\fR, or a pointer
to a function to free the memory allocated for the vector array. If
\fIfreeProc\fR is \fBTCL_VOLATILE\fR, it indicates that \fIdataArr\fR
must be copied and saved.  If \fIfreeProc\fR is \fBTCL_DYNAMIC\fR, it
indicates that \fIdataArr\fR was dynamically allocated and that Tcl
should free \fIdataArr\fR if necessary.  \fBStatic\fR indicates that
nothing should be done to release storage for \fIdataArr\fR.
.TP
Results:
Returns \fBTCL_OK\fR if the vector is successfully resized.  If
\fInewSize\fR is negative, a vector \fIvecName\fR does not exist, or
memory cannot be allocated for the vector, then \fBTCL_ERROR\fR is
returned and \fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_ResizeVector\fR 
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_ResizeVector\fR (\fIvecPtr\fR, \fInewSize\fR)
.RS 1.25i
Blt_Vector *\fIvecPtr\fR;
int \fInewSize\fR;
.RE
.CE
.TP
Description:
Resets the length of the vector pointed to by \fIvecPtr\fR to
\fInewSize\fR.  If \fInewSize\fR is smaller than the current size of
the vector, it is truncated.  If \fInewSize\fR is greater, the vector
is extended and the new components are initialized to \fB0.0\fR.
Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
notifications.
.TP
Results:
Returns \fBTCL_OK\fR if the vector is successfully resized.  If
\fInewSize\fR is negative or memory can not be allocated for the vector, 
then \fBTCL_ERROR\fR is returned and \fIinterp->result\fR will contain 
an error message.
.sp
.PP
\fBBlt_VectorExists\fR 
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_VectorExists\fR (\fIinterp\fR, \fIvecName\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
.RE
.CE
.TP
Description:
Indicates if a vector named \fIvecName\fR exists in \fIinterp\fR.
.TP
Results:
Returns \fB1\fR if a vector \fIvecName\fR exists and \fB0\fR otherwise.
.RE
.sp
.PP
If your application needs to be notified when a vector changes, it can
allocate a unique \fIclient identifier\fR for itself.  Using this
identifier, you can then register a call-back to be made whenever the
vector is updated or destroyed.  By default, the call-backs are made at
the next idle point.  This can be changed to occur at the time the
vector is modified.  An application can allocate more than one
identifier for any vector.  When the client application is done with
the vector, it should free the identifier.
.PP
The call-back routine must of the following type.
.CS
.RS
.sp
typedef void (\fBBlt_VectorChangedProc\fR) (Tcl_Interp *\fIinterp\fR, 
.RS .25i
ClientData \fIclientData\fR, Blt_VectorNotify \fInotify\fR);
.RE
.sp
.RE
.CE
.fi
\fIClientData\fR is passed to this routine whenever it is called.  You
can use this to pass information to the call-back.  The \fInotify\fR 
argument indicates whether the vector has been updated of destroyed. It
is an enumerated type.
.CS
.RS
.sp
typedef enum {
    \fBBLT_VECTOR_NOTIFY_UPDATE\fR=1,
    \fBBLT_VECTOR_NOTIFY_DESTROY\fR=2
} \fBBlt_VectorNotify\fR;
.sp
.RE
.CE
.PP
\fBBlt_AllocVectorId\fR
.RS .25i
.TP 1i
Synopsis:
.CS
Blt_VectorId \fBBlt_AllocVectorId\fR (\fIinterp\fR, \fIvecName\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
.RE
.CE
.TP
Description:
Allocates an client identifier for with the vector \fIvecName\fR.
This identifier can be used to specify a call-back which is triggered
when the vector is updated or destroyed.
.TP
Results:
Returns a client identifier if successful.  If \fIvecName\fR is not
the name of a vector, then \fBNULL\fR is returned and
\fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_GetVectorById\fR 
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_GetVector\fR (\fIinterp\fR, \fIclientId\fR, \fIvecPtrPtr\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
Blt_VectorId \fIclientId\fR;
Blt_Vector **\fIvecPtrPtr\fR;
.RE
.CE
.TP 1i
Description:
Retrieves the vector used by \fIclientId\fR.  \fIClientId\fR is a valid
vector client identifier allocated by \fBBlt_AllocVectorId\fR.
\fIVecPtrPtr\fR will point be set to the address of the vector.
.TP
Results:
Returns \fBTCL_OK\fR if the vector is successfully retrieved.  
.RE
.sp
.PP
\fBBlt_SetVectorChangedProc\fR
.RS .25i
.TP 1i
Synopsis:
.CS
void \fBBlt_SetVectorChangedProc\fR (\fIclientId\fR, \fIproc\fR, \fIclientData\fR);
.RS 1.25i
Blt_VectorId \fIclientId\fR;
Blt_VectorChangedProc *\fIproc\fR;
ClientData *\fIclientData\fR;
.RE
.CE
.TP
Description: 
Specifies a call-back routine to be called whenever the vector
associated with \fIclientId\fR is updated or deleted.  \fIProc\fR is a
pointer to call-back routine and must be of the type
\fBBlt_VectorChangedProc\fR.  \fIClientData\fR is a one-word value to
be passed to the routine when it is invoked. If \fIproc\fR is
\fBNULL\fR, then the client is not notified.
.TP
Results:
The designated call-back procedure will be invoked when the vector is 
updated or destroyed.
.RE
.sp
.PP
\fBBlt_FreeVectorId\fR
.RS .25i
.TP 1i
Synopsis:
.CS
void \fBBlt_FreeVectorId\fR (\fIclientId\fR);
.RS 1.25i
Blt_VectorId \fIclientId\fR;
.RE
.CE
.TP
Description: 
Frees the client identifier.  Memory allocated for the identifier 
is released.  The client will no longer be notified when the
vector is modified.
.TP
Results:
The designated call-back procedure will be no longer be invoked when
the vector is updated or destroyed.
.RE
.sp
.PP
\fBBlt_NameOfVectorId\fR
.RS .25i
.TP 1i
Synopsis:
.CS
char *\fBBlt_NameOfVectorId\fR (\fIclientId\fR);
.RS 1.25i
Blt_VectorId \fIclientId\fR;
.RE
.CE
.TP
Description: 
Retrieves the name of the vector associated with the client identifier
\fIclientId\fR.  
.TP
Results:
Returns the name of the vector associated with \fIclientId\fR.  If
\fIclientId\fR is not an identifier or the vector has been destroyed, 
\fBNULL\fR is returned.
.RE
.sp
.PP
\fBBlt_InstallIndexProc\fR
.RS .25i
.TP 1i
Synopsis:
.CS
void \fBBlt_InstallIndexProc\fR (\fIindexName\fR, \fIprocPtr\fR)
.RS 1.25i
char *\fIindexName\fR;
Blt_VectorIndexProc *\fIprocPtr\fR;
.RE
.CE
.TP
Description: 
Registers a function to be called to retrieved the index \fIindexName\fR
from the vector's array variable.  
.sp
typedef double Blt_VectorIndexProc(Vector *vecPtr);
.sp
The function will be passed a pointer to the vector.  The function must
return a double representing the value at the index.
.TP
Results:
The new index is installed into the vector.
.RE
.RE
.SH C API EXAMPLE
The following example opens a file of binary data and stores it in an
array of doubles. The array size is computed from the size of the
file. If the vector "data" exists, calling \fBBlt_VectorExists\fR,
\fBBlt_GetVector\fR is called to get the pointer to the vector.
Otherwise the routine \fBBlt_CreateVector\fR is called to create a new
vector and returns a pointer to it. Just like the Tcl interface, both
a new Tcl command and array variable are created when a new vector is
created. It doesn't make any difference what the initial size of the
vector is since it will be reset shortly. The vector is updated when
\fBlt_ResetVector\fR is called.  Blt_ResetVector makes the changes
visible to the Tcl interface and other vector clients (such as a graph
widget).
.sp
.CS
#include <tcl.h>
#include <blt.h>				
...
Blt_Vector *vecPtr;
double *newArr;
FILE *f;
struct stat statBuf;
int numBytes, numValues;

f = fopen("binary.dat", "r");
fstat(fileno(f), &statBuf);
numBytes = (int)statBuf.st_size;

/* Allocate an array big enough to hold all the data */
newArr = (double *)malloc(numBytes);
numValues = numBytes / sizeof(double);
fread((void *)newArr, numValues, sizeof(double), f);
fclose(f);

if (Blt_VectorExists(interp, "data"))  {
    if (Blt_GetVector(interp, "data", &vecPtr) != TCL_OK) {
	return TCL_ERROR;
    }
} else {
   if (Blt_CreateVector(interp, "data", 0, &vecPtr) != TCL_OK) {
	return TCL_ERROR;
   }
}
/* 
 * Reset the vector. Clients will be notified when Tk is idle. 
 * TCL_DYNAMIC tells the vector to free the memory allocated 
 * if it needs to reallocate or destroy the vector.
 */
if (Blt_ResetVector(vecPtr, newArr, numValues, numValues, 
	TCL_DYNAMIC) != TCL_OK) {
    return TCL_ERROR;
}
.CE
.SH "INCOMPATIBILITIES"
In previous versions, if the array variable isn't global 
(i.e. local to a Tcl procedure), the vector is automatically 
destroyed when the procedure returns.
.CS
proc doit {} {
    # Temporary vector x
    vector x(10)
    set x(9) 2.0
      ...
}
.CE
.PP
This has changed.  Variables are not automatically destroyed when
their variable is unset.  You can restore the old behavior by
setting the "-watchunset" switch.
.CE
.SH KEYWORDS
vector, graph, Blt_Vector