General Issues
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
|
6.5: Interaction Between Gri and Operating System
6.5.1: Using the OS from within Gri
Gri uses the operating system internally for things like paging through
help information.
It also gives access to the operating system from within a gri program,
with the `system ' and `open ' commands, and with the back-tic
unix notation. (Note On unix systems, `sh ' is normally
used, to get the C shell, write `system csh ... ', etc.)
The operating system may be called within Gri commands, using a
syntax borrowed from the `Bash ' unix shell. After substituting
synonyms in the commandline, Gri scans for dollar-parenthesis blocks
(e.g. `\$(system-command) ', replacing them with the textual result
of sending the indicated system-command to the OS. The replacements are
done from left to right in the commandline, starting at the deepest
nesting level.
Often the dollar-parentheis syntax is used in title commands, to
indicate the full pathname of the Gri commandfile, e.g.
draw title "\$(pwd)/\.command_file."
|
In assignment to synonyms, expansion of dollar-parenthesis is not done.
Thus the operating system is called twice on the second line below, and
not at all on the first line; to see this, run it as `gri -s8 -t '.
\dir = "\$(echo $MY_DIR)"
show "\$(head -1 \dir/MY_FILE)"
|
Syntax Note Dollar-parenthesis blocks must be prefixed with
backslash to avoid confusion with math expressions within strings, for
example to avoid breaking `draw label "$(x,y)$" at 3 3 cm '. This
is an example of how TeX notation and unix shell notation collide.
Example It is a good idea to employ unix environment variables to name
directories containing data, so that Gri scripts will work unchanged
even if the data are moved (so long as the environment variables are
altered), e.g.
# Figure how many lines in a file
\dir ="$(echo DIRECTORY_WHERE_I_STORE_SOLAR_DATA)"
open "\dir/solar_data_file_name`
...
open "\$(echo DIR_ANOTHER)/another_data_set"
|
Another method is to pass instructions to the operating system with the
`system ' command. This discards output. Whatever follows the word
`system ' is first scanned for synonyms (but not rpn expressions or
variables); after replacement of any existing synonyms, the line is
passed directly to the operating system. Any results are printed on the
terminal.
Frequently used system commands are `\.awk. ' (a builtin synonym
naming the awk program on your system), `head ', `grep ' and
`sed '. Examples:
6.5.2: Using Gri from within the OS
This section only applies to unix systems.
Save the folowing into a file called `p' and chmod it to make it
executable. It runs Gri on a named file, with the `-yes ' flag set
so that any `query ' commands are automatically answered in the
affirmative, and then displays the results in a Ghostscript window.
(USAGE: `p cmdfile.gri ')
#!/usr/bin/sh
# Run Gri, then plot in gs window
case $# in
1)
base=`basename $1 .gri | sed -e s/.*,#`
gri -yes $base.gri && ghostview $base.ps
;;
*)
echo "Proper usage: $0 cmdfile.gri"
;;
esac
|
|