Re: Re: C f-format-like output in Mma
- To: mathgroup at smc.vnet.net
- Subject: [mg7916] Re: [mg7710] Re: [mg7683] C f-format-like output in Mma
- From: jvallino at mbl.edu (Joe Vallino)
- Date: Mon, 21 Jul 1997 03:22:07 -0400
- Organization: Marine Biological Laboratory
- Sender: owner-wri-mathgroup at wolfram.com
In article <5q766r$10u at smc.vnet.net>, withoff at wolfram.com says...
>
>Andreas Siemer wrote:
>>
>> Hi folks,
>>
>> does anyone know whether there is a simple way to format output
>> of real numbers in Mma with fixed space and a fixed number of digits
>> following the decimal point in a way similar to the C or FORTRAN
>> f-format?
>>
>> Thanks for any suggestions!
>>
>> --
>>
>> ---------------------------------------------------------------------------
>> From: Dr. Andreas Siemer
To: mathgroup at smc.vnet.net
>> To: mathgroup at smc.vnet.net
>> Alfred-Wegener-Institut fuer Polar- und Meeresforschung
>> Sektion Physik I
>> Am Handelhafen 12
>> D-27570 Bremerhaven, Germany
>>
>> Tel.: +49-471-4831-524
>> FAX: +49-471-4831-425 ( indicate recipient: Siemer/Physik I
>> )
>> email: asiemer at AWI-Bremerhaven.de
>> ---------------------------------------------------------------------------
>
>Yes.
>
>Here is one example.
>
>In[8]:= data = Table[Random[] 10^k, {k, -20, 20, 5}]
>
> -21 -16 -11 -6
>Out[8]= {6.79773 10 , 4.93667 10 , 2.4602 10 , 1.74807 10 , 0.715808,
>
> 9 14 18
>> 58151.4, 1.34651 10 , 6.98729 10 , 3.97218 10 }
>
>In[9]:= PaddedForm[ColumnForm[FortranForm /@ data], {8, 3}]
>
>Out[9]//PaddedForm= 6.798e-21
> 4.937e-16
> 2.460e-11
> 1.748e-6
> 0.716
> 58151.398
> 1.347e9
> 6.987e14
> 3.972e18
>
>There are many variants of this. Using PaddedForm, NumberForm, etc., and
>options of these functions you can basically do anything that you want.
>
>Dave Withoff
>Wolfram Research
>
Here's one I use to write matrices to a file:
writeMatrix[data_List, filename_String] := Module[{outfile},
outfile = OpenWrite[filename];
SetOptions[outfile,FormatType\[Rule]OutputForm,PageWidth\[Rule]\[Infinity]];
Write[outfile,MatrixForm[Map[FortranForm,data,{2}],TableSpacing->{0,3}]];
Close[outfile];
]
------------------------------------------------------
Joseph Vallino | (508) 289-7648
Ecosystem Center | FAX: (508) 457-1548
Marine Biological Laboratory | jvallino at mbl.edu
Woods Hole, MA 02543 US | http://eco25.mbl.edu/