MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

How to evaluate a notebook programmatically?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98575] How to evaluate a notebook programmatically?
  • From: "Paul Ellsmore" <paul.ellsmore at nanion.co.uk>
  • Date: Mon, 13 Apr 2009 03:33:44 -0400 (EDT)

Hi,

 

In one notebook, "gui.nb", I have the code for a user interface. In another,
"functional.nb" I have around 3000 lines of code, in several hundred cells.
I want to click a button (or something similar) in gui.nb, and tell
Mathematica to execute all the cells in functional.nb. Functional.nb will
use values for global variables that have been assigned in gui.nb, and
gui.nb will display the results of the execution of functional.nb. Seems
straightforward.

 

Now in functional.nb, we group all the cells together, so that we can
manually execute them all with a single shift-click. What is the
programmatical equivalent of this? I have looked through all the tutorials
etc on controlling notebooks from the front end, frontendtokens etc., but
nothing seems to do quite what I want. The options seem to be:

 

Option 1. Merge all the cells in functional.nb, and assign that cell to a
Function, which can then be called from gui.nb. This is highly undesirable,
because if an error occurs, we find out about it at the end of 3000 lines of
code, with no idea where the error occurred. The cell structure in
Mathematica is just too valuable to throw away. I guess that using workbench
might mitigate some of these issues, but that means my colleagues and I all
having to learn a new (and complicated) tool.

 

Option 2. Assign each of the (hundreds of!) cells to a separate function,
and call each of them in turn from gui.nb. A lot of hard work here with the
potential for errors in naming and ordering the functions in the two
notebooks, and probably an increase in execution time.

 

Option 3. Make all the cells in functional.nb initialization cells, then get
gui.nb to open functional.nb each time we want to evaluate it, and then
close it again. Very clunky, and again probably slow.

 

I am sure there are better options than these? Any ideas?

 

Thanks,

 

Paul.

 

 

 

Dr. Paul A. Ellsmore

 

Nanion Limited

Oxford Centre for Innovation

Mill Street

Oxford

United Kingdom

OX2 0JX

 

Tel: +44 (0) 1865 811175

Fax: +44 (0) 1865 248594

 


------=_NextPart_000_0010_01C9BB7F.DD815090
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
X-Sun-Content-Length: 8687

<html xmlns:v="urn:schemas-microsoft-com:vml" =
xmlns:o="urn:schemas-microsoft-com:office:office" =
xmlns:w="urn:schemas-microsoft-com:office:word" =
xmlns:st1="urn:schemas-microsoft-com:office:smarttags" =
xmlns="http://www.w3.org/TR/REC-html40";>

<head>
<meta http-equiv=Content-Type content="text/html; =
charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<o:SmartTagType =
namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="Street"/>
<o:SmartTagType =
namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="City"/>
<o:SmartTagType =
namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="address"/>
<o:SmartTagType =
namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="place"/>
<o:SmartTagType =
namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="country-region"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:Arial;
	color:windowtext;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Hi,<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>In one notebook, &#8220;gui.nb&#8221;, I have the =
code for a
user interface. In another, &#8220;functional.nb&#8221; I have around =
3000
lines of code, in several hundred cells. I want to click a button (or =
something
similar) in gui.nb, and tell Mathematica to execute all the cells in
functional.nb. Functional.nb will use values for global variables that =
have
been assigned in gui.nb, and gui.nb will display the results of the =
execution
of functional.nb. Seems straightforward.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Now in functional.nb, we group all the cells =
together, so
that we can manually execute them all with a single shift-click. What is =
the
programmatical equivalent of this? I have looked through all the =
tutorials etc
on controlling notebooks from the front end, frontendtokens etc., but =
nothing
seems to do quite what I want. The options seem to =
be:<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Option 1. Merge all the cells in functional.nb, and =
assign
that cell to a Function, which can then be called from gui.nb. This is =
highly
undesirable, because if an error occurs, we find out about it at the end =
of 3000
lines of code, with no idea where the error occurred. The cell structure =
in
Mathematica is just too valuable to throw away. I guess that using =
workbench
might mitigate some of these issues, but that means my colleagues and I =
all having
to learn a new (and complicated) tool.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Option 2. Assign each of the (hundreds of!) cells to =
a
separate function, and call each of them in turn from gui.nb. A lot of =
hard
work here with the potential for errors in naming and ordering the =
functions in
the two notebooks, and probably an increase in execution =
time.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Option 3. Make all the cells in functional.nb =
initialization
cells, then get gui.nb to open functional.nb each time we want to =
evaluate it,
and then close it again. Very clunky, and again probably =
slow.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>I am sure there are better options than these? Any =
ideas?<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Thanks,<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Paul.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>&nbsp;<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Dr. Paul A. Ellsmore</span></font><o:p></o:p></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span =
style='font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Nanion Limited</span></font><o:p></o:p></p>

<p class=MsoNormal><st1:City w:st="on"><st1:place w:st="on"><font =
size=2
  face=Arial><span =
style='font-size:10.0pt;font-family:Arial'>Oxford</span></font></st1:pl=
ace></st1:City><font
size=2 face=Arial><span =
style='font-size:10.0pt;font-family:Arial'> Centre for
Innovation</span></font><o:p></o:p></p>

<p class=MsoNormal><st1:Street w:st="on"><st1:address =
w:st="on"><font size=2
  face=Arial><span style='font-size:10.0pt;font-family:Arial'>Mill =
Street</span></font></st1:address></st1:Street><o:p></o:p></p>

<p class=MsoNormal><st1:City w:st="on"><st1:place w:st="on"><font =
size=2
  face=Arial><span =
style='font-size:10.0pt;font-family:Arial'>Oxford</span></font></st1:pl=
ace></st1:City><o:p></o:p></p>

<p class=MsoNormal><st1:country-region w:st="on"><st1:place =
w:st="on"><font
  size=2 face=Arial><span =
style='font-size:10.0pt;font-family:Arial'>United
  Kingdom</span></font></st1:place></st1:country-region><o:p></o:p></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>OX2 0JX</span></font><o:p></o:p></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span =
style='font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Tel: +44 (0) 1865 811175</span></font><o:p></o:p></p>

<p class=MsoNormal><font size=2 face=Arial><span =
style='font-size:10.0pt;
font-family:Arial'>Fax: +44 (0) 1865 248594</span></font><o:p></o:p></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span =
style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>

------=_NextPart_000_0010_01C9BB7F.DD815090--


  • Prev by Date: Re: Scaling JPEGs or TIFFs inside PDF slides (using Illustrator)?
  • Next by Date: Re: how to build pattern for a square matrix of reals?
  • Previous by thread: Re: Should I be using Mathematica at all?
  • Next by thread: Re: How to evaluate a notebook programmatically?