summaryrefslogtreecommitdiffstats
path: root/funtools/doc/view.html
blob: 6f1faa811133b691d89facb8fff85fba76d27b9d (plain)
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
<!-- =defdoc funview funview n -->
<HTML>
<HEAD>
<TITLE>Database View Support for Tables</TITLE>
</HEAD>
<BODY>

<!-- =section funview NAME -->
<H2><A NAME="funview">Funview: Database View Support for Tables</A></H2>

<!-- =section funview SYNOPSIS -->
<H2>Summary</H2>
<P>
This document contains a summary of the options for utilizing
database-inspired Views of tables.

<!-- =section funview DESCRIPTION -->
<H2>Description</H2>

<H2>Database Views</H2>
<P>
In database parlance, a <B>View</B> defines a "virtual table", i.e.,
a description of row and/or column selection filters (but with no
permanent storage space allocated). When used in place of a table, a
View selects the specified rows and/or columns from one or more real
tables. Views enable you to see complicated data tables in a more
convenient format. They also can be used as a security mechanism, by
restricting user access to specific columns and/or rows.  [See:
<pre>
http://www.cs.unibo.it/~ciaccia/COURSES/RESOURCES/SQLTutorial/sqlch5.htm
</pre>
for a good discussion of SQL Views.]

<P>
Funtools supports an expanded notion of Views for all tabular data
(FITS tables, raw binary tables, and ASCII column files). Funtools
Views allow you to pre-set values for the filter specification, the
columns to activate, and display format (though the latter is for
fundisp only).  Setting the filter and column activation values
provides functionality equivalent to that of a classical database
View, while the ability to set the format is similar to classical
report writing capabilities.

<H2>Funtools View Attributes</H2>
<P>
A Funtools View is a text file containing one or more of the following
columns:
<PRE>
  column         description
  ------         -----------------------------
  view           name of view
  file           data file name or template
  filter         filter specification
  columns        columns to activate
  format         fundisp format specification
</PRE> 
All of the attribute columns are optional, including
the <B>view</B> name itself. This means that a View can be named or
unnamed. Unnamed Views can refer to a specific file or a template of
files (obviously if neither the view or the file column is specified,
the input View specification will never be used). You can specify any
combination of filter, column, and format parameters. (It also is
possible to apply file-specific View to other files; see the discussion
on <B>View Lists</B> below). Each column has a size limit of 1024 characters.

<P>
For example, consider the following View file:
<PRE>
  view    file                    format  columns       filter
  ----    ----------------------  ------  ------------  -------
  x3      ${HOME}/data/snr.ev     I=%4d   x y pi pha    cir 512 512 .1 
  x2      ${HOME}/data/snr.ev             x y pi pha    cir 512 512 .1 
  x1      ${HOME}/data/snr.ev                           cir 512 512 .1 
  x1a     ${HOME}/data/snr.ev             x y pi pha
  x0      ${HOME}/data/snr.ev
  xf                              I=%4d
  xc                                      x y pi pha
  xr                                                    cir 512 512 .1
          *.ev                            x y pi pha
          *.fit                           x y dx dy     cir 400 400  3
          *.fits                  I=%3d   x y dx dy     cir 400 400  3
</PRE>
This database example is in rdb format, i.e. using tab delimiters and
permitting null values. Any valid ASCII table format is acceptable,
but if you use a format that does not permit null values, it will be
necessary to quote the null strings.

<P>
The first five entries (x3, x2, x1, x1a, x0) are named entries defining
default values specifically for the snr.ev data file. Typically, you
would use these Views by specifying View name, and the corresponding
file, filter, column, and format values would be used. Note that the x0
View is essentially an alias for the pathname of this file.

<P>
The next three entries define defaults that can be applied to any
file.  You typically would use these View names in conjunction with
a specific file name (see <B>View Lists</B> below) so that the associated
parameter(s) were applied to that file.

<P>
The last three entry in the database define unnamed Views that
pertains to all files ending with the specified templates. In these
cases, any View that specifies a file name matching the file template
would be processed with the associated parameter attributes.

<H2>Invoking a Funtools View (in Place of an Input File)</H2>
<P>
To use a Funtools View, you simply pre-pend the "v:" prefix to a View name or
a file name where an input file name usually is specified. For example:
<PRE>
  fundisp v:x3
