🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: sci.math.num-analysis
3 messages
3 total messages Started by actize Mon, 23 Nov 1992 00:49
calling Fortran libraries with C
#948
Author: actize
Date: Mon, 23 Nov 1992 00:49
9 lines
733 bytes
I program in C, and most of our mathematical libraries are in Fortran 77.
Our online documentation describes a few things, such as 
1.	Fortran calls by address
2.	The order of array storage is different.

Does anybody have experience with this, and advice ?

David
actize@garnet.berkeley.edu
Re: calling Fortran libraries with C
#950
Author: Mike Gross
Date: Mon, 23 Nov 1992 04:25
46 lines
2023 bytes
In <1ep9qjINNsni@agate.berkeley.edu> actize@garnet.berkeley.edu () writes:

>I program in C, and most of our mathematical libraries are in Fortran 77.
>Our online documentation describes a few things, such as 
>1.	Fortran calls by address
>2.	The order of array storage is different.

>Does anybody have experience with this, and advice ?

>David
>actize@garnet.berkeley.edu

If you're programming on a Sun, the SunOS fortran manual has a whole chapter
on this. IBM's RS-6000 has a similar document, though it isn't as detailed.

A few more differences (assuming you're on a Unix system):

All fortran routines are converted to lowercase and have an underscore appended
to the end of the function name.

Strings are passed in an odd manner--there is an extra argument at the *end*
of the argument list for each string passed. This is a long (*not* a long *)
and it holds the length of the string in bytes.

Subroutines return int *'s. Functions return the corresponding type in C (passed
by reference, of course).

You must link in libF77.a (or libV77.a if you need VMS compatibility).

int * <--> INTEGER or INTEGER*4
long * <--> INTEGER*8
char * <--> CHARACTER or INTEGER*1 or CHARACTER*n or LOGICAL
double * <--> DOUBLE PRECISION or REAL*8
float * <--> REAL or REAL*4

Complex numbers correspond to a structure of two of the appropriate floating
point type.

If you're programming a VMS system, all this is BS.

Good luck.

Mike Gross
Physics Board
Univ of California                 GO SLUGS!!!!!
Santa Cruz, CA 95064
Re: calling Fortran libraries with C
#960
Author: Rodney Lessard
Date: Mon, 23 Nov 1992 20:13
51 lines
2252 bytes
In article <1ep9qjINNsni@agate.berkeley.edu> actize@garnet.berkeley.edu () writes:
>I program in C, and most of our mathematical libraries are in Fortran 77.
>Our online documentation describes a few things, such as 
>1.	Fortran calls by address
>2.	The order of array storage is different.
>
>Does anybody have experience with this, and advice ?
>
>David
>actize@garnet.berkeley.edu

I have had some experience with this phenomena by calling NCAR
graphics and IMSL fortran routines from my C code. It is actually
not that difficult. Here some examples.

1. Fortran programs must be declared extern.
	extern int srface();
2. Like you mentioned arguments must be passed by address.
	call srface(x,y,10) looks like

	static int c_10 = 10;
	float x[100],y[100];
	srface(x,y,&c_10);
3. String arguments must be passed their length at the end of the
argument list.
	call srface(x,y,'Title') looks like

	srface(x,y,"Title",5L);
4. Ordering of multi-dimensional arrays is different. For example
	x(10)(20) would look like
	x[200] where x(1)(1..20) fills x[0..19] and so on.

This part is a little tricky and may need some test programs if
your not sure. After all is said and done maybe you should try
the f2c program available from netlib to get some idea of how it
is done. Note: you will have to do some tricks to get common
block declarations going. Basically you declare a structure.
E-mail me if you need more help.

Cheers






-- 
| Rod Lessard					lessard@acs.ucalgary.ca      |
| Cosmic Ray Group				2500 University Drive	     |
| Dept. of Physics and Astronomy		Calgary, AB, Canada	     |
| University of Calgary				(403) 220 - 3640	     |
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads