660 likes | 1.25k Views
FORTRAN 90. An introduction to programming in Fortran 90 http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html. FORmula TRANslation. Program structure. A FORTRAN 90 program has 4 main elements. 1. Program name. Program structure. Comments. Continuation Lines.
E N D
FORTRAN 90 An introduction to programming in Fortran 90 http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html FORmula TRANslation
Program structure A FORTRAN 90 program has 4 main elements.
1. Program name Program structure
2. Specification part 1. Constants have fix value 2. Variables may change value during execution of program Data types: 1. INTEGER 2. REAL 3. DOUBLE PRECISION 4. CHARACTER 4. LOGICAL 5. COMPLEX Program structure
Data types: Constants, Variables • INTEGER • REAl • DOUBLE PRECISION • CHARACTER • LOGICAL • COMPLEX
Constants PARAMETER Program structure
Variables IMPLICIT NONE Program structure
Variables IMPLICIT NONE Program structure
Converting between types of variable • dbl transform a variable to double precision • Int truncate a real number to an integer • nint round a real number to the nearest integer x = i/j x = real(i) / real (j)
Initialization Variable Initialization
Assignment Variable Initialization
Arithmetic operator Variable Initialization
Input - READ READ (*,*) list Variable Initialization
Input - READ Variable Initialization
2. Execution part Program structure
WRITE WRITE (*,*) list
Example WRITE
Simple Example PROGRAM test IMPLICIT NONE REAL :: num1, num2, sum WRITE (*,*) "please neter two real number" READ(*,*) num1, num2 sum = num1 + num2 WRITE (*,*) "sum of two number is", sum END PROGRAM test