this is simple enough to do by hand..you will spend more time trying to automate the process than just typing the code out.
First a little manipulation of the original expression to get rid of the Abs
cons = {
c1 -> 1.31446,
c2 -> 1.58986,
c3 -> 0.91209,
c4 -> 0.84136}
dp = Piecewise[
{{c1 Tan[c2 y] + c3 y, Abs[y] < c4},
{1/(1 - y), c4 <= y < 1},
{-1/(1 + y), -1 < y <= -c4 }}]
dd = D[dp, y]
here you can use FortranForm
to pull out parts of the expression:
FortranForm[dd[[1, 1, 1]]]
c3 + c1*c2*Sec(c2*y)**2
just do that as needed and paste to the code as you write:
real function df(y)
implicit none
real::y
real,parameter::c1=1.31446,c2=1.58986,c3=0.91209,c4=0.84136
if(abs(y).gt.1)then
df=0
elseif( y.le.-c4)then
df=(1+y)**(-2)
elseif(y.gt.c4)then
df=(1-y)**2
else
df=c3 + c1*c2*Sec(c2*y)**2
endif
end
D
to your functionR
is meaningless. If you want to see the C-code forR
, useExportString[R,"C"]
. You have to search a bit for the relevant part of the code, though. Afterwards, you can easily translate it to fortran by hand (at least the standard arithmetics can be copied)... $\endgroup$Compile
at all if the goal is to create fortran code. $\endgroup$