Gri Commands
|
12.27: The `
|
`open \filename' |
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" |
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.
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 |
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 |
awk
' users could easily fill in the code to handle
datasets spanning several days.