MathGroup Archive 1992

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

Search the Archive

Splice Output Forms

  • To: mathgroup at (Mathematica user group)
  • Subject: Splice Output Forms
  • From: Mark Sofroniou <M.Sofroniou at>
  • Date: Fri, 6 Mar 92 21:04:37 GMT

I am completely stuck on the following problem and would be extremely grateful
for any suggestions.

I am using the Splice[] command for unstructured communication with Mathematica.

Typically I am working with a C template "" so that the command is
and Mathematica output is spliced into "file.c"

I would like to give as input the dimension of an array (df).

I would like as output LITERALLY of the form 

q[1] = q0[1] + dt*p0[1];
 :       :        :
 :       :        :
q[df] = q0[df] + dt*p0[df];

At the appropriate point in the spliced file.
(with no extra "" or {} or anything else, so that the output does not need to
be `run over' with an editor).

(this is simplified but contains the essence of the problem).

What I have tried;

It is not possible to use Do[Print[....],{i,df}] because this outputs to the
$Output channel which is the screen by default. The required results are printed
on the screen and not placed in the appropriate point in the spliced file.

To illustrate the problem I have the following file:

Some C coding ....

<*  df = 2; dhp0 =Table[p0[i],{i,df}]; (* set up a length 2 test problem *)

stemp = OpenWrite["temp"];

Do[ WriteString[stemp,SequenceForm[
"q[",i,"] = q0[",i,"] + dt*",dhp0 [[i]],";\n"]] ,{i,df}];

Close[stemp]; (* write the desired output into a temporary file. *)
	      (* the file temp now contains EXACTLY the right output, 
	         but inserting the contents of the file in exactly the right 
	         place in the Spliced file.c is where the difficulty arises. *)

stext = OpenRead["temp"];
Read[stext,Record]      (* The file temp can be read in line by line. *)

<* (* or the following works just as well.. *)
*> (but the resulting output is contained in quotes "" and it is not possible
    to generalise to implement df times - try this in a Do loop to see what I 

Using ReadList would read in all the lines of the file, but encloses them with
List() containing arguments separated by commas.

It would be nice just to give a command like !!temp but this defaults output to the screen.

A lot of commands like TableForm print the appropriate output on the screen
but since they act as wrappers do not affect the output to a file.

If anyone has any suggestions I would be very grateful. I have been through the
entire Mathematica book several times over looking for the appropriate
commands to do the trick. I can't believe such a format is not possible
since Mathematica provides so many input/output format commands.

		Thanks in advance

Mark Sofroniou
Dept of Mathematical Sciences
Loughborough University

email address :  M.Sofroniou at

  • Prev by Date: Numerically solving InterpolatingFunction
  • Next by Date: Partial Fraction Decomposition with imaginary coeff.
  • Previous by thread: Numerically solving InterpolatingFunction
  • Next by thread: Partial Fraction Decomposition with imaginary coeff.