next up previous contents
Next: Defining new Types Up: 6.2.2 Language Binding Previous: FORTRAN/C Binding

C/FORTRAN Binding

The language binding from C to FORTRAN is useful to make a utility library written in C accessible to a FORTRAN program. Within VISTA this facility is used to access the PIF database[Fas91, Tup92, Fas94b] in the PifApplicationInterface project in FORTRAN. This kind of language binding is much more complex, because of the possibility to create new data types in C. The predefined data conversions are shown in Table 6.7. A main problem is the pointer data type because its size may be larger than a INTEGER type in FORTRAN.

  table3208
Tabelle 6.7: Type conversion C to FORTRAN

In FORTRAN all parameters are passed as usual, no special compiler dependent features have to be used if the C function has input only, call by value,. This conversion is automatically done in the wrapping code. String parameters in FORTRAN have a length parameter and are not terminated by the zero character. In case of an input parameter, a C string with the value of the FORTRAN string is temporary allocated and automatically freed when exiting the function. Output parameters are similar, but only a character array of the FORTRAN string size plus one for the string termination is allocated. The string is then stored on exiting the function in the FORTRAN string parameter. String arrays are handled similarly because the size of each string (all have same length) and the size of the array is known. All parameters declared as indices with the key index in the parameter documentation are automatically converted from FORTRAN to C indices. LOGICAL values are converted in the vBoolean type in both directions. C pointers are always stored as INTEGER and it is assumed that all pointers are allocated in the same four GigaByte memory segment. This is currently true for Digital UNIX but may lead to problems in the future.

For constants and enumerations defined in C and exported to FORTRAN by TAC a FORTRAN include file is automatically generated. An example of this is the binding of the interface layer node enumeration in the project PifApplicationInterface. The enumeration is shown in Figure 6.8.

  figure3262
Abbildung 6.8: C enumeration for FORTRAN binding

With the following TAC rule in the description file of the module
block3271
the binding of the module PaiFortranTAC-Definition is created. The enumeration values with the /*** comments instead of simply /* are bound to FORTRAN if the documentation key fortran-name is used. In this case, since the binding name is ``pal'', a FORTRAN include file ``pal.inc'' is automatically generated with the parameter statements shown in Figure 6.9. The symbolic name PaiFortran-TAC-Objects is bound to the object files created for the functional binding of the module.

  figure3284
Abbildung 6.9: FORTRAN parameter statements for C constants

The type of the constant is always defined in front of the PARAMETER statement to avoid conflict with default IMPLICIT parameter types or specific overrides. This file can be included directly by the FORTRAN compiler or by using the FORTRAN compiler in combination with the Cpp preprocessor to make the file inclusion system independent.


next up previous contents
Next: Defining new Types Up: 6.2.2 Language Binding Previous: FORTRAN/C Binding

IUE WWW server
Fri Jan 3 17:00:13 MET 1997