Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use "cfort.h'? 1

Status
Not open for further replies.

rock31

Programmer
Jul 18, 2004
38
US
Hello,
I have to call several subroutines written in C language to my Fortran main program, and also there are more subroutines archived in a dynamic library compiled from subroutines and functions in C. Someone told me that this is dealt with by “cfort.h”.
I just don’t know how to use this “cfort.h”, and where to start. Would anyone please give me some information?
Thanks a lot
 
What happens if you try to call the C functions from fortran?

Many fortran compilers add an underscore to function names whereas C compilers do not. One way to get around this problem is to recompile the C routines with defines like

#define func1 func1_

Perhaps this is what should be in cfort.h


CaKiwi
 
hello, CaKiwi,
Thank you very much for your reply.
What you mentioned about naming rules for subroutines is one difference between Fortran and C. Except the naming issue, there are also other issues need to take care of. Such as array, Fortran arranges an array in a form as (A(1,1), A(1,2), … A(1,N) A(2,1), … A(2,N) ….), while C arranges an array in the reverse order as (A(1,1), A(2, 1), A(3, 1) … A(1,2), ….). Fortran is not case sensitive, and C is case sensitive. So, direct calling the program in C to Fortran may bring a lot of errors.
I am sure if I understand your points correctly.
Thanks a lot
 
Sorry, the last sentence is not what I wana say.
It should be
"I am not sure if I understand your points correctly"
 
Possible solutions to the multi-dimensional array problem are either don't use them or treat them a single dimsensional arrays in C and index them manually the fortran way. Declaring all your function names lower case should solve the case problem.

Are these just theoretical problems or ones you have actually encountered? I suggest you try a test fortran program calling you C functions and see what problems you find.

CaKiwi
 
Hello, Cakiwi,
Thank you very much for your reply. Honestly, all I said here as you say are just theoretically problems. But I am sure these are problems I have to deal with. Your suggestion is definitely good. I do need to do the test as you suggested.
Thanks a lot
Rock31
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top