FOR_C

FC FAQs 
FC Examples
FC Extensions
License-Single
License - Group
HOME

Cobalt Blue Logo

FOR_C 
Examples


Argument Translation

Automatically generated C prototypes improve function translations, so appropriate arguments can be translated as pass by value for simpler C code, ANSI C style function definitions are also available.

FORTRAN,
	subroutine reports( n, page )
	integer n, page
	page = n+page
	...

729fader.gif (1726 bytes)

C,
#include "reports.h"
void /*FUNCTION*/ reports(n, page)
long int n, *page;
{
	*page = n + *page;
	...

Character Translations

FORTRAN characters are translated to null terminated C strings to permit access by standard C functions. Where translations to standard C strcpy() or strcmp() are not possible, special functions are called to mimic FORTRAN's fixed length behavior. Optional translations to variable length strings are available.

FORTRAN,
	character str*7, last*5
	str = 'start'
10	if( str .ne. 'end' ) str = last

729fader.gif (1726 bytes)

C,
	char last[6], str[8];
	strcpy( str, "start  " );
L_10:
	if( strcmp(str,"end    ") != 0 )
		f_strncpy( str, last, 7 );

Common Translations

Commons translate to external C structures, declared prior to the function. These translations are optimized to take advantage of C scoping rules, so subsequent common translations in the file are not regenerated. Parameter translations to C macros are optimized similarly. Optional common translations to simple externals are available.

FORTRAN,
	parameter( maxflgs = 3 )
	common /io/ unit, status, dirflag(maxflgs)
	integer unit, status, dirflag

729fader.gif (1726 bytes)

C,
#define MAXFLGS 3
struct t_io {
	long int unit, status, dirflag[MAXFLGS];
	}	io;

Data Translations

Whenever possible, FOR_C generates the simplest and most obvious translations, as evidenced by these DATA statement and initialization translations. DATA statements with individual array elements or implied DO loops generate assigned initializations that are executed one time in C.

FORTRAN,
	integer datum / 33 /
	real flow
	data flow / 10. /

729fader.gif (1726 bytes)

C,
	static long datum = 33;
	static float flow = 10.;

Read and Write Translations

List directed WRITEs become fprintf( ). List directed READs become a special version of fscanf( ) to mimic FORTRAN behavior. Formatted READ and WRITE translate to function replicating FORTRAN, while optional translations to fscanf( ) and fprintf( ) (shown below) are also available.

FORTRAN,
	write( *, * ) 'Enter the index and flowrate for ', 
               idata
	read( 3, * ) i, rdata
	write( (*,'(1X,"Enter the pressure for ",I3)') 
               idata

729fader.gif (1726 bytes)

C,
	fprintf( stdout, "Enter the index and flowrate for 
               %ld \n", idata );
	fscanld( UFP(3), "%ld %f ", &i, &rdata );
	fprintf( stdout, " Enter the pressure for %3ld\n", 
               idata );