</PRE>
specifies that the View named x3 (with its file name and associated
parameters) is processed as the input file to fundisp. Using the
example database, above, this is equivalent to:
<PRE>
  fundisp  -f "I=%4d" ${HOME}/data/snr.ev'[cir 512 512 .1]'  "x y pi pha"
</PRE>
That is, the format is used with fundisp's -f (format) switch, while the
filename and extension are composed of the x3 View's filename and
region filter.

<P>
Similarly, executing a command such as:
<PRE>
  fundisp v:foo.fit
</PRE>
will match the unnamed View associated with the template "*.fit".
This is equivalent to executing:
<PRE>
  fundisp foo.fit'[cir 400 400 3]' "x y dx dy"
</PRE>
Of course, if you omit the "v:" prefix, then no View processing takes place:
<PRE>
  fundisp foo.fit    # process foo.fit without any View parameters
  fundisp x3         # error (assuming there is no file named x3)
</PRE>

<H2>Basic View Matching Rules</H2>

<P>
When a "v:" prefix is recognized, Funtools searches for a View database
file in the following order:
<PRE>
  location             description
  ------------         ------------------------------------
  FUN_VIEWFILE         environment variable (any file name)
  ./.funtools.vu       hidden file, default name
  $HOME/.funtools.vu   hidden file, default name
</PRE>
The first View database file located is used to construct a new
filename, as well as an activation column specification and a format
specification. The following rules are used:

<P>
1. An attempt is made to match the input name (i.e., the part of the
input View after the "v:" prefix) against the <B>view</B> column value
(if present) of each row in the database. If a match is found, the
values of all non-blank columns are saved for later use.  Also note
that the first match terminates the search: i.e., <B>the order of the
database rows matters</B>.

<P>
2. If no <B>view</B> match is made, an attempt is made to match the input
name against the <B>file</B> column value (if present). Matching is
performed on the full pathname of both the input name and the
database file name, and on the non-directory (root) part of these
files. This means that the root specification:
<PRE>
  fundisp v:snr.ev
</PRE>
will match a row in the database that has a full pathname in the file,
allowing you to use a <B>file</B>-matched View without having to
specify the full pathname. In this example, the "v:snr.ev" View
specification will match the first row (v:x3) in the database:
<PRE>
  x3   ${HOME}/data/snr.ev     I=%4d   x y pi pha    cir 512 512 .1 
</PRE>
even though the row contains a fully qualified pathname as the file
value. Once again, values of all non-blank columns are saved, and the
first match terminates the search.

<P>
3. If neither a <B>view</B> or a <B>view</B> match has been found,
then a simple template match is attempted against the <B>view</B>
values. Template matching supports a simplified version of file
globbing (not a regular expression), with support for a single "*"
(all characters), "?" (single character), or "[...]" (range) specification.

<P>
4. If no template match was found on the <B>view</B> column, then a
simple template match is attempted against the <B>file</B> columns.

<P>
5. If no match is found, then the filename (minus the "v:" prefix) is 
returned.

<H2>More on View Matching Rules: Single vs. Multiple Matches </H2>

The matching rules described above stop after the first match,
regardless of whether that match provides values for all three
parameters (filter, columns, and format). In cases where a <B>view</B>
or <B>file</B> match does not provide all three values, it is possible
that a template match might do so. With regard to the example View
database above, the x1 View provides only a filter, while omitting
both the format and columns values. But note that the final rows in
the database could provide the values via a template match on the
filename. This sort of multiple matching is especially valuable in
order to provide "global" values to several Views.

<P>
Obviously, multiple matching might not be wanted in every
case. Therefore, we support both multiple matching and single matching
according to the value of the FUN_VIEWMATCH environment variable.  If
the FUN_VIEWMATCH environment variable exists and if its value begins
with "s", then a single match is used and missing parameters are not
filled in with subsequent template matches on the file name. That is,
matching rules above are followed exactly as explained above.  If the
value of this environment variable begins with "m" (or does not exist),
then multiple matches are used to try to fill in missing parameters.
In this case, template matching always takes place and missing values are
taken from these template matches.

<P>
Thus, in the example above, the View specification:
<PRE>
  fundisp v:x1
</PRE>
will take the file name and filter value from the x1 View:
<PRE>
  x1      ${HOME}/data/snr.ev                           cir 512 512 .1 
</PRE>
The column value then will be taken from the "*.ev" file template match
against the x1 file name:
<PRE>
          *.ev                            x y pi pha
</PRE>
Note once again that order is important: missing values are taken in the
order in which the template matches are processed.

