---------------------------------------------------------------------- Ten dokument jest lekko zmodyfikowana (fragmenty dotyczace SGI) kopia: http://wwwcn.cern.ch/asdcgi/listcernlibfaqs.pl/10 warto tez spojrzec tu marcin ----------------------------------------------------------------------
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
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 cfilename.c fort77 +ppu -c ffilename.f fort77 +ppu cfilename.o ffilename.o -L /cern/new/lib -lpacklib l .... -o outfilename
xlc -c -Dextname -I/cern/pro/include cfilename.c xlf -qextname -c ffilename.f xlf -qextname cfilename.o ffilename.o -L /cern/new/lib -lpacklib l .... -o outfilename
cc /INCLUDE=CERN_ROOT:[INCLUDE] cfilename.c fortran ffilename.FOR link/exe=outfilename cfilename,ffilename, ...
cc -c -Dextname -I/cern/pro/include cfilename.c f77 -c ffilename.f f77 cfilename.o ffilename.o -L /cern/pro/lib -lpacklib l .... -o outfilename
They have been compiled, linked and run with the following commands (using the first code example)
cc -c -Dextname -Ae -I/cern/pro/include chbook-example.c fort77 +ppu chbook-example.o `cernlib packlib,mathlib` -o chbook-example chbook-example
xlc -c -Dextname -I/cern/pro/include chbook-example.c xlf -qextname 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
cc -c -Dextname -I/cern/pro/include chbook-example.c f77 chbook-example.o `cernlib packlib,mathlib` -o chbook-example chbook-example