[comp.lang.pascal] Fortran routines from pascal?

cnbr17@vaxa.strath.ac.uk (03/07/91)

Hi all,
	I am supervising a project student who has been writing some
software in Pascal, and she now has a need to call a NAG Fortran
library routine from within her program. Does anyone know how to go
about calling a Fortran routine from Pascal? I have called NAG routines
from C without too much trouble, but I don't know what differences there
would be with Pascal.
	This is on an HP 9000 series 300 workstation running HP-Ux 7.0
if that helps.

Thanks,
Peter.

-- 
================================================================================
Peter Duffy           |JANET:   p.duffy@uk.ac.strath.vaxa
EEE Dept.             |Internet:p.duffy%vaxa.strath.ac.uk@nsfnet-relay.ac.uk
Strathclyde University|BITNET:  p.duffy%vaxa.strath.ac.uk@UKACRL
Glasgow G1 1XW        |UUCP:    p.duffy%vaxa.strath.ac.uk@ukc.uucp
Scotland.             |
================================================================================

bigelow@hpfcso.FC.HP.COM (Jim Bigelow) (03/13/91)

>	This is on an HP 9000 series 300 workstation running HP-Ux 7.0
> if that helps.

It does.  

> ... Does anyone know how to go
> about calling a Fortran routine from Pascal? 

1) You must provide an external declaration for the fortran routines.  If the 
external name is the same as the one you're going to use in the Pascal
code, nothing more need be done.  If the name is different you must
use the $alias  directive (be sure to add the the leading '_').  For
example,

procedure fortran_sub; external;
procedure fortran_routine $alias '_real_name'$; external;

2) Pascal to Fortran Inter-language Compatibility

  Pascal	Fortran

  boolean	logical*1
		logical*2 logical*4 -- won't work

  char		character*1

  integer	integer (*4)

  -32768..32767 integer (*2)

  real		real (*4)

  longreal	double precision

  enumberated   use integer*2
   type

  subrange	use integer*4
   (32-bit)

  subrange	use integer*2
   (16-bit)

  set		none

  record	record

  pointer	none

  var^		none

2) calling FORTRAN

  Arrays
    pascal stores in row-major, FORTRAN in column-major

  Files
    A FORTRAN unita can not be passed to a Pascal routine to perfrom
    I/O. Conversly, Pascal files can not be passed to FORTRAN.

  Parameter Passing
    FORTRAN passes by reference, therefore all pascal paramters must
    be var.
  
  Complex numbers
    Pascal must define a type complex:
    	type complex : record
		real_part,
		imaginary_part : real;
		end;

   FORTRAN complex*16 not supported in pascal
  
  Fortran Hollerith and Character:
    Equivalent to Pascal packed array of char


  Pascal procedure parameters

   Fortran must allow for the static link associated with all pascal
   functions when accepting a pascal function as a parameter.


Please write for more information/claraification (jim@hpfcrt.hp.com)
or refer to the follwoing manuals:

   "HP-UX Paortability Guide"   	B1864-90006
   "HP-UX Assembler and Tools"		B1699-90000
   "HP Pascal Language Reference"	B1689-90600


Best Regards,

Jim Bigelow

HP Pascal HP9000 S300/S400
Colorado language Lab.

Hewlett Packard MS 96
3404 East Harmony Road
Ft. Collins, CO 80525
USA

cd5340@mars.njit.edu (David Charlap) (03/14/91)

I don't know about your implimentation, but on the PC, there are other
more serious concerns.  mostly, that each language uses a different 
convention for parameter/return-address passing.  MS-fortran allows
the user to specify if a procedure is to use FORTRAN, PASCAL, or C 
calling conventions.  MS-pascal and MS-C also have similar declarations.
If the wrong conventions are used, no parameters will pass correctly,
and there's no gurantee that anything will work right.

MS-Fortran also allows strings to be formatted as PASCAL or C strings
in addition to the CHARACTER*n type that FORTRAN normally uses.
--
David Charlap                   "Invention is the mother of necessity"
cd5340@mars.njit.edu            "Necessity is a mother"
Operators are standing by	"mother!" - Daffy Duck