MathGroup Archive 2003

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

Search the Archive

RE: Re: question Mathematica 5 "Print to the same line"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45062] RE: [mg44919] Re: [mg44703] question Mathematica 5 "Print to the same line"
  • From: "Ingolf Dahl" <ingolf.dahl at telia.com>
  • Date: Mon, 15 Dec 2003 06:02:55 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

PRINTING SEVERAL TIMES TO THE SAME LINE
I have rewritten Omega Consulting solution (see below) to the problem of
printing to a single line, and reformulated the solution as a single command
PrintToTaggedCell[expr_,celltag_].
It is easy to handle a number of different tagged cells at the same time,
using this command. In this way it might be possible to supervise the
evaluation of a complex calculation or use Mathematica to supervise
processes without generating copious output lists. It is also possible to
achieve structured output.
First time this command is used with a specific value of celltag, the
expression expr is printed to a cell, tagged with celltag. Next time this
command is used with the same value of celltag, the content of the tagged
cell is overwritten with the new value of expr.
It might be useful to turn on "Show Cell Tags", found beneath menu headline
"Find".
The arguments expr and celltag can be strings or anything the command
ToString can convert to strings.
The tagged cell is created beneath the cell containing the creating command.
The cell might be copied to another place, but the original tagged cell must
be deleted to keep the mechanisms working.
I have complemented The PrintToTaggedCell command with a corresponding
command for graphics ShowToTaggedCell[plot_celltag_]. Here plot should be a
single Graphics object, generated by for instance Plot or Show. With this
command, we might even be able to animate some figures, in another way than
the official. To suppress the output of Plot, it might be useful to use the
option DisplayFunction -> Identity, see examples.
If you find the commands useful, or if you suggest or have made some
improvements, please inform me.
Ingolf Dahl
ingolf.dahl at telia.com

The Mathematica commands follow below. They can also be downloaded from
http://w1.318.telia.com/~u31815170/Mathematica/PrintToTaggedCell.nb

PrintToTaggedCell[expr_, celltag_] :=
    If[NotebookFind[EvaluationNotebook[], ToString[celltag], All,
          CellTags] == $Failed,
      CellPrint[
        Cell[ToString[expr], "Print", CellTags -> ToString[celltag]]], ,
      NotebookWrite[EvaluationNotebook[],
        Cell[ToString[expr], "Print", CellTags -> ToString[celltag]]]];

ShowToTaggedCell[plot_, celltag_] :=
    If[NotebookFind[EvaluationNotebook[], ToString[celltag], All,
          CellTags] == $Failed,
      CellPrint[
        Cell[TextData[{Cell[
                GraphicsData["PostScript", DisplayString[plot]]]}],
          "Graphics", CellTags -> ToString[celltag]]], ,
      NotebookWrite[EvaluationNotebook[],
        Cell[TextData[{Cell[
                GraphicsData["PostScript", DisplayString[plot]]]}],
          "Graphics", CellTags -> ToString[celltag]]]];

Examples to evaluate (Try these!):

PrintToTaggedCell["Hej", 8]

PrintToTaggedCell["Hopp", "8"]

PrintToTaggedCell["Hopp", "figure"]

plot1 = Plot[Sin[x], {x, 0, 2*Pi}, DisplayFunction -> Identity];
plot2 = Plot[Cos[x], {x, 0, 2*Pi}, DisplayFunction -> Identity]; 1 + 2

ShowToTaggedCell[plot1, "figure"]

ShowToTaggedCell[plot2, "figure"]

ShowToTaggedCell[Show[plot1, plot2], "figure"]

Do[plot3 = Plot[Sin[x - Pi*i/18], {x, 0, 2*Pi}, DisplayFunction ->
Identity];
  ShowToTaggedCell[plot3, "figure"], {i, 1, 36}]

Do[PrintToTaggedCell[Date[][[{4, 5, 6}]], clock]; Pause[0.5], {40}]


>-----Original Message-----
>From: Omega Consulting [mailto:info at omegaconsultinggroup.com]
To: mathgroup at smc.vnet.net
>Sent: Tuesday, December 09, 2003 09:32
>To: mathgroup at smc.vnet.net
>Subject: [mg45062] [mg44919] Re: [mg44703] question Mathematica 5 "Print to the
>same line"
>
>
>This can be done with a little bit of frontend programming:
>
>i = 0;
>CellPrint[
>     Cell[ToString[i], "Print", CellTags -> "target"]
>     ];
>For[i = 1, i < 100, i++,
>   NotebookFind[EvaluationNotebook[], "target", All, CellTags];
>    NotebookWrite[EvaluationNotebook[],
>     Cell[ToString[i], "Print", CellTags -> "target"]
>     ]
>   ]
>
>At 04:13 AM 11/21/2003, Boender, Gert-Jan wrote:
>>I have a question about printing the value of a variable in Mathematica.
>>I use in the functions a wrote sometimes "Print" to visualize
>>the status of the calculation. However, each time the Print comment is
>>given the
>>value of the variable is printed in the next line. This results in a
>>inconvenient long list.
>>Could I print to the same line,  that I can read immediately the recent
>>status of the process from that line?
>>
>>Thanks,
>>
>>Gert Jan Boender
>>
>>Dr. Ir. Gert Jan Boender
>>Animal Sciences Group, Wageningen UR
>>Quantitative Veterinary Epidemiology
>>PO Box 65
>>8200 AB Lelystad
>>The Netherlands
>>tel +31-320-238543
>>fax +31-320-238050
>>email : gertjan.boender at wur.nl
>>internet : www.asg.wur.nl
>>
>>Dit bericht is uitsluitend bestemd voor geadresseerde. Het bericht kan
>>vertrouwelijke informatie bevatten. Gebruik door derden of openbaarmaking
>>van dit bericht zonder toestemming van ID-Lelystad is niet
>toegestaan. Als
>>u dit bericht per abuis heeft ontvangen, wordt u verzocht het te
>>vernietigen en ons te informeren.
>>This message is intended exclusively for the addressee. It may contain
>>information that is confidential. Any use or publication of this e-mail
>>message without permission of ID-Lelystad is not allowed. If you are not
>>the intended recipient please notify us and destroy this message.
>
>--------------------------------------------------------------
>Omega Consulting
>"The final answer to your Mathematica needs"
>http://omegaconsultinggroup.com
>


  • Prev by Date: Out of Memory under AIX (Mathematica 5)
  • Next by Date: Re: Re: Map Question
  • Previous by thread: Re: question Mathematica 5 "Print to the same line"
  • Next by thread: sounds