Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCE 206 1 Syntax Details Fortran is not case sensitive; any use of capitals is for the programmer’s convenience. All programs are “wrapped” with PROGRAM.

Similar presentations


Presentation on theme: "CSCE 206 1 Syntax Details Fortran is not case sensitive; any use of capitals is for the programmer’s convenience. All programs are “wrapped” with PROGRAM."— Presentation transcript:

1 CSCE 206 1 Syntax Details Fortran is not case sensitive; any use of capitals is for the programmer’s convenience. All programs are “wrapped” with PROGRAM program_name END PROGRAM program_name

2 CSCE 206 2 Syntax Details Symbols/Identifiers Must start with an alpha character Must be alphanumeric or underscore characters Must be lessequal 31 characters long

3 CSCE 206 3 Syntax Details Declaration of variables IMPLICIT none should always be used REAL :: list of real variables INTEGER :: list of integer variables LOGICAL :: list of logical variables COMPLEX :: list of complex variables CHARACTER :: list of char variables CHARACTER(nn) :: list of char variables CHARACTER(LEN=nn) :: list of char variables

4 CSCE 206 4 Syntax Details REAL,PARAMETER :: x = value Makes the variable a constant whose value cannot be changed from that originally assigned to it

5 CSCE 206 5 Syntax Details—Arithmetic Expressions Exponentiations first, left to right, with multiple exponentiations done right to left Then mults and divs left to right with equal priority Then adds and subs left to right with equal priority Must include all operators between operands Cannot use multiple + or – signs in sequence DO NOT RELY ON THE RULES PARENTHESISE FOR CLARITY

6 CSCE 206 6 Syntax Details—Arithmetic Expressions Detailed rules exist for arithmetic evaluation Ignore the rules Parenthesise as needed to ensure clarity, and use the builtin functions INT(), REAL(), etc., so that there is no question as to what you intend to be the result of your expression.

7 CSCE 206 7 Syntax Details--Assignments Written var = expression but interpreted var  expression Continuation to line n+1 indicated with & at the end of line n Up to 132 characters per line, up to 39 continuation lines permitted for a single statement

8 CSCE 206 8 Input and Output PRINT *, list of variables WRITE(6,*) list of variables WRITE(6,nn) list of variables nnFORMAT(format statement here) The first two are “free format” and the last pair is a specifically formatted output statement By default, “unit 5” is stdin for reading and “unit 6” is stdout for writing READ *, list of variables READ(6,*) list of variables

9 CSCE 206 9 Input and Output from Files OPEN(UNIT=n,FILE=“filename”,STATUS=“OLD”) READ(n,*) list of variables CLOSE(n) will allow reading from an external file filename Similarly, for writing, we would use OPEN(UNIT=n,FILE=“filename”,STATUS=“NEW”) WRITE(n,*) list of variables CLOSE(n) To open/create a file filename and write to it Format statements can also be used

10 CSCE 206 10 Logical Expressions.EQ..NE..LT..GT..LE..GE..AND..OR..NOT..TRUE..FALSE. Rules of Boolean logic apply Precedence rules apply, but can be ignored if you remember to parenthesise properly

11 CSCE 206 11 If-Then-Else IF(logical expression) THEN sequence of statements END IF label: IF(logical expression) THEN sequence of statements END IF label The labelling can be used on all IF statement structures

12 CSCE 206 12 If-Then-Else IF(logical expression) THEN sequence of statements ELSE sequence of statements END IF

13 CSCE 206 13 If-Then-Else IF(logical expression) THEN sequence of statements ELSE IF (logical expression) THEN sequence of statements. ELSE sequence of statements END IF

14 CSCE 206 14 If-Then-Else SELECT CASE (selector variable) CASE(values) sequence of statements CASE(values) sequence of statements. CASE DEFAULT sequence of statements END SELECT

15 CSCE 206 15 The End


Download ppt "CSCE 206 1 Syntax Details Fortran is not case sensitive; any use of capitals is for the programmer’s convenience. All programs are “wrapped” with PROGRAM."

Similar presentations


Ads by Google