comp.lang.ada
 help / color / mirror / Atom feed
From: gisle@apal.ii.uib.no (Gisle S�lensminde)
Subject: Re: help on interfacing with fortran
Date: 2000/01/16
Date: 2000-01-16T00:00:00+00:00	[thread overview]
Message-ID: <slrn883q7d.899.gisle@apal.ii.uib.no> (raw)
In-Reply-To: 38818E32.FD90616B@cstc.org

In article <38818E32.FD90616B@cstc.org>, Paolo M. Pumilia wrote:
>
>I would like to interface a set of fortran soubroutines and functions
>to main Ada procedure.
>Here are enclosed three functions and a subroutine which i am working
>on, at present. They are all stored in a single file, that i used to
>compile and link to its fortran main code.
>
>The Ada procedure makes one call to the subroutine start_carry(idum),
>getting an integer number (idum) in return
>
>Then the function rnor(idum) will be called, returnig a real*8 random
>number.
>
>How to perform such calls?
>
>I took a look at tha ARM, but its contents appears rather cryptic to me.
>I have been reading a few introductive manuals (Lovelace, Dodrill-tutor,
>etc) but they don't cover this topic very well.

>Interfacing is completely new in my experience. Could those four fortran
>codes be kept within a single file or should they be included into an
>Ada package or procedure?

>A procedure for each function or subroutine should be prepared? How do
>calls between fortran functions (not involving Ada code) will be 
>performed?

Here is a pice of code that do what you tried to do. Since it seems
that you have some problem with the Ada syntax in general, I have 
tried to make some hopefully useful comments in the code. The code
seemed to work on SGI IRIX 6.5 with gnat 3.11b and g77. The code was
compiled with:

g77 -c -fno-second-underscore rnor.f
gnatmake ada_main.adb -largs rnor.o

with Interfaces.Fortran;
use Interfaces.Fortran;
procedure Ada_Main is
   package Fortran renames Interfaces.Fortran;

   -- I use the "Fortran types" decleard in interfaces.fortran,
   -- which match the types used by the fortran compiler.

   dummy : Fortran.Fortran_Integer;

   -- This is how external fortran subroutines is declared.
   -- Fist a specification, followed by a pragma import.

   procedure start_carry (dummy : in out Fortran.Fortran_Integer);
   pragma Import (Fortran, Start_Carry,"start_carry_");

   -- Unlike Fortran, functions in Ada do not allow
   -- out parameters in functions.
   function rnor(dum : in Fortran.Fortran_Integer) return Fortran.Real;

   -- The pragma imports use the optional third parameter that
   -- specifies the link name. Somtimes this is neccesary, since
   -- different compilers on a single platform may give functions
   -- and subroutines different link names, by inserting underscores.
   pragma Import (Fortran, Rnor, "rnor_");

   A : Fortran.Real;
begin
   -- And here comes the calls
   start_carry(dummy);
   a := rnor(dummy);
end Ada_Main ;


 

>Here is my guess applied to Ada_Main procedure:

- Gisle S�lensminde (gisle@ii.uib.no)




  reply	other threads:[~2000-01-16  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-16  0:00 help on interfacing with fortran Paolo M. Pumilia
2000-01-16  0:00 ` Gisle S�lensminde [this message]
2000-01-25  0:00   ` pumilia
     [not found] <CB1575D4D198D311A3F800600803947E70B5F5@scopent3.mar.hp.com>
2000-01-20  0:00 ` Oliver Kellogg
2000-01-22  0:00   ` Paolo M. Pumilia
2000-01-22  0:00     ` Oliver Kellogg
2000-01-23  0:00     ` Oliver Kellogg
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox