Program: f2cvv Purpose: This program generates C code for the F2C/C2F interface routines. Category: SYSTEM File: f2cvv.c Author: K.G. Begeman Description: This program creates c source code for the intermediate routines necessary to call C routines from Fortran and Fortran routines from C. The name of the Fortran callable routine is as stated in the document, the C callable routine has the same name with postfix '_c'. All arguments are passed by reference, except fortran character arguments. For Fortran character types a special C type has been defined, fchar, which is a struct which holds the address of the Fortran character string and its length. For the Fortran types integer, integer(kind=8), logical and complex C types fint, fint8, bool and complex are defined. The correspondence of fortran types with C types is as follows: FORTRAN C integer <-> * fint integer*8 <-> * fint8 logical <-> * bool real <-> * float double precision <-> * double complex <-> * complex character <-> fchar Except for fortran character functions, the number and type of arguments correspond as stated above. Fortran character functions correspond with C procedures of type void with an extra fchar as first argument, which corresponds with the character returned by the fortran function. A fchar struct contains a character pointer 'a' to the Fortran character string and a fint 'l' which holds the length of the character string. A complex struct contains a float 'r' which holds the real part and a float 'i' which holds the imaginary part. For the interpretation of fortran logicals, two macros are defined, tobool(l) and toflog(l); tobool converts a Fortran logical to a C true or false value, toflog converts a C true or false value to a Fortran logical. To set a bool to a Fortran .TRUE. or .FALSE., the macros TRUE and FALSE can be used. These four macros are defined in the definition file generated by f2cvv. Operation: The program reads the routine definition from the source file. The routine definition is placed in the comment area of the source code and should be preceded by '@' in the first or second column on each new line. The syntax of the routine definition is as follows: procedure_name ( [type [, type [, type [ ... ] ] ] ] ) where: procedure_name = { subroutine }, { type function } type = { character }, { integer }, {integer*8}, { logical }, { real }, { double precision }, { complex } Note that integer(kind=8) is specified here as integer*8. Use: F2CVV . From the extension of the input source F2CVV deduces whether an F2C or an C2F interface should be created. Recognized extensions are: c C source f FORTRAN source for FORTRAN source shl SHELTRAN source The resulting interface is in _ftoc.c or in _ctof.c depending whether the input source is in C or Fortran/Sheltran. For each in the an .h file is created by F2CVV which holds the template of the procedure which can be used by C programmers. When a file with extension h is entered on the command line, F2CVV will generate an include file with that name which holds the definitions (typedefs) for the different c types and defines the macros described above. C programmers have to include this file into their source in order to define the different C types. Example: FORTRAN source sub.f: subroutine sub( a, b, c ) character*(*) a integer b real c C Next follows the definition for F2Cvv: C@ subroutine sub( character, integer, real ) ..... end character*(*) function fie( a, b ) logical a integer b C Next follows the definition for F2Cvv: C@ character function fie( logical, integer ) ..... end F2CVV creates: sub.h, fie.h and sub_ctof.c sub.h: extern void sub_c( fchar, fint *, float *); fie.h: extern void fie_c( fchar, bool *, fint *); Notes: F2CVV works only for ANSI C compilers. Interfaces are implemented for ALLIANT, ALPHA OSF1, CONVEX, HP, IBM AIX, DECSTATIONS, SILICON GRAPHICS, SONY, SUN and VMS. Also an interface to the public domain Fortran to C compiler is implemented. You should compile this programme with -D__F2C__. For use with the gnu fortran 77 compiler compile with -D__g77__. For ALLIANT, ALPHA OSF1, IBM AIX, DECSTATIONS and SILICON GRAPHICS there are some auxiliary routines necessary which can be found in f2cvv_aux.src. The source code of these routines is extracted with xfile. The name of the fortran routines as seen by a c program is usually the default name convention of the fortran compiler. Some fortran compilers allow you to add an underscore to this name. If you want to compile your fortran sources with this compiler option, compile f2cvv with -DALWAYS_UNDERSCORE on the command line. There are also some test programs in the f2cvv source file. They test the F2C and C2F interface. To test the interface program do the following: xfile -DTESTBED f2cvv.c This command will extract subc.c subf.f mainc.c mainf.f and Makefile. Currently this program is only maintained for Linux and Mac OS X, for g77 (deprecated) and gfortran. Updates: May 16, 1989 : KGB, Creation date. Apr 9, 1990 : KGB, Adapted for GNU (gcc) compiler. May 23, 1990 : KGB, Implemented for HP. Feb 5, 1993 : KGB, Implemented for gcc on HP and f2c. Sep 1, 1996 : KGB, Implemented for g77. May 4, 2007 : JPT, Implemented for Apple Mac. Mar 11, 2011 : JPT, Support for 64 bit integers.