请教?把fortran翻译成c&c++,以下是fortran写的程序,我用f2c翻译不成功?
c *** test nl2sol and nl2sno on madsen example ***
integer iv(62), uiparm(1)
real v(147), x(2), urparm(1)
external madr, madj
x(1) = 3.0
x(2) = 1.0
iv(1) = 0
call nl2sol(3, 2, x, madr, madj, iv, v, uiparm, urparm, madr)
iv(1) = 12
x(1) = 3.0
x(2) = 1.0
call nl2sno(3, 2, x, madr, iv, v, uiparm, urparm, madr)
stop
end
subroutine madr(n, p, x, nf, r, uiparm, urparm, ufparm)
integer n, p, nf, uiparm(1)
real x(p), r(n), urparm(1)
external ufparm
r(1) = x(1)**2 + x(2)**2 + x(1)*x(2)
r(2) = sin(x(1))
r(3) = cos(x(2))
return
end
subroutine madj(n, p, x, nf, j, uiparm, urparm, ufparm)
integer n, p, nf, uiparm(1)
real x(p), j(n,p), urparm(1)
external ufparm
j(1,1) = 2.0*x(1) + x(2)
j(1,2) = 2.0*x(2) + x(1)
j(2,1) = cos(x(1))
j(2,2) = 0.0
j(3,1) = 0.0
j(3,2) = -sin(x(2))
return
end
integer function imdcon(k)
c
integer k
c
c *** return integer machine-dependent constants ***
c
c *** k = 1 means return standard output unit number. ***
c *** k = 2 means return alternate output unit number. ***
c *** k = 3 means return input unit number. ***
c (note -- k = 2, 3 are used only by test programs.)
c
integer mdcon(3)
data mdcon(1)/6/, mdcon(2)/8/, mdcon(3)/5/
c
imdcon = mdcon(k)
return
c *** last card of imdcon follows ***
end
real function rmdcon(k)
c
c *** return machine dependent constants used by nl2sol ***
c
c +++ comments below contain data statements for various machines. +++
c +++ to convert to another machine, place a c in column 1 of the +++
c +++ data statement line(s) that correspond to the current machine +++
c +++ and remove the c from column 1 of the data statement line(s) +++
c +++ that correspond to the new machine. +++
c
integer k
c
c *** the constant returned depends on k...
c
c *** k = 1... smallest pos. eta such that -eta exists.
c *** k = 2... square root of 1.001*eta.
c *** k = 3... unit roundoff = smallest pos. no. machep such
c *** that 1 + machep .gt. 1 .and. 1 - machep .lt. 1.
c *** k = 4... square root of 0.999*machep.
c *** k = 5... square root of 0.999*big (see k = 6).
c *** k = 6... largest machine no. big such that -big exists.
c
real big, eta, machep
c/+
real sqrt
c/
real one001, pt999
c
data one001/1.001/, pt999/0.999/
c
c +++ ibm 360, ibm 370, or xerox +++
c
c data big/z7fffffff/, eta/z00100000/, machep/z3c100000/
c
c +++ data general +++
c
c data big/0.7237e+76/, eta/0.5398e-78/, machep/0.9537e-06/
c
c +++ dec 11 +++
c
c data big/1.7e+38/, eta/2.9388e-39/, machep/1.1921e-07/
c
c +++ hp3000 +++
c
c data big/1.1579e+77/, eta/8.6362e-78/, machep/2.3842e-07/
c
c +++ honeywell +++
c
c data big/o376777000000/, eta/o404400400000/,
c 1 machep/o716400000000/
c
c +++ dec10 +++
c
c data big/"377777777777/, eta/"000400000021/,
c 1 machep/"147400000000/
c
c +++ burroughs +++
c
c data big/o0777777777777777/, eta/o1771000000000000/,
c 1 machep/o1301000000000000/
c
c +++ control data +++
c
data big/37754000000000000000b/, eta/00024000000000000000b/,
1 machep/16414000000000000000b/
c
c +++ prime +++
c
c data big/1.7e+38/, eta/1.47e-39/, machep/2.38419e-7/
c
c +++ univac +++
c
c data big/1.69e+38/, eta/5.9e-39/, machep/1.4901162e-8/
c
c +++ vax +++
c
c data big/1.7e+38/, eta/2.939e-39/, machep/5.9604645e-08/
c
c------------------------------- body --------------------------------
c
go to (10, 20, 30, 40, 50, 60), k
c
10 rmdcon = eta
go to 999
c
20 rmdcon = sqrt(one001*eta)
go to 999
c
30 rmdcon = machep
go to 999
c
40 rmdcon = sqrt(pt999*machep)
go to 999
c
50 rmdcon = sqrt(pt999*big)
go to 999
c
60 rmdcon = big
c
999 return
c *** last card of rmdcon follows ***
end
subroutine nl2sol(n, p, x, calcr, calcj, iv, v, uiparm, urparm,
1 ufparm)
c
c *** minimize nonlinear sum of squares using analytic jacobian ***
c *** (nl2sol version 2.2) ***
c
integer n, p, iv(1), uiparm(1)
real x(p), v(1), urparm(1)
c dimension iv(60+p), v(93 + n*p + 3*n + p*(3*p+33)/2)
c dimension uiparm(*), urparm(*)
external calcr, calcj, ufparm
问题点数:100、回复次数:18Top
1 楼programjun(lijun)回复于 2003-10-03 20:30:46 得分 0
由于程序太长,不能贴在上面,有兴趣的可以发邮件!
谢谢!
这个程序是一个非线形算法NL2SOL,全牛顿算法.Top
2 楼lemon520(喷血)回复于 2003-10-03 22:49:04 得分 10
C++里面可以直接用呀!
extern "C"Top
3 楼Wolf0403(废人:独活十年~心如刀割)回复于 2003-10-03 23:08:50 得分 10
进来才发现偶什么都不懂。。。晕ingTop
4 楼leyt(思维机器)回复于 2003-10-04 09:36:15 得分 10
学习中Top
5 楼ipgk(loboho)回复于 2003-10-04 16:04:11 得分 10
fortran以前学过一点忘得一干二净了Top
6 楼programjun(lijun)回复于 2003-10-04 21:56:23 得分 0
我是要使用用这个算法
如果看不懂这个算法的缘由,根本不能运用到实际当中去,因为我不会fortran,只好翻译成c
来看了.我去查了很多国外的网站,几乎没有用c写的,即使有,也需要注册帐号且付费.
没办法了,只好在这里找高手求救.有会的请给出邮件地址,我把源文件和f2c工具发给你.
谢谢!
Top
7 楼dancerindark(麦田里守望者)回复于 2003-10-06 13:02:28 得分 10
好象清华出过一本关于c语言的数值算法的,对于这些问题看程序还不如看数学书。Top
8 楼programjun(lijun)回复于 2003-10-06 14:03:24 得分 0
是的,这种书我很多,一个数学公式的算法的程序写法很多,需要有算公式或者解集的经验
能很好的写出高效的计算方法,也不是一件容易的事.Top
9 楼scie()回复于 2003-10-10 16:18:07 得分 10
发给我吧,我会Fortran也会C,我不用F2C,手工转就行了。
scie@tom.comTop
10 楼scie()回复于 2003-10-12 11:00:57 得分 10
明天就要上班了,本想利用周末帮你翻的,看来没时间了。找点该算法的资料看看,自己写一个就行了,通过程序学一个算法是比较费劲的。Top
11 楼cupidvenus(小鱼儿)回复于 2003-10-14 10:26:43 得分 10
发给我吧,我会Fortran也会C,我不用F2C,手工转就行了。
21cn.comTop
12 楼cupidvenus(小鱼儿)回复于 2003-10-14 21:13:16 得分 10
发给我吧,我会Fortran也会C,我不用F2C,手工转就行了。
yy29@21cn.comTop
13 楼LHCat(青苹果乐园)回复于 2003-10-22 18:14:14 得分 10
用visual fortran 把他编译成dll
然后加入你的c++的工程中
应该可以Top
14 楼programjun(lijun)回复于 2003-11-21 18:07:19 得分 0
cupidvenus(小鱼儿)
我已经把全部的程序发给你了,希望能得到你的回应.
谢谢!Top
15 楼W32API()回复于 2003-11-22 08:55:45 得分 0
atiace@sina.comTop
16 楼W32API()回复于 2003-11-22 08:56:30 得分 0
可以发过来看看,不过太长的话就不一定有时间去看了。Top
17 楼cupidvenus(小鱼儿)回复于 2003-11-22 10:03:46 得分 0
程序很长啊!慢慢看了。Top
18 楼programjun(lijun)回复于 2003-11-22 13:12:41 得分 0
谢谢了,慢慢等待着.Top




