Re: [Dev-C++] Mixed Language Programming w/Dev-Cpp
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <h.r...@gm...> - 2002-10-29 21:37:18
|
> Hi, > > Wondering if anyone has experience with mixed language programming and > whether it can be done with Dev-Cpp? > > In particular, I'm writing a mathematical simulation in C (using Dev-Cpp) > and would like to make using of some existing numerical routines in > Fortran. > My C knowledge is necessity-based self-taught and so limited; don't know > anything about Fortran. Neither do I know much about using > compilers/linkers/etc in command line mode (which is why I use Dev-Cpp--I > let it worry about that stuff). > > Still, I know that built-in to the gcc interface is the g77 compiler so > there must be a way to compile the fortran source to an object with g77 > and > then link to & call the routines from C. Could it be as simple as added > fortran source files to my Dev-Cpp project? If so, any thoughts on how to > prototype the Fortran functions & subfunctions to make them accessible to > the C calling routines? > > BTW, I've tried f2c but have been unable to make that work. That approach > is suboptimal anyway because the resulting C code is far less efficient > than > the original Fortran source. > > Perhaps specifics would help. The fortran code I'm trying to use is a > single file ode.f The entry point is the subroutine ode. Here's how the > file is laid out: > > // ode.f > > subroutine ode(f,neqn,y,t,tout,relerr,abserr,iflag,work,iwork) > implicit real*8(a-h,o-z) > > c f -- double precision subroutine f(t,y,yp) to evaluate > c derivatives yp(i)=dy(i)/dt > c neqn -- number of equations to be integrated (integer*4) > c y(*) -- solution vector at t (real*8) > c t -- independent variable (real*8) > c tout -- point at which solution is desired (real*8) > c relerr,abserr -- relative and absolute error tolerances for local > c error test (real*8). at each step the code requires > c dabs(local error) .le. dabs(y)*relerr + abserr > c for each component of the local error and solution vectors > c iflag -- indicates status of integration (integer*4) > c work(*) (real*8) -- arrays to hold information internal to > c iwork(*) (integer*4) which is necessary for subsequent calls > > . . . ode calls de: > subroutine de(f,neqn,y,t,tout,relerr,abserr,iflag, > 1 yy,wt,p,yp,ypout,phi,alpha,beta,sig,v,w,g,phase1,psi,x,h,hold, > 2 start,told,delsgn,ns,nornd,k,kold,isnold) > implicit real*8(a-h,o-z) > > . . . de calls step & intrp: > subroutine step(x,y,f,neqn,h,eps,wt,start, > 1 hold,k,kold,crash,phi,p,yp,psi, > 2 alpha,beta,sig,v,w,g,phase1,ns,nornd) > implicit real*8(a-h,o-z) > > subroutine intrp(x,y,xout,yout,ypout,neqn,kold,phi,psi) > implicit real*8(a-h,o-z) > // end ode.f > > The derivative function f is written in C (and that's where I was having > probs with the f2c route). > > All help is appreciated (sorry for the long post). > > Scott > there are many interesting articels about this topic in the web, e.g.: Carsten A. Arnholm Mixed language programming using C++ and FORTRAN 77 at: http://home.online.no/~arnholm/cppf77.htm#Section1 If you use google for search you will find many others. Horst -- Horst Rößner Postf. 1802 52205 Stolberg ICQ ID #74808448 h.r...@gm... h.g...@t-... +++ GMX - Mail, Messaging & more http://www.gmx.net +++ NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen! |