ACCELERATOR PHYSICS GROUP

Interacting with MAD9

This page gives some advice about ways you can run MAD Version 9.  They may make interaction with the program more convenient.

MAD9's input and output streams

Unlike MAD Version 8, MAD9 behaves as a "standard Unix command" under Unix-like operating systems.  That is to say that it has 3 pre-defined input and output streams that may be associated with files or pipes: As a consequence, it is possible to run MAD9 in a variety of ways that may be found convenient for different applications or users.  Some examples are described below.  Others are certainly possible.  If you have any other interesting suggestions please send them to cern.mad.

MAD9 is also often used to create table files of optical functions, tracking co-ordinates, transfer matrices and other quantities.  Normally the user specifies their names in input commands.  These files are not discussed on this page.  See the Madtomma pages for information about one way of using these files.


Terminal output under Unix

The most rudimentary, but still widely used, interface to MAD9 is a Unix terminal window.  Here are some ways you can run MAD9 in a Unix terminal window.
N.B.  It is assumed here that the terminal is running the csh or tcsh shell but some information is also given for other shells where known.

All output to terminal only

mad9
mad9 < test.mad
These assume, respectively, that the input commands are going to come from the terminal or from a file test.mad.  Both stdout and stderr outputs then appear in the same terminal window.  This is of limited application since you can't look back very far to see what came out earlier and the output is lost once it has moved up your screen.

Output results to a file, ECHO to the terminal

You can do a bit better with
mad9 > test.mou
mad9 < test.mad > test.mou
These will send all the standard output to test.mou.  (In the second case, input will come from test.mad.)  However you will continue to see the standard error (stderr) output on the terminal.   However this is not very satisfactory either since any results computed by MAD only appear in test.mou and you may want to know what they were before you decide what to do next.

If the file test.mou already exists, you need to delete it before doing this.

In the Bourne shell, the syntax for this is the same.

All output to a file

mad9 >& test.mou
mad9 < test.mad >& test.mou
will send both stderr and stdout to the file test.mou.  That way you can pick through all results and/or debug your job at leisure afterwards, e.g. with an editor, or you could get an analysis of the CPU time.  However, while MAD9 is running, you are completely blind to what is going on:  you don't even know if the job is going badly wrong and should be stopped.

In the Bourne shell, the syntax for this is

mad9 2> test.mou
mad9 < test.mad 2> test.mou

All output to terminal, just the results to a file

mad9 | tee test.mou
mad9 < test.mad | tee test.mou
will send both stderr and stdout to the terminal but the stdout will also go to thefile test.mou.  That way you can pick through all results and/or debug your job at leisure afterwards, e.g. with an editor, or you could get an analysis of the CPU time.  However, while MAD9 is running, you are completely blind to what is going on:  you don't even know if the job is going badly wrong and should be stopped.

In the Bourne shell, the syntax for this is the same.

Everything to a file AND to the terminal

The magic syntax for this is
mad9  |& tee test.mou
mad9  < test.mad | & tee test.mou
This way you see everything (stdout and stderr) whizz by on the terminal but you collect it all in the file as well.

If you give the option -a to the tee command, test.mou will be appended to and not over-written.

I have not managed to find the syntax for this in the Bourne shell:  if you can, help please tell me.

Everything to a file AND to the terminal .... but not so fast

mad9  |& tee test.mou | more
mad9  < test.mad |& tee test.mou | more
This way everything (stdout and stderr) does not whizz by on the terminal but you are able to let one screen's worth go by at at time by pressing the spacebar (this might be keyboard-dependent). This way, you have time to look at what is happening and you collect all the output in the file test.mou as well.

I have not managed to find the syntax for this in the Bourne shell:  if you can help, please tell me.

Terminal output in a Mathematica notebook

I know how to do this.  Instructions to be written

Terminal output in an Emacs window

Just use
mad9
mad9 < test.mad
in an Emacs terminal buffer.  Then you can scroll back and/or save the contents using Emacs commands.  This used to be the way I used MAD Version 8.

The input stream to MAD

If you use syntax like
mad9 < test.mad
then MAD9 will stop when it encounters a STOP; command in the file test.mad.  If you wish to continue typing more commands, it is better to start mad9 without the input re-direction and then give the MAD9 command
call,file="test.mad"
so that MAD9 simply passes control back to the terminal input stream.  I.e., any STOP; command in test.mad will NOT cause mad9 to stop.  You can then call other files, paste chunks of input at the terminal prompt or type commands manually.

JMJ
Modified 6/3/2000.