proc getdata


Welcome     Gallery     Handbook


Manual page for proc_getdata(PL)

proc getdata accesses or defines data for plotting. proc getdata must be executed before any data-based plotting can be done.


Features

Data may be specified literally within the script file, or it may be located in an external file or be the result of an externally executed command.

Conditional selection of data records (select).

Data filtering (filter) for purposes such as combining or rearranging fields, performing calculations, truncating outliers, etc.

Field names may be assigned explicitly (fieldnames or fieldnamerows), or via a data file header line (fieldnameheader). These names can then be used anywhere a data field reference is expected.

Data sets with variable number of fields per row can be accomodated by setting a maximum nfields value.

Data may be located at the end of the script file, to get it out of the way (#intrailer).


Examples

Virtually all of the Gallery examples use #proc getdata.


Acceptable data formats

See dataformat .


Prerequisites

None.


Troubleshooting

Set showresults: yes in order to see the data after it is read and parsed. Especially useful when working with filter.


Variables that are set

The variable NRECORDS will be set to the number of records read, and the variable NFIELDS will be set to the number of fields per record.


Handling error conditions gracefully

If no data records were read, NRECORDS will be set to zero. This may be tested using script code such as this, which generates an image containing the words "No data found" :

 #proc getdata
    ...
 
 #proc endproc
 #if @NRECORDS = 0
   #proc annotate
   location: 3 3
   text: No data found.
 
   #exit
 #endif

Setting variables from within a data file

Data files may contain embedded #set commands to set ploticus variables. This may be a convenient way for title, labels, etc. to be driven by the data file. The syntax is the same as in ploticus scripts:

#set varname = value

varname will be set to value. value may contain embedded spaces or any other character. value may not be a $function(), nor may it contain any other @variables. None of the other script operators, such as #if, are supported in this context.


Mandatory attributes

A data source (either file, pathname, command, or data) must be specified. Default field delimitation method is spacequoted; delim must be set for other types such as tab-delimited or comma-quote delimited.


Attributes

data multiline-text

Literal specification of plotting data. Terminates at first blank (empty) line. Example:

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

file filename

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 standardinput attribute may be used). Example: filename: myfile.dat

pathname filename

Name of a file containing plotting data. The file will be opened directly. Shell variables and metacharacters may not be used.

command shell command line

An external shell command that will produce plot data on its standard output.
Example: command: cat mydat | uniq -c

delim spacequoted | whitespace | comma | tab

The type of delimiting method to be used when parsing the data. spacequoted is the default (space is equivalent to spacequoted). See dataformat for details.
Example: delim: comma

fieldnames namelist

If specified, the names given in namelist may be used in any plotting proc to identify data fields. namelist is a list delimited by spaces and/or commas. Names may include any alphanumeric characters with a maximum length of 38, and are case-insensitive. Field names may not contain embedded spaces or commas.
Example: fieldnames: date group n

fieldnamerows multiline text

Same as fieldnames (see above), except that field names are given one per line. Must be terminated by a blank line. Example:

fieldnamerows:
  id
  type
  age
  sex
  

fieldnameheader yes | no

Allows field names to be embedded in the input data. If yes, the first non-comment line in the data is expected to hold a list of field names. See the fieldnames attribute above for more information about field names. If the data attribute is used, use of fieldnames is more efficent than fieldnameheader.

nfields n

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.

standardinput yes | no

If yes, data is read from the standard input.

#intrailer

Indicates that a data attribute will be given in a #proc trailer, at the end of the script file. See EXAMPLES, below.

commentchar string

A character or group of characters that is used to signify a comment in the data file. Commented lines will be skipped. Default is //. Example: commentchar: #

showresults yes | no

If yes, the results, after selecting and/or filtering, are written to the diagnostic file, which may be useful in debugging, etc.

rotate yes | no

Allows data to be given all in one row, even when plotting proc expects one record per instance (which most do). Only applicable if your data set has one row. (There still must be a blank line following the data attribute.) To rotate more than one row, use proc processdata.
Example: see bars1

select conditional expression

This allows data records to be selected for inclusion based upon a selection expression. Incoming data fields are referenced by number, using a double at-sign (@@) prefix. select cannot be used along with the data attribute. Hint: use the showresults attribute when debugging.
Example: select: @@3 = g
This would select all data records having 3rd field equal to g.

filter multiline text

An embedded script which processes incoming data records. 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.

The embedded script will be applied once to every incoming data record. The script should produce some "output"; generally the last statement is a ##print. The output must use the same delimitation method as the input. The script uses the same syntax as the greater ploticus script, except that:

  • directives must begin with two pound signs (##) instead of one
  • local variables begin with two at signs (@@) instead of one
  • fields on the incoming data record are accessed like this: @@1 for the first field, @@2 for the second, etc. If you are using field names, these may be used as well, eg: @@score.
  • the only directives that may be used are ##set, ##if, ##elseif, ##else, ##print, ##call, and ##exit

Other things worth noting:

  • the filter script is terminated using a blank line.
  • use the showresults attribute when debugging.
  • if filter is used along with select, the select is applied first.
  • filter cannot be used along with the data attribute.
  • filter can only access fields from one data record at a time.
  • variables from the ploticus script may be referenced within the filter script (use one at-sign @). Evaluation occurs before the filter script executes.
  • 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.
  • 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.
     filter:
          ##if @@2 = M || @@3 = M
            ##exit
          ##endif
          ##set DIFF = $daysdiff(@@3,@@2)
          ##print @@1 @@DIFF
    
  • There are several more filter examples in the FAQ


More examples

Data specification may be located at the end of the script file by using #intrailer and #proc trailer. 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:

 #proc getdata
 #intrailer

other #procs, etc.

 #proc trailer
 Data:	0.3 0.5 2.3
	3.5 9.4 1.4
	..etc..
end of file





data display engine  
Copyright Steve Grubb


Markup created by unroff 1.0,    January 11, 2002.