MathGroup Archive 2004

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

Search the Archive

Re: Streaming input (with Linux)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46397] Re: [mg46349] Streaming input (with Linux)
  • From: Yasvir Tesiram <yat at omrf.ouhsc.edu>
  • Date: Mon, 16 Feb 2004 23:43:20 -0500 (EST)
  • References: <200402161359.IAA20493@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,
It's hard to know exactly what you are trying to achieve. I assume you 
have written a series of Mathematica commands in a file and then using 
Get (<<), have evaluated the contents of the file.
In this case, the file my_script.m need not have the extension .m. It 
could be anything so as long as it contains valid Mathematica 
expressions, Mathematica will evaluate it immediately. If however, you 
want to pass arguments to the sequence of events executed by your file, 
then you have to write a "function" that can take arguments. Thus you 
may want to rewrite the contents of my_script.m as in the following 
example;

script[a_, b_, c_] := Module[{f},

     f = Table[a + b*x + c*x^2, {x, -1.0, 1.0, 0.1}];
     ListPlot[f, PlotRange -> All, PlotJoined -> True]
     ]

Then execute (use) the function with

script[1, 2, 3]

See the notes on packages etc for additional information.

You can of course Read the contents of your my_script.m file into 
Mathematica line by line or  list (using ReadList) as Strings. Then use 
replacement rules to substitute for the arguments (parameters) and then 
evaluate the whole thing by converting to an expression using 
ToExpression.

Clear[x1, x2]
(*this reads the first line*)
f4 = ReadList["~/myscript.longextension", String, 1]

{Plot[x^2,{x,-x1, x2}]}

StringReplace[f4[[1]], {"-x1" -> "-2.0", "x2" -> "2.0"}] // ToExpression


Cheers
Yas




On Feb 16, 2004, at 7:59 AM, Alessandro Antonucci wrote:

> Hello everyone,
> I have build up a very simple script in Mathematica,
> taking tree real parameters in input and  giving as
> output a real number.
>
> At the moment my script read an input file
> containing the tree parameters, but it would
> be better for me to tell the script the parameters
> with a direct command line instruction.
>
> Does anyone knows how to do something like
>
>> 	math < my_script.m   par1 par2 par3
>
> And how to handle the parameters inside the script ?
>


  • Prev by Date: Re: Solve or LinearSolve or ...?
  • Next by Date: FW: RE: matrix operations
  • Previous by thread: Streaming input (with Linux)
  • Next by thread: Re: Streaming input (with Linux)