CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C C F O R T _ F C N . F C C C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C The following Fortran code is used to illustrate a simple FORTRAN C function and its unit test driver. C C Note: We use the Pre-processor to handle the #defines and C coditional Compilation. C C C Uncomment the following #define if you want DEBUG info. C /* #define DEBUG */ C C Define an output file name C #define OUTFILE 'fout.dat' /* Fortran Data Output File */ #define NPTS 3 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C C UNIT Test driver to test the function fort_fcn C C C C Standalone main program to test routine: 'fort_fcn' C C C C Parameter: C C C C C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC #ifdef UNIT_TEST PROGRAM FUNIT_TEST REAL PARAM1 INTEGER UNIT UNIT = 6 write(6,*)'------------- FORTRAN UNIT TEST ROUTINE -----------' write(6,*)'Unit Testing the Fortran fcn with parameter: ',UNIT write(6,*) '' C C Call the subroutine being tested with a variety of arguments C PARAM1 = FORT_FCN( UNIT) write(6,*)'Fortran function returned: ',PARAM1 write(6,*) '' END #endif C C Here is the only function in this the file C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C C C FUNCTION FORT_FCN C C C C Test function to illustrate FORTRAN code C C C C Parameter: C C C C index - The unit where the output should go C C C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC REAL FUNCTION FORT_FCN( index ) INTEGER index REAL *8 x(NPTS) C/* C * Write some stuff to the ouput unit specified in the calling sequence. C */ x(1) = 666 write(index,*)'-------------' write(index,*)'Entering the Fortran function with parameter: ',index write(index,*) '' C/* C * Here's a swatch of debugging code hidden behind the pre-processor C * directive 'DEBUG'. If this C * directive is set with '#define DEBUG' or set on the compiler command line with C * the flag '-DDEBUG' , then this code will become active. C */ #ifdef DEBUG C/* C * Here is some debugging code...It writes to the standard output ( Device 6 ) C * Note: There's nothing assigned to the array 'x' so this will print junk C * if you turn on DEBUG. C */ 500 CONTINUE write(6,*)'' write(6,*)'Debugging in FORTRAN Function: ' write(6,*)'----------------------' DO 510 loop = 1, NPTS write(6,*) x(i) 510 CONTINUE #endif C C Finally we return a value through the function name C FORT_FCN = 666.0 RETURN END