File: getdata

package info (click to toggle)
ploticus-doc 2.33-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,392 kB
  • ctags: 169
  • sloc: pascal: 469; makefile: 63; sh: 11
file content (723 lines) | stat: -rw-r--r-- 15,426 bytes parent folder | download
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
.ig >>
<STYLE TYPE="text/css">
<!--
        A:link{text-decoration:none}
        A:visited{text-decoration:none}
        A:active{text-decoration:none}
        OL,UL,P,BODY,TD,TR,TH,FORM { font-family: arial,helvetica,sans-serif;; font-size:small; color: #333333; }

        H1 { font-size: x-large; font-family: arial,helvetica,sans-serif; }
        H2 { font-size: large; font-family: arial,helvetica,sans-serif; }
        H3 { font-size: medium; font-family: arial,helvetica,sans-serif; }
        H4 { font-size: small; font-family: arial,helvetica,sans-serif; }
-->
</STYLE>
<title>ploticus: proc getdata</title>
<body bgcolor=D0D0EE vlink=0000FF>
<br>
<br>
<center>
<table cellpadding=2 bgcolor=FFFFFF width=550><tr>
<td>
  <table cellpadding=2 width=550><tr>
  <td><br><h2>proc getdata</h2></td>
  <td align=right>
  <small>
  <a href="../doc/welcome.html"><img src="../doc/ploticus.gif" border=0></a><br>
  Version 2.33 Jun'06
     </small><br><a href="../doc/scripthome.html">Scripts</a>
  <td></tr></table>
</td></tr>
<td>
<br>
<br>
.>>

.TH proc_getdata PL "02-JUN-2006   PL ploticus.sourceforge.net"
 
.LP
\fBproc getdata\fR gets data for plotting,
and must be invoked before plotting any data.
Data may be read from files, from commands, or specified directly, and various 
.ig >>
<a href="dataformat.html">
.>>
\0input data formats
.ig >>
</a>
.>>
are supported.
The data which are read become the 
.ig >>
<a href="dataformat.html#currentds">
.>>
\0current data set
.ig >>
</a>
.>>
that subsequent plotting procs will access,
and replace any data that were read in (or generated) previously.
.LP
\fBproc getdata\fR will set the variable \fBNRECORDS\fR to the number of data rows gotten.
The variable \fBNFIELDS\fR will be set to the number of fields per data row.

.ig >>
<br><br>
.>>
.SH See also
.ig >>
<a href="dataformat.html">
.>>
\0Discussion of input data formats and parsing rules
.ig >>
</a>
.>>
.LP
.ig >>
<a href="dataformat.html#currentds">
.>>
\0Discussion of working with multiple data sets
.ig >>
</a>
.>>

.ig >>
<br><br><br>
.>>
.SH Attributes
Default field delimitation method is \fCspacequoted\fR; \fCdelim\fR must be set for other
types such as tab-delimited or comma-quote delimited.


.ig >>
<br><br><br>
.>>

.SH Specifying a data source
One (and only one) of the following data sources \fBmust\fR be specified:

.LP
\fBfile\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fIfilename\fR
.IP \0
Shell-expandable name of a file containing plotting data.
This name will be used along with cat(1) in a shell command, thus
exported shell variables and metacharacters may be part of the name.
A dash (-) may be used if data is to be read from the standard input,
(or the \fCstandardinput\fR attribute may be used).
.IP
Security concern: user-supplied values, such as CGI user variables, should not be used to build \fCfilename\fR. 
.IP
On win32 platforms, or when operating in
.ig >>
<a href="cgi.html">
.>>
\0direct CGI mode
.ig >>
</a>
.>>
(2.31-08+)
\fCfilename\fR automatically maps to \fCpathname\fR .
.IP
Example: \fCfilename: myfile.dat\fR

.ig >>
<br><br>
.>>

.LP
\fBpathname\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fIfilename\fR
.IP \0
Name of a file containing plotting data.
The file will be opened directly.
.IP
Security concern: user-supplied values, such as CGI user variables, should not be used to build the \fCpathname\fR, 
unless proper measures are taken to detect and remove the \fC../\fR construct (used as a hack 
to see higher levels of the file system).

.ig >>
<br><br>
.>>

.LP
\fBdata\fR 
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="attributetypes.html#text">
.>>
\0multiline-text
.ig >>
</a>
.>>
.IP \0
Literal specification of plotting data.  Terminates at
first blank (empty) line.  Data may include a field name header.
Example:
.nf
.ft C
data:   "Case 1"   0   4   4.1   
        "Case 2"   1   5   4.4  
        "Case 3"   2   2   4.0 
        "Case 4"   3   9   4.8

.fi
.ig >>
<br><br>
.>>

.LP
\fBcommand\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fIshell command line\fR
.IP \0
An external shell command that will produce plot data on its standard output.
.IP
Security concern: user-supplied values, such as CGI user variables, should not be used to build the shell command.
If this must be done, use \fC#shell / #endshell\fR along with \fCdata:\fR, which provides some protection against
shell metacharacter hacks.
.IP
Example: \fCcommand: cat mydat | uniq -c\fR

.ig >>
<br><br>
.>>

.LP
\fBcommandmr\fR
.ig >>
&nbsp; &nbsp;
.>>
\fImulti-row shell command\fR
.IP \0
Same as \fCcommand\fR but shell command can occupy multiple rows, and is is terminated by a blank line.  
Command can be up to ~1000 characters long.
.IP
Security concern: user-supplied values, such as CGI user variables, should not be used to build the shell command.
If this must be done, use #shell / #endshell along with \fCdata:\fR, which provides some protection against
shell metacharacter hacks.
.IP
You can overlay flow-of-control directives as in this example:
.nf
 \0 commandmr:  cat foo.dat |
 \0             process_step1 |
 \0     #if @sortmode = 1
 \0             sort +2 -3
 \0     #else
 \0             cat -
 \0     #endif
 \0
.fi

.ig >>
<br><br>
.>>

.LP
\fBstandardinput\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fCyes\fR | \fCno\fR
.IP \0
If \fCyes\fR, data stream is read from the ploticus standard input.


.ig >>
<br><br>
.>>

.LP
\fBsql\fR
.ig >>
&nbsp; &nbsp;
.>>
\fIsql command\fR
.IP \0
Submit the given sql command and capture the results as tabular data,
using sql result column names as the field names.
This is currently available only for builds related to the
.ig >>
<a href="http://quisp.sourceforge.net">
.>>
\0QUISP/SHSQL
.ig >>
</a>
.>>
package.

.ig >>
<br><br>
.>>

.LP
\fBsqlmr\fR
.ig >>
&nbsp; &nbsp;
.>>
\fImulti-row sql command\fR
.IP \0
Same as \fCsql\fR but SQL command can occupy multiple rows, and is is terminated by a blank line.
Command can be up to ~1000 characters long.
You can overlay flow-of-control directives as in this example:
.nf
 \0 sqlmr: select id, lastname, firstname, balance
 \0        from accounts
 \0   #if @mode = 1
 \0        where acct_type = g
 \0   #endif
 \0     
.fi
.LP
\fB#intrailer\fR
.IP \0
Indicates that a \fCdata\fR attribute
will be given in a #proc trailer, at the end of the script file.
See EXAMPLES, below.


.ig >>
<br><br><br>
.>>

.SH Characteristics of the data stream
.LP
\fBdelim\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fCspacequoted\fR | \fCwhitespace\fR | \fCcomma\fR | \fCtab\fR
.IP \0
The type of delimiting method to be used when 
parsing the data.  \fCspacequoted\fR is the default (\fCspace\fR is
equivalent to \fCspacequoted\fR).  See
.ig >>
<a href="dataformat.html">
.>>
\0dataformat
.ig >>
</a>
.>>
for details.
.br
Example: \fCdelim: comma\fR

.ig >>
<br><br>
.>>

.LP
\fBnfields\fR  
.ig >>
&nbsp; &nbsp;
.>>
\fIn\fR
.IP \0
If specified, this sets the expected number of fields per record.
If a data row has more than the expected number of fields, extra fields are silently ignored. 
If a data row has less than the expected number of fields, blank fields are silently added.
This is applied after any \fCfilter\fR processing.
If not specified, the first non-comment non-header row encountered will set the expected number of fields.

.ig >>
<br><br>
.>>

.LP
\fBcommentchar\fR 
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="attributetypes.html#string">
.>>
\0string
.ig >>
</a>
.>>
.IP \0
A character or group of characters that is used to signify a comment in the data file.
Commented lines will be skipped.  Default is \fC//\fR.
Example: \fCcommentchar: #\fR



.ig >>
<br><br><br>
.>>

.SH Setting field names

.LP
\fBfieldnameheader\fR  
.ig >>
&nbsp; &nbsp;
.>>
\fCyes\fR | \fCno\fR
.IP \0
Allows field names to be embedded in the input data.
If \fCyes\fR, the first non-comment line in the data is expected to
contain field names.  This line is not considered part of the data.
The field name header should be delimited like the rest of the data.
Field names may not contain embedded white space, commas, or quote characters
but (2.30+) there is a way to encode spaces and commas... see
.ig >>
<a href="settings.html#encodenames">
.>>
\0proc settings encodenames.
.ig >>
</a>
.>>


.ig >>
<br><br>
.>>
 
.LP
\fBfieldnames\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fInamelist\fR
.IP \0
Specify field names for input data fields.
\fInamelist\fR is a list delimited by spaces and/or commas.
Names may include any alphanumeric characters with a maximum length of 48, and are case-insensitive.
Field names may not contain embedded spaces or commas, 
but (2.30+) you can encode them... see
.ig >>
<a href="settings.html#encodenames">
.>>
\0proc settings encodenames.
.ig >>
</a>
.>>
Note: if you are using a \fCfilter\fR (see below) you may want to use \fCpf_fieldnames\fR
(see below) to name the result fields.

.br
Example: \fCfieldnames: date group n\fR

.ig >>
<br><br>
.>>

.LP
\fBfieldnamerows\fR 
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="attributetypes.html#text">
.>>
\0multiline text
.ig >>
</a>
.>>
.IP \0
Same as \fCfieldnames\fR (see above), except that field names are given one per line.
Must be terminated by a blank line.
Example: 
.br
.nf
fieldnamerows:
  id
  type
  age
  sex
.fi


.LP
\fBpf_fieldnames\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fInamelist\fR
.IP \0
Assign new field names to \fCfilter\fR result.
See \fCfilter\fR attribute described below.
Useful when the filter result has a different logical record format than the input.
See also \fCfieldnames\fR above.
.br
Example: \fCpf_fieldnames: date z sum1 sum2\fR

.ig >>
<br><br><br>
.>>

.SH Development & debugging
.LP
\fBshowresults\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fCyes\fR | \fCno\fR
.IP \0
If \fCyes\fR, the results, after any selecting and/or filtering, are
written to the diagnostic file,
which may be useful in debugging, etc.


.ig >>
<br><br><br>
.>>

.SH Selecting and manipulating input rows

.LP
\fBselect\fR 
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="select.html">
.>>
\0select expression
.ig >>
</a>
.>>
.IP \0
This allows certain data records to be selected for inclusion based
upon a 
.ig >>
<a href="select.html">
.>>
\0selection expression.
.ig >>
</a>
.>>
Incoming data fields are referenced by number,
using a double at-sign (\fC@@\fR) prefix.  
Hint: use the \fCshowresults\fR attribute when debugging.
.br
Example: \fCselect: @@3 = g\fR
.br
This would select all data records having 3rd field equal to \fCg\fR.

.ig >>
<br><br>
.>>

.LP
\fBrotate\fR  
.ig >>
&nbsp; &nbsp;
.>>
\fCyes\fR | \fCno\fR
.IP \0
Allows data to be given all in one row, even when plotting proc
expects one record per instance (which most do).
Only applicable data set has one row.
To rotate more than one row, use 
.ig >>
<a href="processdata.html">
.>>
\0proc processdata
.ig >>
</a>
.>>
with \fCaction: rotate\fR.

.ig >>
<br><br>
.>>

.LP
\fBfilter\fR 
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="attributetypes.html#text">
.>>
\0multiline text
.ig >>
</a>
.>>
.IP \0
An embedded script which allows flexible processing to be applied to 
incoming data records one at a time.
Typical uses are for
concatenating or splitting fields, doing on-the-fly date conversions,
or generating derived fields such as the sum of several fields or the difference 
between two fields.
.br
.br
.IP \0
The embedded script will be applied once to every incoming data record.
The script should produce some "output"; generally the last statement is a
\fB##print\fR.  
The output must use the same delimitation method as the input.
The output may have a different logical record format than the input.
If you are using field names, 
the \fCpf_fieldnames\fR attribute (see above) may be used to name the
filter result fields when result record format differs from that of the input.
.IP \0
The script uses the same syntax as the greater ploticus script, except that:
.RS
.IP \(bu
directives must begin with two pound signs (\fC##\fR) instead of one
.IP \(bu
local variables begin with two at signs (\fC@@\fR) instead of one
.IP \(bu
fields on the incoming data record are accessed like this: \fC@@1\fR for
the first field, \fC@@2\fR for the second, etc.  If you are using field
names, these may be used as well, eg: \fC@@score\fR.
.IP \(bu
the only directives that may be used are 
\fB##set\fR, \fB##if\fR, \fB##elseif\fR, \fB##else\fR, \fB##print\fR, \fB##call\fR,
and \fB##exit\fR
.RE
.IP \0
Other things worth noting:
.RS
.IP \(bu
the filter script is terminated using a blank line.
.IP \(bu
use the \fCshowresults\fR attribute when debugging.
.IP \(bu
if \fCfilter\fR is used along with \fBselect\fR, the \fCselect\fR is applied first.  
.IP \(bu 
\fCfilter\fR cannot be used on data specified using the \fCdata\fR attribute.
.IP \(bu
\fCfilter\fR can only access fields from one data record at a time.
.IP \(bu
variables from the ploticus script may be referenced within
the \fCfilter\fR script (use one at-sign \fC@\fR).
Evaluation occurs before the filter script executes.
.IP \(bu
ploticus script #if/#else statements (single pound sign)
may be used to selectively execute portions of the filter script.
Interpretation occurs before the filter script executes.
.IP 
Example: This filters out data records
having field 2 or field 3 equal to M.  It then
calulates the difference in days between two dates
and puts this difference in the variable DIFF.
Finally it "prints" incoming field 1 along with DIFF.
Thus the result of this #proc getdata
will have be data records having two fields.
.nf
.ft C
\0filter:
\0     ##if @@2 = M || @@3 = M
\0       ##exit
\0     ##endif
\0     ##set DIFF = $daysdiff(@@3,@@2)
\0     ##print @@1 @@DIFF
.fi
.ft R
.IP 
There are several more \fCfilter\fR examples in the 
.ig >>
<a href="faq.html#filter">
.>>
\0FAQ
.ig >>
</a>
.>>

.ig >>
<br><br><br>
.>>

.SH More examples
.LP
Data specification may be located at the end of the script file
by using \fB#intrailer\fR and \fB#proc trailer\fR.  This may be
useful in "getting the data out of the way", or with automated building
of script files.
Here is how this is done:
.nf
.ft C
\0#proc getdata
\0#intrailer

\fIother #procs, etc.\fR

\0#proc trailer
\0Data:	0.3 0.5 2.3
	3.5 9.4 1.4
	\fI..etc..\fR
\fIend of file\fR

.ig >>
<br><br>
.>>

.SH Variables that are set by proc getdata
.LP
\fBNRECORDS\fR = the number of data rows gotten
.LP
\fBNFIELDS\fR = the number of fields per record

.ig >>
<br><br><br>
.>>

.SH Hints
.LP
It is possible to
.ig >>
<a href="dataformat.html#set">
.>>
\0set working variables from within the data file.
.ig >>
</a>
.>>
.LP
During debugging, set \fCshowresults: yes\fR in order to see the data after it is read and parsed.
Especially useful when working with \fCfilter\fR.
.LP
In dynamic content environments it's good to gracefully handle the 
situation of an empty data file or command that produced no output.  Example:
.IP \0
.nf
\0#proc getdata
\0   ...
\0
\0#proc endproc
\0#if @NRECORDS = 0
\0  #proc annotate
\0  location: 3 3
\0  text: No data found.
\0
\0  #exit
\0#endif
.fi



.ig >>
<br>
<br>
</td></tr>
<td align=right>
<a href="../doc/welcome.html">
<img src="../doc/ploticus.gif" border=0></a><br><small>data display engine &nbsp; <br>
<a href="../doc/Copyright.html">Copyright Steve Grubb</a>
<br>
<br>
<center>
<img src="../gallery/all.gif"> 
</center>
</td></tr>
</table>
<br>
<center>
Ploticus is hosted at http://ploticus.sourceforge.net <br>
<img src="http://sourceforge.net/sflogo.php?group_id=38453" width="88" height="31" border="0" alt="SourceForge Logo">
</center>
.>>