24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix A. Sample <strong>Fortran</strong> Programs<br />

The following programs are provided as coding examples <strong>for</strong> <strong>XL</strong> <strong>Fortran</strong>. A<br />

number of these samples illustrate various aspects of SMP programming that may<br />

be new to many users. If you are new to SMP programming, you should examine<br />

these samples to gain a better understanding of the SMP coding style. Every<br />

attempt has been made to internally document key areas of the source to assist you<br />

in this ef<strong>for</strong>t.<br />

You can compile and execute the first program to verify that the compiler is<br />

installed correctly and your user ID is set up to execute <strong>Fortran</strong> programs.<br />

Example 1 - <strong>XL</strong> <strong>Fortran</strong> Source File<br />

PROGRAM CALCULATE<br />

!<br />

! Program to calculate the sum of up to n values of x**3<br />

! where negative values are ignored.<br />

!<br />

IMPLICIT NONE<br />

INTEGER I,N<br />

REAL SUM,X,Y<br />

READ(*,*) N<br />

SUM=0<br />

DO I=1,N<br />

READ(*,*) X<br />

IF (X.GE.0) THEN<br />

Y=X**3<br />

SUM=SUM+Y<br />

END IF<br />

END DO<br />

WRITE(*,*) ’This is the sum of the positive cubes:’,SUM<br />

END<br />

Execution Results<br />

Here is what happens when you run the program:<br />

$ a.out<br />

5<br />

37<br />

22<br />

-4<br />

19<br />

6<br />

This is the sum of the positive cubes: 68376.00000<br />

© Copyright <strong>IBM</strong> Corp. 1990, 2004 405

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!