Thread: [Dev-C++] Mixed Language Programming w/Dev-Cpp
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Scott W. <se...@al...> - 2002-10-29 20:33:49
|
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
|
|
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! |
|
From: Ioannis V. <no...@ho...> - 2002-10-30 09:26:44
|
> -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Scott Williams > Sent: Tuesday, October 29, 2002 10:34 PM > To: Dev-Cpp-Users@Lists. Sourceforge. Net > Subject: [Dev-C++] Mixed Language Programming w/Dev-Cpp >=20 >=20 > Hi, >=20 > Wondering if anyone has experience with mixed language programming and > whether it can be done with Dev-Cpp? >=20 > In particular, I'm writing a mathematical simulation in C=20 > (using Dev-Cpp) > and would like to make using of some existing numerical=20 > routines in Fortran. > My C knowledge is necessity-based self-taught and so limited;=20 > don't know > anything about Fortran. Neither do I know much about using > compilers/linkers/etc in command line mode (which is why I=20 > use Dev-Cpp--I > let it worry about that stuff). >=20 > Still, I know that built-in to the gcc interface is the g77=20 > compiler so > there must be a way to compile the fortran source to an=20 > object with g77 and > then link to & call the routines from C. Could it be as=20 > simple as added > fortran source files to my Dev-Cpp project? If so, any=20 > thoughts on how to > prototype the Fortran functions & subfunctions to make them=20 > accessible to > the C calling routines? Well if you download the whole MINGW distribution it contains a Fortran compiler. In theory as i can think of it, if you compile your fortran source code files to .o files and use C-style declarations of those functions in your C source code, you should be able to use them. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2002-10-30 09:40:13
|
I think there might be acoule of gotchas more to think about. Doesn't fortran have the reversed row/column order for multi-dimensional arrays? Anyway, I assume that there already exists excellent FAQ documents for this kind of problems. /Per W On Wed, 30 Oct 2002, Ioannis Vranos wrote: > > -----Original Message----- > > From: dev...@li... > > [mailto:dev...@li...] On Behalf > > Of Scott Williams > > Sent: Tuesday, October 29, 2002 10:34 PM > > To: Dev-Cpp-Users@Lists. Sourceforge. Net > > Subject: [Dev-C++] Mixed Language Programming w/Dev-Cpp > > > > > > 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? > > > Well if you download the whole MINGW distribution it contains a Fortran > compiler. In theory as i can think of it, if you compile your fortran > source code files to .o files and use C-style declarations of those > functions in your C source code, you should be able to use them. > > > Ioannis > > * Ioannis Vranos > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ioannis V. <no...@ho...> - 2002-10-30 10:33:43
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Wednesday, October 30, 2002 11:40 AM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] Mixed Language Programming w/Dev-Cpp > > > I think there might be acoule of gotchas more to think about. > > Doesn't fortran have the reversed row/column order for > multi-dimensional > arrays? I do not remember anything from Fortran except that it allows for counters in loops i, j etc.. But what you mentioned sounds like a syntax issue rather than an implementation issue. > > Anyway, I assume that there already exists excellent FAQ documents for > this kind of problems. Probably. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |