MathGroup Archive 1998

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

Search the Archive

Re: Re: Outputting Strings to a file

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14200] Re: [mg14189] Re: [mg14175] Outputting Strings to a file
  • From: "Clemens Frey" <Clemens.Frey at uni-bayreuth.de>
  • Date: Wed, 7 Oct 1998 03:00:35 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

-----Urspr|ngliche Nachricht-----
Von: David Withoff <withoff at wolfram.com> An: mathgroup at smc.vnet.net
<mathgroup at smc.vnet.net> Datum: Donnerstag, 1. Oktober 1998 02:44
Betreff: [mg14189] Re: [mg14175] Outputting Strings to a file


>> I am trying to output text to a file.  My data is in an array such as:
>>
>> {1,"AL",0.500000,0.500000,0.500000,0.300000,1.000000}
>>
>> or
>>
>> {"Line One","Line Two"}
>>
>> The program that is going to read the output file doesn't want the
>> quotes or the commas.
>>
>> I want the final file to look like:
>>
>> Line One
>> Line Two
>> 1 Al 0.500000 0.500000 0.500000 0.300000 1.000000
>>
>> How do I get Mathematica to output text without the quotes?  If I can
>> get that I'm pretty sure I can get the numbers and spacing correct.
>>
>> I'm running Mathmatica 3.0 on a powermac if that is important.
>>
>> Thanks for any help.
>>
>> --
>> Tom Murray
>>
>>      I believe in what I see
>>      I believe in what I hear
>>      I believe that what I'm feeling
>>      Changes how the world appears
>>
>>      Rush - "TOTEM" - Test For Echo
>
>Here is one possibility.  I expect that some variant of this, or other
>formatting functions, will do what you want.
>
>In[6]:= expr = {1,"AL",0.500000,0.500000,0.500000,0.300000,1.000000}
>
>Out[6]= {1, AL, 0.5, 0.5, 0.5, 0.3, 1.}
>
>In[7]:= Infix[expr /. p_Real -> PaddedForm[p, {7, 6}], " "]
>
>Out[7]= 1 AL  0.500000  0.500000  0.500000  0.300000  1.000000
>
>In[8]:= Write["file", OutputForm[
>            Infix[expr /. p_Real -> PaddedForm[p, {7, 6}], " "] ]
>        ]
>
>In[9]:= !!file
>1 AL  0.500000  0.500000  0.500000  0.300000  1.000000
>
>If you can get what you want formatted on the screen (probably in
>OutputForm), then you can write it to a file, as the same functionality
>is used for both purposes.
>
>Dave Withoff
>Wolfram Research
>
>

Hi MathGroupers!

I think that there are enough built-in features in Mathematica to get
adequate output.
Let test1 and test2 be defined as follows:

test1 = {1,"AL",0.500000,0.500000,0.500000,0.300000,1.000000}; test2 =
{"Line One","Line Two"};

Besides, we have an OutputStream str1 (e.g. opend by str1 =
OpenWrite[...])

Then we can write (using Mathematica2.2)

WriteString[
    str1,
    TableForm[test1,TableDirections->{Row}] ];
WriteString[str1,"\n"];

to get the first list as a row with a newline at the end:

1 AL 0.5 0.5 0.5 0.3 1.


Another option of TableForm can be used to control the spacing, like in

WriteString[
    str1,
   TableForm[test2,TableDirections->{Column},TableSpacing->{0}] ];
WriteString[str1,"\n"];

which outputs the second list as a column:

Line One
Line Two


Hope this helps.
Clemens




  • Prev by Date: Subscripting Matrices (Syntax Question ?)
  • Next by Date: 3-D to 2-D slice revisited
  • Previous by thread: Re: Subscripting Matrices (Syntax Question ?)
  • Next by thread: 3-D to 2-D slice revisited