Write2
Write2[file, val1 = expr1, val2 = expr2, ...]
writes the settings val1 = expr1, val2 = expr2
in sequence followed by a newline, to the specified output file. Setting the option FormatType
of Write2
to FortranForm
results in Fortran syntax output.
See also
Overview, Isolate, PaVeReduce.
Examples
FullForm[$FortranContinuationCharacter]
&
t = Collect[((a - c)^2 + (a - b)^2)^2, a, Factor]
4a4−8a3(b+c)+8a2(b2+bc+c2)−4a(b+c)(b2+c2)+(b2+c2)2
This writes the assignment r=t to a file.
tempfilename = ToString[$SessionID] <> ".s";
Write2[tempfilename, r = t];
This shows the contents of the file.
TableForm[ReadList[If[$OperatingSystem === "MacOS", ":", ""] <> tempfilename, String]]
r = ( 4*a∧4 - 8*a∧3*(b + c) - 4*a*(b + c)*(b∧2 + c∧2) + (b∧2 + c∧2)∧2 + 8*a∧2*(b∧2 + b*c + c∧2) );
DeleteFile[If[$OperatingSystem === "MacOS", ":", ""] <> tempfilename]
t2 = x + Isolate[t, a, IsolateNames -> w]
4a4−8a3w(19)+8a2w(21)−4aw(19)w(20)+w(20)2+x
Write2[tempfilename, r = t2];
TableForm[ReadList[If[$OperatingSystem === "MacOS", ":", ""] <> tempfilename, String]]
w[19] = (b + c );w[20] = (b∧2 + c∧2 );w[21] = (b∧2 + b*c + c∧2 );r = ( 4*a∧4 + x - 8*a∧3*HoldForm[w[19]] - 4*a*HoldForm[w[19]]* HoldForm[w[20]] + HoldForm[w[20]]∧2 + 8*a∧2*HoldForm[w[21]] );
DeleteFile[If[$OperatingSystem === "MacOS", ":", ""] <> tempfilename]
This is how to write out the expression t2
in Fortran format.
Write2[tempfilename, r = t2, FormatType -> FortranForm];
TableForm[ReadList[If[$OperatingSystem === "MacOS", ":", ""] <> tempfilename, String]]
w(19)= b + c w(20)= b**2 + c**2 w(21)= b**2 + b*c + c**2 r = x + a**4*4D0 - a**3*8D0*w(19) - a*4D0*w(19)*w(20) + & w(20)**2 + a**2*8D0*w(21)
DeleteFile[If[$OperatingSystem === "MacOS", ":", ""] <> tempfilename];
Clear[w, t, t2, r, tempfilename];