<H2>View Lists: Applying a View to Any File</H2>

<P>
It is possible to apply a named View, or even several Views, to any
data file by appending a <B>viewlist</B> immediately after the standard "v:"
prefix. A viewlist takes the form:
<PRE>
  :v1,v2,...vn:
</PRE>
where v1, v2, etc. are named Views. The two ":" colon characters surrounding
the list are required. Thus, the syntax for applying a viewlist to a file is:
<PRE>
  v::view1,view2,...viewn:filename
</PRE>
Note that the name after the last ":" is assumed to be a file; it is
not permissible (or sensible) to use a View name.

<P>
For example, the View specification:
<PRE>
  fundisp v::x2:foo
</PRE>
applies the x2 View to the file foo (even if there is a View named foo)
and (in using our example database) is equivalent to:
<PRE>
  ./fundisp foo'[cir 512 512 .1] "x y pi pha"
</PRE>
The same command can be effected using a list of Views:
<PRE>
  fundisp v::x1,x1a:foo
</PRE>

<P>
What happens if a viewlist is used and the file also matches a
template? Consider, for example, this View specification:
<PRE>
  fundisp v::x2:foo.fit
</PRE>
Here, the x2 View will supply filter and column values, while the
template *.fit can also supply (different) filter and column
values. In this case, the explicitly specified Views of the viewlist
trump the matched view values.

<P>
On the other hand, if a file template match can supply a View value
that is not supplied by the viewlist, then that value will be taken
from the file template match. For example:
<PRE>
  fundisp v::x2:foo.fits
</PRE>
does not explicitly supply a format value, but the file match on *.fits
can and does. You can avoid supplying missing values using file template
matching by replacing the first ":" with a "-" in a viewlist
specification:
<PRE>
  fundisp v:-x2:foo.fits
</PRE>
The use of ":+" to explicitly allow file template matching is also
supported, but is the same as the default case. Note that the nuances
of viewlist support are subject to change as our experience and
understanding grow.

<H2>Overriding Values Associated with a View</H2>

<P>
To override values associated with a View, simply supply the override
values in the correct place on the command line. Thus, given
the example database described above, the command:
<PRE>
  fundisp v:x3
</PRE>
specifies that the View named x3, along with its file name and
associated parameters, be processed as the input file to fundisp in
this way:
<PRE>
  fundisp  -f "I=%4d" ${HOME}/data/snr.ev'[cir 512 512 .1]'  "x y pi pha"
</PRE>
To override one or more of these values, simply specify a new value
for the format, filter, or columns.  For example, if your input View file
contains a filter, then the View will use that filter as an override
of the View filter:
<PRE>
  fundisp v:x3'[cir 400 400 3]'
</PRE>
will use the columns and format of the x3 View but not the x3 filter. Further
examples are:
<PRE>
  fundisp v:x3 "x y dx dy"    # activate a different set of columns
  fundisp -f "I=%3d" v:x3     # use a different format statement
</PRE>

<P>
Note that extension names, extension index values, and other
non-filter specifications <B>do not</B> override the View
filter. Thus:
<PRE>
  fundisp v:foo.fit[3]
</PRE>
will still use the filter associated with the .fit template (see above), since
the "3" is an extension index, not a filter.

<H2>Environment Variables</H2>

The following environment variables are used by Funtools Views:
<DL>
<DT><B>FUN_VIEWNAME</B>
<DD> The <B>FUN_VIEWNAME</B> environment variable specifies the
name and location of the View database file. If not present, the
files ./.funtools.vu and $HOME/.funtools.vu are searched for, in
that order.

<DT><B>FUN_VIEWMATCH</B>
<DD> The <B>FUN_VIEWMATCH</B> environment variable specifies whether a
single match or multiple match algorithm is used to locate parameter
values. If the value of this environment variable begins with "s",
then a single match is used and missing parameters are not filled in
with subsequent template matches on the file name. If the value begins
with "m", then multiple matches are used to try to fill in missing 
parameters. The default is to use multiple matches.
</DL>

<H2>Restrictions and Problems</H2>

Support for overriding a filter (while not overriding extension names,
extension indexes, etc.) requires that we can sense the presence of a
filter in a bracket specification. It is unclear yet whether our
algorithm is perfect.

<P>
<A HREF="./help.html">Go to Funtools Help Index</A>

<H5>Last updated: August 3, 2007</H5>

</BODY>
</HTML>