Skip to main content
2 of 2
edited body

I also have this problem, and try this code F90Format

Unprotect[D]; Clear[D]; Protect[D];
NN[exp_] := N[exp, 50];
Unprotect[Real];
RTogle = False;
Real /: Format[r_Real /; r >= 0, FortranForm] /; (RTogle = ! RTogle) :=
   Module[{mantissa, exponent, tmp},
   {mantissa, exponent} = MantissaExponent[r];
   If[r === 0., exponent = 1];
   SequenceForm[10 mantissa, D, exponent - 1]
   ];
Protect[Real];
F90Format[exp_, pre_: ""] := Module[{tmp, sqrt, splits},
   tmp = FortranForm[exp];
   tmp = ToString[tmp, PageWidth -> Infinity, 
     TotalWidth -> Infinity];
   splits = StringSplit[tmp, " "];
   tmp = Fold[If[StringLength[Last@#1] + StringLength[#2] > 100,
       Join[#1, {#2}],
       Join[Most[#1], {StringJoin[Last[#1], #2]}]] &,
     {First@splits}, Rest[splits]];
   tmp = StringJoin @@ Riffle[tmp, " &\n"];
   tmp = pre <> tmp;
   Return[tmp];
   ];