[PDF] [PDF] Introduction to Fortran 90 - PRACE materials

Third standard in 1991: Fortran 90 ▻ Adds new Teach you the fundamentals of modern Fortran look at the manual of your favourite compiler, there's a lot to



Previous PDF Next PDF





[PDF] Fortran 90 for Beginners - Universitäts-Sternwarte München

Gehrke, W , Fortran90 Referenz-Handbuch, 1991, Hanser, München, ISBN ' Fortran 90', RRZN (available at the LRZ) less important for beginners



[PDF] Introduction to Fortran 90

release of Fortran 77 The Fortran 90 standard introduces many new facilities for array Overtime rate is a time and a half of the basic rate - Basic rate can not 



[PDF] Fortran 90 Handbook

For an informal and tutorial approach to learning Fortran 90, the book, Programmers A good Fortran programmer's manual also will point out nonstandard 



[PDF] Fortran 90 Tutorial

http://wwwcn cern ch/asdoc/f90 html The author wishes to thank Michel Goossens (CERN/CN) for his helpful and skilful as- sistance in preparing this tutorial 



[PDF] Beginner Fortran 90 tutorial

1 Basic program structure in Fortran A very basic program in Fortran contains: myprogram f90 then compile the code using the command: gfortran 



[PDF] Fortran 90 Basics

A Fortran 90 constant may be an integer, real, logical, complex, and character string ○We will not discuss complex constants ○We will not discuss complex 



[PDF] COURS DE FORTRAN 90 - Institut de Mathématiques de Bordeaux

Le but de ce cours est d'apprendre `a programmer en fortran 90 Il est prévu pour 8 séances 90 par rapport au vieux fortran 77 (modules, interfaces génériques, surcharge d'opérateurs, pointeurs) guide emacs version 140904 pdf 107 



[PDF] Introduction to Fortran 90 - PRACE materials

Third standard in 1991: Fortran 90 ▻ Adds new Teach you the fundamentals of modern Fortran look at the manual of your favourite compiler, there's a lot to



[PDF] Introduction to Fortran 90 for Scientists and Engineers

You will need to find out, from a manual or from someone else, how to enter A token in Fortran 90 is a basic significant sequence of characters, e g labels, 



[PDF] An introduction to programming in Fortran 90 - Monoceros

