Updated doc about WIN32.
[ir-tcl-moved-to-github.git] / doc / ir-tcl.sgml
1 <!doctype linuxdoc system>
2
3 <!--
4   $Id: ir-tcl.sgml,v 1.31 1999-12-10 10:36:13 adam Exp $
5 -->
6
7 <article>
8 <title>IrTcl User's Guide and Reference 
9 <author><htmlurl url="http://www.indexdata.dk/" name="Index Data">,
10 <tt><htmlurl url="mailto:info@indexdata.dk" name="info@indexdata.dk"></tt>
11 <date>$Revision: 1.31 $
12 <abstract>
13 This document describes IrTcl -- an information retrieval toolkit for
14 Tcl and Tk that provides access to the Z39.50/SR protocol.
15 </abstract>
16
17 <toc>
18
19 <sect>Introduction
20
21 <p>
22 This document describes the <sf/IrTcl/ information retrieval toolkit,
23 which offers a high-level, client interface to the Z39.50 and SR protocols.
24 The toolkit is based on the Tcl/Tk toolkit developed by Prof. John
25 K. Ousterhout at the University of California &lsqb;ref 1&rsqb;. 
26 Tcl is a simple, somewhat shell-like, interpreted language. What
27 makes Tcl attractive is that it also offers a C API, which makes
28 extensions to the language possible. The most important Tcl extension is
29 probably Tk -- A Motif look-and-feel interface to the X window
30 system.
31
32 To interface the Z39.50/SR protocol <sf/IrTcl/ uses <bf/YAZ/.
33 <bf/YAZ/ offers two transport types: RFC1729/BER on TCP/IP and the mOSI
34 protocol stack.
35 However, the mOSI transport is only an option, and hence it is not
36 needed unless you wish to communicate within an OSI environment.
37 See &lsqb;ref 2&rsqb; for more information about the XTI/mOSI implementation.
38
39 <sf/IrTcl/ is usually build as a <it/dynamic/ library (WIN32)
40 or shared Object (Unix) which is dynamically loaded by using the Tcl's
41 <tt/load/ command. However, <sf/IrTcl/ can be compiled as a
42 traditional <it/static/ library as well.
43
44 <sect>Compilation and installation
45
46 <p>
47 <sect1>UNIX
48 <p>
49 In order to compile the software on UNIX you need:
50 <itemize>
51 <item> An ANSI C compiler such as GNU C.
52 <item> <htmlurl url="http://www.scriptics.com" name="Tcl">.
53  Version 8.0 and 8.2 has been tested.
54 <item> <htmlurl url="http://www.indexdata.dk/yaz/" name="YAZ">
55  version 1.5 or higher.
56 </itemize>
57
58 As an option you may want:
59 <itemize>
60 <item> <htmlurl url="http://www.scriptics.com" name="Tk">.
61 Version 8.0 and 8.2 has been tested.
62 <item> XTI/mOSI
63 </itemize>
64
65 Unpack the <sf/IrTcl/ package at the same directory level as <bf/YAZ/.
66
67 Type:
68 <tscreen><verb>
69 $ ./configure
70 </verb></tscreen>
71
72 This command tries to configure <sf/IrTcl/ for your system and creates
73 a <tt>Makefile</tt>.
74
75 The <tt>configure</tt> command tries to locate the file <tt/tclConfig.sh/
76 which should be generated by Tcl's installation script. Configure
77 looks for ther Tcl shell on your system in order to locate this file.
78 For example if <tt/tclsh/ is located in <tt>/home/joe/bin</tt>, configure will
79 assume that <tt>tclConfig.sh</tt> is installed in <tt>/home/joe/lib</tt>, 
80 in which case the prefix is <tt>/home/joe</tt>. If you have
81 more than one Tcl version installed on your system, or if configure
82 cannot find the <tt/tclConfig.sh/, you can specify in which directory
83 it is, by supplying option <tt>--with-tclconfig</tt> - for example:
84 <tscreen><verb>
85 $ ./configure --with-tclconfig=/home/joe/lib
86 </verb></tscreen>
87
88 The <sf/IrTcl/ executables are installed in prefix/bin and libraries
89 and support files are installed in prefix/irtcl.
90
91 Compile <sf/IrTcl/ by typing:
92 <tscreen><verb>
93 $ make
94 </verb></tscreen>
95
96 For Tcl versions that support dynamic libraries the command above
97 will create the shared library, <tt/irtcl.so/, as well as the
98 normal static library, <tt/libirtcl.a/.
99
100 For Tcl versions that doesn't support dynamic libraries the
101 make command will create two shells will build-in <sf/IrTcl/ support --
102 a Tcl shell called <tt/ir-tcl/ and a Tcl/Tk shell called <tt/ir-tk/.
103 The traditional static library, <tt/libirtcl.a/, is build as well.
104
105 To install the programs and support files type:
106 <tscreen><verb>
107 $ make install
108 </verb></tscreen>
109
110 If you wish to install man pages type:
111 <tscreen><verb>
112 $ make install.man
113 </verb></tscreen>
114
115 Summary of files installed (the names refer to the Makefile variables):
116
117 <descrip>
118 <tag><tt>irtcl.so</tt></tag> The <sf/IrTcl/ shared dynamic library. 
119 The actual name of this library vary. Installed in <tt>IRTCLDIR</tt>.
120 This file is only generated when using newer versions of Tcl/Tk.
121
122 <tag><tt>ir-tk</tt></tag> The <sf/IrTcl/ shell for Tk. This shell
123  is not needed when using a Tk version that supports shared libraries.
124  Installed in <tt>BINDIR</tt> -- defaults to
125  <tt>/usr/local/bin</tt>. <tt>ir-tk</tt> works like
126  <tt>wish</tt> &mdash without arguments it reads commands from stdin.
127  A source file may be specified by option <tt>-f</tt>. <tt>ir-tk</tt>
128  accept the same set of options as <tt>wish</tt>.
129
130 <tag><tt>ir-tcl</tt></tag> The <sf/IrTcl/ shell for Tcl. This program
131  is not needed when using a Tcl that supports shared libraries. Installed
132  in <tt>BINDIR</tt> -- defaults to <tt>/usr/local/bin</tt>.
133
134 <tag><tt>client.tcl</tt></tag> A graphical client for <tt>ir-tk</tt>.
135  The client is installed as an executable script called <tt>irclient</tt> in
136  <tt>BINDIR</tt>. This client needs a number of files, bitmaps, etc.
137  The client looks for the files in the current directory &mdash if
138  this fails it tries to look in the directory <tt>IRTCLDIR</tt>
139  -- defaults to <tt>/usr/local/lib/irtcl</tt>.
140
141 <tag><tt>libirtcl.a</tt></tag> The <sf/IrTcl/ library. 
142  Installed in <tt>LIBDIR</tt> -- defaults to <tt>/usr/local/lib</tt>.
143
144 <tag><tt>ir-tcl.h</tt></tag> The <sf/IrTcl/ header file.
145  Installed in <tt>INCDIR</tt> -- defaults to <tt>/usr/local/include</tt>.
146
147 <tag><tt>irtdb.tcl</tt></tag> A setup file with definitions
148  of target and queries. Read and updated by <tt>client.tcl</tt>. Installed
149  in <tt>IRTCLDIR</tt> -- defaults to <tt>/usr/local/lib/irtcl</tt>.
150
151 <tag><tt>formats/*</tt></tag> Display format files written
152  in Tk. Read by <tt>client.tcl</tt>. Installed 
153  in <tt>IRTCLDIR</tt> -- defaults to <tt>/usr/local/lib/irtcl</tt>.
154
155 <tag><tt>bitmaps/*</tt></tag> Various bitmap files. Read by
156  <tt>client.tcl</tt>. Installed 
157  in <tt>IRTCLDIR</tt> -- defaults to <tt>/usr/local/lib/irtcl</tt>.
158
159 <tag><tt>LICENSE</tt></tag> LICENSE file. Read by
160  <tt>client.tcl</tt>. Installed 
161  in <tt>IRTCLDIR</tt> -- defaults to <tt>/usr/local/lib/irtcl</tt>.
162 </descrip>
163
164 <p>
165 Basic Tcl is handled by the program <tt/tclsh/. The script
166 must use the <tt/load/ command to load the <sf/IrTcl/ dynamic
167 library. If dynamic libraries are unsupported the <tt/ir-tcl/ program
168 should be used instead, since that program is statically linked
169 with the <sf/IrTcl/ library.
170
171 So the static, non-dynamic, version goes like this:
172 <tscreen><verb>
173    $ ir-tcl
174    % 
175 </verb></tscreen>
176 and the dynamic version goes like:
177 <tscreen><verb>
178    $ tclsh
179    % load ./irtcl.tcl
180    %
181 </verb></tscreen>
182   
183 <sect1>WIN32
184 <p>
185
186 <sf/IrTcl/ is shipped with a "makefile" for the NMAKE tool that comes
187 with Visual C++.
188
189 Start an MS-DOS prompt and switch the sub directory <tt>WIN</tt> where
190 the file <tt>makefile</tt> is located. Customize the installation
191 by editing the <tt>makefile</tt> file (for example by using wordpad).
192
193 The following summarises the most important settings in that
194 file.
195
196 <descrip>
197 <tag><tt>YAZDIR</tt></tag> Specifies where YAZ is located.
198 <tag><tt>DEBUG</tt></tag> If set to 1, the software is
199 compiled with debugging libraries. If set to 0, the software
200 is compiled with release (non-debugging) libraries.
201 </descrip>
202
203 When satisfied with the settings in the makefile type
204 <tscreen><verb>
205 nmake
206 </verb></tscreen>
207
208 If compilation was successful the executables <tt>irtcl.dll</tt>
209 is put in directory <tt>BIN</tt>. 
210
211 To start the test client that comes with <sf/IrTcl/ make sure
212 both <tt/YAZ.DLL/ and <tt/IRTCL.DLL/ are in current directory
213 or in your PATH. Go to the top-level directory of <sf/IrTcl/
214 and type "wish -f client.tcl". You might want to make a
215 short-cut to start this.
216
217 <sect1>Using Tk
218
219 <p>
220 If your Tcl/Tk supports dynamic libraries you can use the
221 <tt/load/ command from within <tt/wish/ as described in the previous
222 section.
223 If not, you must use the <tt>ir-tk</tt> shell that acts as <tt>wish</tt>
224 except that it includes the <sf/IrTcl/ commands.
225
226 The enclosed script <tt>client.tcl</tt> is a graphical client
227 which demonstates an example of a user interface for the Z39.50/SR protocols. 
228 At first the script was relatively small but it has grown since the 
229 beginning. At present it is about 3000 lines. 
230
231 To start the client with dynamic library support use:
232 <tscreen><verb>
233 $ wish -f client.tcl
234 </verb></tscreen>
235
236 Note: Substitute the real name for the wish interpreter above, for
237 version 8.0 it is probably called <tt/wish8.0/.
238
239 To start the client without dynamic library support use:
240 <tscreen><verb>
241 $ ./ir-tk -f client.tcl
242 </verb></tscreen>
243
244 The client lets up define targets and query types within the interface.
245 Hence, you will not need to modify configation files. 
246
247 Stuff concerning targets can be found in the pull down menu 'Target'
248 with the following options:
249 <descrip>
250 <tag>Connect</tag> Establishes connection to a target.
251 <tag>Disconnect</tag> Closes a target connection.
252 <tag>About</tag> Shows implementation Id, implementation Version, etc 
253  for the current target.
254 <tag>Setup</tag> Pops up a target definition window. You may alter
255  a target definition.
256 <tag>Setup new</tag> Lets you define a new target.
257 </descrip> 
258
259 The term query type refers to a collection of search fields. The
260 pull down menu Options|Query deals with queries. You may
261 insert/modify/remove query types.
262
263 <sect>Overview of the API
264
265 <p>
266 Basically, <sf/IrTcl/ is a set of commands introduced to Tcl.
267 When extending Tcl there are two approaches: action-oriented commands
268 and object-oriented commands.
269
270 Action-oriented commands manipulate
271 Tcl variables and each command introduces only one action.
272 The string manipulation commands in Tcl are action oriented.
273
274 Object-oriented commands are added for every declared
275 variable (object). Object-oriented commands usually provide a set of
276 actions (methods) to manipulate the object.
277 The widgets in Tk (X objects) are examples of the object-oriented style.
278
279 <sf/IrTcl/ commands are object-oriented. The main reason
280 for this is that the data structures involved in the IR protocol
281 are not easily represented by Tcl data structures.
282 Also, the <sf/IrTcl/ objects tend to exist for a relativly long time.
283 Note that although we use the term object-oriented commands, this
284 does not mean that the programming style is strictly object-oriented. For
285 example, there is such no such thing as inheritance.
286
287 We are now ready to present the three commands introduced to Tcl by
288 <sf/IrTcl/:
289
290 <descrip>
291 <tag/ir/ The ir object represents a connection to a target. More
292 precisely it describes a Z-association. 
293 <tag/ir-set/ The ir-set describes a result set, which is
294 conceptually a collection of records returned by the target.
295 The ir-set object may retrieve records from a target by means of
296 the ir object; it may read/write records from/to a local file or it may be
297 updated with a user-edited record. 
298 <tag/ir-scan/ The scan object represents a list of scan lines
299 retrieved from a target.
300 </descrip>
301
302 <bf/Example/
303
304 To create a new IR object called <tt/z-assoc/ write:
305 <tscreen><verb>
306    ir z-assoc
307 </verb></tscreen>
308
309 <bf/End of example/
310
311 Each object provides a set of <em/settings/ which may either be
312 readable, writeable of both. All settings immediately follow
313 the name of the object. If a value is present the setting
314 is set to <em/value/.
315
316 <bf/Example/
317
318 We wish to set the preferred-message-size to 18000 on the
319 <tt/z-assoc/ object:
320
321 <tscreen><verb>
322    z-assoc preferredMessageSize 18000
323 </verb></tscreen>
324
325 To read the current value of preferred-message-size use:
326
327 <tscreen><verb>
328    z-assoc preferredMessageSize
329 </verb></tscreen>
330 <bf/End of example/
331
332 One important category consists of settings is those that relate to the
333 event-driven model. When <sf/IrTcl/ receives responses from the target, i.e.
334 init responses, search responses, etc., a <em/callback/ routine
335 is called. Callback routines are represented in Tcl as
336 a list, which is re-interpreted prior to invocation.
337 The method is similar to the one used in Tk to capture X events.
338
339 For each SR/Z39.50 request there is a corresponding object action. The most
340 important actions are:
341 <descrip>
342 <tag/connect/ Establishes connection with a target
343 <tag/init/ Sends an initialize request.
344 <tag/search/ Sends a search request.
345 <tag/present/ Sends a present request.
346 <tag/scan/ Sends a scan request.
347 </descrip>
348
349 <bf/Example/
350
351 This example shows a complete connect - init - search - present scenario. 
352
353 First an IR object, called <tt/z/, is created.
354 Also a result set <tt/z.1/ is introduced by the <tt/ir-set/ 
355 and it is specified that the result set uses <tt/z/ as its association.
356
357 The setting <tt/databaseNames/ is set to the 
358 database <tt/books/ to which the following searches are directed.
359 A callback is then defined and a connection is established to
360 <tt/fake.com/ by the <tt/connect/ action.
361 If the connect succeeds the <tt/connect-response/ is called.
362
363 In the Tcl procedure, <tt/connect-response/, a callback is defined
364 <em/before/ the init request is executed. 
365 The Tcl procedure <tt/init-response/ is called when a 
366 init response is returned from the target.
367
368 The <tt/init-response/ procedure sets up a <tt/search-response/ 
369 callback handler and sends a search-request by using a query which
370 consists of a single word <tt/science/.
371
372 When the <tt/search-response/ procedure is called it defines
373 a variable <tt/hits/ and sets it to the value of the setting
374 <tt/resultCount/. If <tt/hits/ is positive a present-request is
375 sent -- asking for 5 records from position 1. 
376
377 Finally, a present response is received and the number of records
378 returned is stored in the variable <tt/ret/.
379
380 <tscreen><verb>
381 ir z
382 z databaseNames books
383 ir-set z.1 z
384 z callback {connect-response}
385 z connect fake.com
386
387 proc connect-response {} {
388     z callback {init-response}
389     z init
390 }
391
392 proc init-response {} {
393     z callback {search-response}
394     z.1 search science
395 }
396
397 proc search-response {} {
398     set hits [z.1 resultCount]
399     puts "$hits hits"
400     if {$hits > 0} {
401         z callback {present-response}
402         z.1 present 1 5
403     }
404 }
405
406 proc present-response {} {
407     set ret [z.1 numberOfRecordsReturned]
408     puts "$ret records returned"
409 }
410 </verb></tscreen>
411 <bf/End of example/
412
413 The previous example program doesn't care about error conditions. 
414 If errors occur in the program they will be trapped by the Tcl error 
415 handler. This is not always appropriate. However, Tcl offers a 
416 <tt/catch/ command to support error handling by the program itself.
417
418 <sect>Associations
419
420 <p>
421 The ir object describes an association with a target.
422 This section covers the connect-init-disconnect actions provided
423 by the ir object.
424 An ir object is created by the <tt/ir/ command and the
425 created object enters a 'not connected' state, because it isn't
426 connected to a target yet. 
427
428 <sect1>Connect
429
430 <p>
431 A connection is established by the <tt/connect/ action which is
432 immediately followed by a hostname. A number of settings affect the
433 <tt/connect/ action. Obviously, these settings should be set
434 <bf/before/ connecting. The settings are:
435
436 <descrip>
437 <tag><tt>comstack </tt><tt>mosi|tcpip</tt></tag>
438  Comstack type.
439 <tag><tt>protocol </tt><tt>Z39|SR</tt></tag>
440  Protocol type - ANSI/NISO Z39.50 or ISO SR.
441 <tag><tt>callback </tt><em>list</em></tag>
442  Tcl script called when the connection is established.
443 <tag><tt>failback </tt><em>list</em></tag>
444  Fatal error Tcl script. Called on protocol errors or if target
445  closes connection.
446 </descrip>
447
448 If the connect is unsuccessful either the connect action itself
449 will return an error code or the failback handler is invoked.
450
451 In general, the <tt>failback</tt> handler is invoked when serious
452 unrecoverable errors occur when communicating with the target. 
453 In this case the <sf/IrTcl/ system shuts down the connection.
454 The <tt>failback</tt> handler might inspect the <tt>failInfo</tt>
455 setting to determine the cause of the failure; it returns
456 two elements. The first is an error integer; the second is an 
457 english representation of the error. The error codes and
458 the corresponding messages are:
459
460 <descrip>
461 <tag><tt>0</tt></tag>ok
462 <tag><tt>1</tt></tag>connect failed
463 <tag><tt>2</tt></tag>connection closed
464 <tag><tt>3</tt></tag>connection closed
465 <tag><tt>4</tt></tag>failed to decode incoming APDU
466 <tag><tt>5</tt></tag>unknown APDU
467 </descrip>
468
469 Note: in case 3 the connection was closed during read a read operation
470 whereas in case 4 it was closed during a write operation.
471
472 <sect1>Init
473
474 <p>
475 If the connect operation succeeds the <tt/init/ action should be used. 
476 The init related settings are:
477
478 <descrip>
479 <tag><tt>preferredMessageSize </tt><em>integer</em></tag>
480  Preferred-message-size. Default value is 30000.
481 <tag><tt>maximumRecordSize </tt><em>integer</em></tag>
482  Maximum-record-size. Default value is 30000.
483 <tag><tt>idAuthentication </tt><em>string</em> ...</tag>
484  Id-authentication. There are three forms. If any empty is
485  given, the Id-authentication is not used.  If one non-empty string
486  is given, the 'open' authentication is used. If three strings are 
487  specified, the version 'id-pass' authentication (version 3 only) 
488  is used in which case the first string is groupId; the second string 
489  is userId and the third string is password.
490 <tag><tt>implementationName </tt><em>string</em></tag>
491  Implementation-name of origin system. 
492 <tag><tt>implementationId</tt></tag>
493  Implementation-id of origin system. This setting is read-only.
494 <tag><tt>implementationVersion</tt></tag>
495  Implementation-version of origin system. This settings is read-only.
496 <tag><tt>options </tt><em>list</em></tag>
497  Options to be negotiated in the init service. The list contains 
498  the options that are set. Possible values are <tt>search</tt>, 
499  <tt>present</tt>, <tt>delSet</tt>, <tt>resourceReport</tt>, 
500  <tt>triggerResourceCtrl</tt>, <tt>resourceCtrl</tt>,
501  <tt>accessCtrl</tt>, <tt>scan</tt>, <tt>sort</tt>, 
502  <tt>extendedServices</tt>, <tt>level-1Segmentation</tt>, 
503  <tt>level-2Segmentation</tt>, <tt>concurrentOperations</tt> and
504  <tt>namedResultSets</tt>. Currently the default options are:
505  <tt>search</tt>, <tt>present</tt>, <tt>scan</tt> and 
506  <tt>namedResultSets</tt>. The <tt>options</tt> setting is set to its default
507  value when an ir object is created and when a <tt>disconnect</tt>
508  action is performed.
509 <tag><tt>protocolVersion </tt><em>integer</em></tag>
510  Protocol version: 2, 3, etc. Default is 2.
511 <tag><tt>referenceId </tt><em>string</em></tag>
512  Reference-id of init operation. If <em>string</em> is empty no 
513  reference-id is used.
514 <tag><tt>initResponse </tt><em>list</em></tag>
515  Init-response Tcl script.
516 <tag><tt>callback </tt><em>list</em></tag>
517  General response Tcl script. Only used if <tt>initResponse</tt>
518  is not specified.
519 </descrip>
520
521 The init-response handler should inspect some of the settings shown
522 below:
523
524 <descrip>
525 <tag><tt>initResult </tt>returns <em>boolean</em></tag>
526  Init response status. True if init operation was successful; 
527  false otherwise.
528 <tag><tt>preferredMessageSize </tt>returns <em>integer</em></tag>
529  Preferred-message-size after negotiation.
530 <tag><tt>maximumRecordSize </tt>returns <em>integer</em></tag>
531  Maximum-record-size after negotiation.
532 <tag><tt>targetImplementationName </tt>returns <em>string</em></tag>
533  Implementation-name of target system.
534 <tag><tt>targetImplementationId </tt>returns <em>string</em></tag>
535  Implementation-id of target system.
536 <tag><tt>targetImplementationVersion </tt>returns <em>string</em></tag>
537  Implementation-version of target system.
538 <tag><tt>options </tt>returns <em>list</em></tag>
539  Options after negotiation. The list contains the options that are set.
540 <tag><tt>protocolVersion </tt>returns <em>integer</em></tag>
541  Protocol version: 2, 3, etc after negotiation.
542 <tag><tt>userInformationField </tt>returns <em>string</em></tag>
543  User information field.
544 <tag><tt>referenceId </tt>returns <em>string</em></tag>
545  Reference-id of init response.
546 </descrip>
547
548 <bf/Example/
549
550 Consider a client with the ability to access multiple targets.
551
552 We define a list of targets that we wish to connect to.
553 Each item in the list describes the target parameters with
554 the following four components: association-name, comstack-type,
555 protocol-type and a hostname.
556
557 The list for the two targets: ISO/SR target DANBIB and TCP/Z39.50 
558 target Data Research, will be defined as:
559 <tscreen><verb>
560 set targetList { {danbib mosi SR 0103/find2.denet.dk:4500}
561                  {drs tcpip Z39 dranet.dra.com} }
562 </verb></tscreen>
563
564 The Tcl code below defines, connect and initialize the
565 targets in <tt/targetList/:
566
567 <tscreen><verb>
568 foreach target $targetList {
569     set assoc [lindex $target 0]
570     ir $assoc
571     $assoc comstack [lindex $target 1]
572     $assoc protocol [lindex $target 2]
573     $assoc failback [list fail-response $assoc]
574     $assoc callback [list connect-response $assoc]
575     $assoc connect [lindex $target 3]
576 }
577
578 proc connect-response {assoc} {
579     $assoc callback [list init-response $assoc]
580     $assoc init
581 }
582
583 proc fail-response {assoc} {
584     puts "$assoc closed connection or protocol error"
585 }
586
587 proc init-response {assoc} {
588     if {[$assoc initResult]} {
589         puts "$assoc initialized ok"
590     } else {
591         puts "$assoc didn't initialize"
592     }
593 }
594 </verb></tscreen>
595
596 <tt/target/ is bound to each item in the list of targets.
597 The <tt/assoc/ is set to the ir object name.
598 Then, the comstack, protocol and failback are set for the <tt/assoc/ object.
599 The ir object name is argument to the <tt/fail-response/ and 
600 <tt/connect-response/ routines. 
601 Note the use of the Tcl <tt/list/ command which 
602 is necessary here because the argument contains variables 
603 (<tt/assoc/) that should be substituted before the handler is defined.
604 After the connect operation, the <tt/init-response/ handler
605 is defined in much the same way as the failback handler.
606 And, finally, an init request is executed.
607
608 <bf/End of example/
609
610 <sect1>Disconnect
611
612 <p>
613 To terminate the connection the <tt/disconnect/ action should be used. 
614 This action has no parameters. 
615 Another connection may be established by a new <tt/connect/ action on
616 the same ir object.
617
618 <sect>Result sets
619
620 <p>
621 This section covers the queries used by <sf/IrTcl/, and how searches and
622 presents are handled.
623
624 A search operation and a result set is described by the ir set object.
625 The ir set object is defined by the <tt/ir-set/ command which
626 has two parameters. The first is the name of the new ir set object, and
627 the second, which is optional, is the name of an assocation -- an ir
628 object. The second argument is required if the ir set object should be able
629 to perform searches and presents. However, it is not required if
630 only ``local'' operations is done with the ir set object.
631
632 When the ir set object is created a number of settings are inherited
633 from the ir object, such as the selected databass, query type,
634 etc. Thus, the ir object contains what we could call default
635 settings.
636
637 <sect1>Queries
638
639 <p>
640 Search requests are sent by the <tt/search/ action which
641 takes a query as parameter. There are two types of queries,
642 RPN and CCL, controlled by the setting <tt/queryType/.
643 A string representation for the query is used in <sf/IrTcl/ since
644 Tcl has reasonably powerful string manipulaton capabilities.
645 The RPN query used in <sf/IrTcl/ is the prefix query notation also used in
646 the <bf/YAZ/ test client.
647
648 The CCL query is an uninterpreted octet-string which is parsed by the target.
649 We refer to the standard: ISO 8777. Note that only a few targets
650 actually support the CCL query and the interpretation of
651 the standard may vary.
652
653 The prefix query notation (which is converted to RPN) offer a few
654 operators. They are:
655
656 <descrip>
657 <tag><tt>@attr </tt><em>list op</em></tag>
658  The attributes in list are applied to op
659 <tag><tt>@and </tt><em>op1 op2</em></tag>
660  Boolean <em/and/ on op1 and op2
661 <tag><tt>@or </tt><em>op1 op2</em></tag>
662  Boolean <em/or/ on op1 and op2
663 <tag><tt>@not </tt><em>op1 op2</em></tag>
664  Boolean <em/not/ on op1 and op2
665 <tag><tt>@prox </tt><em>list op1 op2</em></tag>
666  Proximity operation on op1 and op2. Not implemented yet.
667 <tag><tt>@set </tt><em>name</em></tag>
668  Result set reference
669 <tag><tt>@attrset </tt><em>set</em></tag>
670  Whole query uses the specified attribute <em>set</em>. If this operator is
671  used it must be defined at the beginning of the query.
672 </descrip>
673
674 It is simple to build RPN queries in <sf/IrTcl/. Search terms
675 are sequences of characters, as in:
676 <tscreen><verb>
677    science
678 </verb></tscreen>
679
680 Boolean operators use the prefix notation (instead of the suffix/RPN),
681 as in:
682 <tscreen><verb>
683    @and science technology
684 </verb></tscreen>
685
686 Search terms may be associated with attributes. These
687 attributes are indicated by the <tt/@attr/ operator.
688 Assuming the bib-1 attribute set, we can set the use-attribute 
689 (type is 1) to title (value is 4):
690
691 <tscreen><verb>
692    @attr 1=4 science
693 </verb></tscreen>
694
695 Also, it is possible to apply attributes to a range of search terms.
696 In the query below, both search terms have use=title but the <tt/tech/
697 term is right truncated:
698
699 <tscreen><verb>
700    @attr 1=4 @and @attr 5=1 tech beta
701 </verb></tscreen>
702
703 To search for the DatabaseInfo records from an Explain server, we 
704 could use
705 <tscreen><verb>
706    @attrset exp1 @attr 1=1 DatabaseInfo
707 </verb></tscreen>
708
709 <sect1>Search
710
711 <p>
712 The settings that affect the search are listed below:
713
714 <descrip>
715 <tag><tt>databaseNames </tt><em>list</em></tag>
716  Database-names.
717 <tag><tt>smallSetUpperBound </tt><em>integer</em></tag>
718  Small set upper bound. Default 0.
719 <tag><tt>largeSetLowerBound </tt><em>integer</em></tag>
720  Large set lower bound. Default 2.
721 <tag><tt>mediumSetPresentNumber </tt><em>integer</em></tag>
722  Medium set present number. Default 0.
723 <tag><tt>replaceIndicator </tt><em>boolean</em></tag>
724  Replace-indicator. Default true (1).
725 <tag><tt>setName </tt><em>string</em></tag>
726  Name of result set. Default name of set is <tt/default/.
727 <tag><tt>queryType rpn|ccl</tt></tag>
728  Query type-1 or query type-2. Default rpn (type-1).
729 <tag><tt>preferredRecordSyntax </tt><em>string</em></tag>
730  Preferred record syntax -- UNIMARC, USMARC, etc. 
731 <tag><tt>smallSetElementSetNames </tt><em>string</em></tag>
732  small-set-element-set names. If <em>string</em> is empty
733  the element set is not set. Default is empty (not set).
734 <tag><tt>mediumSetElementSetNames </tt><em>string</em></tag>
735  medium-set-element-set names. If <em>string</em> is empty
736  the element set is not set. Default is empty (not set).
737 <tag><tt>nextResultSetPosition </tt>returns <em>integer</em></tag>
738  Next result set position.
739 <tag><tt>referenceId </tt><em>string</em></tag>
740  Reference-id. If <em>string</em> is empty no reference-id is used.
741 <tag><tt>searchResponse </tt><em>list</em></tag>
742  Search-response Tcl script.
743 <tag><tt>callback </tt><em>list</em></tag>
744  General response Tcl script. Only used if searchResponse is not specified.
745  This setting is valid only for the <tt/ir/ object -- not the
746  <tt/ir-set/ object.
747 </descrip>
748
749 Setting the <tt/databaseNames/ is mandatory. All other settings
750 have reasonable defaults.
751 The search-response handler, specified by the <tt/callback/ - or
752 the <tt/searchResponse/ setting, 
753 should read some of the settings shown below:
754
755 <descrip>
756 <tag><tt>searchStatus</tt> returns <em>boolean</em></tag>
757  Search-status. True if search operation was successful; false
758  otherwise.
759 <tag><tt>responseStatus </tt>returns <em>list</em></tag>
760  Response status information.
761 <tag><tt>resultCount </tt>returns <em>integer</em></tag>
762  result-count
763 <tag><tt>numberOfRecordsReturned </tt>returns <em>integer</em></tag>
764  Number of records returned.
765 <tag><tt>referenceId </tt>returns <em>string</em></tag>
766  Reference-id of search response.
767 </descrip>
768
769 The <tt/responseStatus/ signals one of three conditions which
770 is indicated by the value of the first item in the list:
771
772 <descrip>
773 <tag><tt>NSD</tt></tag> indicates that the target has returned one or 
774 more non-surrogate diagnostic messages. The <tt/NSD/ item is followed by 
775 a list with all non-surrogate messages. Each non-surrogate message consists
776 of three items. The first item of the three items is the error
777 code (integer); the next item is a textual representation of the error
778 code in plain english; the third item is additional information, possibly
779 empty if no additional information was returned by the target.
780
781 <tag><tt>DBOSD</tt></tag> indicates a successful operation where the
782 target has returned one or more records. Each record may be
783 either a database record or a surrogate diagnostic.
784
785 <tag><tt>OK</tt></tag> indicates a successful operation -- no records are
786 returned from the target. 
787 </descrip>
788
789 <bf/Example/
790
791 We continue with the multiple-targets example. 
792 The <tt/init-response/ procedure will attempt to make searches:
793
794 <tscreen><verb>
795 proc init-response {assoc} {
796     puts "$assoc connected"
797     ir-set ${assoc}.1 $assoc
798     $assoc.1 queryType rpn
799     $assoc.1 databaseNames base-a base-b
800     $assoc callback [list search-response $assoc ${assoc}.1]
801     $assoc.1 search "@attr 1=4 @and @attr 5=1 tech beta"
802 }
803 </verb></tscreen>
804
805 An ir set object is defined and the
806 ir object is told about the name of ir object.
807 The ir set object use the name of the ir object as prefix.
808
809 Then, the query-type is defined to be RPN, i.e. we will
810 use the prefix query notation later on.
811
812 Two databases, <tt/base-a/ and <tt/base-b/, are selected.
813
814 A <tt/search-response/ handler is defined with the
815 ir object and the ir-set object as parameters and
816 the search is executed.
817
818 The first part of the <tt/search-response/ looks like:
819 <tscreen><verb>
820 proc search-response {assoc rset} {
821     set status [$rset responseStatus]
822     set type [lindex $status 0]
823     if {$type == "NSD"} {
824         set code [lindex $status 1]
825         set msg [lindex $status 2]
826         set addinfo [lindex $status 3]
827         puts "NSD $code: $msg: $addinfo"
828         return
829     } 
830     set hits [$rset resultCount]
831     if {$type == "DBOSD"} {
832         set ret [$rset numberOfRecordsReturned]
833         ...
834     }
835 }
836 </verb></tscreen>
837 The response status is stored in variable <tt/status/ and 
838 the first element indicates the condition.
839 If non-surrogate diagnostics are returned they are displayed.
840 Otherwise, the search was a success and the number of hits
841 is read. Finally, it is tested whether the search response
842 returned records (database or diagnostic).
843
844 Note that we actually didn't inspect the search status (setting
845 <tt/searchStatus/) to determine whether the search was successful or not, 
846 because the standard specifies that one or more non-surrogate
847 diagnostics should be returned by the target in case of errors.
848
849 <bf/End of example/
850
851 If one or more records are returned from the target they
852 will be stored in the result set object.
853 In the case in which the search response contains records, it is
854 very similar to the present response case. Therefore, some settings
855 are common to both situations.
856
857 <sect1>Present
858
859 <p>
860 The <tt/present/ action sends a present request. The <tt/present/ is
861 followed by two optional integers. The first integer is the 
862 result-set starting position -- defaults to 1. The second integer 
863 is the number of records requested -- defaults to 10. 
864 The settings which could be modified before a <tt/present/
865 action are:
866
867 <descrip>
868 <tag><tt>preferredRecordSyntax </tt><em>string</em></tag>
869  preferred record syntax -- UNIMARC, USMARC, etc.
870 <tag><tt>elementSetNames </tt><em>string</em></tag>
871  Element-set names. If <em>string</em> is empty
872  the element set is not set. Default is empty (not set).
873 <tag><tt>referenceId </tt><em>string</em></tag>
874  Reference-id. If <em>string</em> is empty no reference-id is used.
875 <tag><tt>presentResponse </tt><em>list</em></tag>
876  Present-response Tcl script. 
877 <tag><tt>callback </tt><em>list</em></tag>
878  General response Tcl script. Only used if presentResponse is not specified 
879  This setting is valid only for the <tt/ir/ object -- not the
880  <tt/ir-set/ object.
881 </descrip>
882
883 The present-response handler should inspect the settings
884 shown in table below.
885 Note that <tt/responseStatus/ and <tt/numberOfRecordsReturned/
886 settings were also used in the search-response case.
887
888 As in the search response case, records returned from the
889 target are stored in the result set object.
890
891 <descrip>
892 <tag><tt>presentStatus </tt>returns <em>boolean</em></tag>
893  Present-status.
894 <tag><tt>responseStatus </tt>returns <em>list</em></tag>
895  Response status information.
896 <tag><tt>numberOfRecordsReturned </tt>returns <em>integer</em></tag>
897  Number of records returned.
898 <tag><tt>nextResultSetPosition </tt>returns <em>integer</em></tag>
899  Next result set position.
900 <tag><tt>referenceId </tt>returns <em>string</em></tag>
901  Reference-id of present response.
902 </descrip>
903
904 <sect1>Records
905
906 <p>
907 Search responses and present responses may result in
908 one or more records stored in the ir set object if
909 the <tt/responseStatus/ setting indicates database or
910 surrogate diagnostics (<tt/DBOSD/). The individual
911 records, indexed by an integer position offset, should then be 
912 inspected.
913
914 If element set names have been specified either in the
915 search requests (<tt>smallSetElementSetNames</tt> /
916 <tt>mediumSetElementSetNames</tt>) or present requests 
917 (<tt>elementSetNames</tt>) the individual records in the
918 ir set object are assigned appropriate element set ids. 
919 In this mode records at a given position are treated different as
920 long as they have difference element set ids.
921 To inspect records with a particular element set id in subsequent
922 operations use the <tt>recordElements</tt> setting followed by the id.
923 If you have more than one record at a given position and you do not
924 use <tt>recordElements</tt> the record selected at the given position
925 is undefined.
926
927 The action <tt>type</tt> followed by an integer returns information 
928 about a given position in an ir set. There are three possiblities:
929
930 <descrip>
931 <tag><tt/SD/</tag> The item is a surrogate diagnostic record.
932 <tag><em/empty/</tag> There is no record at the specified position.
933 <tag><tt/DB/</tag> The item is a database record.
934 </descrip>
935
936 To handle the first case, surrogate diagnostic record, the
937 <tt/Diag/ action should be used. It returns three
938 items: error code (integer), text representation in plain english
939 (string), and additional information (string, possibly empty).
940
941 In the second case, no record, note that there still might
942 be a record at the position but with an id that differs from that
943 specified by <tt>recordElements</tt>.
944
945 In the third case, database record, the <tt/recordType/ action should
946 be used. It returns the record type at the given position.
947 Some record types are:
948
949 <tscreen>
950 UNIMARC
951 INTERMARC
952 CCF
953 USMARC
954 UKMARC
955 NORMARC
956 LIBRISMARC
957 DANMARC
958 FINMARC
959 SUTRS
960 </tscreen>
961
962 <bf/Example/
963
964 We continue our search-response example. In the case,
965 <tt/DBOSD/, we should inspect the result set items. 
966 Recall that the ir set name was passed to the
967 search-response handler as argument <tt/rset/.
968
969 <tscreen><verb>
970     if {$type == "DBOSD"} {
971         set ret [$rset numberOfRecordsReturned]
972         for {set i 1} {$i<=$ret} {incr i} {
973             set itype [$rset type $i]
974             if {$itype == "SD"} {
975                 set diag [$rset Diag $i]
976                 set code [lindex $diag 0]
977                 set msg [lindex $diag 1]
978                 set addinfo [lindex $diag 2]
979                 puts "$i: NSD $code: $msg: $addinfo"
980             } elseif {$itype == "DB"} {
981                 set rtype [$rset recordType $i]
982                 puts "$i: type is $rtype"
983             }
984         }
985     }
986 </verb></tscreen>
987 Each item in the result set is examined. 
988 If an item is a diagnostic message it is displayed; otherwise
989 if it's a database record its type is displayed.
990
991 <bf/End of example/
992
993 <sect1>MARC records
994
995 <p>
996 In the case, where there is a MARC record at a given position we
997 want to display it somehow. The action <tt/getMarc/ is what we need.
998 The <tt/getMarc/ is followed by a position integer and the type of
999 extraction we want to make: <tt/field/ or <tt/line/.
1000
1001 The <tt/field/ and <tt/line/ type are followed by three
1002 parameters that serve as extraction masks.
1003 They are called tag, indicator and field.
1004 If the mask matches a tag/indicator/field of a record the information
1005 is extracted. Two characters have special meaning in masks: the
1006 dot (any character) and star (any number of any character).
1007
1008 The <tt/field/ type returns one or more lists of field information
1009 that matches the mask specification. Only the content of fields
1010 is returned.
1011
1012 The <tt/line/ type, on the other hand, returns a Tcl list that
1013 completely describe the layout of the MARC record -- including
1014 tags, fields, etc.
1015
1016 The <tt/field/ type is sufficient and efficient in the case, where only a
1017 small number of fields are extracted, and in the case where no
1018 further processing (in Tcl) is necessary.
1019
1020 However, if the MARC record is to be edited or altered in any way, the
1021 <tt/line/ extraction is more powerful -- only limited by the Tcl
1022 language itself.
1023
1024 <bf/Example/
1025
1026 Consider the record below:
1027 <tscreen><verb>
1028 001       11224466 
1029 003    DLC
1030 005    00000000000000.0
1031 008    910710c19910701nju           00010 eng  
1032 010    $a    11224466 
1033 040    $a DLC $c DLC
1034 050 00 $a 123-xyz
1035 100 10 $a Jack Collins
1036 245 10 $a How to program a computer
1037 260 1  $a Penguin
1038 263    $a 8710
1039 300    $a p. cm.
1040 </verb></tscreen>
1041
1042 Assuming this record is at position 1 in ir-set <tt/z.1/, we
1043 might extract the title-field (245 * a), with the following command:
1044 <tscreen><verb>
1045 z.1 getMarc 1 field 245 * a
1046 </verb></tscreen>
1047
1048 which gives:
1049 <tscreen><verb>
1050 {How to program a computer}
1051 </verb></tscreen>
1052
1053 Using the <tt/line/ instead of <tt/field/ gives:
1054 <tscreen><verb>
1055 {245 {10} {{a {How to program a computer}} }}
1056 </verb></tscreen>
1057
1058 If we wish to extract the whole record as a list, we use:
1059 <tscreen><verb>
1060 z.1 getMarc 1 line * * *
1061 </verb></tscreen>
1062
1063 giving:
1064 <tscreen><verb>
1065 {001 {} {{{} {   11224466 }} }}
1066 {003 {} {{{} DLC} }}
1067 {005 {} {{{} 00000000000000.0} }}
1068 {008 {} {{{} {910710c19910701nju           00010 eng  }} }}
1069 {010 {  } {{a {   11224466 }} }}
1070 {040 {  } {{a DLC} {c DLC} }}
1071 {050 {00} {{a 123-xyz} }}
1072 {100 {10} {{a {Jack Collins}} }}
1073 {245 {10} {{a {How to program a computer}} }}
1074 {260 {1 } {{a Penguin} }}
1075 {263 {  } {{a 8710} }}
1076 {300 {  } {{a {p. cm.}} }}
1077 </verb></tscreen>
1078
1079 <bf/End of example/
1080
1081 <bf/Example/
1082
1083 This example demonstrates how Tcl can be used to examine
1084 a MARC record in the list notation.
1085
1086 The procedure <tt/extract-format/ makes an extraction of
1087 fields in a MARC record based on a number of masks.
1088 There are 5 parameters, <tt/r/: a
1089 record in list notation, <tt/tag/: regular expression to
1090 match the record tags, <tt/ind/: regular expression to
1091 match indicators, <tt/field/: regular expression to 
1092 match fields, and finally <tt/text/: regular expression to 
1093 match the content of a field.
1094
1095 <tscreen><verb>
1096 proc extract-format {r tag ind field text} {
1097     foreach line $r {
1098         if {[regexp $tag [lindex $line 0]] && \
1099                 [regexp $ind [lindex $line 1]]} {
1100             foreach f [lindex $line 2] {
1101                 if {[regexp $field [lindex $f 0]]} {
1102                     if {[regexp $text [lindex $f 1]]} {
1103                         puts [lindex $f 1]
1104                     }
1105                 }
1106             }
1107         }
1108     }
1109 }
1110 </verb></tscreen>
1111
1112 To match <tt/comput/ followed by any number of character(s) in the
1113 245 fields in the record from the previous example, we could use:
1114 <tscreen><verb>
1115 set r [z.1 getMarc 1 line * * *]
1116
1117 extract-format $r 245 .. . comput
1118 </verb></tscreen>
1119 which gives:
1120 <tscreen><verb>
1121 How to program a computer
1122 </verb></tscreen>
1123
1124 <bf/End of example/
1125
1126 The <tt/putMarc/ action does the opposite of <tt/getMarc/. It
1127 copies a record in Tcl list notation to a ir set object and is
1128 needed if a result-set must be updated by a Tcl modified (user-edited)
1129 record.
1130
1131 <sect1>SUTRS
1132
1133 <p>
1134 In <sf/IrTcl/ a SUTRS record is treated as one single string. To retrieve
1135 a SUTRS record use the <tt>getSutrs</tt> followed by an index.
1136
1137 <sect1>GRS-1
1138 <p>
1139 A GRS-1 record in <sf/IrTcl/ is represented as a list of elements. 
1140 Each element specifies a tag as well as data. The data may
1141 be a subtree, which is represented as a list, and so on.
1142
1143 The method <tt/getGrs/ is followed by a record index and
1144 optional specifiers that selects a specific sub-tree. Each element
1145 consists of 5 elements:
1146
1147 <descrip>
1148 <tag>tag-set</tag> Tag set number.
1149
1150 <tag>value-type</tag> Type of tag value. May be either
1151 <tt/numeric/ of <tt/string/.
1152
1153 <tag>value</tag> The value it self.
1154
1155 <tag>data-type</tag> May be either <tt/octets/, <tt/numeric/,
1156 <tt/ext/, <tt/string/, <tt/bool/, <tt/intUnit/, <tt/empty/,
1157 <tt/notRequested/, <tt/diagnostic/ or <tt/subtree/.
1158
1159 <tag>data</tag>The data associated with element of given type as
1160  indicated before. If data-type is <tt/numeric/ or <tt/string/
1161  then data is encoded as a single Tcl token. The data-type <tt/bool/
1162  is encoded as 0 or 1 for false and  true respectively. If the
1163  data-type is <tt/subtree/ the data is a sub-list.
1164  In all other cases, the data is the empty string.
1165 </descrip>
1166
1167 <bf/Example/
1168
1169 Consider the GRS-1 record below as shown by the <bf/YAZ/ client program:
1170
1171 <tscreen><verb>
1172 (1,1) OID: GILS-schema
1173 (1,14) 2
1174 (2,1)  UTAH EARTHQUAKE EPICENTERS
1175     class=4,type=1,value=us
1176 (4,52) UTAH GEOLOGICAL AND MINERAL SURVEY
1177 (3,Local-Subject-Index) APPALACHIAN VALLEY; EARTHQUAKE; EPICENTER
1178 (2,6)
1179     (1,19) Five files of epicenter data arranged by ...
1180     (3,Format) DIGITAL DATA SETS
1181     (3,Data-Category) TERRESTRIAL
1182     (3,Comments) Data are supplied by the University of Utah ...
1183 (4,70)
1184     (4,90)
1185         (2,10) UTAH GEOLOGICAL AND MINERAL SURVEY
1186         (4,2) 606 BLACK HAWK WAY
1187         (4,3) SALT LAKE CITY
1188         (3,State) UT
1189         (3,Zip-Code) 84108
1190         (2,16) USA
1191         (2,14) (801) 581-6831
1192     (4,7) UTAH EARTHQUAKE EPICENTERS
1193 (4,1) ESDD0006
1194 (1,16) 198903
1195 </verb></tscreen>
1196
1197 The record may be fetched from the result set, <tt/z.1/, at position 1
1198 by using:
1199 <tscreen><verb>
1200 z.1 getGrs 1 
1201 </verb></tscreen>
1202 which will return:
1203 <tscreen><verb>
1204 { 1 numeric 1 oid 1.2.840.10003.13.2 }
1205 { 1 numeric 14 string 2 }
1206 { 2 numeric 1 string
1207    { UTAH EARTHQUAKE EPICENTERS} }
1208 { 4 numeric 52 string {UTAH GEOLOGICAL AND MINERAL SURVEY} }
1209 { 3 string Local-Subject-Index string
1210    {APPALACHIAN VALLEY; EARTHQUAKE; EPICENTER} }
1211 { 2 numeric 6 subtree
1212    { { 1 numeric 19 string
1213       {Five files of epicenter data arranged by ...} }
1214    { 3 string Format string {DIGITAL DATA SETS} }
1215    { 3 string Data-Category string TERRESTRIAL }
1216    { 3 string Comments string   
1217       {Data are supplied by the University of Utah ...} } } }
1218 { 4 numeric 70 subtree
1219    { { 4 numeric 90 subtree
1220       { { 2 numeric 10 string
1221          {UTAH GEOLOGICAL AND MINERAL SURVEY} }
1222       { 4 numeric 2 string {606 BLACK HAWK WAY} }
1223       { 4 numeric 3 string {SALT LAKE CITY} }
1224       { 3 string State string UT }
1225       { 3 string Zip-Code string 84108 }
1226       { 2 numeric 16 string USA }
1227       { 2 numeric 14 string {(801) 581-6831} } } }
1228       { 4 numeric 7 string {UTAH EARTHQUAKE EPICENTERS} } } }
1229 { 4 numeric 1 string ESDD0006 }
1230 { 1 numeric 16 string 198903 } 
1231 </verb></tscreen>
1232
1233 We can choose only to get the path (2,6) by using:
1234
1235 <tscreen><verb>
1236 z.1 getGrs 1 (2,6)
1237 </verb></tscreen>
1238 and we'll get:
1239 <tscreen><verb>
1240 { 2 numeric 6 subtree { { 1 numeric 19 string
1241    {Five files of epicenter data arranged by ...} }
1242    { 3 string Format string {DIGITAL DATA SETS} }
1243    { 3 string Data-Category string TERRESTRIAL }
1244    { 3 string Comments
1245       string {Data are supplied by the University of Utah ...} } } }
1246 </verb></tscreen>
1247
1248 To get the well known (1,19) within the subject (2,6) we use
1249 <tscreen><verb>
1250 z.1 getGrs 1 (2,6) (1,19)
1251 </verb></tscreen>
1252 and get:
1253 <tscreen><verb>
1254 { 2 numeric 6 subtree
1255    { { 1 numeric 19 string
1256       {Five files of epicenter data arranged by ...} } } }
1257 </verb></tscreen>
1258 <bf/End of example/
1259
1260 <sect1>Explain
1261 <p>
1262 Explain records are retrieved like other records. The method,
1263 <tt>getExplain</tt> is followed by an index and and an optional
1264 Explain record pattern.
1265
1266 The returned record is a canonical representation of the Explain record.
1267 An ASN.1 sequence is represented as a list. Each item in the list
1268 consists of the name of the element, followed by its value if the value
1269 is supplied.
1270
1271 The optional pattern that follows the index after <tt>getExplain</tt>
1272 consists of one or more elements, that is matched against the elements
1273 of the actual record.
1274
1275 <bf/Example/
1276
1277 One of the few targets that support explain is the ATT research server
1278 at <tt>z3950.research.att.com</tt>.
1279
1280 The targetInfo record was returned by the target and it's stored in
1281 position 1 in the result set, <tt>z.1</tt>. To retrieve the whole
1282 record we must use
1283 <tscreen><verb>
1284 z.1 getExplain 1
1285 </verb></tscreen>
1286
1287 and we get in return
1288
1289 <tscreen><verb>
1290 {targetInfo commonInfo {name {Lucent Technologies Research Server}}
1291 recentNews icon {namedResultSets 1} {multipleDBsearch 0}
1292 {maxResultSets 100} {maxResultSize 600000} maxTerms timeoutInterval
1293 {welcomeMessage {strings { {language eng}
1294 {text
1295 {Salutations - this is Lucent Technologies experimental Z39.50 server.
1296 No guarentees, but free and unlimited access!}} } } }
1297 {contactInfo {name {Robert Waldstein}} {description {strings
1298 { {language eng}
1299 {text {Librarian system designer - no legal anythings}} } } }
1300 {address {strings { {language eng} {text {Room 3D-591
1301 600 Mountain Ave
1302 Murray Hill
1303 N.J. USA 07974}} } } } {email wald@lucent.com} {phone {908 582-6171}} }
1304 description nicknames {usageRest {strings { {language eng}
1305 {text {None - as long as nonProfit research}} } } } paymentAddr
1306 {hours {strings { {language eng} {text {Should never be down}} } } }
1307 dbCombinations addresses commonAccessInfo } 
1308 </verb></tscreen>
1309
1310 The <tt>targetInfo</tt> above indicates the the record is really a
1311 <tt>targetInfo</tt> record. The <tt>commonInfo</tt>, which is optional, is
1312 not supplied by this server. The <tt>name</tt>, however is supplied,
1313 with the value <tt>Lucent Technologies Research Server</tt>.
1314
1315 To retrieve the <tt>contactInfo</tt> from the record above we can
1316 extract the element from the record by using Tcl's list manipulation
1317 facilities, for example by doing
1318 <tscreen><verb>
1319 set ti [z.1 getExplain 1]
1320 lindex [lindex $ti 0] 12 
1321 </verb></tscreen>
1322 which will return
1323 <tscreen><verb>
1324 contactInfo {name {Robert Waldstein}} {description {strings
1325 { {language eng}
1326 {text {Librarian system designer - no legal anythings}} }
1327 } } {address {strings { {language eng} {text {Room 3D-591
1328 600 Mountain Ave
1329 Murray Hill
1330 N.J. USA 07974}} } } } {email wald@lucent.com} {phone {908 582-6171}}
1331 </verb></tscreen>
1332
1333 We can also extract almost the same by doing
1334 <tscreen><verb>
1335 z.1 getExplain 1 targetInfo contactInfo
1336 </verb></tscreen>
1337 which will return
1338 <tscreen><verb>
1339 {name {Robert Waldstein}} {description {strings { {language eng}
1340 {text {Librarian system designer - no legal anythings}} } } }
1341 {address {strings { {language eng} {text {Room 3D-591
1342 600 Mountain Ave
1343 Murray Hill
1344 N.J. USA 07974}} } } } {email wald@lucent.com} {phone {908 582-6171}}
1345 </verb></tscreen>
1346
1347 <bf/End of example/
1348
1349 <sect>Scan
1350
1351 <p>
1352 To perform scan, a scan object must be created by the <tt>ir-scan</tt>
1353 command. This command has two arguments -- name of the scan object and
1354 name of the ir object. Basically, the scan object, provides one <tt>scan</tt>
1355 action which sends a scan request to the target. The <tt>action</tt>
1356 is followed by a string describing starting point of the term list. The
1357 format used is a simple subset of the query used in search requests. Only
1358 <tt>@attr</tt> specifications and simple terms are allowed.
1359 The settings that affect the scan are:
1360
1361 <descrip>
1362 <tag><tt>stepSize </tt><em>integer</em></tag>
1363  Step size. Default is 0.
1364 <tag><tt>numberOfTermsRequested </tt><em>integer</em></tag>
1365  Number of terms requested. Default is 20.
1366 <tag><tt>preferredPositionInResponse </tt><em>integer</em></tag>
1367  Preferred position in response. Default is 1.
1368 <tag><tt>databaseNames </tt><em>list</em></tag>
1369  Database names. Note that this setting is not (yet) supported for
1370  the scan object. You must set this for the ir object instead.
1371 <tag><tt>referenceId </tt><em>string</em></tag>
1372  Reference-id. If <em>string</em> is empty no reference-id is used.
1373 <tag><tt>scanResponse </tt><em>list</em></tag>
1374  Scan-response Tcl script. 
1375 <tag><tt>callback </tt><em>list</em></tag>
1376  General response Tcl script. Only used if <tt>scanResponse</tt>
1377  is not specified.
1378  This setting is valid only for the <tt/ir/ object -- not the
1379  <tt/ir-set/ object.
1380 </descrip>
1381
1382 The scan object normally holds one or more scan line entries upon
1383 successful completion. The table below summarizes the settings
1384 that should be used in a response handler.
1385
1386 <descrip>
1387 <tag><tt>scanStatus </tt>returns <em>integer</em></tag>
1388  Scan status. An integer between 0 and 6.
1389 <tag><tt>numberOfTermsReturned </tt>returns <em>integer</em></tag>
1390  Number of terms returned. 
1391 <tag><tt>positionOfTerm </tt>returns <em>integer</em></tag>
1392  An integer describing the position of term.
1393 <tag><tt>scanLine </tt>returns <em>list</em></tag>
1394  This function returns information about a given scan line (entry) at a given
1395  index specified by the integer. The first scan line is numbered zero;
1396  the second 1 and so on. A list is returned by the <tt>scanLine</tt>
1397  setting. The first element is <tt>T</tt> if the scan line
1398  is a normal term and <tt>SD</tt> if the scan line is a surrogate 
1399  diagnostic. In the first case (normal) the scan term is second element 
1400  in the list and the number of occurences is the third element.
1401  In the other case (surrogate diagnostic), the second element
1402  is the diagnostic code, the third a text representation of the error
1403  code and the fourth element is additional information.
1404 <tag><tt>referenceId </tt>returns <em>string</em></tag>
1405  Reference-id of scan response.
1406 </descrip>
1407
1408 <bf/Example/
1409
1410 We will scan for the terms after <tt>science</tt> in the Title index.
1411 We will assume that an ir object called <tt>z-assoc</tt> has already
1412 been created.
1413
1414 <tscreen><verb>
1415    z-assoc callback {scan-response}
1416    ir-scan z-scan z-assoc
1417    z-scan scan "@attr 1=4 science"
1418   
1419    proc scan-response {} {
1420        set status [z-scan status]
1421        if {$status == 0} {
1422            set no [z-scan numberOfTermsReturned]
1423            for {set i 0} {$i < $no} {incr i} {
1424                set line [z-scan scanLine $i]
1425                set type [lindex $line 0]
1426                if {$type == "T"} {
1427                    puts [lindex $line 1]
1428                } elseif {$type == "SD"} {
1429                    puts [lindex $line 1]
1430                }
1431            }
1432        }
1433    }
1434 </verb></tscreen>
1435 <bf/End of examle/
1436
1437 <sect>License
1438
1439 <p>
1440 Copyright &copy; 1995-1999, Index Data.
1441
1442 Permission to use, copy, modify, distribute, and sell this software and
1443 its documentation, in whole or in part, for any purpose, is hereby granted,
1444 provided that:
1445
1446 1. This copyright and permission notice appear in all copies of the
1447 software and its documentation. Notices of copyright or attribution
1448 which appear at the beginning of any file must remain unchanged.
1449
1450 2. The names of Index Data or the individual authors may not be used to
1451 endorse or promote products derived from this software without specific
1452 prior written permission.
1453
1454 THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
1455 EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
1456 WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1457 IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
1458 INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
1459 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
1460 NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
1461 LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
1462 OF THIS SOFTWARE.
1463
1464 <sect>About Index Data
1465
1466 <p>
1467 Index Data is a consulting and software-development enterprise that
1468 specialises in library and information management systems. Our
1469 interests and expertise span a broad range of related fields, and one
1470 of our primary, long-term objectives is the development of a powerful
1471 information management
1472 system with open network interfaces and hypermedia capabilities.
1473
1474 We make this software available free of charge, on a fairly unrestrictive
1475 license; as a service to the networking community, and to further the
1476 development of quality software for open network communication.
1477
1478 We'll be happy to answer questions about the software, and about ourselves
1479 in general.
1480
1481 <tscreen><verb>
1482 Index Data
1483 Ryesgade 3
1484 2200 Copenhagen N
1485 Denmark
1486 </verb></tscreen>
1487 <p>
1488 <tscreen><verb>
1489 Phone: +45 3536 3672
1490 Fax  : +45 3536 0449
1491 Email: info@indexdata.dk
1492 </verb></tscreen>
1493
1494 <sect>References
1495
1496 <p>
1497
1498 <descrip>
1499 <tag>1 IrTcl Homepage</tag>
1500 <htmlurl url="http://www.indexdata.dk/irtcl/"
1501 name="http://www.indexdata.dk/irtcl/">
1502
1503 <tag>2 Ousterhout, John K.:</tag>
1504 Tcl and the Tk Toolkit. Addison-Wesley Company Inc (ISBN
1505 0-201-63337-X). The Tcl/Tk toolkit home page is
1506 <htmlurl url="http://www.scriptics.com"
1507  name="http://www.scriptics.com">.
1508 The primary download area is 
1509 <htmlurl url="http://www.scriptics.com/software/download.html"
1510 name="http://www.scriptics.com/software/download.html">.
1511
1512 <tag>3 Welch, Brent B.:</tag>
1513 Practical Programming in Tcl and Tk. Prentice Hall
1514 (ISBN 0-13-616830-2).
1515
1516 </descrip>
1517
1518 </article>