FORTRAN
- To: mathgroup at yoda.physics.unc.edu
- Subject: FORTRAN
- From: CHALLACOMBE at baeyer.chem.fsu.edu
- Date: Fri, 19 Jun 1992 11:07:13 EDT
Dear MathGroup,
John Pender writes;
> does anybody know how to get mathematica to write a bunch of numbers to
> a file in fortran-compatible format? the best option i've found so far
> is to use the ColumnForm command, but as you can see below, the output
> isn't compatible with standard fortran (which uses ** instead of ^). if
> you use the FortranForm command you get (at least on my machine) a lot of
> excess baggage as well. i can work around this problem, but it sure seems
> to me that there's got to be a nice way to do such a simple i/o excercise.
Here is an (inelegent) way of generating strings suitable for output in FORTRAN
data statements, etc.;
format[x_]:=ToString[ PaddedForm[x,{14,13},{
NumberFormat->(SequenceForm[#1,"D",#3]&)
,
ExponentFunction->(If[#==0,0,#]&)
}
]
];
I use it for writing data statements as follows;
WriteString[FileName,
StringJoin[" > ",format[b[i,k+0]],", ",format[b[i,k+1]], ",
",format[b[i,k+2]],",\n"]
];
Hope this helps,
Matt Challacombe
Program in Chemical Physics and SCRI
FSU, Tallahasse, 32306
(challacombe at baeyer.chem.fsu.edu)