Examples

PreviousUpNext
Up: Contents Next: Installing bfort Previous: Command Line Arguments

This section shows the code generated by bfort with various command-line switches.

The command bfort add.c produces

/* add.c */ 
/* Fortran interface file for sun4 */ 
 int  add_( a1, a2) 
int*a1,*a2; 
{ 
return Add(*a1,*a2); 
} 
The command bfort -anyname add.c produces
/* add.c */ 
/* Fortran interface file */ 
#ifdef FORTRANCAPS 
#define add_ ADD 
#elif !defined(FORTRANUNDERSCORE) && !defined(FORTRANDOUBLEUNDERSCORE) 
#define add_ add 
#endif 
 int  add_( a1, a2) 
int*a1,*a2; 
{ 
return Add(*a1,*a2); 
} 
The command bfort -ansiheader foo.c produces
/* add.c */ 
extern int  Add ANSI_ARGS((int, int )); 
For a more sophisticated example, here is the result of bfort -ferr -mpi -mnative -mapptr -ptrprefix MPIR_ -anyname -I pubinc send.c for the MPI routine MPI_Send (implemented in the file send.c, from the MPICH implementation). The file pubinc contains the single line #include "mpiimpl.h".


/* send.c */ 
/* Fortran interface file */ 
#include "mpiimpl.h" 
 
#ifdef POINTER_64_BITS 
extern void *MPIR_ToPointer(); 
extern int MPIR_FromPointer(); 
extern void MPIR_RmPointer(); 
#else 
#define MPIR_ToPointer(a) (a) 
#define MPIR_FromPointer(a) (int)(a) 
#define MPIR_RmPointer(a) 
#endif 
 
#ifdef MPI_BUILD_PROFILING 
#ifdef FORTRANCAPS 
#define mpi_send_ PMPI_SEND 
#elif defined(FORTRANDOUBLEUNDERSCORE) 
#define mpi_send_ pmpi_send__ 
#elif !defined(FORTRANUNDERSCORE) 
#define mpi_send_ pmpi_send 
#else 
#define mpi_send_ pmpi_send_ 
#endif 
#else 
#ifdef FORTRANCAPS 
#define mpi_send_ MPI_SEND 
#elif defined(FORTRANDOUBLEUNDERSCORE) 
#define mpi_send_ mpi_send__ 
#elif !defined(FORTRANUNDERSCORE) 
#define mpi_send_ mpi_send 
#endif 
#endif 
 
 void mpi_send_( buf, count, datatype, dest, tag, comm, __ierr ) 
void             *buf; 
int*count,*dest,*tag; 
MPI_Datatype     datatype; 
MPI_Comm         comm; 
int *__ierr; 
{ 
*__ierr = MPI_Send(buf,*count, 
        (MPI_Datatype)MPIR_ToPointer( *(int*)(datatype) ),*dest,*tag, 
        (MPI_Comm)MPIR_ToPointer( *(int*)(comm) )); 
} 
Note that the -mapptr option has caused the generated code to call routines to convert the integers in Fortran to valid pointers. The option -ptrprefix changed the names of the routines to be MPIR_ToPointer and MPIR_FromPointer. The option -mpi informed bfort that MPI_Datatype and MPI_Comm were pointers rather than nonpointers. The option -ferr converted a routine MPI_Send that returns an error code to a Fortran subroutine that returns the error code in the last argument.


PreviousUpNext
Up: Contents Next: Installing bfort Previous: Command Line Arguments