	 Connecting Mathematica to External Graphics Programs

			   Mark B. Phillips
			     May 15, 1989

I. Two hosts
	A. the graphics host
	B. the Mathematica host


II. Why two hosts?
	A. Makes best use of each machines' capabilities
	B. Mathematica license restrictions --- maybe we
	   CAN'T run Mathematica on the graphics machine

III. Why not use Mathematica's built-in graphics capabilities:
	A. See II.B above
	B. We may have more specicialzed requirements than Mathematica's
	   built-in graphics provide.

IV. The setup (complicated --- there must be a better way!)
	A. Programs which run on the graphics host
		1. Window system, with one window rlogged into
		   Mathematica host
		2. Graphics program
		3. 'elbow'
		4. 'etrigger'
		5. 'mpipestart'
	B. Programs which run on the Mathematica host
		1. Mathematica
		2. mpipe

V. Explanation of complicated setup:

	The setup is based on portability: we want to be able to
	change the graphics host and/or the Mathematica host at any
	time with minimal change to our installation.  If we have
	several graphics hosts or Mathematica hosts available, we'd
	like the final program startup procedure to be independent of
	the combination of machine's we're using.

	On the Graphics host:

		A. Graphics program --- performs two functions:
			1. Reads high level ascii commands from stdin,
			   and writes results of these commands to stdout.
			   We use stdio so that this program could be run
			   independently of Mathematica if necessary.
			   Example commands in HEISENBERG:
				'g' - draw grid (axes and XY plane),
				   and return graphics segment number
				'c x y z r' draw chain and return
				   graphics segment number
				'h n' hide segment number n (make it
				   temporarily invisible)
				'u n' unhide segment number n
				'e n' (permanently) erase segment number n
				etc ...
			2. Allows the user to view the current picture
			   interactively at any time.

		B. 'elbow' --- connects stdio of graphics program to
		   IPC socket.  This is the program that Mathematica,
		   running on the remote host, should invoke to talk
		   to the graphics program on the graphics host.  But,
		   there is a

		   PROBLEM: Since some window systems (eg SunView)
		     require that graphics programs be run as a
		     subprocess of the window manager process, this
		     program cannot always be invoked from a remote
		     host.  Hence, in such situations, we need to be
		     able to start the elbow process manually from the
		     graphics host under the window system.  BUT
		     before elbow can connect to the IPC socket, it
		     needs to know the remote host and socket to which
		     to connect!

		   SOLUTION: after being started, elbow waits for
		     SIGUSR1 signal, at which time it reads remote
		     (Mathematica) host and socket info from a file on
		     the graphics host.

		C. 'etrigger' - short programto accomplish both of the
		   following tasks at once:
			1. write Mathematica host and socket info to a
			   file
			2. Send SIGUSR1 to previously started elbow
			   process


	On the Mathematica host:

		A. Mathematica

		B. mpipe - the external process with which Mathematica
		   communicates. A call in Mathematica of the form
				StartProcess["mpipe"]
		   starts up this process and defines a function called
		   ProgramPipe which can be used to pipe ascii strings
		   through the graphics program running on the graphics
		   host.

		   When mpipe is started, however, it needs to know:
			1. The graphics host name
			2. The PID of the elbow process running on the
			   graphics host
		   To get this information, it reads a file on the Mathematica
		   host.  How did the data get into this file in the first
		   place?  Read on!

	On the Graphics host:

		D. 'mpipestart' - starts 'elbow', then writes the PID
		   and host info (via an rsh command) to a file on the
		   Mathematica host

		E. 'startprogram' - a shell script which calls 'mpipestart'
		   with its horde of required arguments.

	So, the final setup is as follows:

	1. Log onto graphics host, get into window system

	2. 'startprogram' on graphics host

	3. rlogin to Mathematica host and run Mathematica

	4. Give the Mathematica command StartProcess["mpipe"]; this
	   can be done in a file which contains other commands to
	   set up the Mathematica environment.

	This process requires no change when a different graphics host
	is used.  If different Mathematica hosts are used, it only
	requires a change to the 'startprogram' shell script on the
	graphics host.
