LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-05-2009, 01:31 PM   #1
aihaike
Member
 
Registered: Feb 2006
Location: Paris, France
Distribution: Slackware, CentOS
Posts: 270

Rep: Reputation: 20
Question call Fortran90 in C (not C++)


Dear all,

I need to call a Fortran90 function from a C function.
Does anyone know how to do that?
Actually, my Fortran90 function just do anint(x).
I like this Fortran90 feature which I need in C.
If someone knows how to write an equivalent in C that would some the problem.
Anyway, it'd be interesting to know how to call Fortran90 from C.
Thanks in advance,

Eric.
 
Old 06-05-2009, 01:49 PM   #2
noctilucent
Member
 
Registered: Jun 2009
Distribution: slackware
Posts: 123

Rep: Reputation: 34
Hello.

Perhaps it would help if you provided some details about the Fortran90 functionality you need [for those of us who do not know Fortran]. Would macro definitions help you?
 
Old 06-05-2009, 01:52 PM   #3
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Is this what you're looking for?

Code:
int anint(double x)
{
  if(x>0)
    return (int)(x+0.5);
  else return (int)(x-0.5);
}
 
Old 06-05-2009, 08:41 PM   #4
aihaike
Member
 
Registered: Feb 2006
Location: Paris, France
Distribution: Slackware, CentOS
Posts: 270

Original Poster
Rep: Reputation: 20
Thanks guys,

In fact the definition is the following:

Quote:
aint(x) integer portion of |x|. Sign same as sign of x.
anint(x) Nearest integer of x.
We have

Code:
 if x>0 anint(x) = aint(x+.5)
 if x<0 anint(x) = aint(x-.5)
So the problem is similar to simulate aint(x) in C in fact.

Note: anint() and aint() get and return real number.
They are different than floor (greater integer <= x) and ceil (least >= x) which also exist in Fortran.

That's why I wanted to call Fortran90 from C.
It's not obvious for me.

Eric.
 
Old 06-05-2009, 08:44 PM   #5
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
That's exactly the definition I used for my function...
The only difference is the return type. But it's very easy to change if you really need it.
 
Old 06-05-2009, 08:49 PM   #6
aihaike
Member
 
Registered: Feb 2006
Location: Paris, France
Distribution: Slackware, CentOS
Posts: 270

Original Poster
Rep: Reputation: 20
Thumbs up

yes, you're right, I'm sorry !!
It works.
Thanks a lot !!

Eric.
 
Old 06-07-2009, 12:09 PM   #7
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
I have not tried it, but I would expect your fortran function to be directly callable like any other function if all the modules (fortran and C ) were compiled with the gcc suite. You probably would have to correctly prototype the fortran function in C, and it could be there would be some linker option that would need to be set.

But it should work.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] vectors in fortran90 aihaike Programming 2 04-25-2009 06:53 AM
[SOLVED] How to get Fortran90 compiler nelufarup Linux - Software 17 02-19-2009 03:46 AM
How can i make centos 4.5's system call using vDSO(call *%gs:0x10) instead of int80 tclwp Red Hat 3 08-06-2007 12:07 AM
How can I script an autologin, automatically call kde(or simillar) and call an app aboaventura Slackware 8 02-03-2007 11:00 PM
fortran90 kostis Programming 3 11-06-2006 02:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration