Re: Print numbers to ASCII file with precise column widths

*To*: mathgroup at smc.vnet.net*Subject*: [mg100419] Re: Print numbers to ASCII file with precise column widths*From*: dh <dh at metrohm.com>*Date*: Wed, 3 Jun 2009 01:10:16 -0400 (EDT)*References*: <gvq0c8$muk$1@smc.vnet.net>

Hi Chonny, I think PaddedForm mainly deals with real numbers. Therefore, the decimal separator is accounted for by "number of digits". Therefore, for integers, you get one place more than indicated. To obtain an e-representation with a given fileswidth you may e.g. try: ======================= dat = Pi 1. 10^-10; fieldwidth = 8; t = ToString@ NumberForm[dat, {4, 2}, NumberFormat -> (Row[{#1, "e", If[#3 === "", "0", #3]}] &), ExponentFunction -> (# &)]; While[StringLength[t] < fieldwidth, t = " " <> t]; t ============================== Daniel Chonny wrote: > Hi, > I want to generate some "simple" ASCII files suitable for reading > by old Fortran programs, which expect numbers in precise formatted > columns, e.g., "FORMAT(I5,F10.3,E10.5)". I've been trying all sorts > of variations of PaddedForm, FortranForm, OutputForm, ..... > > Here's an example with a simple negative integer: > > strm = OpenWrite["testout.txt"]; > WriteString[strm, ToString[ PaddedForm[-11, 5] ] <> "\n"]; > WriteString[strm, "1234567890"]; > Close[strm]; > FilePrint["testout.txt"]; > > -11 > 1234567890 > > The font in this post doesn't show it, but the "-11" ends in the 6th > column, not the 5th. And then I need to tackle floats with > exponents!! I obviously don't understand the underlying Mathematica > V7 output functionality. >