From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,96424a7ea58e8817 X-Google-Attributes: gid103376,public From: gisle@apal.ii.uib.no (Gisle S�lensminde) Subject: Re: help on interfacing with fortran Date: 2000/01/16 Message-ID: #1/1 X-Deja-AN: 573367532 Content-Transfer-Encoding: 8bit References: <38818E32.FD90616B@cstc.org> Organization: University of Bergen, Norway Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-01-16T00:00:00+00:00 List-Id: 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)