🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.math.num-analysis
Article #960

Re: calling Fortran libraries with C

#960
From: 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	     |
Technical Details
Message-ID: <92Nov23.201317.12471@acs.ucalgary.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!van-bc!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!acs.ucalgary.ca!lessard
References: <1ep9qjINNsni@agate.berkeley.edu>

Show Full Headers
Complete Article Headers
Newsgroups: sci.math.num-analysis
Path: arc1-ca.pugleaf.net!sparky!uunet!van-bc!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!acs.ucalgary.ca!lessard
From: lessard@acs.ucalgary.ca (Rodney Lessard)
Subject: Re: calling Fortran libraries with C
Sender: news@acs.ucalgary.ca (USENET News System)
Message-ID: <92Nov23.201317.12471@acs.ucalgary.ca>
Date: Mon, 23 Nov 92 20:13:17 GMT
Distribution: ba
References: <1ep9qjINNsni@agate.berkeley.edu>
Nntp-Posting-Host: acs5.acs.ucalgary.ca
Organization: The University of Calgary, Alberta
Keywords: Fortran, C
Lines: 51