programming and Fortran 90 to write straightforward programs The course is You will need to be familiar with basic Linux commands (e g those covered in 

[PDF] fortran 90 example

[PDF] fortran 90 function

[PDF] fortran 90 handbook pdf

[PDF] fortran 90 pi

[PDF] fortran 90 programming pdf

[PDF] fortran 90 read

[PDF] fortran 90 standard pdf

[PDF] fortran 90 textbook

[PDF] fortran 90 textbook pdf

[PDF] fortran 90 tutorial pdf

[PDF] fortran 90 write format

[PDF] fortran 90/95 pdf

[PDF] fortran 95 compiler

[PDF] fortran 95 continuation line

[PDF] fortran 95 do loop

Introduction to Fortran 90

F. Salvadore I. Baccarelli G. Amati

CINECA Roma - SCAI Department

Roma, 20-23 January 2014

Part I

A Fortran Survey 1

Program main unit, source formats, comments, declarations and instructions. Fundamental operators, expressions, conditional constructs, loops, functions: arguments passing, intent, interface, intrinsic and external functions. Modules: contains and use. Intrinsic types: integer, real, complex, logical, and parameter. I/O base.

Outline

Introduction

Fortran Basics

More Fortran Basics

Integer Types and Iterating

More on Compiling and Linking

Homeworks

FormulaT ranslator History

I Developed in the 50s among the earliest high level languages (HLL) I Widely and rapidly adopted in the area of numerical, scientific, engineering and technical applications I

First standard in 1966: Fortran 66

I

The first of all programming language standards

I

Second standard in 1978: Fortran 77

I

Third standard in 1991: Fortran 90

I Adds new, modern features such as structured constructs, array syntax and ADT

IExtended and revised in 1997: Fortran 95

IFurther extended with published Technical Reports I

Fourth standard in 2004: Fortran 2003

I Major revision, incorporates TRs, adds many new features (OO!), still not fully supported I

Fifth standard in 2010: Fortran 2008

Fortran General Philosophy

I

Strongly oriented tonumber crunching

I

Efficient language, highly optimized code

I Basic data types and operators mapping "naturally" to CPUs

ITranslated by a compiler to machine language

ILanguage rules allow for aggressive, automatic optimization IFacilities to build new data types from the basic ones IFlexible flow control structures mapping the most common numerical computing use cases I

Scientific computing specialized syntax

I A wealth of math data types and functions available as intrinsics of the language ICompact, readable array syntax to operate on many values as a whole

Technical and Scientific Computing

I

Why Fortran is bad

I Current standard embodies four different language versions,...

I... all of them still alive in legacy codes

INon-numeric computing in Fortran is a real pain

IThere are more C than Fortran programmers

IGUI and DB accesses are best programmed in C

IC99 partly addressed numerical computing needsI

Why Fortran is good

I

Fortran is highly tuned for numerical computation

IFortran is older and more "rigid" than C, compilers optimize better IMuch better than C at managing user defined data types IObject-oriented features are now part of the language IProvides facilities for interoperability with C and other languages

Technical and Scientific Computing

I

Why Fortran is bad

I Current standard embodies four different language versions,...

I... all of them still alive in legacy codes

INon-numeric computing in Fortran is a real pain

IThere are more C than Fortran programmers

IGUI and DB accesses are best programmed in C

IC99 partly addressed numerical computing needsI

Why Fortran is good

I

Fortran is highly tuned for numerical computation

IFortran is older and more "rigid" than C, compilers optimize better IMuch better than C at managing user defined data types IObject-oriented features are now part of the language IProvides facilities for interoperability with C and other languages

Our Aims

I

Teach you the fundamentals of modern FortranI

For both reading (old and new) and writing (new) programsI

Showing common idiomsI

Illustrating and demonstrating many of the extensions introduced in the more recent standardsI

Illustrating best practicesI

Blaming bad onesI

Making you aware of the typical trapsI

You"ll happen to encounter things we didn"t cover, but it will be easy for you to learn more... or to attend a more advanced course!I A course is not a substitute for a reference manual or a good book!I

Neither a substitute for personal practice

Our Aims

I

Teach you the fundamentals of modern FortranI

For both reading (old and new) and writing (new) programsI

Showing common idiomsI

Illustrating and demonstrating many of the extensions introduced in the more recent standardsI

Illustrating best practicesI

Blaming bad onesI

Making you aware of the typical trapsI

You"ll happen to encounter things we didn"t cover, but it will be easy for you to learn more... or to attend a more advanced course!I A course is not a substitute for a reference manual or a good book!I

Neither a substitute for personal practice

Our Aims

I

Teach you the fundamentals of modern FortranI

For both reading (old and new) and writing (new) programsI

Showing common idiomsI

Illustrating and demonstrating many of the extensions introduced in the more recent standardsI

Illustrating best practicesI

Blaming bad onesI

Making you aware of the typical trapsI

You"ll happen to encounter things we didn"t cover, but it will be easy for you to learn more... or to attend a more advanced course!I A course is not a substitute for a reference manual or a good book!I

Neither a substitute for personal practice

Outline

Introduction

Fortran Basics

My First Fortran Program

Compiling and Linking Your First Program

Making Choices

More Types and Choices

Wrapping it Up 1

More Fortran Basics

Integer Types and Iterating

More on Compiling and Linking

Homeworks

Outline

Introduction

Fortran Basics

My First Fortran Program

Compiling and Linking Your First Program

Making Choices

More Types and Choices

Wrapping it Up 1

More Fortran Basics

Integer Types and Iterating

More on Compiling and Linking

Homeworks

My First Scientific Program in Fortran

! roots of a 2nd degree equation with real coefficients program second_degree_eq implicit none real :: delta real :: x1, x2 real :: a, b, c print *,"Solving ax^2+bx+c=0, enter a, b, c:" read ( *,*) a, b, c delta = sqrt(b **2 - 4.0*a*c)! square root of discriminant x1 = -b + delta x2 = -b - delta x1 = x1/(2.0 *a) x2 = x2/(2.0 *a)write( *,*) "Real roots:", x1, x2 end program second_degree_eq

My First Scientific Program in Fortran

! roots of a 2nd degree equation with real coefficients program second_degree_eq implicit none real :: delta real :: x1, x2 real :: a, b, c print *,"Solving ax^2+bx+c=0, enter a, b, c:" read ( *,*) a, b, c delta = sqrt(b **2 - 4.0*a*c)! square root of discriminant x1 = -b + delta x2 = -b - delta x1 = x1/(2.0 *a) x2 = x2/(2.0 *a)write( *,*) "Real roots:", x1, x2 end program second_degree_eq

Comments

I Text following!is ignored up to the end of current lineI

Best practice: do comment your code!I

Variable contentsI

AlgorithmsI

AssumptionsI

TricksI

Best practice: do not over-comment your code!I

Obvious comments obfuscate code and annoy readersI ! square root of discriminantis a bad example

Comments

I Text following!is ignored up to the end of current lineI

Best practice: do comment your code!I

Variable contentsI

AlgorithmsI

AssumptionsI

TricksI

Best practice: do not over-comment your code!I

Obvious comments obfuscate code and annoy readersI ! square root of discriminantis a bad example

Comments

I Text following!is ignored up to the end of current lineI

Best practice: do comment your code!I

Variable contentsI

AlgorithmsI

AssumptionsI

TricksI

Best practice: do not over-comment your code!I

Obvious comments obfuscate code and annoy readersI ! square root of discriminantis a bad example

My First Scientific Program in Fortran

! roots of a 2nd degree equation with real coefficients program second_degree_eq implicit none real :: delta real :: x1, x2 real :: a, b, c print *,"Solving ax^2+bx+c=0, enter a, b, c:" read ( *,*) a, b, c delta = sqrt(b **2 - 4.0*a*c)! square root of discriminant x1 = -b + delta x2 = -b - delta x1 = x1/(2.0 *a) x2 = x2/(2.0 *a)write( *,*) "Real roots:", x1, x2 end program second_degree_eq

Program Units: Main Program

I

Fortran code is organized in program unitsI

Main programI

Procedures (subroutines and functions)I

ModulesI

More on this later...I

The main program (one, and only one!) can"t be dispensed withI

It"s called automatically to execute the programI

An optionalprogram program-namecan appear at the

beginningI Anendstatement must terminate it, optionally followed by programorprogram program-nameI Best practice: always mark unit beginning and ending with its type and nameI

Makes your readers (including you) happier

Program Units: Main Program

I

Fortran code is organized in program unitsI

Main programI

Procedures (subroutines and functions)I

ModulesI

More on this later...I

The main program (one, and only one!) can"t be dispensed withI

It"s called automatically to execute the programI

An optionalprogram program-namecan appear at the

beginningI Anendstatement must terminate it, optionally followed by programorprogram program-nameI Best practice: always mark unit beginning and ending with its type and nameI

Makes your readers (including you) happier

Program Units: Main Program

I

Fortran code is organized in program unitsI

Main programI

Procedures (subroutines and functions)I

ModulesI

More on this later...I

The main program (one, and only one!) can"t be dispensed withI

It"s called automatically to execute the programI

An optionalprogram program-namecan appear at the

beginningI Anendstatement must terminate it, optionally followed by programorprogram program-nameI Best practice: always mark unit beginning and ending with its type and nameI

Makes your readers (including you) happier

My First Scientific Program in Fortran

! roots of a 2nd degree equation with real coefficients program second_degree_eq implicit none real :: delta real :: x1, x2 real :: a, b, c print *,"Solving ax^2+bx+c=0, enter a, b, c:" read ( *,*) a, b, c delta = sqrt(b **2 - 4.0*a*c)! square root of discriminant x1 = -b + delta x2 = -b - delta x1 = x1/(2.0 *a) x2 = x2/(2.0 *a)write( *,*) "Real roots:", x1, x2 end program second_degree_eq

Variables

I real :: x1, x2declares two variablesI Named memory locations where values can be storedI Declared by specifying a data type, an optional attribute list, and a comma-separated list of namesI On most CPUs (notably x86),realmeans thatx1andx2host IEEE single precision (i.e. 32 bits) floating point valuesI

A legalnamemust be used for a variable:I

Permitted characters:a-z,A-Z,0-9,_I

The first one cannot be a digit

(e.g.x1is a valid name,1xis not)I At most 31 characters are permitted (63 in Fortran 2003)I A good advice: do not exceed 31 characters in a nameI

Beware: Fortran is CaSe insenSITIVE!

Variables

I real :: x1, x2declares two variablesI Named memory locations where values can be storedI Declared by specifying a data type, an optional attribute list, and a comma-separated list of namesI On most CPUs (notably x86),realmeans thatx1andx2host IEEE single precision (i.e. 32 bits) floating point valuesI

A legalnamemust be used for a variable:I

Permitted characters:a-z,A-Z,0-9,_I

The first one cannot be a digit

(e.g.x1is a valid name,1xis not)I At most 31 characters are permitted (63 in Fortran 2003)I A good advice: do not exceed 31 characters in a nameI

Beware: Fortran is CaSe insenSITIVE!

Variables

I real :: x1, x2declares two variablesI Named memory locations where values can be storedI Declared by specifying a data type, an optional attribute list, and a comma-separated list of namesI On most CPUs (notably x86),realmeans thatx1andx2host IEEE single precision (i.e. 32 bits) floating point valuesI

A legalnamemust be used for a variable:I

Permitted characters:a-z,A-Z,0-9,_I

The first one cannot be a digit

(e.g.x1is a valid name,1xis not)I At most 31 characters are permitted (63 in Fortran 2003)I A good advice: do not exceed 31 characters in a nameI

Beware: Fortran is CaSe insenSITIVE!

Implicit Declarations

I By default, Fortran assumes that variables not appearing in any declaration statement are implicitly declared as follows:I Variables whose name starts withA-HandO-Zare realsI Variables whose name starts withI,J,K,L,M,Nare integersI Best practice: it is strongly recommended to turn off implicit declarations withimplicit none, at the beginning of each program unitI Improves readability and clarity: each variable has its type declaredI Mistyped names can be caught by the compiler as undeclared variables

Implicit Declarations

I By default, Fortran assumes that variables not appearing in any declaration statement are implicitly declared as follows:I Variables whose name starts withA-HandO-Zare realsI Variables whose name starts withI,J,K,L,M,Nare integersI Best practice: it is strongly recommended to turn off implicit declarations withimplicit none, at the beginning of each program unitI Improves readability and clarity: each variable has its type declaredI Mistyped names can be caught by the compiler as undeclared variables

Implicit Declarations

I By default, Fortran assumes that variables not appearing in any declaration statement are implicitly declared as follows:I Variables whose name starts withA-HandO-Zare realsI Variables whose name starts withI,J,K,L,M,Nare integersI Best practice: it is strongly recommended to turn off implicit declarations withimplicit none, at the beginning of each program unitI Improves readability and clarity: each variable has its type declaredI Mistyped names can be caught by the compiler as undeclared variables

Implicit Declarations

I By default, Fortran assumes that variables not appearing in any declaration statement are implicitly declared as follows:I Variables whose name starts withA-HandO-Zare realsI Variables whose name starts withI,J,K,L,M,Nare integersI Best practice: it is strongly recommended to turn off implicit declarations withimplicit none, at the beginning of each program unitI Improves readability and clarity: each variable has its type declaredI Mistyped names can be caught by the compiler as undeclared variables

My First Scientific Program in Fortran

! roots of a 2nd degree equation with real coefficients program second_degree_eq implicit none real :: delta real :: x1, x2 real :: a, b, c print *,"Solving ax^2+bx+c=0, enter a, b, c:" read ( *,*) a, b, c delta = sqrt(b **2 - 4.0*a*c)! square root of discriminant x1 = -b + delta x2 = -b - delta x1 = x1/(2.0 *a) x2 = x2/(2.0 *a)write( *,*) "Real roots:", x1, x2 end program second_degree_eq

A Few First Words on I/O

I The bare minimum: textual input output from/to the user terminalI read(*,*)andread*,readI write(*,*)andprint*,writeI These very common idioms perform formatted, list directed I/OI Formattedmeans that translation from/to user readable text to/from internal binary formats is performedI List directedmeans that external and internal formats are chosen according to the type of each variable or value on the listI read(*,*)andread*,are equivalentI write(*,*)andprint*,are equivalentI

Enough for now, disregard details

A Few First Words on I/O

quotesdbs_dbs21.pdfusesText_27