Print numbers to ASCII file with precise column widths
- To: mathgroup at smc.vnet.net
- Subject: [mg100256] Print numbers to ASCII file with precise column widths
- From: Chonny <jconant at aerodyne.com>
- Date: Fri, 29 May 2009 20:59:15 -0400 (EDT)
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.