Обсуждение: Fortran functions?

Поиск
Список
Период
Сортировка

Fortran functions?

От
Lamar Owen
Дата:
Ok, I have an oddball question.  But let me give you a little background.

As a broadcast engineer, I often need to compute the distance to a groundwave
contour for an AM radio station.  The code to do this is in Fortran 77, which
compiles cleanly with g77 (after I made some minor modifications, since the
original was VAX/VMS Fortran).  Since the results of the calculations are
used for FCC regulatory purposes, it is recommended to use the FCC's actual
code (which is what I have), in Fortran, to perform the calculations.
Otherwise they may not accept my filings, which is expensive (it costs $$$ to
file applications with the FCC).

Has anyone here successfully used Fortran functions in PostgreSQL using g77 as
the compiler?
--
Lamar Owen
WGCR Internet Radio
1 Peter 4:11

Re: Fortran functions?

От
Chris Albertson
Дата:
I've not done exactly what you want but something close.

The easy way is to write a simple wraper function in "C"
that simply calls the FORTRAM function and returns the result.

PostgreSQL does not need to know anything about FORTRAN

Another option is to use "f2c" to convert the FORTRAN to C
but I'd go with the above.

--- Lamar Owen <lamar.owen@wgcr.org> wrote:
<SNIP>
> Has anyone here successfully used Fortran functions in PostgreSQL
> using g77 as the compiler?


=====
Chris Albertson
  Home:   310-376-1029  chrisalbertson90278@yahoo.com
  Cell:   310-990-7550
  Office: 310-336-5189  Christopher.J.Albertson@aero.org

__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

Re: Fortran functions?

От
Tom Lane
Дата:
Lamar Owen <lamar.owen@wgcr.org> writes:
> Has anyone here successfully used Fortran functions in PostgreSQL
> using g77 as the compiler?

No ... but g77 is supposed to produce C-compatible object code as long
as the Fortran isn't too oddball.  I've called g77 Fortran code from C
myself.  (Not sure what you're supposed to do if the Fortran code wants
to pass parameters through unnamed COMMON blocks, or other weirdnesses
:-()

I'd bet you could make it work with at most a thin layer of C wrapper
code.  Are you running into any specific problems?

            regards, tom lane

Re: Fortran functions?

От
Clive Page
Дата:
In article <200207161932.34319.lamar.owen@wgcr.org>,
Lamar Owen <lamar.owen@wgcr.org> wrote:
>Has anyone here successfully used Fortran functions in PostgreSQL using g77 as
>the compiler?

As others have posted, one obvious route is via C wrappers.  If this looks
complicated, there is a package which may help, called cfortran.h
Details on this website: http://www-zeus.desy.de/~burow/cfortran/



--
Clive Page   cgp@le.ac.uk

Re: Fortran functions?

От
Lamar Owen
Дата:
On Wednesday 17 July 2002 05:07 am, Clive Page wrote:
> Lamar Owen <lamar.owen@wgcr.org> wrote:
> >Has anyone here successfully used Fortran functions in PostgreSQL using
> > g77 as the compiler?

> As others have posted, one obvious route is via C wrappers.  If this looks
> complicated, there is a package which may help, called cfortran.h
> Details on this website: http://www-zeus.desy.de/~burow/cfortran/

Yes, people have been pretty helpful in the general case, but this 'package'
:-) may make life easier.  And that's why I asked before attempting it --
someone likely has been there before, let's see what problems and tricks they
found.

When I get to this project (I have to get all the functions I need to compile
under g77 first, and there's ~250,000 lines of quite baroque VAX Fortran
source to go through, and then I need to properly specify the interface in a
way that named COMMON's won't be required, as well as making sure the
functions used don't require passing values back by side effect -- quite a
bit of work before I get to the PostgreSQL side of things), I'll let people
know how it went.
--
Lamar Owen
WGCR Internet Radio
1 Peter 4:11

Re: Fortran functions?

От
Lamar Owen
Дата:
On Wednesday 17 July 2002 05:07 am, Clive Page wrote:
> Lamar Owen <lamar.owen@wgcr.org> wrote:
> >Has anyone here successfully used Fortran functions in PostgreSQL using
> > g77 as the compiler?

> As others have posted, one obvious route is via C wrappers.  If this looks
> complicated, there is a package which may help, called cfortran.h
> Details on this website: http://www-zeus.desy.de/~burow/cfortran/

Ok, another question, since you are basically 'Mr. Fortran' (being published,
after all):
What about PostgreSQL client bindings?  Know of any way of using libpq from
Fortran (g77 again)?

My cross-language linking skills are lacking.
--
Lamar Owen
WGCR Internet Radio
1 Peter 4:11

Re: Fortran functions?

От
Thomas Lockhart
Дата:
> My cross-language linking skills are lacking.

Once you get into it you'll be OK. C wrappers are necessary to convert
all "by value" results to "by reference" for Fortran, and you'll likely
need to do that anyway to get past the user-defined-function calling
parameter list.

In the past (and maybe now) there may be reversed order of arguments on
the stack and may be some name mangling from Fortran (I've seen
underscores added to the front of parameters for the linker).

It's been years since I've glued Fortran to C, but it is definitely
possible. And it should be smoother than back when I was doing it...

                  - Thomas

Re: Fortran functions?

От
Lamar Owen
Дата:
On Wednesday 17 July 2002 09:03 pm, Thomas Lockhart wrote:
> > My cross-language linking skills are lacking.

> Once you get into it you'll be OK. C wrappers are necessary to convert
> all "by value" results to "by reference" for Fortran, and you'll likely
> need to do that anyway to get past the user-defined-function calling
> parameter list.

> It's been years since I've glued Fortran to C, but it is definitely
> possible. And it should be smoother than back when I was doing it...

Well, after really digging into this code, I can see it is going to be yucky.
Very yucky.  Rewrite-city-grade yucky.  Subroutines get their params, some of
which pass back to the calling program -- and some of which are passed back
through COMMON's.  Yucky.

So I may go way-around-my elbow and use the Fortran-to-Python wrapper, and
then use the python PostgreSQL client.  And I'll just pull out the bare
minimum of this code -- which is a dozen or so functions out of 25,000 lines
or so of the core code.

Anyway, many thanks for the help and words of encouragement.
--
Lamar Owen
WGCR Internet Radio
1 Peter 4:11