set2 - The Fortran Basics Handout Two October 2, 2011 A...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The Fortran Basics Handout Two October 2, 2011 A Fortran program consists of a sequential list of Fortran ‘ statements ’ and ‘ constructs ’. A state- ment can be seen a continuous line of code, like ‘ b=a*a*a ’ or ‘ INTEGER :: a,b ’. A construct is a group of statements that together form a specific task and are defined by the Fortran language. You will learn some Fortran constructs later in these notes. When defining the syntax of a Fortran statement or construct, in these notes, the following will be used • Anything inside curly brackets, { } , will be a Fortran keyword. • Anything inside angular brackets, <> , is the choice of the programmer • Anything inside square brackets, [ ], will be optional to the statement. 1 Program Structure When you are writing a Fortran program you must be careful to adhere to the required structure of a Fortran program. Each program ‘unit’ must have this structure. A program unit can be the main program, a subroutine, function or a module. So far you have only been introduced to the main program unit, so for now do not worry about the others. The required structure is explained with the help of your ‘power3.f90’ code, 1. PROGRAM power3 2. !*** program to calculate 3rd power of 5 3. 4. IMPLICIT NONE 5. 6. INTEGER :: a, b 7. 8. a = 5 9. b = a*a*a 10. 11. PRINT*, a,b 12. 13. END PROGRAM power3 1. The program unit header statement must come first, for example PROGRAM < program name > Line 1 in the ‘power3’ code. 2. Next follows the ‘specification region’, in this region you put any external references, data type declarations, interface blocks and the ‘ IMPLICIT NONE ’ statement. Don’t worry about the items listed in the above sentence that you have not met yet they will be explained later when required. Lines 4 → 6 in the ‘power3’ code. 1 3. Next follows the execution statements that follow the logical order of whatever you are trying to do. Lines 8 → 11 in the ‘power3’ code. 4. Finally the ‘ END ’ statement to tell the compiler that there are no more lines to compile. For example END PROGRAM < program name > Line 13 in the ‘power3’ code. 2 Intrinsic Data Types and ‘ IMPLICIT NONE ’ You have already seen the keyword INTEGER used in the ‘power3’ code you wrote earlier. It was used to declare variables of integer type. Fortran has five ‘intrinsic’ data types. The word intrinsic means that they are defined within the Fortran language standard. The five data types are; ‘ INTEGER: ’ For exact whole numbers. ‘ REAL: ’ For real numbers. ‘ COMPLEX: ’ For complex numbers of the form ‘ x+ i y ’. ‘ CHARACTER: ’ For characters and strings of characters....
View Full Document

This note was uploaded on 02/13/2012 for the course MATH 5806 taught by Professor Brooks during the Fall '10 term at Minnesota.

Page1 / 12

set2 - The Fortran Basics Handout Two October 2, 2011 A...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online