MathGroup Archive 1997

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

Search the Archive

How to control the evaluation queue

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8078] How to control the evaluation queue
  • From: dreissNOSPAM at nospam.earthlink.net (David Reiss)
  • Date: Tue, 5 Aug 1997 03:22:43 -0400
  • Organization: EarthLink Network, Inc.
  • Sender: owner-wri-mathgroup at wolfram.com

For Mathematica 3.0.




Assume that there is an open notebook, (call it notebook1.nb) and a
closed notebook (call it test.nb). Assume that notebook1.nb has
two evaluable cells, cellA and cellB.
Assume that test.nb is a notebook on disk (and on the search 
path -- otherwise use its full pathname) that has a sequence of 
evaluable cells.  For this discussion assume that test.nb is 
not open and its two evaluable cells are called cell1 and cell2,

Normally if a user has a number of evaluable cells in an 
open notebook or in multiple open notebooks, the user can 
select and execute cells one at a time, in whatever 
order he or she chooses.  The Kernel will then evaluate 
those cells in the order that they were executed (and if 
several cells are chosen at one time in a notebook, and the 
user evaluates them, they are executed by the kernel in the
order that they appear in the given notebook).

Below are two functions, executeNotebook1 and executeNotebook2.  
The purpose of these functions (they
are different versions yielding the same effective functionality:
executeNotebook1 uses a While statement, whereas executeNotebook2
uses FrontEndExecute) is to open a notebook (they first check 
to see if they have previously opened the notebook in question) 
and execute all of the cells in that notebook in the 
sequence that they appear. NotebookClose can then be used 
to close the notebook.  

My question concerns the evaluation queue and how to gain control
over it from the front end when using notebook manipulation commands.


For example if one has

executeNotebook1["test.nb"];

in cellA of notebook1.nb and 

NotebookClose[openNotebook1];

in the next cell, cellB. Select cellA and cellB together and evaluate them.
Then cellA is first in the evaluation queue and cellB is second. 
The command executeNotebook2["test.nb"] then puts the cells of test.nb
sequentially into the evaluation queue following cellB.
So the evaluation queue looks like:

cellA 
cellB
cell1
cell2

This is actually consistent with the usual expectations
for "manual" cell evaluation.  But in this case the
NotebookClose[openNotebook1] command in cellB will execute
before the commands in cell1 and cell2: test.nb will be 
closed and cell1 and cell2 will be removed from the evaluation
queue and will not be executed.

But, what I want is to be able to select all of the cells
in notebook1.nb, evaluate them, and have the evaluation queue
look like:

cellA
cell1
cell2
cellB

I want to do this independent of the NotebookClose[openNotebook1]
example for cellB above (i.e., cellB could have a command different
from NotebookClose[openNotebook1]. 


Any thoughts on this would be helpful.

---Thanks




(*  **********************************************  *)



Unprotect[openNotebook1,openNotebook2];
Clear[executeNotebook1,executeNotebook2,openNotebook1,openNotebook2];

openNotebook1::usage = "openNotebook1 is a protected variable used by
executeNotebook1.";

openNotebook2::usage = "openNotebook2 is a protected variable used by
executeNotebook2.";
 
executeNotebook1::usage = "executeNotebook1[\"file\"] opens the notebook
given by \"file\" and 
then executes each cell in turn, (thus acting as if each of the cells in
the notebook were each selected and executed one at a time).  The notebook
object is 
called \"openNotebook1\" and the notebook can be closed by 
executing  
\n\n 

NotebookClose[openNotebook1];

\n\n 
Because executeNotebook1 makes use of \"openNotebook1\", it is restricted
to use on a single file at a time."; 


executeNotebook2::usage = "executeNotebook2[\"file\"] works like
executeNotebook1 but uses 
\n
FrontEndExecute[FrontEndToken[\"EvaluateNotebook\"] 
\n
rather than a While, thus acting as if all of the cells were selected and
then evaluated. The opened notebook can be closed by 
executing  
\n\n 

NotebookClose[openNotebook1];

\n "; 



  
  executeNotebook1[file_String] := 
   Module[{tem = 1},
         Unprotect[openNotebook1];
         
         If[MemberQ[Notebooks[], openNotebook1], 
         NotebookClose[openNotebook1]
         ];
         openNotebook1 = NotebookOpen[file, Visible -> True]; 
      SelectionMove[openNotebook1, Next, Cell]; 
      While[tem =!= {}, SelectionEvaluate[openNotebook1]; 
            SelectionMove[openNotebook1, Next, Cell]; 
            tem = NotebookRead[openNotebook1]];
         
         Protect[openNotebook1] ];

 


executeNotebook2[file_String] := 
   Module[{},
         Unprotect[openNotebook2];
         
         If[MemberQ[Notebooks[], openNotebook2], 
         NotebookClose[openNotebook2]
         ];
         openNotebook2 = NotebookOpen[file, Visible -> True]; 
      
         FrontEndExecute[FrontEndToken["EvaluateNotebook"]];
         
         Protect[openNotebook2] ];

-- 
David Reiss
dreissNOSPAM at nospam.earthlink.net
http://home.earthlink.net/~dreiss
To send personal email, remove the words 
"nospam" and "NOSPAM" from the email address


  • Prev by Date: How to change 'working' directory
  • Next by Date: Chaning point size on ErrorListPlot - can it be done?
  • Previous by thread: How to change 'working' directory
  • Next by thread: Chaning point size on ErrorListPlot - can it be done?