navigation map

Chapters:
  1: Introduction
  2: Simple example
  3: Invocation
  4: Finer Control
  5: X-Y Plots
  6: Contour Plots
  7: Image Plots
  8: Examples
  9: Gri Commands
  10: Programming
  11: Environment
  12: Emacs Mode
  13: History
  14: Installation
  15: Gri Bugs
  16: Test Suite
  17: Gri in Press
  18: Acknowledgments
  19: License

Indices:
  Concepts
  Commands
  Variables
index.html#Top HandlingData.html#HandlingData Gri: handling data Gri: ignoring columns index.html#Top Gri: ignoring columns

8.12.1: Handling headers

Case 1 -- known number of header lines. This is easy. If you know that the file has, say, 10 header lines, you can just do this:


open file
skip 10
read columns x y
...

Case 2 -- header itself indicates number of header lines. Quite often the first line of a file will indicate the number of header lines. For example, suppose the first line contains a single number, indicating the number of header lines to follow:


open file
read .skip.
skip .skip.
read columns x y
...

Case 3 -- header lines marked by a textual key. Sometimes header lines are indicated by a textual key, for example, the characters `HEADER' at the start of the line in the file. The easy way to skip such a header is to use a system command. Depending on your familiarity with the operating system (here presumed to be Unix), you might choose to use Grep, Awk, or Perl. Here are examples:


open "grep -v '^HEADER' file |"

For more on the `|' mechanism, see see Open. The Grep command prints lines which do not match the indicated string (because of the `-v' switch), and the `^' character stands for the start of the line (see Grep). Thus all lines with the key word at the start of the line are skiped.

Case 4 -- reading and using information in header. Consider a dataset in which the first line gives the time of observation, followed by a list of observations. This might be, for example, an indication of the data taken from a weather balloon released at a particular time from a fixed location, with the main data being air temperature as a function of elevation of the balloon. The time indication might be, for instance, the hour number. One might need to know the time to print a label on the diagram. You could do that by:


open file
read .time.
read columns x y
draw curve
sprintf \label "Time of observation is %f hour" .time.
draw title "\label"

where the `sprintf' command has been used to change the numerical time indication into a synonym that can be inserted into a quoted string for drawing the title of the diagram (see Sprintf). Here the time has been assumed to be a decimal hour. You might also have three numbers on the line, perhaps a day, an hour and a minute. Then you could do something like


open file
read .d. .h. .m.
read columns x y
draw curve
sprintf \label "Obs. %.0f:%.0f, day %.0f" .h. .m. .d.
draw title "\label"

Here the `%.0f' code is used to ensure no numbers will be written after the decimal point. Naturally, you could convert this to a decimal day, by e.g.


...
.dday. = {rpn .day. .hour. 24 / .min. 24 / 60 /}
sprintf \label "Decimal day is %.4f" .dday.
...

(Some of you might know how many minutes in a day, but I'm silly so I kept the extra mathematical step -- nothing is lost by being straightforward!)

navigation map