Let's say I have some expression like,
expr = 1*a + 2*b +3*c + 4*d
I want to write this to a string that I can then use in some other Fortran script. I want all the integers to be of the form "X.0_dp". To do this I can simply do,
StringReplace[
ToString[expr, FortranForm], {"1" -> "2.0_dp", "2" -> "2.0_dp",
"3" -> "3.0_dp", "4" -> "4.0_dp"}]
which works a treat.
Now, is there a way such that I don't have to do this by hand, and generalizes to all integers? e.g. something of the form,
StringReplace[
ToString[expr, FortranForm], {"x" -> "x.0_dp"}]
Thanks for any help
StringReplace[ToString[expr, FortranForm], x : NumberString :> If[StringFreeQ[x, "."], x <> ".0_dp", x <> "0_dp"]]
suit your needs? $\endgroup$