C ================================================================================ C = = C = F O R T _ M A I N . F = C = = C ================================================================================ C C Simple FORTRAN Program driver program that uses the C Preprocessor C C C Note: To compile this program either use the makefile provided and type C C make f_simple C C or simply enter the command: C C f77 -e fort_main.F C C at the UNIX prompt. C C C ------------------------------------ C C NOTE: This program uses Pre-processor directives to define symbolic constants C and control conditional compilation. Use the -F option on f77 if you C want to view the pre-processed output that the compiler will see. C C C Here we define some symbolic constants. C Using the preprocessor, we've localized all the magic numbers in the program C so they're all defined at this point. Now if we want to change them, we only have C to make a single change. C #define PI 3.14159265358979324 /* Universal Constant */ #define OUTFILE 'out.dat' /* Output filename */ #define NPTS 30 /* # Of data points to print */ #define ILLUSTRATE_FUNCTION_CALL #define ILLUSTRATE_SUBROUTINE_CALL C C ================================================================================ C = F _ S I M P L E = C ================================================================================ C Here is a simple main program. Use this as a skeleton for getting started with C your own FORTRAN programs. C PROGRAM F_SIMPLE REAL PARAM1 INTEGER OUT_UNIT, I C /* C * First we open a file and associate the filename given in the OUTFILE C * macro with the unit # 7. This gives you a basic output file to store C * your data. Use your FORTRAN reference to read about the 'STATUS' field C * and the implications of using the strings 'OLD' and 'NEW. C */ OUT_UNIT = 7 open(UNIT=OUT_UNIT, FILE=OUTFILE, STATUS='OLD') C /* C * Next we write out some mindless text so you know the driver is running... C */ write(6,*) '' write(6,*) ' --> Hello World, This is the FORTRAN program driver...' write(6,*) '' C C Here's an example illustrating a call to a subroutine. This section of C code is enabled by setting the macro 'ILLUSTRATE_SUBROUTINE_CALL' with C either a #define or using the '-D' flag on the command line for the C compiler. C #ifdef ILLUSTRATE_SUBROUTINE_CALL PARAM1 = PI write(6,*)'Calling a fortran Subroutine' call fort_sub(PARAM1, OUT_UNIT) write(6,*)'Fortran Subroutine returned' write(6,*) '' #else write(6,*)'' write(6,*)'Simple Subroutine call not compiled.' write(6,*)'Define the macro: ILLUSTRATE_SUBROUTINE_CALL to compile in the call' write(6,*)'' #endif C C Here's and example illustrating the call to a function. THis section C of code is enabled by setting the macro 'ILLUSTRATE_FUNCTION_CALL' with C either a #define or using the -D flag to f77. C C #ifdef ILLUSTRATE_FUNCTION_CALL write(6,*)'Calling a FORTRAN function' PARAM1 = fort_fcn( 6 ) write(6,*)'Fortran Function returned: ',PARAM1 write(6,*) '' #else write(6,*)'' write(6,*)'Simple Function call not compiled.' write(6,*)'Define the macro: ILLUSTRATE_FUNCTION_CALL to compile in the call' write(6,*)'' #endif C C Here's an example of some debugging code hidden behind the preprocessor C symbol DEBUG C #ifdef DEBUG write(6,*) '' write(6,*) ' This is a section of DEBUG Code... Print whatever you like here.' write(6,*) '' #endif C /* C * Here's a loop to generate data from the Sine function C */ C C C C Here's the end of the program C END