Warning: as @george points out in the comments, something is wrong with the output of this package. It produced incorrect d0d0. I don't have time to investigate at the moment, so making it community wiki. Feel free to post your own (corrected) answer based on the information here.
Using the Format.m
package that @Orders posted,
expr = C3 (c - y) +
C3 (c + y) + ((1 + nu) (-1 + 2 nu) P (c - y) ArcTan[(-c + y)/
x])/(π Y) + ((1 + nu) (-1 + 2 nu) P (c +
y) ArcTan[(c + y)/x])/(π Y) + ((-1 + nu) (1 + nu) P x Log[
x^2 + (c - y)^2])/(π Y) + ((1 + nu) P (x - nu x) Log[
x^2 + (c + y)^2])/(π Y);
FortranAssign["expr", expr, AssignReplace -> {"log" -> "dlog"}, AssignOptimize -> False]
gives the following
expr = C3*(c - y) + C3*(c + y) + (3.183098861837907d-1*(1.d0 + n
& u)*(-1.d0d0 + 2.d0*nu)*P*(c - y)*atan((-c + y)/x))/Y + (3.183098
& 861837907d-1*(1.d0 + nu)*(-1.d0d0 + 2.d0*nu)*P*(c + y)*atan((c +
& y)/x))/Y + (3.183098861837907d-1*(-1.d0d0 + nu)*(1.d0 + nu)*P*x
& *dlog((c - y)**2 + x*x))/Y + (3.183098861837907d-1*(1.d0 + nu)*P
& *(x - nu*x)*dlog((c + y)**2 + x*x))/Y
The 3.183d-1
you see here is simply a decimal approximation of 1/Pi
to double precision.
We can also use automatic expression optimization, which changes the formula to an equivalent form that minimizes the number of arithmetic operations. For this it needs to use temporary variables, which I named tempXX
here.
FortranAssign["expr", expr, AssignReplace -> {"log" -> "dlog"},
"OptimizationSymbol" -> temp]
temp1 = -y
temp2 = c + temp1
temp6 = 1.d0 + nu
temp7 = 2.d0*nu
temp8 = -1.d0d0 + temp7
temp4 = c + y
temp9 = 1/Y
temp10 = 1/x
temp20 = x*x
expr = C3*temp2 + C3*temp4 + 3.183098861837907d-1*P*temp4*temp6*
& temp8*temp9*atan(temp10*temp4) + 3.183098861837907d-1*P*temp2*te
& mp6*temp8*temp9*atan(temp10*(-c + y)) + 3.183098861837907d-1*(-1
& .d0d0 + nu)*P*temp6*temp9*x*dlog(temp20 + temp2*temp2) + 3.18309
& 8861837907d-1*P*temp6*temp9*(x - nu*x)*dlog(temp20 + temp4*temp4
& )
Getting the package to work in Mathematca 10:
If you try to load it as is, it will complain about not finding Utilities`FilterOptions`
, a package that no longer ships with Mathematica 10. To fix this,
Change BeginPackage["Format`", "Utilities`FilterOptions`"]
to BeginPackage["Format`"]
.
Add FilterOptions[fun_, opts___] := Sequence@@FilterRules[{opts}, Options[fun]]
right after Begin["Private`"]
.
FortranForm
cannot translate functions. It can only translate simple expressions, and even then its result is more of a starting point ... I would useReplaceAll
onArcTan -> ATAN
and would edit the result with a text editor (including fixing numbers). $\endgroup$ – Szabolcs Mar 13 '16 at 16:55