Gri Commands

1: Introduction
2: Simple example
3: Fancy example
4: Running Gri
5: Programming Gri
6: General Issues
7: X-Y Plots
8: Contour Plots
9: Image Plots
10: Examples
11: Handling Data
12: Gri Commands
13: Gri Extras
14: Evolution of Gri
15: Installing Gri
16: Gri Bugs
17: System Tools
18: Acknowledgments
19: License
20: Newsgroup

21: Concept Index

12.27: The `open' Command

Possibilities are:
`open \filename'

`open \filename binary \ [uchar|8bit|int|float|double|16bit]'

`open \filename netCDF'

`open "SYS-CMD |" \ [binary [uchar|8bit|int|float|double|16bit]]'

The first three forms work on data files. Use double-quotes around filenames with punctuation in them (e.g. `open "../data"'). Files may be ascii (the default), binary or -- on systems with the `netCDF' libraries installed -- in the `netCDF' format.

For more information on netCDF format, see `http://www.unidata.ucar.edu/packages/netcdf/index.html' here .

The `SYSTEM-COMMAND' form is used to work on a temporary file created by a system command. An overview of useful system commands is provided elsewhere in this manual see Overview of System Tools.

Several binary file types are allowed. The keywords `uchar', etc, can be used to specify the type of data in the file. If no keyword is given, Gri assumes that images use `unsigned char' (8 bits), columns use `float' (32 bits), and that grids use `float' (32 bits).

In the `SYSTEM-COMMAND' form, the indicated system command is performed, with the output being inserted into a temporary file. Future `read', `close', etc, commands apply to to this temporary file. (The temporary file is automatically deleted by Gri, but if Gri aborts the file will not be deleted, so you should scan `/usr/tmp/' for files that you own.) For example
open "cat a.dat | \.awk. '{$1, $2 * 22}' |"
read columns x y

gets awk to multiply the y column by 22. (Note the use of `\.awk.', a builtin synonym naming the awk program on your system.) The ability to use system commands in `open' statements lets you use familiar system tools like `head', `sed', `awk', `perl', etc, to work on your data. For example, if you store your data in compressed form, and do not wish to have temporary files sitting around, you might wish to do something like
open "zcat myfile.dat.Z | "

Files may be opened across the WWW (world-wide web). Below is a replacement for example1.gri see Simple Example.
open "lynx -dump \
  http://www.phys.ocean.dal.ca/~kelley\
/gri/examples/example1.dat \
  | tail +2 |"
read columns x y
draw curve
draw title "Example 1"
Note: the `tail +2' removes the initial blank line that lynx generates.

For complicated data manipulation, a system tool like `awk' or `perl' is ideal.

Here are a couple of examples.

  1. For example, suppose x and y data are stored in Hour.minutesecond format, e.g. 12.2133 means hour 12, minute 21, second 33. Gri doesn't read HMS format, but gawk can be told to:

    open "cat datafile.HMS |        \
        \.awk. '{                   \
        split($1, hms, \".\");      \
        h = hms[1];                 \
        m = int(hms[2] / 100);      \
        s = hms[2] - 100 * m;       \
        x = h + m / 60 + s / 3600;  \
        split($2, hms, \".\");      \
        h = hms[1];                 \
        m = int(hms[2] / 100);      \
        s = hms[2] - 100 * m;       \
        y = h + m / 60 + s / 3600;  \
        print(x,y)                  \
        }' | "
        read columns x y
    

  2. Suppose we have timeseries data in the form
    Tue_Jul_25_11:07:51 0.62
    Tue_Jul_25_11:22:51 0.59
    Tue_Jul_25_11:37:51 0.56    
    

    (stored in a file called `a.dat' day) and we want a graph of the y-variable (0.62, 0.59, 0.56) versus x-variable, time expressed say as seconds in the day. Then here is how that could be done:
    open "cat a |\
        sed -e 's/_/ /g' -e 's/:/ /g' |\
        awk '{print ($4*3600+$5*60+$6, $7)}' |"
    read columns x y
    draw curve
    
    Note that the actual day information is skipped in this example; seasoned `awk' users could easily fill in the code to handle datasets spanning several days.