Re: C++ wrapper for a fortran77 program??

From: Catherine Rees Lay (spamtrap_at_polyhedron.org.uk)
Date: 06/09/04


Date: Wed, 9 Jun 2004 09:49:15 +0100

In article <a71eefaa.0406081846.2a6821cf@posting.google.com>, hc2002
<c.hong@mailcity.com> writes
>beliavsky@aol.com wrote in message
>news:<3064b51d.0406080719.56adbda5@posting.google.com>...
>> c.hong@mailcity.com (hc2002) wrote in message
>>news:<a71eefaa.0406071540.750cdcfc@posting.google.com>...
>> > Hi everyone,
>> >
>> > I have a fortran77 program on unix (made up of 5 fortran program files
>> > and about 5k lines). I would like to make it work on windows. Besides
>> > completely rewriting the fortran program in c or c++, I was told that
>> > a C++ wrapper to call the functions inside of it may work as well. I
>> > am looking for the most practical way to do this project. And if C++
>> > wrapper is the best option, what steps should I take? Some examples
>> > will be appreciated. I know some of c and c++, but not an expert.
>> > Thanks for any of your advice on this...
>> >
>> > Hong
>>
>> If the Unix program is text-based and you want the same thing on
>> Windows, just get a Fortran 77 compiler for Windows (as others have
>> said), such as g77 or Open Watcom. If you want the Windows program to
>> have a GUI, then things are more complicated. Fortran compiler vendors
>> such as Absoft, Intel, Lahey, and Salford do provide facilities to
>> simplify GUI creation without becoming a full-fledged Windows
>> programmer. Other frequently-mentioned choices are Tcl/Tk (free, and
>> usable on Windows and Unix), Borland Delphi, Visual Basic, and Visual
>> C++. Other products to simplify GUI creation are Winteracter and
>> GINOMENU.
>
>Hi guys,
>
>Thanks a lot for all of your good comments. I slightly modified my
>fortran programs and compiled it on G77 compiler. It generated an .exe
>file, which works great! The reason why I was and still am thinking
>about a wrapper is that it might allow other software to call my
>fortran functions more easily. So it can become more portable. I am
>not sure if I am thinking correctly. Any further comments are highly
>appreciated.
>
>Hong

If you want other software to call your functions, possibly the easiest
way is just to take your main program out and compile everything else
into a DLL. Then you can give this to anyone, with details about what
calling convention you use, and they can call your routines.

Now this is where your C++ wrapper might come in useful. If your
routines accept character arguments, for instance, the other software
will have to pass them in the form which your Fortran compiler expects,
and this is unlikely to be the default form that their C++ compiler
uses. With a C++ wrapper which takes arguments the way that C++ passes
them and converts them to what your Fortran expects, you get to figure
out how to make this work properly and they don't have to.

Having said that, if the other software is written in, say, Delphi,
having a C++ wrapper isn't really much more use than the original
Fortran calling sequences. A Delphi wrapper, on the other hand, would
then be just what you want. So don't do a lot of work on this sort of
stuff unless it's actually going to be used. It doesn't make your code
any more portable, it just makes it easier to call from a different
single language.

HTH,

Catherine.

-- 
Catherine Rees Lay
To email me, use my first name in front of the "at".


Relevant Pages

  • Re: Who uses clapack?
    ... been a FORTRAN compiler available for the target platforms that I was ... Even when a FORTRAN compiler is ... on what you are trying to accomplish with a new version of LAPACK. ...
    (comp.lang.fortran)
  • Re: Who uses clapack?
    ... been a FORTRAN compiler available for the target platforms that I was ... Even when a FORTRAN compiler is ... on what you are trying to accomplish with a new version of LAPACK. ...
    (sci.math.num-analysis)
  • Re: g95 versus gfortran
    ... One is to take a stable snapshot of the GCC parts, ideally from a well-debugged non-experimental branch, so that the Fortran parts are the only new things and one doesn't have to deal with updating the Fortran code to deal with changes in the other part of the compiler. ... It's even included as part of the official GCC source tree, which means that changes to GCC are immediately and automatically part of GFortran. ... Version 4.1.2 is the current release branch, which at this point is quite stable, but has a fairly incomplete Fortran compiler. ...
    (comp.lang.fortran)
  • Re: Who uses clapack?
    ... been a FORTRAN compiler available for the target platforms that I was ... Even when a FORTRAN compiler is ... on what you are trying to accomplish with a new version of LAPACK. ...
    (comp.lang.c)
  • Re: calling c from fortran 90
    ... from the fortran 90 program shud be defined. ... a tiny wrapper around the C routines which takes care of the parameter ... interface for the wrapper, or you could write directly an interface ... arrays of elemental types can be passed with caution (no ...
    (comp.lang.fortran)