ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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,
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.