Re: Tentative conclusion: Mathematica cannot outputplain text
- To: mathgroup at smc.vnet.net
- Subject: [mg39810] Re: Tentative conclusion: Mathematica cannot outputplain text
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Sat, 8 Mar 2003 02:45:57 -0500 (EST)
- Organization: The University of Western Australia
- References: <b49nkf$fem$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Carlos Felippa wrote:
> ================ The original posting =========================
> I am converting an old code written 8 yrs ago in Mathematica 2.2 to
> 4.2, and would like to keep the same plain text tabular output.
> To see what I mean, consider the 2.2 fragment
>
> PrintNodeCoordinates[xyzcoor_]:= Module[
> {numnod=Length[xyzcoor],t,n,c},
> t=Table[" ",{numnod+1},{4}];
> For [n=1,n<=numnod,n++,c=xyzcoor[[n]];
> If [Length[c]<=2, AppendTo[c,0]];
> If [Length[c]==1, AppendTo[c,0]];
> t[[n+1,1]]=ToString[n];
> t[[n+1,2]]=PaddedForm[c[[1]]];
> t[[n+1,3]]=PaddedForm[c[[2]]];
> t[[n+1,4]]=PaddedForm[c[[3]]];
> ];
> t[[1]] = {"node","x","y","z"};
> Print[TableForm[t,TableAlignments->{Right},
> TableDirections->{Column,Row},TableSpacing->{0,1}]];
> ];
> PrintNodeCoordinates[
> {{2,3,2000},{5,a+b,168.09},{x_dir,y_dir,z_dir}}];
>
> The output from 2.2 is
>
> node x y z
> 1 2 3 2000
> 2 5 a + b 168.09
> 3 x_dir y_dir z_dir
>
> What you see is exactly what you get if you move the output cell
> to another program like TeX, e.g. for verbatim display.
You can use TextForm to do this -- and there is no need to use Print.
PrintNodeCoordinates[xyzcoor_]:= Module[
{numnod=Length[xyzcoor],t,n,c},
t=Table[" ",{numnod+1},{4}];
For [n=1,n<=numnod,n++,c=xyzcoor[[n]];
If [Length[c]<=2, AppendTo[c,0]];
If [Length[c]==1, AppendTo[c,0]];
t[[n+1,1]]=ToString[n];
t[[n+1,2]]=PaddedForm[c[[1]]];
t[[n+1,3]]=PaddedForm[c[[2]]];
t[[n+1,4]]=PaddedForm[c[[3]]];
];
t[[1]] = {"node","x","y","z"};
TextForm[TableForm[t,TableAlignments->{Right},
TableDirections->{Column,Row},TableSpacing->{0,1}]]
]
If you Put this output to a temporary file you get exactly what you want:
PrintNodeCoordinates[
{{2,3,2000},{5,a+b,168.09},{x_dir,y_dir,z_dir}}] >> /tmp/tmp.out
The file /tmp/tmp.out reads
node x y z
1 2 3 2000
2 5 a + b 168.09
3 x_dir y_dir z_dir
Cheers,
Paul
--
Paul Abbott Phone: +61 8 9380 2734
School of Physics, M013 Fax: +61 8 9380 1014
The University of Western Australia (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009 mailto:paul at physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul