Furthermore, a tool exists (cfortran) to use headerfiles in the C code with the definition of the FORTRAN routines. Then the call of the FORTRAN routine is very easy and all parameters can be handled without special tricks. Especially the calling sequence is independent from the compiler and operating system! Additionally, a tool exists to create such header files (f2h), which is available in the standard CERN program directory. The complete documentation is in cfortran.doc.
/cern/pro/include/cfortran
or are available using anonymous ftp from
asisftp.cern.ch:/cernlib/share/pro/include
To call a (FORTRAN) CERN library routine from C, you have to do the following steps:
#include "cfortran.h" #include "hbook.h" /* if you use hbook routines e.g. */
main(){ real xmin,xmax; integer ncha; HLIMIT(1000); . . HBOOK1(100,"test spectrum",ncha,xmin,xmax,0); . . }
cc -c -Dextname -Ae -I/cern/pro/include/cfortran cfilename.c fort77 +ppu -c ffilename.f fort77 +ppu cfilename.o ffilename.o `cernlib packlib ...` ... -o outfilename
gcc -c -Df2cFortran -I/cern/pro/include/cfortran cfilename.c g77 -c ffilename.f g77 cfilename.o ffilename.o `cernlib packlib ...` ... -o outfilename
xlc -c -Dextname -I/cern/pro/include/cfortran cfilename.c xlf -qextname -c ffilename.f xlf -qextname cfilename.o ffilename.o `cernlib packlib ...` ... -o outfilename
cc -c -Dextname -I/cern/pro/include/cfortran cfilename.c f77 -c ffilename.f f77 -nofor_main cfilename.o ffilename.o `cernlib packlib ...` ... -o outfilename
cc -c -I/cern/pro/include/cfortran cfilename.c f77 -c ffilename.f f77 cfilename.o ffilename.o `cernlib packlib ...` ... -o outfilename
cc /INCLUDE=CERN_ROOT:[INCLUDE] cfilename.c fortran ffilename.FOR link/exe=outfilename cfilename,ffilename, ...
They have been compiled, linked and run with the following commands (using the first code example)
cc -c -Dextname -Ae -I/cern/pro/include/cfortran chbook-example.c fort77 +ppu chbook-example.o `cernlib packlib,mathlib` -o chbook-example ./chbook-example
gcc -c -Df2cFortran -I/cern/pro/include/cfortran chbook-example.c g77 chbook-example.o `cernlib packlib,mathlib` -o chbook-example ./chbook-example
xlc -c -Dextname -I/cern/pro/include/cfortran chbook-example.c xlf -qextname chbook-example.o `cernlib packlib,mathlib` -o chbook-example ./chbook-example
cc -c -Dextname -I/cern/pro/include/cfortran chbook-example.c f77 -nofor_main chbook-example.o `cernlib packlib,mathlib` -o chbook-example ./chbook-example
cc /INCLUDE=CERN_ROOT:[INC] chbook-example.c link/exe=CHBOOK-EXAMPLE CHBOOK-EXAMPLE.obj,cern_root:[lib]packlib/lib,mathlib/lib,kernlib/lib RUN CHBOOK-EXAMPLE
If you prefer to use the gnu C compiler gcc, you could link using gcc and adding the FORTRAN specific libraries after the CERN libraries. The names of these libraries are different on all systems:
-lcl -lisamstub Example: gcc chbook-example.o `cernlib packlib,mathlib` -lcl -lisamstub -o chbook-example