473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Many Fortran code! How to call Fortran code from C/C++?

Hi all,

As a C/C++ programmer, there are a few reasons to use Fortran:

(1) Fortran is very similar to Matlab and easy to port;
(2) Fortran has support of complex numbers and vectorized numbers and
the operations in Fortran are naturally element-wise, operating on a
whole vector.
(3) There are many scientific codes are in Fortran.

-------------

So how do I call Fortran program from my C program?

I am using MSVS. NET 2003, VisualC++ and Intel C++ therein, and also
the Intel Visual Fortran therein.

To give an example, I want to call a Fortran program from C++, which
is in its bare form, it is a function that evaluates something and
pass the results back; I also want to call C++ from Fortran, one
example is that many good numerical integral codes are in Fortran, but
I want to provide my integrand function in C++.

How to do these interfaces? Pointers and readings are appreciated!
Thanks for your help!

Aug 22 '07 #1
8 2056
Luna Moon wrote:
Hi all,

As a C/C++ programmer, there are a few reasons to use Fortran:

(1) Fortran is very similar to Matlab and easy to port;
(2) Fortran has support of complex numbers and vectorized numbers and
the operations in Fortran are naturally element-wise, operating on a
whole vector.
(3) There are many scientific codes are in Fortran.

-------------

So how do I call Fortran program from my C program?

I am using MSVS. NET 2003, VisualC++ and Intel C++ therein, and also
the Intel Visual Fortran therein.

To give an example, I want to call a Fortran program from C++, which
is in its bare form, it is a function that evaluates something and
pass the results back; I also want to call C++ from Fortran, one
example is that many good numerical integral codes are in Fortran, but
I want to provide my integrand function in C++.

How to do these interfaces? Pointers and readings are appreciated!
Thanks for your help!
RTFM
Aug 22 '07 #2
Luna Moon <lu**********@gmail.comwrites:
>So how do I call Fortran program from my C program?
It depends.
http://www-h.eng.cam.ac.uk/help/tpl/...languages.html
mostly deals with issues in a linux situation.
Aug 22 '07 #3
Tim Love wrote:
Luna Moon <lu**********@gmail.comwrites:
>So how do I call Fortran program from my C program?

It depends.
http://www-h.eng.cam.ac.uk/help/tpl/...languages.html
mostly deals with issues in a linux situation.
Search the C standard for the word Fortran, and read the associated
text. If you don't find Fortran, or the associated text doesn't
describe such calls, what should you assume?

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Aug 22 '07 #4
On Aug 21, 8:22 pm, Luna Moon <lunamoonm...@gmail.com>
[snip]
So how do I call Fortran program from my C program?

I am using MSVS. NET 2003, VisualC++ and Intel C++ therein, and also
the Intel Visual Fortran therein.
[snap]

All the news groups you posted to, and none of them
are on-topic for your question. You need to try in a
newsgroup that has some connection to your compilers.
Try something with microsoft or windows or DOS in
the name, maybe visualC in the name, like that.
If you go to groups.google.com and look at the
news groups under microsoft.public.* you should
find some helpful areas. And IIRC, Intel maintains
some on-line forums at their web site for the Fortran
aspects.
Socks

Aug 22 '07 #5
On Wed, 22 Aug 2007 08:23:38 -0700, Puppet_Sock wrote
(in article <11**********************@i38g2000prf.googlegroups .com>):
On Aug 21, 8:22 pm, Luna Moon <lunamoonm...@gmail.com>
[snip]
>So how do I call Fortran program from my C program?

I am using MSVS. NET 2003, VisualC++ and Intel C++ therein, and also
the Intel Visual Fortran therein.

All the news groups you posted to, and none of them
are on-topic for your question.
Perhaps one should be familiar with the groups in question before making such
statements about them. I'd agree that this is obviously off-topic for
sci.math.num-analysis. I don't frequent comp.programming enough to know, but
it does seem likely to be off-topic there. I don't read comp.lang.c++, but
from what I have heard, the question might not be welcome there.

