Hello All,

I am trying from a Fortran program, to call a subroutine that I wrote in C...I named the C code file as filename.c and the subroutine is: void filename()

Now in a fortran program, I am calling this subroutine as: Call filename()

I am getting the following error:

fortcom: Error: subrts_Hamact_Lanczos.f, line 1267: This scalar name is invalid in this context. [FILENAME]
call filename()
-----------^
compilation aborted for subrts_Hamact_Lanczos.f (code 1)
make: *** [subrts_Hamact_Lanczos.o] Error 1


Can anyone guide me on this? How can I call an external C subroutine from fortran ?

Thanks..

Did you try to use a different name? Is filename a reserved word in FORTRAN (and is FORTRAN case-insensitive) ?

Also, did you make the C function the correct calling convention for FORTRAN? Here are the available options.

Strictly speaking, it's off topic message about Fortran language implementation, not about C language.
It would appear you have Intel Fortran (former CVF) compiler. See this Fortran implementation reference manual (you may download it via
http://www-curri.u-strasbg.fr/documentation/calcul/doc/compilateurs/intel_fc_80/fcompindex.htm
), compiler directives for external procedures on C. As far as I know you must declare interface in your Fortran program:

INTERFACE
SUBROUTINE FILENAME
!DEC$ ATTRIBUTES C, ALIAS::"filename"::cfilename
END SUBROUTINE
END INTERFACE

I have no CVF so try as is or (better) consult on fortran forum(s)...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.