MathGroup Archive 2012

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

Search the Archive

Re: Executing a Notebook and saving the modified Notebook - all without the GUI

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125156] Re: Executing a Notebook and saving the modified Notebook - all without the GUI
  • From: "C. Mundi" <cmundi at gmail.com>
  • Date: Sat, 25 Feb 2012 01:54:19 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Thanks for your reply.  It is interesting but does not match my problem
statement.
On Feb 23, 2012 6:14 AM, "Arturas Acus" <arturas.acus at tfai.vu.lt> wrote:

> Dear Mundi
>
> Probably not exactly what you want, but may be you can use something
> from below.
>
> First of all to run graphical Mathematica programs like Plot from
> command line you need to run vnc server
>
>  vncserver :1
>
> Then You can use JLink in the following way
>
>
>
> ----------------- put into somefile.m --------------
>
>  whereIam = "/home/acus/";
> $Path = Append[$Path, whereIam];
> SetDirectory[whereIam];
>
> Needs["JLink`"];
> $FrontEndLaunchCommand = "mathematica -mathlink -display :1 -nogui";
> arprisijungiau = ConnectToFrontEnd[];
> Put[arprisijungiau, "testNon.txt"]
>
> tempNotebookName = "test1.nb";
> grMain1 = UseFrontEnd[Plot[Sin[x], {x, 0, Pi}]];
>
> If[tempNotebookName =!= "EvaluationNotebook[]", If[
>    (tmpNb = NotebookOpen[ToFileName[whereIam, tempNotebookName]]
>        ) === $Failed, SetDirectory[whereIam];
>  tmpNb = CreateDocument[]; NotebookSave[tmpNb, tempNotebookName];
>  SelectionMove[tmpNb, After, Notebook];
>  NotebookWrite[tmpNb,
>   CellGroupData[
>    Prepend[(Cell[{ToBoxes[#]}] & /@
>       {grMain1, grErr1, grStep1,
>         rezults}),
>     Cell["Parameters {\[Lambda],\[Mu],g,a}:  " <>
>       ToString[
>        Evaluate[
>         NumberForm[#, {3, 4}] & /@ N[{\[Lambda], \[Mu], ggg, aa}]]],
>      "Subsection"]], Open]];
>  NotebookSave[tmpNb];
>  PutAppend[tempNotebookName];
>  PutAppend[rezults, tempNotebookName];
>  NotebookClose[tmpNb, Interactive -> False];,
>  CellPrint /@ {grMain1, grErr1, grStep1}]]
>
>
> ------------------------------------------
>
>
> Then simply:
>
> math < ./somefile.m > outIfYouWant.txt
>
>
> So, you need:
> 1. vnc server
> 2. configure to connect front end using JLink.
> 3. To use UseFrontEnd[] for graphical commands and
> 4. properly print cells for nice output to the notebook your are working
> with.
>
> Of course, "simple" is not so simple.
>
>
> Sincerely, Arturas Acus
>
>
>
>
> Kt, 2012 02 23 05:46 -0500, C. Mundi ra=C5=A1=C4=97:
> > Surely there is a "simple" way to tell Mathematica from the command
> > line to run a notebook and save the state of the notebook!  We would
> > have hoped for something like "mathematica.exe --nogui --notebook
> > Test.nb" would work, especially if we embedded something like
> > "NotebookSave[]; End[];" at the end of the file.
> >
> > We've been searching for an answer to this question for days, and none
> > of the answers we've found actually solves our problem.  So before you
> > answer, please read my question, which I will try to make very clear
> > with a very simple example at the risk of seeming pedantic.
> >
> > Given a Notebook file, Test.nb with a single cell
> >
> >     In[1]:= Plot[Cos[x], {x, 0, 2 Pi}]
> >
> > we can open the Notebook in the front end, Evaluate the (whole)
> > Notebook and get the expected Out which is a plot of a single cycle.
> > We now save the notebook, using the GUI menus.  We then open Test.nb
> > in the front end and we see both the input expression and the output
> > plot saved previously.  Good.
> >
> > Now we want to do everything *without* the GUI.  Let our INPUT be the
> > original Test.nb file, i.e. inputs but no outputs yet.  Let our RESULT
> > be a modified Test.nb including the plot.  We seek a sequence of batch-
> > like commands which will transform our INPUT into our RESULT, viz.
> > with no GUI interaction and in fact under the control of an external
> > unix shell script.  It is permissible for the script to cause
> > mathematica to access files besides Test.nb.
> >
> > We need the output to be in NB form, because we need the embedded
> > graphics.  But we also need to evaluate the notebook in an automated,
> > unattended way.
> >
> > At this time, solutions based on MathLink are not attractive to us.
> >
> > We have looked at FrontEndToken but have not yet found a way to effect
> > the result we seek.  We also note that some of the interesting
> > FrontEndTokens -- particularly those related to Evaluate -- come with
> > warnings that they are not yet fully integrated into the long-term
> > plan for Mathematica.  That sounds ominous.
> >
> > Gracias!
> >
>
>
>


  • Prev by Date: Re: Extensive replacement of trigonometric functions
  • Next by Date: Re: How add a menu item with a menu key using an init.m
  • Previous by thread: Re: Executing a Notebook and saving the modified Notebook - all without the GUI
  • Next by thread: Dynamically finding distances and angles between user-specified points