However, questions like this are definitely considered on topic in
comp.lang.fortran. I'd say it even counts as a FAQ. In fact, that's closer to
the reason I didn't take the time to answer.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
________________________________________________

Hogwasher, Premier News and Mail for OS X
http://www.asar.com/cgi-bin/product....hogwasher.html
________________________________________________

Aug 22 '07 #6

"Luna Moon" <lu**********@gmail.comwrote in message
news:11**********************@e9g2000prf.googlegro ups.com...
>
So how do I call Fortran program from my C program?
Too bad you're not using Ada. The interface between Ada and
Fortran is easy. For that matter, ther interface between Ada and
C is easy. Maybe you could simply create an Ada wrapper so
you could make the C and Fortran Code work together in a
more straightforward manner.

Richard Riehle
Sep 4 '07 #7
LR
Hi Richard,

ad******@sbcglobal.net wrote:
"Luna Moon" <lu**********@gmail.comwrote in message
news:11**********************@e9g2000prf.googlegro ups.com...
>So how do I call Fortran program from my C program?
Too bad you're not using Ada. The interface between Ada and
Fortran is easy.
Is that true no matter your platform and compilers?
For that matter, ther interface between Ada and
C is easy.
Same question.

LR
Sep 4 '07 #8

"LR" <lr***@superlink.netwrote in message
news:46***********************@news.uslec.net...
Hi Richard,

ad******@sbcglobal.net wrote:
>"Luna Moon" <lu**********@gmail.comwrote in message
news:11**********************@e9g2000prf.googlegr oups.com...
>>So how do I call Fortran program from my C program?
Too bad you're not using Ada. The interface between Ada and
Fortran is easy.

Is that true no matter your platform and compilers?
For that matter, ther interface between Ada and
C is easy.
This is especially true for C. I have not yet used it for Fortran, but
the interfaces are defined at the language level with special libraries.
The mechanism is implemented through a combination of libraries
and pragmas (compiler directives). For example, a matrix in Fortran
is very different from a matrix in either Ada or C so there is a pragma
for Fortran that automatically compensates for this.

I recommend contacting AdaCore, a company in New York City
that specializes in Ada compilers. Someone there can give you
more information.

Richard Riehle
Sep 4 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Greg | last post by:
Hello, I've to manage many 'table' (having same scheme) on the same server. And I ask myself what could be the best to do (and if you know, why) : Creating as many database (the name would...
3
by: Mikey | last post by:
Hi all. In the process of trying to figure this thing out, I've been doing the old "stand around in the store and read as much as possible before you look like a derelict" thing. This time, with...
2
by: Keith | last post by:
I am having a problem creating a many-to-many-to-many type relationship. It works fine, but when I create a view to query it and test it, it does not generate the results I expected. Below...
1
by: ning | last post by:
It's easy to present "One - Many" relationship in XML, but how to present "Many - Many" relationship in XML?
2
by: Megan | last post by:
hello everybody, i know this is a very long post, but i wanted to provide as much detail as possible. quick overview- i want to create a couple of many to many relationships and am wondering...
1
by: Johnny Meredith | last post by:
Hi, I'm building a database that, once a year, generates surveys that are emailed to people in our organization. The recipients of the surveys are managers of various departments. The emails...
1
by: Phil W | last post by:
Hello, I have set up my database in access using many to many relationships (it's the good ol' books and authors one again). I've actually extended it to include other people who contribute in...
13
by: the other john | last post by:
The trouble currently with 3 tables. I'm excluding non-relevant fields... tbl_users PK_user_ID tbl_developers PK_developer_ID FK_developer_user_ID FK_developer_project_ID
1
by: radiodave | last post by:
I don't know how to ask this question but I'll try: I'm making a database (Access 2003) for an Opera buff. I have tables related like: each Opera has many Productions (Madame Butterfly has an...
11
by: RobertJohn | last post by:
Hi all I am using Access 2007 to start a small home library application, and so far it has two tables. 1. Books, with fields Book_ID (Primary Key) and Title, and 2. Authors, with fields...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.