I am a Theoretical Physics research student, working in Cosmology. In course of my research I have use to rather huge library of Fortran codes and I used C for my programming needs.
I have been able to link the two programs in numerous test files and they work brilliantly. But for them I have been using the object files to link them all. But when I tried to run the real deal through C, include reference to the Fortran header files. They seem to integrate and call each other fine but the format of the Fortran header file is incomptible with the C compiler, so when it jumps to the header file it start throwing errors that it cannot understand the syntax.
For example, the Fortran header file defines double variables with real*8 so when C reads them it throws errors. The same happens with comments in the file as well.
So, I want to ask is there any way through which I can go about this problem? i.e. make the fortran format header file readible through C.
I looked over the internet and found confusing answers, and I do not know which one to follow. Any help in this matter will be appreciated :)
Fortran usually passes its variables by reference (passes pointers). That means that you MUST give addresses in your calling C-program.
Function results, may be passed by value, for example, the following code calls a FORTRAN function called "gamma":
Make sure that the size of the variable in the calling program is identical to the size in the Fortran routine:
The Fortran function must be declared at the beginning of the C calling function:
Note we have to pass all variables to Fortran as pointers. Although the function name is not case sensitive in Fortran, it gains an underscore in the C declaration and when it is called:
The Fortran function receives the variables as follows:
The precise size of these variables depends on your system's architecture (32 bit verses 64 bit), so you need to confirm the correspondence between ints, floats and doubles in C and Fortran on your system.