Re: Background jobs with Mathematica 3.0 under Linux ?
- To: mathgroup@smc.vnet.net
- Subject: [mg10376] Re: Background jobs with Mathematica 3.0 under Linux ?
- From: "P.J. Hinton" <paulh@wolfram.com>
- Date: Mon, 12 Jan 1998 04:10:08 -0500
- Organization: "Wolfram Research, Inc."
- References: <694ab6$ijs@smc.vnet.net>
On 8 Jan 1998, Axel Kowald wrote: > I would like to use Mathematica 3.0 on our Linux system to run some of > my notebooks in the background. Normally, I would mark the cells I want > to be evaluated as initialization cells and then type a command line > like: > > math -batchoutput < test.nb & > > Unfortunately I keep getting the error message: "Cannot initialize Motif > window graphic". > What went wrong ? With Mathematica 2.2 it worked that way ! Your approach won't work with Mathematica 3.0 because the structure of a notebook file has changed radically between versions 2.2 and 3.0. Here is what an initialziation cell looked like in a Mathematica 2.2 notebook: (*^ bunch of header info and non-initialization cells here *) 2 + 2 (* more notebook stuff afterwards *) In a version 2.2 notebook, the kernel saw only the contents of initialization cells because everything else was commented out with the (* and *) delimiters. This is why you could run a notebook through a batch file. Here is what the same notebook looks like in version 3.0. Notebook[{ Cell[BoxData[ RowBox[{"2", "+", "2"}]], "Input", InitializationCell->True] }, FrontEndVersion->"X 3.0", ScreenRectangle->{{0, 1024}, {0, 768}}, WindowSize->{520, 600}, WindowMargins->{{Automatic, 115}, {41, Automatic}} ] Notice that the entire notebook file now looks like a Mathematica expression. On the good side, this enables you to manipulate notebooks within the kernel. However, it makes it impossible to use notebooks as batch inputs. QUALIFICATION: You could write a sophisticated program to scan through the Notebook[] expression (since it contains a list) and use MakeExpression[] on the contents of Input cells which have the option InitializationCell->True and then do the evaluation, but this is left as an exercise for the ambitious student :-). If you still have access to the Mathematica 2.2 X front end, you could create your batch files using it and then run the .ma file through the version 3.0 kernel (this will most likely work). Otherwise, you'll probably have to write the batch file using a text editor. You might be able to use the version 3.0 X front end if you convert your Input cells to InputForm and save the notebook as text from the Edit -> Save As Special menu, but I haven't tested this extensively. If you go the text editor route, but still would prefer to see your results in a notebook, you should take a look at Roman Maeder's package ProgrammingInMathematica`NotebookLog` that resides in the AddOns/ExtraPackages/ProgrammingInMathematica directory. It is described in detail in his book _Programming in Mathematica_, 3rd ed. (Addison-Wesley, 1996), and it allows you to store the output from a kernel session in the form of a Mathematica notebook. I suspect that I know what is going on with the " Cannot initialize Motif graphics ". When you pass the command line switch "-batchoutput" to the kenrel, it sets the global session variable $BatchOutput to be True.. There is a line of code in the package that loads the Motif graphics packages evaluates the following logical operation: !($BatchOutput || $Remote || $ParentLink =!= Null || $MessageList==={HoldForm[LinkConnect::linkc]}) Since $BatchOutput is True, the parenthesized expression evaluates to True, and the ! operator negates this to False. This causes the following expression to evaluate Print[" Cannot initialize Motif graphics "] The message is benign. You can avoid it altogether by not invoking this switch and using the following syntax, which is recommended in the version 3.0 Getting Started guide: math < infile > outfile where infile is the batch file and outfile is where the output is to be directed. In this case $BatchOutput is initialized to False. However, if you do this, and your batchfile contains commands that will cause graphics objects to be rendered, you might see Motif graphics windows popping up on your desktop every once in a while. The will all be removed when the batch file is complete and the kernel shuts down. -- P.J. Hinton Mathematica Programming Group paulh@wolfram.com Wolfram Research, Inc. http://www.wolfram.com/~paulh/ Disclaimer: Opinions expressed herein are those of the author alone.