[Date Index] [Thread Index] [Author Index]
Print numbers to ASCII file with precise column widths
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.