Many Fortran code! How to call Fortran code from C/C++? - Fortran
This is a discussion on Many Fortran code! How to call Fortran code from C/C++? - Fortran ; 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 ...
-
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!
-
Re: Many Fortran code! How to call Fortran code from C/C++?
"Luna Moon" <lunamoonmoon> wrote in message
news:1187742132.236717.297560@e9g2000prf.googlegroups.com...
> 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!
From Fortan calling C++, make sure the C++ functions are declared extern "C"
so there is no mangeling going on. Then check to see how to call C
functions from Fortran.
Either way, you'll have to check your compiler's documentation. It can be
different for different compilers.
-
Re: Many Fortran code! How to call Fortran code from C/C++?
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
-
Re: Many Fortran code! How to call Fortran code from C/C++?
Luna Moon <lunamoonmoon> writes:
>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.
-
Re: Many Fortran code! How to call Fortran code from C/C++?
On Aug 21, 8:22 pm, Luna Moon <lunamoonm...>
[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
-
Re: Many Fortran code! How to call Fortran code from C/C++?
On Wed, 22 Aug 2007 08:23:38 -0700, Puppet_Sock wrote
(in article <1187796218.813476.159280@i38g2000prf.googlegroups.com>):
> On Aug 21, 8:22 pm, Luna Moon <lunamoonm...>
> [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-****ysis. 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
________________________________________________
-
Re: Many Fortran code! How to call Fortran code from C/C++?
"Luna Moon" <lunamoonmoon> wrote in message
news:1187742132.236717.297560@e9g2000prf.googlegroups.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
-
Re: Many Fortran code! How to call Fortran code from C/C++?
Hi Richard,
adaworks@sbcglobal.net wrote:
> "Luna Moon" <lunamoonmoon> wrote in message
> news:1187742132.236717.297560@e9g2000prf.googlegroups.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
-
Re: Many Fortran code! How to call Fortran code from C/C++?
"LR" <lruss@superlink.net> wrote in message
news:46dd5c52$0$24567$cc2e38e6@news.uslec.net...
> Hi Richard,
>
> adaworks@sbcglobal.net wrote:
>> "Luna Moon" <lunamoonmoon> wrote in message
>> news:1187742132.236717.297560@e9g2000prf.googlegroups.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
Similar Threads
-
By Application Development in forum c++
Replies: 8
Last Post: 09-04-2007, 10:50 AM
-
By Application Development in forum Fortran
Replies: 12
Last Post: 08-02-2007, 07:36 AM
-
By Application Development in forum Fortran
Replies: 4
Last Post: 07-09-2007, 04:05 PM
-
By Application Development in forum Fortran
Replies: 1
Last Post: 07-07-2007, 06:45 AM
-
By Application Development in forum Fortran
Replies: 0
Last Post: 03-13-2007, 05:56 PM