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 `
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]]' |
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 |
\.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 | " |
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 |
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.